Title: [205105] trunk/Source/WebCore
Revision
205105
Author
[email protected]
Date
2016-08-28 10:36:05 -0700 (Sun, 28 Aug 2016)

Log Message

MathML renderers should use struct to pass long list of LayoutUnits
https://bugs.webkit.org/show_bug.cgi?id=161084

Patch by Frederic Wang <[email protected]> on 2016-08-23
Reviewed by Darin Adler.

RenderMathMLFraction, RenderMathMLMenclose, RenderMathMLScripts and RenderMathMLUnderOver
have helper functions to retrieve a list of LayoutUnit parameters. We gather them in a single
struct instead of using a long list of LayoutUnit& parameters.

No new tests, behavior is unchanged.

* rendering/mathml/RenderMathMLFraction.cpp:
(WebCore::RenderMathMLFraction::getFractionParameters):
(WebCore::RenderMathMLFraction::getStackParameters):
(WebCore::RenderMathMLFraction::layoutBlock):
* rendering/mathml/RenderMathMLFraction.h:
* rendering/mathml/RenderMathMLMenclose.cpp:
(WebCore::RenderMathMLMenclose::getSpaceAroundContent):
(WebCore::RenderMathMLMenclose::computePreferredLogicalWidths):
(WebCore::RenderMathMLMenclose::layoutBlock):
* rendering/mathml/RenderMathMLMenclose.h:
* rendering/mathml/RenderMathMLScripts.cpp:
(WebCore::RenderMathMLScripts::getScriptMetricsAndLayoutIfNeeded):
(WebCore::RenderMathMLScripts::layoutBlock):
* rendering/mathml/RenderMathMLScripts.h:
* rendering/mathml/RenderMathMLUnderOver.cpp:
(WebCore::RenderMathMLUnderOver::getVerticalParameters):
(WebCore::RenderMathMLUnderOver::layoutBlock):
* rendering/mathml/RenderMathMLUnderOver.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (205104 => 205105)


--- trunk/Source/WebCore/ChangeLog	2016-08-28 16:54:43 UTC (rev 205104)
+++ trunk/Source/WebCore/ChangeLog	2016-08-28 17:36:05 UTC (rev 205105)
@@ -1,3 +1,35 @@
+2016-08-23  Frederic Wang  <[email protected]>
+
+        MathML renderers should use struct to pass long list of LayoutUnits
+        https://bugs.webkit.org/show_bug.cgi?id=161084
+
+        Reviewed by Darin Adler.
+
+        RenderMathMLFraction, RenderMathMLMenclose, RenderMathMLScripts and RenderMathMLUnderOver
+        have helper functions to retrieve a list of LayoutUnit parameters. We gather them in a single
+        struct instead of using a long list of LayoutUnit& parameters.
+
+        No new tests, behavior is unchanged.
+
+        * rendering/mathml/RenderMathMLFraction.cpp:
+        (WebCore::RenderMathMLFraction::getFractionParameters):
+        (WebCore::RenderMathMLFraction::getStackParameters):
+        (WebCore::RenderMathMLFraction::layoutBlock):
+        * rendering/mathml/RenderMathMLFraction.h:
+        * rendering/mathml/RenderMathMLMenclose.cpp:
+        (WebCore::RenderMathMLMenclose::getSpaceAroundContent):
+        (WebCore::RenderMathMLMenclose::computePreferredLogicalWidths):
+        (WebCore::RenderMathMLMenclose::layoutBlock):
+        * rendering/mathml/RenderMathMLMenclose.h:
+        * rendering/mathml/RenderMathMLScripts.cpp:
+        (WebCore::RenderMathMLScripts::getScriptMetricsAndLayoutIfNeeded):
+        (WebCore::RenderMathMLScripts::layoutBlock):
+        * rendering/mathml/RenderMathMLScripts.h:
+        * rendering/mathml/RenderMathMLUnderOver.cpp:
+        (WebCore::RenderMathMLUnderOver::getVerticalParameters):
+        (WebCore::RenderMathMLUnderOver::layoutBlock):
+        * rendering/mathml/RenderMathMLUnderOver.h:
+
 2016-08-28  Andreas Kling  <[email protected]>
 
         Clean up some .text attribute setters that don't throw.

Modified: trunk/Source/WebCore/rendering/mathml/RenderMathMLFraction.cpp (205104 => 205105)


--- trunk/Source/WebCore/rendering/mathml/RenderMathMLFraction.cpp	2016-08-28 16:54:43 UTC (rev 205104)
+++ trunk/Source/WebCore/rendering/mathml/RenderMathMLFraction.cpp	2016-08-28 17:36:05 UTC (rev 205105)
@@ -81,9 +81,10 @@
         m_lineThickness = 0;
 }
 
-void RenderMathMLFraction::getFractionParameters(LayoutUnit& numeratorGapMin, LayoutUnit& denominatorGapMin, LayoutUnit& numeratorMinShiftUp, LayoutUnit& denominatorMinShiftDown)
+RenderMathMLFraction::FractionParameters RenderMathMLFraction::fractionParameters()
 {
     ASSERT(!isStack());
+    FractionParameters parameters;
 
     // We try and read constants to draw the fraction from the OpenType MATH and use fallback values otherwise.
     const auto& primaryFont = style().fontCascade().primaryFont();
@@ -90,41 +91,46 @@
     const auto* mathData = style().fontCascade().primaryFont().mathData();
     bool display = mathMLStyle()->displayStyle();
     if (mathData) {
-        numeratorGapMin = mathData->getMathConstant(primaryFont, display ? OpenTypeMathData::FractionNumDisplayStyleGapMin : OpenTypeMathData::FractionNumeratorGapMin);
-        denominatorGapMin = mathData->getMathConstant(primaryFont, display ? OpenTypeMathData::FractionDenomDisplayStyleGapMin : OpenTypeMathData::FractionDenominatorGapMin);
-        numeratorMinShiftUp = mathData->getMathConstant(primaryFont, display ? OpenTypeMathData::FractionNumeratorDisplayStyleShiftUp : OpenTypeMathData::FractionNumeratorShiftUp);
-        denominatorMinShiftDown = mathData->getMathConstant(primaryFont, display ? OpenTypeMathData::FractionDenominatorDisplayStyleShiftDown : OpenTypeMathData::FractionDenominatorShiftDown);
+        parameters.numeratorGapMin = mathData->getMathConstant(primaryFont, display ? OpenTypeMathData::FractionNumDisplayStyleGapMin : OpenTypeMathData::FractionNumeratorGapMin);
+        parameters.denominatorGapMin = mathData->getMathConstant(primaryFont, display ? OpenTypeMathData::FractionDenomDisplayStyleGapMin : OpenTypeMathData::FractionDenominatorGapMin);
+        parameters.numeratorMinShiftUp = mathData->getMathConstant(primaryFont, display ? OpenTypeMathData::FractionNumeratorDisplayStyleShiftUp : OpenTypeMathData::FractionNumeratorShiftUp);
+        parameters.denominatorMinShiftDown = mathData->getMathConstant(primaryFont, display ? OpenTypeMathData::FractionDenominatorDisplayStyleShiftDown : OpenTypeMathData::FractionDenominatorShiftDown);
     } else {
         // The MATH table specification suggests default rule thickness or (in displaystyle) 3 times default rule thickness for the gaps.
-        numeratorGapMin = display ? 3 * ruleThicknessFallback() : ruleThicknessFallback();
-        denominatorGapMin = numeratorGapMin;
+        parameters.numeratorGapMin = display ? 3 * ruleThicknessFallback() : ruleThicknessFallback();
+        parameters.denominatorGapMin = parameters.numeratorGapMin;
 
         // The MATH table specification does not suggest any values for shifts, so we leave them at zero.
-        numeratorMinShiftUp = 0;
-        denominatorMinShiftDown = 0;
+        parameters.numeratorMinShiftUp = 0;
+        parameters.denominatorMinShiftDown = 0;
     }
+
+    return parameters;
 }
 
-void RenderMathMLFraction::getStackParameters(LayoutUnit& gapMin, LayoutUnit& topShiftUp, LayoutUnit& bottomShiftDown)
+RenderMathMLFraction::StackParameters RenderMathMLFraction::stackParameters()
 {
     ASSERT(isStack());
-
+    StackParameters parameters;
+    
     // We try and read constants to draw the stack from the OpenType MATH and use fallback values otherwise.
     const auto& primaryFont = style().fontCascade().primaryFont();
     const auto* mathData = style().fontCascade().primaryFont().mathData();
     bool display = mathMLStyle()->displayStyle();
     if (mathData) {
-        gapMin = mathData->getMathConstant(primaryFont, display ? OpenTypeMathData::StackDisplayStyleGapMin : OpenTypeMathData::StackGapMin);
-        topShiftUp = mathData->getMathConstant(primaryFont, display ? OpenTypeMathData::StackTopDisplayStyleShiftUp : OpenTypeMathData::StackTopShiftUp);
-        bottomShiftDown = mathData->getMathConstant(primaryFont, display ? OpenTypeMathData::StackBottomDisplayStyleShiftDown : OpenTypeMathData::StackBottomShiftDown);
+        parameters.gapMin = mathData->getMathConstant(primaryFont, display ? OpenTypeMathData::StackDisplayStyleGapMin : OpenTypeMathData::StackGapMin);
+        parameters.topShiftUp = mathData->getMathConstant(primaryFont, display ? OpenTypeMathData::StackTopDisplayStyleShiftUp : OpenTypeMathData::StackTopShiftUp);
+        parameters.bottomShiftDown = mathData->getMathConstant(primaryFont, display ? OpenTypeMathData::StackBottomDisplayStyleShiftDown : OpenTypeMathData::StackBottomShiftDown);
     } else {
         // We use the values suggested in the MATH table specification.
-        gapMin = display ? 7 * ruleThicknessFallback() : 3 * ruleThicknessFallback();
+        parameters.gapMin = display ? 7 * ruleThicknessFallback() : 3 * ruleThicknessFallback();
 
         // The MATH table specification does not suggest any values for shifts, so we leave them at zero.
-        topShiftUp = 0;
-        bottomShiftDown = 0;
+        parameters.topShiftUp = 0;
+        parameters.bottomShiftDown = 0;
     }
+
+    return parameters;
 }
 
 RenderMathMLOperator* RenderMathMLFraction::unembellishedOperator()
@@ -195,24 +201,22 @@
     LayoutUnit denominatorAscent = ascentForChild(denominator());
     LayoutUnit denominatorDescent = denominator().logicalHeight() - denominatorAscent;
     if (isStack()) {
-        LayoutUnit gapMin, topShiftUp, bottomShiftDown;
-        getStackParameters(gapMin, topShiftUp, bottomShiftDown);
-        LayoutUnit gap = topShiftUp - numeratorDescent + bottomShiftDown - denominatorAscent;
-        if (gap < gapMin) {
+        StackParameters parameters = stackParameters();
+        LayoutUnit gap = parameters.topShiftUp - numeratorDescent + parameters.bottomShiftDown - denominatorAscent;
+        if (gap < parameters.gapMin) {
             // If the gap is not large enough, we increase the shifts by the same value.
-            LayoutUnit delta = (gapMin - gap) / 2;
-            topShiftUp += delta;
-            bottomShiftDown += delta;
+            LayoutUnit delta = (parameters.gapMin - gap) / 2;
+            parameters.topShiftUp += delta;
+            parameters.bottomShiftDown += delta;
         }
-        verticalOffset += numeratorAscent + topShiftUp; // This is the middle of the stack gap.
+        verticalOffset += numeratorAscent + parameters.topShiftUp; // This is the middle of the stack gap.
         m_ascent = verticalOffset + mathAxisHeight();
-        verticalOffset += bottomShiftDown - denominatorAscent;
+        verticalOffset += parameters.bottomShiftDown - denominatorAscent;
     } else {
-        LayoutUnit numeratorGapMin, denominatorGapMin, numeratorMinShiftUp, denominatorMinShiftDown;
-        getFractionParameters(numeratorGapMin, denominatorGapMin, numeratorMinShiftUp, denominatorMinShiftDown);
-        verticalOffset += std::max(numerator().logicalHeight() + numeratorGapMin + m_lineThickness / 2, numeratorAscent + numeratorMinShiftUp); // This is the middle of the fraction bar.
+        FractionParameters parameters = fractionParameters();
+        verticalOffset += std::max(numerator().logicalHeight() + parameters.numeratorGapMin + m_lineThickness / 2, numeratorAscent + parameters.numeratorMinShiftUp); // This is the middle of the fraction bar.
         m_ascent = verticalOffset + mathAxisHeight();
-        verticalOffset += std::max(m_lineThickness / 2 + denominatorGapMin, denominatorMinShiftDown - denominatorAscent);
+        verticalOffset += std::max(m_lineThickness / 2 + parameters.denominatorGapMin, parameters.denominatorMinShiftDown - denominatorAscent);
     }
 
     LayoutPoint denominatorLocation(horizontalOffset(denominator(), element().denominatorAlignment()), verticalOffset);

Modified: trunk/Source/WebCore/rendering/mathml/RenderMathMLFraction.h (205104 => 205105)


--- trunk/Source/WebCore/rendering/mathml/RenderMathMLFraction.h	2016-08-28 16:54:43 UTC (rev 205104)
+++ trunk/Source/WebCore/rendering/mathml/RenderMathMLFraction.h	2016-08-28 17:36:05 UTC (rev 205105)
@@ -60,8 +60,19 @@
     RenderBox& denominator() const;
     LayoutUnit horizontalOffset(RenderBox&, MathMLFractionElement::FractionAlignment);
     void updateLineThickness();
-    void getFractionParameters(LayoutUnit& numeratorGapMin, LayoutUnit& denominatorGapMin, LayoutUnit& numeratorMinShiftUp, LayoutUnit& denominatorMinShiftDown);
-    void getStackParameters(LayoutUnit& gapMin, LayoutUnit& topShiftUp, LayoutUnit& bottomShiftDown);
+    struct FractionParameters {
+        LayoutUnit numeratorGapMin;
+        LayoutUnit denominatorGapMin;
+        LayoutUnit numeratorMinShiftUp;
+        LayoutUnit denominatorMinShiftDown;
+    };
+    FractionParameters fractionParameters();
+    struct StackParameters {
+        LayoutUnit gapMin;
+        LayoutUnit topShiftUp;
+        LayoutUnit bottomShiftDown;
+    };
+    StackParameters stackParameters();
 
     LayoutUnit m_ascent;
     LayoutUnit m_defaultLineThickness { 1 };

Modified: trunk/Source/WebCore/rendering/mathml/RenderMathMLMenclose.cpp (205104 => 205105)


--- trunk/Source/WebCore/rendering/mathml/RenderMathMLMenclose.cpp	2016-08-28 16:54:43 UTC (rev 205104)
+++ trunk/Source/WebCore/rendering/mathml/RenderMathMLMenclose.cpp	2016-08-28 17:36:05 UTC (rev 205105)
@@ -59,12 +59,15 @@
     return 0.05f * style().fontCascade().size();
 }
 
-void RenderMathMLMenclose::getSpaceAroundContent(LayoutUnit contentWidth, LayoutUnit contentHeight, LayoutUnit& leftSpace, LayoutUnit& rightSpace, LayoutUnit& topSpace, LayoutUnit& bottomSpace) const
+RenderMathMLMenclose::SpaceAroundContent RenderMathMLMenclose::spaceAroundContent(LayoutUnit contentWidth, LayoutUnit contentHeight) const
 {
-    leftSpace = rightSpace = topSpace = bottomSpace = 0;
+    SpaceAroundContent space;
+    space.right = 0;
+    space.top = 0;
+    space.bottom = 0;
+    space.left = 0;
 
     LayoutUnit thickness = ruleThickness();
-
     // In the MathML in HTML5 implementation note, the "left" notation is described as follows:
     // - left side is 3\xi_8 padding + \xi_8 border + \xi_8 margin = 5\xi_8
     // - top space is Overbar Vertical Gap + Overbar Rule Thickness = 3\xi_8 + \xi_8 = 4\xi_8
@@ -71,13 +74,13 @@
     // - bottom space is Underbar Vertical Gap + Underbar Rule Thickness = 3\xi_8 + \xi_8 = 4\xi_8
     // The "right" notation is symmetric.
     if (hasNotation(MathMLMencloseElement::Left))
-        leftSpace = std::max(leftSpace, 5 * thickness);
+        space.left = std::max(space.left, 5 * thickness);
     if (hasNotation(MathMLMencloseElement::Right))
-        rightSpace = std::max(rightSpace, 5 * thickness);
+        space.right = std::max(space.right, 5 * thickness);
     if (hasNotation(MathMLMencloseElement::Left) || hasNotation(MathMLMencloseElement::Right)) {
         LayoutUnit extraSpace = 4 * thickness;
-        topSpace = std::max(topSpace, extraSpace);
-        bottomSpace = std::max(bottomSpace, extraSpace);
+        space.top = std::max(space.top, extraSpace);
+        space.bottom = std::max(space.bottom, extraSpace);
     }
 
     // In the MathML in HTML5 implementation note, the "top" notation is described as follows:
@@ -85,13 +88,13 @@
     // - top side is Vertical Gap + Rule Thickness + Extra Ascender = 3\xi_8 + \xi_8 + \xi_8 = 5\xi_8
     // The "bottom" notation is symmetric.
     if (hasNotation(MathMLMencloseElement::Top))
-        topSpace = std::max(topSpace, 5 * thickness);
+        space.top = std::max(space.top, 5 * thickness);
     if (hasNotation(MathMLMencloseElement::Bottom))
-        bottomSpace = std::max(bottomSpace, 5 * thickness);
+        space.bottom = std::max(space.bottom, 5 * thickness);
     if (hasNotation(MathMLMencloseElement::Top) || hasNotation(MathMLMencloseElement::Bottom)) {
         LayoutUnit extraSpace = 4 * thickness;
-        leftSpace = std::max(leftSpace, extraSpace);
-        rightSpace = std::max(rightSpace, extraSpace);
+        space.left = std::max(space.left, extraSpace);
+        space.right = std::max(space.right, extraSpace);
     }
 
     // For longdiv, we use our own rules for now:
@@ -100,10 +103,10 @@
     // - right space is like "right" notation
     // - left space is longDivLeftSpace * \xi_8
     if (hasNotation(MathMLMencloseElement::LongDiv)) {
-        topSpace = std::max(topSpace, 5 * thickness);
-        bottomSpace = std::max(bottomSpace, 5 * thickness);
-        leftSpace = std::max(leftSpace, longDivLeftSpace * thickness);
-        rightSpace = std::max(rightSpace, 4 * thickness);
+        space.top = std::max(space.top, 5 * thickness);
+        space.bottom = std::max(space.bottom, 5 * thickness);
+        space.left = std::max(space.left, longDivLeftSpace * thickness);
+        space.right = std::max(space.right, 4 * thickness);
     }
 
     // In the MathML in HTML5 implementation note, the "rounded" notation is described as follows:
@@ -110,10 +113,10 @@
     // - top/bottom/left/right side have 3\xi_8 padding + \xi_8 border + \xi_8 margin = 5\xi_8
     if (hasNotation(MathMLMencloseElement::RoundedBox)) {
         LayoutUnit extraSpace = 5 * thickness;
-        leftSpace = std::max(leftSpace, extraSpace);
-        rightSpace = std::max(rightSpace, extraSpace);
-        topSpace = std::max(topSpace, extraSpace);
-        bottomSpace = std::max(bottomSpace, extraSpace);
+        space.left = std::max(space.left, extraSpace);
+        space.right = std::max(space.right, extraSpace);
+        space.top = std::max(space.top, extraSpace);
+        space.bottom = std::max(space.bottom, extraSpace);
     }
 
     // In the MathML in HTML5 implementation note, the "rounded" notation is described as follows:
@@ -120,10 +123,10 @@
     // - top/bottom/left/right spaces are \xi_8/2
     if (hasNotation(MathMLMencloseElement::UpDiagonalStrike) || hasNotation(MathMLMencloseElement::DownDiagonalStrike)) {
         LayoutUnit extraSpace = thickness / 2;
-        leftSpace = std::max(leftSpace, extraSpace);
-        rightSpace = std::max(rightSpace, extraSpace);
-        topSpace = std::max(topSpace, extraSpace);
-        bottomSpace = std::max(bottomSpace, extraSpace);
+        space.left = std::max(space.left, extraSpace);
+        space.right = std::max(space.right, extraSpace);
+        space.top = std::max(space.top, extraSpace);
+        space.bottom = std::max(space.bottom, extraSpace);
     }
 
     // In the MathML in HTML5 implementation note, the "circle" notation is described as follows:
@@ -134,14 +137,16 @@
     // Then for example the top space is \sqrt{2}contentHeight/2 - contentHeight/2 + \xi_8/2 + \xi_8.
     if (hasNotation(MathMLMencloseElement::Circle)) {
         LayoutUnit extraSpace = (contentWidth * (sqrtOfTwoFloat - 1) + 3 * thickness) / 2;
-        leftSpace = std::max(leftSpace, extraSpace);
-        rightSpace = std::max(rightSpace, extraSpace);
+        space.left = std::max(space.left, extraSpace);
+        space.right = std::max(space.right, extraSpace);
         extraSpace = (contentHeight * (sqrtOfTwoFloat - 1) + 3 * thickness) / 2;
-        topSpace = std::max(topSpace, extraSpace);
-        bottomSpace = std::max(bottomSpace, extraSpace);
+        space.top = std::max(space.top, extraSpace);
+        space.bottom = std::max(space.bottom, extraSpace);
     }
 
     // In the MathML in HTML5 implementation note, the "vertical" and "horizontal" notations do not add space around the content.
+
+    return space;
 }
 
 void RenderMathMLMenclose::computePreferredLogicalWidths()
@@ -151,9 +156,9 @@
     RenderMathMLRow::computePreferredLogicalWidths();
 
     LayoutUnit preferredWidth = m_maxPreferredLogicalWidth;
-    LayoutUnit leftSpace, rightSpace, dummy;
-    getSpaceAroundContent(preferredWidth, 0, leftSpace, rightSpace, dummy, dummy);
-    m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = leftSpace + preferredWidth + rightSpace;
+    SpaceAroundContent space = spaceAroundContent(preferredWidth, 0);
+    m_maxPreferredLogicalWidth = space.left + preferredWidth + space.right;
+    m_maxPreferredLogicalWidth = m_minPreferredLogicalWidth;
 
     setPreferredLogicalWidthsDirty(false);
 }
@@ -171,16 +176,15 @@
     RenderMathMLRow::layoutRowItems(contentAscent, contentDescent);
     LayoutUnit contentWidth = logicalWidth();
 
-    LayoutUnit leftSpace, rightSpace, topSpace, bottomSpace;
-    getSpaceAroundContent(contentWidth, contentAscent + contentDescent, leftSpace, rightSpace, topSpace, bottomSpace);
-    setLogicalWidth(leftSpace + contentWidth + rightSpace);
-    setLogicalHeight(topSpace + contentAscent + contentDescent + bottomSpace);
+    SpaceAroundContent space = spaceAroundContent(contentWidth, contentAscent + contentDescent);
+    setLogicalWidth(space.left + contentWidth + space.right);
+    setLogicalHeight(space.top + contentAscent + contentDescent + space.bottom);
 
-    LayoutPoint contentLocation(leftSpace, topSpace);
+    LayoutPoint contentLocation(space.left, space.top);
     for (auto* child = firstChildBox(); child; child = child->nextSiblingBox())
         child->setLocation(child->location() + contentLocation);
 
-    m_contentRect = LayoutRect(leftSpace, topSpace, contentWidth, contentAscent + contentDescent);
+    m_contentRect = LayoutRect(space.left, space.top, contentWidth, contentAscent + contentDescent);
 
     clearNeedsLayout();
 }

Modified: trunk/Source/WebCore/rendering/mathml/RenderMathMLMenclose.h (205104 => 205105)


--- trunk/Source/WebCore/rendering/mathml/RenderMathMLMenclose.h	2016-08-28 16:54:43 UTC (rev 205104)
+++ trunk/Source/WebCore/rendering/mathml/RenderMathMLMenclose.h	2016-08-28 17:36:05 UTC (rev 205105)
@@ -46,7 +46,13 @@
     LayoutUnit ruleThickness() const;
     bool hasNotation(MathMLMencloseElement::MencloseNotationFlag notationFlag) const { return downcast<MathMLMencloseElement>(element()).hasNotation(notationFlag); }
 
-    void getSpaceAroundContent(LayoutUnit contentWidth, LayoutUnit contentHeight, LayoutUnit& leftSpace, LayoutUnit& rightSpace, LayoutUnit& topSpace, LayoutUnit& bottomSpace) const;
+    struct SpaceAroundContent {
+        LayoutUnit left;
+        LayoutUnit right;
+        LayoutUnit top;
+        LayoutUnit bottom;
+    };
+    SpaceAroundContent spaceAroundContent(LayoutUnit contentWidth, LayoutUnit contentHeight) const;
 
     LayoutRect m_contentRect;
 };

Modified: trunk/Source/WebCore/rendering/mathml/RenderMathMLScripts.cpp (205104 => 205105)


--- trunk/Source/WebCore/rendering/mathml/RenderMathMLScripts.cpp	2016-08-28 16:54:43 UTC (rev 205104)
+++ trunk/Source/WebCore/rendering/mathml/RenderMathMLScripts.cpp	2016-08-28 17:36:05 UTC (rev 205105)
@@ -216,7 +216,7 @@
     m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth;
 }
 
-void RenderMathMLScripts::getScriptMetricsAndLayoutIfNeeded(RenderBox* base, RenderBox* script, LayoutUnit& minSubScriptShift, LayoutUnit& minSupScriptShift, LayoutUnit& maxScriptDescent, LayoutUnit& maxScriptAscent)
+void RenderMathMLScripts::getScriptMetricsAndLayoutIfNeeded(RenderBox* base, RenderBox* script, ScriptMetrics& metrics)
 {
     LayoutUnit baseAscent = ascentForChild(*base);
     LayoutUnit baseDescent = base->logicalHeight() - baseAscent;
@@ -252,21 +252,21 @@
     }
 
     if (m_scriptType == Sub || m_scriptType == SubSup || m_scriptType == Multiscripts || m_scriptType == Under || m_scriptType == UnderOver) {
-        minSubScriptShift = std::max(subscriptShiftDown, baseDescent + subscriptBaselineDropMin);
+        metrics.subShift = std::max(subscriptShiftDown, baseDescent + subscriptBaselineDropMin);
         if (!isRenderMathMLUnderOver()) {
             // It is not clear how to interpret the default shift and it is not available yet anyway.
             // Hence we just pass 0 as the default value used by toUserUnits.
             LayoutUnit specifiedMinSubShift = toUserUnits(element().subscriptShift(), style(), 0);
-            minSubScriptShift = std::max(minSubScriptShift, specifiedMinSubShift);
+            metrics.subShift = std::max(metrics.subShift, specifiedMinSubShift);
         }
     }
     if (m_scriptType == Super || m_scriptType == SubSup || m_scriptType == Multiscripts  || m_scriptType == Over || m_scriptType == UnderOver) {
-        minSupScriptShift = std::max(superscriptShiftUp, baseAscent - superScriptBaselineDropMax);
+        metrics.supShift = std::max(superscriptShiftUp, baseAscent - superScriptBaselineDropMax);
         if (!isRenderMathMLUnderOver()) {
             // It is not clear how to interpret the default shift and it is not available yet anyway.
             // Hence we just pass 0 as the default value used by toUserUnits.
             LayoutUnit specifiedMinSupShift = toUserUnits(element().superscriptShift(), style(), 0);
-            minSupScriptShift = std::max(minSupScriptShift, specifiedMinSupShift);
+            metrics.supShift = std::max(metrics.supShift, specifiedMinSupShift);
         }
     }
 
@@ -276,8 +276,8 @@
         script->layoutIfNeeded();
         LayoutUnit subAscent = ascentForChild(*script);
         LayoutUnit subDescent = script->logicalHeight() - subAscent;
-        maxScriptDescent = subDescent;
-        minSubScriptShift = std::max(minSubScriptShift, subAscent - subscriptTopMax);
+        metrics.descent = subDescent;
+        metrics.subShift = std::max(metrics.subShift, subAscent - subscriptTopMax);
     }
         break;
     case Super:
@@ -285,8 +285,8 @@
         script->layoutIfNeeded();
         LayoutUnit supAscent = ascentForChild(*script);
         LayoutUnit supDescent = script->logicalHeight() - supAscent;
-        maxScriptAscent = supAscent;
-        minSupScriptShift = std::max(minSupScriptShift, superscriptBottomMin + supDescent);
+        metrics.ascent = supAscent;
+        metrics.supShift = std::max(metrics.supShift, superscriptBottomMin + supDescent);
     }
         break;
     case SubSup:
@@ -302,8 +302,8 @@
             LayoutUnit subDescent = subScript->logicalHeight() - subAscent;
             LayoutUnit supAscent = ascentForChild(*supScript);
             LayoutUnit supDescent = supScript->logicalHeight() - supAscent;
-            maxScriptAscent = std::max(maxScriptAscent, supAscent);
-            maxScriptDescent = std::max(maxScriptDescent, subDescent);
+            metrics.ascent = std::max(metrics.ascent, supAscent);
+            metrics.descent = std::max(metrics.descent, subDescent);
             LayoutUnit subScriptShift = std::max(subscriptShiftDown, baseDescent + subscriptBaselineDropMin);
             subScriptShift = std::max(subScriptShift, subAscent - subscriptTopMax);
             LayoutUnit supScriptShift = std::max(superscriptShiftUp, baseAscent - superScriptBaselineDropMax);
@@ -323,8 +323,8 @@
                     subScriptShift += subSuperscriptGapMin - subSuperscriptGap;
             }
 
-            minSubScriptShift = std::max(minSubScriptShift, subScriptShift);
-            minSupScriptShift = std::max(minSupScriptShift, supScriptShift);
+            metrics.subShift = std::max(metrics.subShift, subScriptShift);
+            metrics.supShift = std::max(metrics.supShift, supScriptShift);
         }
     }
     }
@@ -349,15 +349,17 @@
     recomputeLogicalWidth();
     base->layoutIfNeeded();
 
-    LayoutUnit supScriptShift = 0;
-    LayoutUnit subScriptShift = 0;
-    LayoutUnit scriptDescent = 0;
-    LayoutUnit scriptAscent = 0;
     LayoutUnit space = spaceAfterScript();
 
+    // We determine the minimal shift/size of each script and take the maximum of the values.
+    ScriptMetrics metrics;
+    metrics.subShift = 0;
+    metrics.supShift = 0;
+    metrics.descent = 0;
+    metrics.ascent = 0;
     if (m_scriptType == Multiscripts)
-        getScriptMetricsAndLayoutIfNeeded(base, firstPreScript, subScriptShift, supScriptShift, scriptDescent, scriptAscent);
-    getScriptMetricsAndLayoutIfNeeded(base, firstPostScript, subScriptShift, supScriptShift, scriptDescent, scriptAscent);
+        getScriptMetricsAndLayoutIfNeeded(base, firstPreScript, metrics);
+    getScriptMetricsAndLayoutIfNeeded(base, firstPostScript, metrics);
 
     LayoutUnit baseAscent = ascentForChild(*base);
     LayoutUnit baseDescent = base->logicalHeight() - baseAscent;
@@ -364,8 +366,8 @@
     LayoutUnit baseItalicCorrection = std::min(base->logicalWidth(), italicCorrection(base));
     LayoutUnit horizontalOffset = 0;
 
-    LayoutUnit ascent = std::max(baseAscent, scriptAscent + supScriptShift);
-    LayoutUnit descent = std::max(baseDescent, scriptDescent + subScriptShift);
+    LayoutUnit ascent = std::max(baseAscent, metrics.ascent + metrics.supShift);
+    LayoutUnit descent = std::max(baseDescent, metrics.descent + metrics.subShift);
     setLogicalHeight(ascent + descent);
 
     switch (m_scriptType) {
@@ -376,7 +378,7 @@
         base->setLocation(baseLocation);
         horizontalOffset += base->logicalWidth();
         LayoutUnit scriptAscent = ascentForChild(*firstPostScript);
-        LayoutPoint scriptLocation(mirrorIfNeeded(horizontalOffset - baseItalicCorrection, *firstPostScript), ascent + subScriptShift - scriptAscent);
+        LayoutPoint scriptLocation(mirrorIfNeeded(horizontalOffset - baseItalicCorrection, *firstPostScript), ascent + metrics.subShift - scriptAscent);
         firstPostScript->setLocation(scriptLocation);
     }
         break;
@@ -387,7 +389,7 @@
         base->setLocation(baseLocation);
         horizontalOffset += base->logicalWidth();
         LayoutUnit scriptAscent = ascentForChild(*firstPostScript);
-        LayoutPoint scriptLocation(mirrorIfNeeded(horizontalOffset, *firstPostScript), ascent - supScriptShift - scriptAscent);
+        LayoutPoint scriptLocation(mirrorIfNeeded(horizontalOffset, *firstPostScript), ascent - metrics.supShift - scriptAscent);
         firstPostScript->setLocation(scriptLocation);
     }
         break;
@@ -419,10 +421,10 @@
             LayoutUnit subSupPairWidth = std::max(subScript->logicalWidth(), supScript->logicalWidth());
             horizontalOffset += space + subSupPairWidth;
             LayoutUnit subAscent = ascentForChild(*subScript);
-            LayoutPoint subScriptLocation(mirrorIfNeeded(horizontalOffset - subScript->logicalWidth(), *subScript), ascent + subScriptShift - subAscent);
+            LayoutPoint subScriptLocation(mirrorIfNeeded(horizontalOffset - subScript->logicalWidth(), *subScript), ascent + metrics.subShift - subAscent);
             subScript->setLocation(subScriptLocation);
             LayoutUnit supAscent = ascentForChild(*supScript);
-            LayoutPoint supScriptLocation(mirrorIfNeeded(horizontalOffset - supScript->logicalWidth(), *supScript), ascent - supScriptShift - supAscent);
+            LayoutPoint supScriptLocation(mirrorIfNeeded(horizontalOffset - supScript->logicalWidth(), *supScript), ascent - metrics.supShift - supAscent);
             supScript->setLocation(supScriptLocation);
         }
         LayoutPoint baseLocation(mirrorIfNeeded(horizontalOffset, *base), ascent - baseAscent);
@@ -432,10 +434,10 @@
             supScript = subScript->nextSiblingBox();
             ASSERT(supScript);
             LayoutUnit subAscent = ascentForChild(*subScript);
-            LayoutPoint subScriptLocation(mirrorIfNeeded(horizontalOffset - baseItalicCorrection, *subScript), ascent + subScriptShift - subAscent);
+            LayoutPoint subScriptLocation(mirrorIfNeeded(horizontalOffset - baseItalicCorrection, *subScript), ascent + metrics.subShift - subAscent);
             subScript->setLocation(subScriptLocation);
             LayoutUnit supAscent = ascentForChild(*supScript);
-            LayoutPoint supScriptLocation(mirrorIfNeeded(horizontalOffset, *supScript), ascent - supScriptShift - supAscent);
+            LayoutPoint supScriptLocation(mirrorIfNeeded(horizontalOffset, *supScript), ascent - metrics.supShift - supAscent);
             supScript->setLocation(supScriptLocation);
 
             LayoutUnit subSupPairWidth = std::max(subScript->logicalWidth(), supScript->logicalWidth());

Modified: trunk/Source/WebCore/rendering/mathml/RenderMathMLScripts.h (205104 => 205105)


--- trunk/Source/WebCore/rendering/mathml/RenderMathMLScripts.h	2016-08-28 16:54:43 UTC (rev 205104)
+++ trunk/Source/WebCore/rendering/mathml/RenderMathMLScripts.h	2016-08-28 17:36:05 UTC (rev 205105)
@@ -56,7 +56,13 @@
     bool getBaseAndScripts(RenderBox*& base, RenderBox*& firstPostScript, RenderBox*& firstPreScript);
     LayoutUnit spaceAfterScript();
     LayoutUnit italicCorrection(RenderBox* base);
-    void getScriptMetricsAndLayoutIfNeeded(RenderBox* base, RenderBox* script, LayoutUnit& minSubScriptShift, LayoutUnit& minSupScriptShift, LayoutUnit& maxScriptDescent, LayoutUnit& maxScriptAscent);
+    struct ScriptMetrics {
+        LayoutUnit subShift;
+        LayoutUnit supShift;
+        LayoutUnit ascent;
+        LayoutUnit descent;
+    };
+    void getScriptMetricsAndLayoutIfNeeded(RenderBox* base, RenderBox* script, ScriptMetrics&);
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/rendering/mathml/RenderMathMLUnderOver.cpp (205104 => 205105)


--- trunk/Source/WebCore/rendering/mathml/RenderMathMLUnderOver.cpp	2016-08-28 16:54:43 UTC (rev 205104)
+++ trunk/Source/WebCore/rendering/mathml/RenderMathMLUnderOver.cpp	2016-08-28 17:36:05 UTC (rev 205105)
@@ -179,10 +179,18 @@
     return scriptOperator && scriptOperator->hasOperatorFlag(MathMLOperatorDictionary::Accent);
 }
 
-bool RenderMathMLUnderOver::getVerticalParameters(LayoutUnit& underGapMin, LayoutUnit& overGapMin, LayoutUnit& underShiftMin, LayoutUnit& overShiftMin, LayoutUnit& underExtraDescender, LayoutUnit& overExtraAscender, LayoutUnit& accentBaseHeight) const
+RenderMathMLUnderOver::VerticalParameters RenderMathMLUnderOver::verticalParameters() const
 {
+    VerticalParameters parameters;
+
     // By default, we set all values to zero.
-    underGapMin = overGapMin = underShiftMin = overShiftMin = underExtraDescender = overExtraAscender = accentBaseHeight = 0;
+    parameters.underGapMin = 0;
+    parameters.overGapMin = 0;
+    parameters.underShiftMin = 0;
+    parameters.overShiftMin = 0;
+    parameters.underExtraDescender = 0;
+    parameters.overExtraAscender = 0;
+    parameters.accentBaseHeight = 0;
 
     const auto& primaryFont = style().fontCascade().primaryFont();
     auto* mathData = primaryFont.mathData();
@@ -189,10 +197,13 @@
     if (!mathData) {
         // The MATH table specification does not really provide any suggestions, except for some underbar/overbar values and AccentBaseHeight.
         LayoutUnit defaultLineThickness = ruleThicknessFallback();
-        underGapMin = overGapMin = 3 * defaultLineThickness;
-        underExtraDescender = overExtraAscender = defaultLineThickness;
-        accentBaseHeight = style().fontMetrics().xHeight();
-        return true;
+        parameters.underGapMin = 3 * defaultLineThickness;
+        parameters.overGapMin = 3 * defaultLineThickness;
+        parameters.underExtraDescender = defaultLineThickness;
+        parameters.overExtraAscender = defaultLineThickness;
+        parameters.accentBaseHeight = style().fontMetrics().xHeight();
+        parameters.useUnderOverBarFallBack = true;
+        return parameters;
     }
 
     if (is<RenderMathMLBlock>(base())) {
@@ -199,30 +210,33 @@
         if (auto* baseOperator = downcast<RenderMathMLBlock>(base()).unembellishedOperator()) {
             if (baseOperator->hasOperatorFlag(MathMLOperatorDictionary::LargeOp)) {
                 // The base is a large operator so we read UpperLimit/LowerLimit constants from the MATH table.
-                underGapMin = mathData->getMathConstant(primaryFont, OpenTypeMathData::LowerLimitGapMin);
-                overGapMin = mathData->getMathConstant(primaryFont, OpenTypeMathData::UpperLimitGapMin);
-                underShiftMin = mathData->getMathConstant(primaryFont, OpenTypeMathData::LowerLimitBaselineDropMin);
-                overShiftMin = mathData->getMathConstant(primaryFont, OpenTypeMathData::UpperLimitBaselineRiseMin);
-                return false;
+                parameters.underGapMin = mathData->getMathConstant(primaryFont, OpenTypeMathData::LowerLimitGapMin);
+                parameters.overGapMin = mathData->getMathConstant(primaryFont, OpenTypeMathData::UpperLimitGapMin);
+                parameters.underShiftMin = mathData->getMathConstant(primaryFont, OpenTypeMathData::LowerLimitBaselineDropMin);
+                parameters.overShiftMin = mathData->getMathConstant(primaryFont, OpenTypeMathData::UpperLimitBaselineRiseMin);
+                parameters.useUnderOverBarFallBack = false;
+                return parameters;
             }
             if (baseOperator->hasOperatorFlag(MathMLOperatorDictionary::Stretchy) && !baseOperator->isVertical()) {
                 // The base is a horizontal stretchy operator, so we read StretchStack constants from the MATH table.
-                underGapMin = mathData->getMathConstant(primaryFont, OpenTypeMathData::StretchStackGapBelowMin);
-                overGapMin = mathData->getMathConstant(primaryFont, OpenTypeMathData::StretchStackGapAboveMin);
-                underShiftMin = mathData->getMathConstant(primaryFont, OpenTypeMathData::StretchStackBottomShiftDown);
-                overShiftMin = mathData->getMathConstant(primaryFont, OpenTypeMathData::StretchStackTopShiftUp);
-                return false;
+                parameters.underGapMin = mathData->getMathConstant(primaryFont, OpenTypeMathData::StretchStackGapBelowMin);
+                parameters.overGapMin = mathData->getMathConstant(primaryFont, OpenTypeMathData::StretchStackGapAboveMin);
+                parameters.underShiftMin = mathData->getMathConstant(primaryFont, OpenTypeMathData::StretchStackBottomShiftDown);
+                parameters.overShiftMin = mathData->getMathConstant(primaryFont, OpenTypeMathData::StretchStackTopShiftUp);
+                parameters.useUnderOverBarFallBack = false;
+                return parameters;
             }
         }
     }
 
     // By default, we just use the underbar/overbar constants.
-    underGapMin = mathData->getMathConstant(primaryFont, OpenTypeMathData::UnderbarVerticalGap);
-    overGapMin = mathData->getMathConstant(primaryFont, OpenTypeMathData::OverbarVerticalGap);
-    underExtraDescender = mathData->getMathConstant(primaryFont, OpenTypeMathData::UnderbarExtraDescender);
-    overExtraAscender = mathData->getMathConstant(primaryFont, OpenTypeMathData::OverbarExtraAscender);
-    accentBaseHeight = mathData->getMathConstant(primaryFont, OpenTypeMathData::AccentBaseHeight);
-    return true;
+    parameters.underGapMin = mathData->getMathConstant(primaryFont, OpenTypeMathData::UnderbarVerticalGap);
+    parameters.overGapMin = mathData->getMathConstant(primaryFont, OpenTypeMathData::OverbarVerticalGap);
+    parameters.underExtraDescender = mathData->getMathConstant(primaryFont, OpenTypeMathData::UnderbarExtraDescender);
+    parameters.overExtraAscender = mathData->getMathConstant(primaryFont, OpenTypeMathData::OverbarExtraAscender);
+    parameters.accentBaseHeight = mathData->getMathConstant(primaryFont, OpenTypeMathData::AccentBaseHeight);
+    parameters.useUnderOverBarFallBack = true;
+    return parameters;
 }
 
 void RenderMathMLUnderOver::layoutBlock(bool relayoutChildren, LayoutUnit pageLogicalHeight)
@@ -261,38 +275,37 @@
         logicalWidth = std::max(logicalWidth, over().logicalWidth());
     setLogicalWidth(logicalWidth);
 
-    LayoutUnit underGapMin, overGapMin, underShiftMin, overShiftMin, underExtraDescender, overExtraAscender, accentBaseHeight;
-    bool underOverBarFall = getVerticalParameters(underGapMin, overGapMin, underShiftMin, overShiftMin, underExtraDescender, overExtraAscender, accentBaseHeight);
+    VerticalParameters parameters = verticalParameters();
     LayoutUnit verticalOffset = 0;
     if (m_scriptType == Over || m_scriptType == UnderOver) {
-        verticalOffset += overExtraAscender;
+        verticalOffset += parameters.overExtraAscender;
         over().setLocation(LayoutPoint(horizontalOffset(over()), verticalOffset));
-        if (underOverBarFall) {
+        if (parameters.useUnderOverBarFallBack) {
             verticalOffset += over().logicalHeight();
             if (hasAccent()) {
                 LayoutUnit baseAscent = ascentForChild(base());
-                if (baseAscent < accentBaseHeight)
-                    verticalOffset += accentBaseHeight - baseAscent;
+                if (baseAscent < parameters.accentBaseHeight)
+                    verticalOffset += parameters.accentBaseHeight - baseAscent;
             } else
-                verticalOffset += overGapMin;
+                verticalOffset += parameters.overGapMin;
         } else {
             LayoutUnit overAscent = ascentForChild(over());
-            verticalOffset += std::max(over().logicalHeight() + overGapMin, overAscent + overShiftMin);
+            verticalOffset += std::max(over().logicalHeight() + parameters.overGapMin, overAscent + parameters.overShiftMin);
         }
     }
     base().setLocation(LayoutPoint(horizontalOffset(base()), verticalOffset));
     verticalOffset += base().logicalHeight();
     if (m_scriptType == Under || m_scriptType == UnderOver) {
-        if (underOverBarFall) {
+        if (parameters.useUnderOverBarFallBack) {
             if (!hasAccentUnder())
-                verticalOffset += underGapMin;
+                verticalOffset += parameters.underGapMin;
         } else {
             LayoutUnit underAscent = ascentForChild(under());
-            verticalOffset += std::max(underGapMin, underShiftMin - underAscent);
+            verticalOffset += std::max(parameters.underGapMin, parameters.underShiftMin - underAscent);
         }
         under().setLocation(LayoutPoint(horizontalOffset(under()), verticalOffset));
         verticalOffset += under().logicalHeight();
-        verticalOffset += underExtraDescender;
+        verticalOffset += parameters.underExtraDescender;
     }
 
     setLogicalHeight(verticalOffset);

Modified: trunk/Source/WebCore/rendering/mathml/RenderMathMLUnderOver.h (205104 => 205105)


--- trunk/Source/WebCore/rendering/mathml/RenderMathMLUnderOver.h	2016-08-28 16:54:43 UTC (rev 205104)
+++ trunk/Source/WebCore/rendering/mathml/RenderMathMLUnderOver.h	2016-08-28 17:36:05 UTC (rev 205105)
@@ -56,7 +56,17 @@
     LayoutUnit horizontalOffset(const RenderBox&) const;
     bool hasAccent(bool accentUnder = false) const;
     bool hasAccentUnder() const { return hasAccent(true); };
-    bool getVerticalParameters(LayoutUnit& underGapMin, LayoutUnit& overGapMin, LayoutUnit& underShiftMin, LayoutUnit& overShiftMin, LayoutUnit& underExtraDescender, LayoutUnit& overExtraAscender, LayoutUnit& accentBaseHeight) const;
+    struct VerticalParameters {
+        bool useUnderOverBarFallBack;
+        LayoutUnit underGapMin;
+        LayoutUnit overGapMin;
+        LayoutUnit underShiftMin;
+        LayoutUnit overShiftMin;
+        LayoutUnit underExtraDescender;
+        LayoutUnit overExtraAscender;
+        LayoutUnit accentBaseHeight;
+    };
+    VerticalParameters verticalParameters() const;
 };
 
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to