Title: [205098] trunk
Revision
205098
Author
[email protected]
Date
2016-08-28 01:26:07 -0700 (Sun, 28 Aug 2016)

Log Message

More cleanup for the mpadded implementation
https://bugs.webkit.org/show_bug.cgi?id=161136

Source/WebCore:

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

We perform the following cleanup for the mpadded renderer class:
1) We do not store the ascent on the class. This may make update more reliable and will
help for general improvement of MathML ascents (bug 155879).
2) We split resolveWidth/resolveAttributes into smaller functions and improve the coding
style. This helps to calculate firstLineBaseline in 1).
3) We do not override updateFromElement and styleDidChange to perform setNeedsLayout calls.
These calls already seem unnecessary and can be removed even more safely after 1).

We add a test for style change. Change of attributes as well as metrics calcuation of empty
and non-empty mpadded elements are already covered by other tests.

Test: mathml/presentation/mpadded-style-change.html

* rendering/mathml/RenderMathMLPadded.cpp:
(WebCore::RenderMathMLPadded::voffset): New helper function to resolve voffset.
(WebCore::RenderMathMLPadded::lspace): Ditto for lspace.
(WebCore::RenderMathMLPadded::mpaddedWidth): Ditto for width.
(WebCore::RenderMathMLPadded::mpaddedHeight): Ditto for height.
(WebCore::RenderMathMLPadded::mpaddedDepth): Ditto for detph.
(WebCore::RenderMathMLPadded::computePreferredLogicalWidths): Use mpaddedWidth().
(WebCore::RenderMathMLPadded::layoutBlock): Use the new helper functions.
(WebCore::RenderMathMLPadded::firstLineBaseline): Use voffset or mpaddedHeight for baseline
calculation instead of m_padded.
(WebCore::RenderMathMLPadded::resolveWidth): Deleted. Renamed mpaddedWidth.
(WebCore::RenderMathMLPadded::resolveAttributes): Deleted. Split into smaller functions.
(WebCore::RenderMathMLPadded::updateFromElement): Deleted. We do not need to call
setNeedsLayout.
(WebCore::RenderMathMLPadded::styleDidChange): Deleted. Ditto.
* rendering/mathml/RenderMathMLPadded.h: Update function declaration and remove m_ascent.

LayoutTests:

We add a test for style change in mpadded.

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

* mathml/presentation/mpadded-style-change-expected.html: Added.
* mathml/presentation/mpadded-style-change.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (205097 => 205098)


--- trunk/LayoutTests/ChangeLog	2016-08-28 05:55:17 UTC (rev 205097)
+++ trunk/LayoutTests/ChangeLog	2016-08-28 08:26:07 UTC (rev 205098)
@@ -1,3 +1,15 @@
+2016-08-28  Frederic Wang  <[email protected]>
+
+        More cleanup for the mpadded implementation
+        https://bugs.webkit.org/show_bug.cgi?id=161136
+
+        We add a test for style change in mpadded.
+
+        Reviewed by Darin Adler.
+
+        * mathml/presentation/mpadded-style-change-expected.html: Added.
+        * mathml/presentation/mpadded-style-change.html: Added.
+
 2016-08-27  Chris Dumez  <[email protected]>
 
         Update generated bindings to throw a SecurityError when denying cross-origin access to properties

Added: trunk/LayoutTests/mathml/presentation/mpadded-style-change-expected.html (0 => 205098)


--- trunk/LayoutTests/mathml/presentation/mpadded-style-change-expected.html	                        (rev 0)
+++ trunk/LayoutTests/mathml/presentation/mpadded-style-change-expected.html	2016-08-28 08:26:07 UTC (rev 205098)
@@ -0,0 +1,21 @@
+<!doctype html>
+<html class="reftest-wait">
+  <head>
+    <title>mpadded style change</title>
+    <meta charset="utf-8"/>
+    <style>
+      math.large { font-size: 2px; }
+    </style>
+  </head>
+  <body>
+    <math class="large">
+      <mspace width="10em" height="5em" depth="5em" mathbackground="green"/>
+      <mpadded mathbackground="blue"
+               width="40em" depth="30em" height="20em"
+               lspace="5em" voffset="-15em">
+        <mspace width="10em" height="5em" depth="5em" mathbackground="red"/>
+      </mpadded>
+      <mspace width="10em" height="5em" depth="5em" mathbackground="green"/>
+    </math>
+  </body>
+</html>

Added: trunk/LayoutTests/mathml/presentation/mpadded-style-change.html (0 => 205098)


--- trunk/LayoutTests/mathml/presentation/mpadded-style-change.html	                        (rev 0)
+++ trunk/LayoutTests/mathml/presentation/mpadded-style-change.html	2016-08-28 08:26:07 UTC (rev 205098)
@@ -0,0 +1,29 @@
+<!doctype html>
+<html class="reftest-wait">
+  <head>
+    <title>mpadded style change</title>
+    <meta charset="utf-8"/>
+    <style>
+      math.normal { font-size: 1px; }
+      math.large { font-size: 2px; }
+    </style>
+    <script type="text/_javascript_">
+      function doTest() {
+        document.getElementById("math").setAttribute("class", "large")
+        document.documentElement.removeAttribute("class");
+      }
+      window.addEventListener("load", doTest, false);
+    </script>
+  </head>
+  <body>
+    <math id="math" class="normal">
+      <mspace width="10em" height="5em" depth="5em" mathbackground="green"/>
+      <mpadded mathbackground="blue"
+               width="40em" depth="30em" height="20em"
+               lspace="5em" voffset="-15em">
+        <mspace width="10em" height="5em" depth="5em" mathbackground="red"/>
+      </mpadded>
+      <mspace width="10em" height="5em" depth="5em" mathbackground="green"/>
+    </math>
+  </body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (205097 => 205098)


--- trunk/Source/WebCore/ChangeLog	2016-08-28 05:55:17 UTC (rev 205097)
+++ trunk/Source/WebCore/ChangeLog	2016-08-28 08:26:07 UTC (rev 205098)
@@ -1,3 +1,40 @@
+2016-08-28  Frederic Wang  <[email protected]>
+
+        More cleanup for the mpadded implementation
+        https://bugs.webkit.org/show_bug.cgi?id=161136
+
+        Reviewed by Darin Adler.
+
+        We perform the following cleanup for the mpadded renderer class:
+        1) We do not store the ascent on the class. This may make update more reliable and will
+        help for general improvement of MathML ascents (bug 155879).
+        2) We split resolveWidth/resolveAttributes into smaller functions and improve the coding
+        style. This helps to calculate firstLineBaseline in 1).
+        3) We do not override updateFromElement and styleDidChange to perform setNeedsLayout calls.
+        These calls already seem unnecessary and can be removed even more safely after 1).
+
+        We add a test for style change. Change of attributes as well as metrics calcuation of empty
+        and non-empty mpadded elements are already covered by other tests.
+
+        Test: mathml/presentation/mpadded-style-change.html
+
+        * rendering/mathml/RenderMathMLPadded.cpp:
+        (WebCore::RenderMathMLPadded::voffset): New helper function to resolve voffset.
+        (WebCore::RenderMathMLPadded::lspace): Ditto for lspace.
+        (WebCore::RenderMathMLPadded::mpaddedWidth): Ditto for width.
+        (WebCore::RenderMathMLPadded::mpaddedHeight): Ditto for height.
+        (WebCore::RenderMathMLPadded::mpaddedDepth): Ditto for detph.
+        (WebCore::RenderMathMLPadded::computePreferredLogicalWidths): Use mpaddedWidth().
+        (WebCore::RenderMathMLPadded::layoutBlock): Use the new helper functions.
+        (WebCore::RenderMathMLPadded::firstLineBaseline): Use voffset or mpaddedHeight for baseline
+        calculation instead of m_padded.
+        (WebCore::RenderMathMLPadded::resolveWidth): Deleted. Renamed mpaddedWidth.
+        (WebCore::RenderMathMLPadded::resolveAttributes): Deleted. Split into smaller functions.
+        (WebCore::RenderMathMLPadded::updateFromElement): Deleted. We do not need to call
+        setNeedsLayout.
+        (WebCore::RenderMathMLPadded::styleDidChange): Deleted. Ditto.
+        * rendering/mathml/RenderMathMLPadded.h: Update function declaration and remove m_ascent.
+
 2016-08-27  Alex Christensen  <[email protected]>
 
         URLParser should parse relative URLs

Modified: trunk/Source/WebCore/rendering/mathml/RenderMathMLPadded.cpp (205097 => 205098)


--- trunk/Source/WebCore/rendering/mathml/RenderMathMLPadded.cpp	2016-08-28 05:55:17 UTC (rev 205097)
+++ trunk/Source/WebCore/rendering/mathml/RenderMathMLPadded.cpp	2016-08-28 08:26:07 UTC (rev 205098)
@@ -37,31 +37,33 @@
 {
 }
 
-void RenderMathMLPadded::resolveWidth(LayoutUnit& width)
+LayoutUnit RenderMathMLPadded::voffset() const
 {
-    auto& paddedElement = element();
-    width = toUserUnits(paddedElement.width(), style(), width);
-    if (width < 0)
-        width = 0;
+    return toUserUnits(element().voffset(), style(), 0);
 }
 
-void RenderMathMLPadded::resolveAttributes(LayoutUnit& width, LayoutUnit& height, LayoutUnit& depth, LayoutUnit& lspace, LayoutUnit& voffset)
+LayoutUnit RenderMathMLPadded::lspace() const
 {
-    resolveWidth(width);
-    auto& paddedElement = element();
-    height = toUserUnits(paddedElement.height(), style(), height);
-    depth = toUserUnits(paddedElement.depth(), style(), depth);
-    lspace = toUserUnits(paddedElement.lspace(), style(), lspace);
-    voffset = toUserUnits(paddedElement.voffset(), style(), voffset);
-    if (height < 0)
-        height = 0;
-    if (depth < 0)
-        depth = 0;
+    LayoutUnit lspace = toUserUnits(element().lspace(), style(), 0);
     // FIXME: Negative lspace values are not supported yet (https://bugs.webkit.org/show_bug.cgi?id=85730).
-    if (lspace < 0)
-        lspace = 0;
+    return std::max<LayoutUnit>(0, lspace);
 }
 
+LayoutUnit RenderMathMLPadded::mpaddedWidth(LayoutUnit contentWidth) const
+{
+    return std::max<LayoutUnit>(0, toUserUnits(element().width(), style(), contentWidth));
+}
+
+LayoutUnit RenderMathMLPadded::mpaddedHeight(LayoutUnit contentHeight) const
+{
+    return std::max<LayoutUnit>(0, toUserUnits(element().height(), style(), contentHeight));
+}
+
+LayoutUnit RenderMathMLPadded::mpaddedDepth(LayoutUnit contentDepth) const
+{
+    return std::max<LayoutUnit>(0, toUserUnits(element().depth(), style(), contentDepth));
+}
+
 void RenderMathMLPadded::computePreferredLogicalWidths()
 {
     ASSERT(preferredLogicalWidthsDirty());
@@ -71,9 +73,8 @@
 
     // Only the width attribute should modify the width.
     // We parse it using the preferred width of the content as its default value.
-    LayoutUnit width = m_maxPreferredLogicalWidth;
-    resolveWidth(width);
-    m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = width;
+    m_maxPreferredLogicalWidth = mpaddedWidth(m_maxPreferredLogicalWidth);
+    m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth;
 
     setPreferredLogicalWidthsDirty(false);
 }
@@ -93,41 +94,31 @@
     contentWidth = logicalWidth();
 
     // We parse the mpadded attributes using the content metrics as the default value.
-    LayoutUnit width = contentWidth;
-    LayoutUnit ascent = contentAscent;
-    LayoutUnit descent = contentDescent;
-    LayoutUnit lspace = 0;
-    LayoutUnit voffset = 0;
-    resolveAttributes(width, ascent, descent, lspace, voffset);
+    LayoutUnit width = mpaddedWidth(contentWidth);
+    LayoutUnit ascent = mpaddedHeight(contentAscent);
+    LayoutUnit descent = mpaddedDepth(contentDescent);
 
     // Align children on the new baseline and shift them by (lspace, -voffset)
-    LayoutPoint contentLocation(lspace, ascent - contentAscent - voffset);
+    LayoutPoint contentLocation(lspace(), ascent - contentAscent - voffset());
     for (auto* child = firstChildBox(); child; child = child->nextSiblingBox())
         child->setLocation(child->location() + contentLocation);
 
     // Set the final metrics.
     setLogicalWidth(width);
-    m_ascent = ascent;
     setLogicalHeight(ascent + descent);
 
     clearNeedsLayout();
 }
 
-void RenderMathMLPadded::updateFromElement()
-{
-    RenderMathMLRow::updateFromElement();
-    setNeedsLayoutAndPrefWidthsRecalc();
-}
-
-void RenderMathMLPadded::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
-{
-    RenderMathMLRow::styleDidChange(diff, oldStyle);
-    setNeedsLayoutAndPrefWidthsRecalc();
-}
-
 Optional<int> RenderMathMLPadded::firstLineBaseline() const
 {
-    return Optional<int>(std::lround(static_cast<float>(m_ascent)));
+    // We try and calculate the baseline from the position of the first child.
+    LayoutUnit ascent;
+    if (auto* baselineChild = firstChildBox())
+        ascent = ascentForChild(*baselineChild) + baselineChild->logicalTop() + voffset();
+    else
+        ascent = mpaddedHeight(0);
+    return Optional<int>(std::lround(static_cast<float>(ascent)));
 }
 
 }

Modified: trunk/Source/WebCore/rendering/mathml/RenderMathMLPadded.h (205097 => 205098)


--- trunk/Source/WebCore/rendering/mathml/RenderMathMLPadded.h	2016-08-28 05:55:17 UTC (rev 205097)
+++ trunk/Source/WebCore/rendering/mathml/RenderMathMLPadded.h	2016-08-28 08:26:07 UTC (rev 205098)
@@ -44,14 +44,12 @@
     void layoutBlock(bool relayoutChildren, LayoutUnit pageLogicalHeight = 0) final;
     Optional<int> firstLineBaseline() const final;
 
-    void updateFromElement() final;
-    void styleDidChange(StyleDifference, const RenderStyle* oldStyle) final;
-
     MathMLPaddedElement& element() const { return static_cast<MathMLPaddedElement&>(nodeForNonAnonymous()); }
-    void resolveWidth(LayoutUnit& width);
-    void resolveAttributes(LayoutUnit& width, LayoutUnit& height, LayoutUnit& depth, LayoutUnit& lspace, LayoutUnit& voffset);
-
-    LayoutUnit m_ascent;
+    LayoutUnit voffset() const;
+    LayoutUnit lspace() const;
+    LayoutUnit mpaddedWidth(LayoutUnit contentWidth) const;
+    LayoutUnit mpaddedHeight(LayoutUnit contentHeight) const;
+    LayoutUnit mpaddedDepth(LayoutUnit contentDepth) const;
 };
 
 } // namespace WebCore
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to