Implement mspace with negative width

RESOLVED FIXED in mozilla23

Status

()

defect
P3
normal
RESOLVED FIXED
8 years ago
6 years ago

People

(Reporter: fredw, Assigned: fredw)

Tracking

(Depends on 1 bug, Blocks 1 bug, {dev-doc-complete, helpwanted})

Trunk
mozilla23
Points:
---
Dependency tree / graph
Bug Flags:
in-testsuite +

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(3 attachments, 4 obsolete attachments)

Assignee

Description

8 years ago
Follow-up of bug 716349.
Assignee

Updated

8 years ago
Blocks: 716349
No longer depends on: 716349
Assignee

Updated

8 years ago
No longer blocks: 716349
Depends on: 716349
Assignee

Updated

7 years ago
Assignee

Updated

7 years ago
Duplicate of this bug: 656429
Assignee

Comment 2

7 years ago
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)
Assignee

Comment 3

7 years ago
Posted file testcase
Assignee

Comment 4

7 years ago
Posted patch Reftests (obsolete) — Splinter Review
Attachment #686725 - Flags: review?(karlt)
Assignee

Updated

7 years ago
Attachment #686711 - Attachment is patch: false
Attachment #686711 - Attachment mime type: text/plain → text/html
Assignee

Comment 5

7 years ago
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
Assignee

Comment 6

7 years ago
Mass change: setting priority to 3 for bugs preventing Gecko's Native MathML to be enabled by default in MathJax.
Keywords: helpwanted
Assignee

Updated

7 years ago
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)
Assignee

Comment 8

6 years ago
Posted patch ReftestSplinter Review
Assignee: nobody → fred.wang
Attachment #686725 - Attachment is obsolete: true
Status: NEW → ASSIGNED
Attachment #686725 - Flags: review?(karlt)
Attachment #734252 - Flags: review?(karlt)
Assignee

Comment 9

6 years ago
Posted patch Patch V2 (obsolete) — Splinter Review
Attachment #686709 - Attachment is obsolete: true
Attachment #686709 - Flags: review?(karlt)
Attachment #734253 - Flags: review?(karlt)
Assignee

Comment 10

6 years ago
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:

http://fred-wang.github.io/AcidTestsMathML/acid2/
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); 

Imagine:

<mrow>
  <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
expected.

Another situation is:

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

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.
Assignee

Comment 13

6 years ago
Yes, I considered the two cases you mention. I think that can get even more complicated in situations like

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

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).
Assignee

Comment 14

6 years ago
Posted 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+
Assignee

Comment 17

6 years ago
Attachment #736785 - Attachment is obsolete: true
https://hg.mozilla.org/mozilla-central/rev/e542d6f1abae
https://hg.mozilla.org/mozilla-central/rev/adbcf488cebf
Status: ASSIGNED → RESOLVED
Last Resolved: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla23
You need to log in before you can comment on or make changes to this bug.