Closed Bug 717546 Opened 12 years ago Closed 11 years ago

Implement mspace with negative width


(Core :: MathML, defect, P3)






(Reporter: fredw, Assigned: fredw)


(Depends on 1 open bug, Blocks 1 open bug)


(Keywords: dev-doc-complete, helpwanted)


(3 files, 4 obsolete files)

Follow-up of bug 716349.
Blocks: 716349
No longer depends on: 716349
No longer blocks: 716349
Depends on: 716349
A patch partially implementing negative spaces. It only enables negative spacing via mspace (not mpadded or mo) and within mrow-like elements (not math or mtd). A negative space moving a child to a negative X coordinate (I don't think that happens in practice) is treated as if the child was moved to 0.

I don't plan to do something more general at the moment. My goal is just to support MathJax's use cases where negative spaces are used to make a child closer to its previous sibling. MathJax always adds an <mrow> so no need to consider the cases of math & mtd, which seem more involved.
Attachment #686709 - Flags: review?(karlt)
Attached file testcase
Attached patch Reftests (obsolete) — Splinter Review
Attachment #686725 - Flags: review?(karlt)
Attachment #686711 - Attachment is patch: false
Attachment #686711 - Attachment mime type: text/plain → text/html
If later we want to implement negative width for <mspace/> children of <math> or <mtd>, we should probably move the work of nsMathMLContainerFrame::FixInterFrameSpacing to Place before. Making this dependent on bug 433064.
Depends on: 433064
Mass change: setting priority to 3 for bugs preventing Gecko's Native MathML to be enabled by default in MathJax.
Keywords: helpwanted
Priority: -- → P3
Comment on attachment 686709 [details] [diff] [review]
Partial support for negative mspace@width

>     mX += space * GetThinSpace(font);
>     return *this;
>   }
>   nsIFrame* Frame() const { return mChildFrame; }
>-  nscoord X() const { return mX; }
>+  nscoord X() const { return NS_MAX(0, mX); }

NS_MAX needs to be changed to std::max here.

>   const nsHTMLReflowMetrics& ReflowMetrics() const { return mSize; }
>   nscoord Ascent() const { return mSize.ascent; }
>   nscoord Descent() const { return mSize.height - mSize.ascent; }
>   const nsBoundingMetrics& BoundingMetrics() const {
>     return mSize.mBoundingMetrics;
>   }
> private:
>diff --git a/layout/mathml/nsMathMLmspaceFrame.cpp b/layout/mathml/nsMathMLmspaceFrame.cpp
>--- a/layout/mathml/nsMathMLmspaceFrame.cpp
>+++ b/layout/mathml/nsMathMLmspaceFrame.cpp
>@@ -55,16 +55,17 @@ nsMathMLmspaceFrame::ProcessAttributes(n
>   mWidth = 0;
>   GetAttribute(mContent, mPresentationData.mstyle, nsGkAtoms::width,
>                value);
>   if (!value.IsEmpty()) {
>     ParseNumericValue(value, &mWidth,
>                       nsMathMLElement::PARSE_ALLOW_NEGATIVE,
>                       aPresContext, mStyleContext);
>   }
>+  mPresentationData.negativeLeadingSpace = NS_MAX(0, -mWidth);

and here (see bug Bug 786533)
Attached patch ReftestSplinter Review
Assignee: nobody →
Attachment #686725 - Attachment is obsolete: true
Attachment #686725 - Flags: review?(karlt)
Attachment #734252 - Flags: review?(karlt)
Attached patch Patch V2 (obsolete) — Splinter Review
Attachment #686709 - Attachment is obsolete: true
Attachment #686709 - Flags: review?(karlt)
Attachment #734253 - Flags: review?(karlt)
I just unbitrot the patches. This still allows to address MathJax's use cases, to pass the reftest as well as the MathML Acid2 test:
Attachment #734252 - Flags: review?(karlt) → review+
Comment on attachment 734253 [details] [diff] [review]
Patch V2

>+  // negative leading space of the frame.
>+  nscoord negativeLeadingSpace;

Please adjust the comment here to clarify that this is a positive value when
the offset is negative.

>     nscoord space =
>       GetInterFrameSpacing(font->mScriptLevel,
>                            prevFrameType, mChildFrameType,
>                            &mFromFrameType, &mCarrySpace);
>+    nsIMathMLFrame* mathMLFrame = do_QueryFrame(mChildFrame);
>+    if (mathMLFrame) {
>+      nsPresentationData presentationData;
>+      mathMLFrame->GetPresentationData(presentationData);
>+      mX -= presentationData.negativeLeadingSpace;
>+    }
>     mX += space * GetThinSpace(font);
>     return *this;

Please leave the "mX += space * GetThinSpace(font);" line adjacent to the code
that initializes "space".

>-  nscoord X() const { return mX; }
>+  nscoord X() const { return std::max(0, mX); 


  <mspace width="-1em"/>
  <mspace width="1em" mathbackground="red"/>
  <mspace width="1em" mathbackground="blue"/>

I think there is an effect here that the position of the blue element is
offset, but the position of the red element is not, which is probably not

Another situation is:

  <mspace width="2em" mathbackground="red"/>
    <mspace> width="-1em"/>
    <mspace width="1em" mathbackground="blue"/>

I'd expect width="-1em" to be effective here, which requires some propagation
of the negative space to the mrow.

Does anything go wrong if X() returns a negative nscoord?

Perhaps it is only aDesiredSize.width that need be non-negative?

Can mBoundingMetrics.width be used instead of
nsPresentationData::negativeLeadingSpace to store negative offsets?
Looks like nsBoundingMetrics::width is really an advance rather than a width (and perhaps would be better named "advance").
I expect aDesiredSize.width would still need to be non-negative.
Attachment #734253 - Flags: review?(karlt) → review-
The comment "// XXXfredw Negative spaces are not implemented. See bug 717546" can be removed when this is fixed.
Yes, I considered the two cases you mention. I think that can get even more complicated in situations like

  <mspace width="2em" mathbackground="red"/>
    <mspace width="1em"/>
    <mspace width="1em"/>
    <mspace width="-4em"/>
    <mspace width="2em" mathbackground="blue"/>

where the blue rectangle should be over the red rectangle or when you combine that with several nested mrow's. I think I tried to propagate the negative space at some point but that didn't work very well. As I said in comment 2, my plan was really to consider the cases that happen in practice. Negative space are generally just used to adjust distance between two elements so basically you have

X <mspace width="-.3em"/> Y

where Y is never moves farther than X. Hence that seems a bit overkill to implement the whole negative spaces for MathJax purpose only (there would be other cases to consider like negative mpadded, negative mo@lspace/mo@rspace, how to handle the topmost math/mtd etc).

I'll try to reconsider this. Using negative mBoundingMetrics.width might help, but I need to check that we don't assume in some place that it is nonnegative. That could lead to more issues like bug 567718.

I'm still wondering if bug 433064 should be fixed before (Actually, I now agree adding an anonymous mrow frame as a child of the <math> element would solve many issues and make the code cleaner and more consistent but line breaking should probably be reimplemented before too, which will take some work).
Attached patch Patch V3 (obsolete) — Splinter Review
Attachment #736785 - Flags: review?(karlt)
Comment on attachment 736785 [details] [diff] [review]
Patch V3

Now that mRowChildFrameIterator::X() can return -ve,
nsMathMLContainerFrame::Place() needs to ensure that aDesiredSize.width is
non-negative, or there will be assertions like bug 716349 when an mspace is the single child of an mrow.  r+ with a std::max(0, mBoundingMetrics.width) to address that.

Perhaps nsMathMLmspaceFrame::Reflow() should be ensuring that rightBearing >=
leftBearing, which would require that GetItalicCorrection handle empty metrics
specially, but we can see how this works out with rightBearing < leftBearing.
Attachment #736785 - Flags: review?(karlt) → review+
Attachment #736785 - Attachment is obsolete: true
Closed: 11 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla23
You need to log in before you can comment on or make changes to this bug.