Changeset 198998 in webkit


Ignore:
Timestamp:
Apr 4, 2016 1:25:37 AM (8 years ago)
Author:
fred.wang@free.fr
Message:

Refactor RenderMathMLRow layout functions to avoid using flexbox
https://bugs.webkit.org/show_bug.cgi?id=153208

Patch by Frederic Wang <fwang@igalia.com> on 2016-04-04
Reviewed by Martin Robinson.

Source/WebCore:

This is the first patch to rewrite MathML layout without relying on
flexboxes or anonymous renderers.
We have done some temporary changes to allow overriding of
layoutBlock and to implement paintChildren, but this will be remove in a
follow-up patch. We also implement firstLineBaseline,
computePreferredLogicalWidths and layoutBlock of RenderMathMLRow without
using any flexbox functions. We adjust a bit the MathML CSS to take into
account these changes. Finally, we delete the unused helper function to
create anonymous RenderMathMLRow.

  • css/mathml.css:

(ms, mtext, mi, mn, mo, annotation, mtd): Prevent linebreaking inside token elements and table cells, otherwise this cause test failures with the new implementation of RenderMathMLRow.
(math, mrow, mfenced, merror, mphantom, mstyle, menclose): Deleted. We no longer rely on flexbox for baseline alignment of RenderMathMLRow.

  • rendering/RenderFlexibleBox.h: Allow overrider of the LayoutBlock for the moment.
  • rendering/RenderObject.h:

(WebCore::RenderObject::isRenderMathMLMenclose): Add helper function.

  • rendering/mathml/RenderMathMLMenclose.h: ditto.
  • rendering/mathml/RenderMathMLBlock.h:

(WebCore::ascentForChild): Add helper function to easily compute the ascent of a child.

  • rendering/mathml/RenderMathMLRow.cpp: Reimplement the class without using the flexbox layout.

(WebCore::RenderMathMLRow::firstLineBaseline): Implement the function to determine the baseline.
(WebCore::RenderMathMLRow::computeLineVerticalStretch): Add a function that browses non-stretchy children to determine the desired vertical stretch metrics.
(WebCore::RenderMathMLRow::computePreferredLogicalWidths): Implement the function to determine the preferred widths of the RenderMathMLRow.
(WebCore::RenderMathMLRow::layoutRowItems): Helper function that layouts children (stretching vertical operators if needed), calculate the exact logical width and position children.
(WebCore::RenderMathMLRow::layoutBlock): Implement the function to do the actual layout, which essentially calls layoutRowItems.
(WebCore::RenderMathMLRow::paintChildren): Temporarily implement this function, which just calls paintChild on each child.
(WebCore::RenderMathMLRow::createAnonymousWithParentRenderer): Deleted. We actually don't create anonymous RenderMathMLRow at the moment.
(WebCore::RenderMathMLRow::layout): Deleted.

  • rendering/mathml/RenderMathMLRow.h: Update declarations of functions.

LayoutTests:

Apply some small adjustments to MathML tests after the refactoring of RenderMathMLRow.

  • TestExpectations: Skip fractions-positions reftest for now. The small difference will be fixed after refactoring completely RenderMathMLFraction. We also ignore a test for margin/padding on MathML renderers.
  • platform/gtk/mathml/opentype/opentype-stretchy-horizontal-expected.png: Update reference to take into account small changes in stretch size.

The intended test behavior (reading variants and construction from the MATH table) is preserved.

  • platform/gtk/mathml/opentype/opentype-stretchy-horizontal-expected.txt: ditto.
  • platform/mac/mathml/opentype/opentype-stretchy-horizontal-expected.png: ditto.
  • platform/mac/mathml/opentype/opentype-stretchy-horizontal-expected.txt: ditto.
Location:
trunk
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r198996 r198998  
     12016-04-04  Frederic Wang  <fwang@igalia.com>
     2
     3        Refactor RenderMathMLRow layout functions to avoid using flexbox
     4        https://bugs.webkit.org/show_bug.cgi?id=153208
     5
     6        Reviewed by Martin Robinson.
     7
     8        Apply some small adjustments to MathML tests after the refactoring of RenderMathMLRow.
     9
     10        * TestExpectations: Skip fractions-positions reftest for now. The small difference will be fixed after refactoring completely RenderMathMLFraction.
     11          We also ignore a test for margin/padding on MathML renderers.
     12        * platform/gtk/mathml/opentype/opentype-stretchy-horizontal-expected.png: Update reference to take into account small changes in stretch size.
     13        The intended test behavior (reading variants and construction from the MATH table) is preserved.
     14        * platform/gtk/mathml/opentype/opentype-stretchy-horizontal-expected.txt: ditto.
     15        * platform/mac/mathml/opentype/opentype-stretchy-horizontal-expected.png: ditto.
     16        * platform/mac/mathml/opentype/opentype-stretchy-horizontal-expected.txt: ditto.
     17
    1182016-04-04  Hunseop Jeong  <hs85.jeong@samsung.com>
    219
  • trunk/LayoutTests/TestExpectations

    r198955 r198998  
    112112# This test verifies dynamic manipulation of the mroot and msqrt elements.
    113113mathml/roots-removeChild.html [ ImageOnlyFailure ]
     114
     115# There is a small 1px size difference but this will be fixed when we refactor completely RenderMathMLFraction.
     116mathml/presentation/fractions-positions.html [ Skip ]
     117
     118# For now we ignore margin/padding/border properties of MathML renderers.
     119mathml/presentation/bug97990.html [ Skip ]
    114120
    115121# This test verifies that a mismatch reftest will fail as intended if both results are same. (introduced in r93187)
  • trunk/LayoutTests/platform/gtk/mathml/opentype/opentype-stretchy-horizontal-expected.txt

    r174605 r198998  
    55    RenderBody {BODY} at (8,16) size 784x125
    66      RenderBlock {P} at (0,0) size 784x25
    7         RenderMathMLMath {math} at (0,2) size 18x23 [padding: 0 1 0 1]
    8           RenderMathMLRow {mstyle} at (1,0) size 16x23
    9             RenderMathMLUnderOver {mover} at (0,0) size 16x23
    10               RenderMathMLOperator {mo} at (0,1) size 16x22
     7        RenderMathMLMath {math} at (0,2) size 10x23 [padding: 0 1 0 1]
     8          RenderMathMLRow {mstyle} at (1,0) size 8x23
     9            RenderMathMLUnderOver {mover} at (0,0) size 8x23
     10              RenderMathMLOperator {mo} at (-5,1) size 17x22
    1111                RenderMathMLBlock (anonymous, flex) at (2,0) size 11x4
    1212                  RenderBlock (anonymous) at (0,0) size 1x4
    1313                    RenderText at (0,-3) size 1x0
    1414                      text run at (0,-3) width 1: "\x{219C}"
    15               RenderMathMLSpace {mspace} at (4,0) size 8x1
     15              RenderMathMLSpace {mspace} at (0,0) size 8x1
    1616        RenderText {#text} at (0,0) size 0x0
    1717      RenderBlock {P} at (0,41) size 784x25
    18         RenderMathMLMath {math} at (0,2) size 28x23 [padding: 0 1 0 1]
    19           RenderMathMLRow {mstyle} at (1,0) size 26x23
    20             RenderMathMLUnderOver {mover} at (0,0) size 26x23
    21               RenderMathMLOperator {mo} at (0,1) size 26x22
     18        RenderMathMLMath {math} at (0,2) size 17x23 [padding: 0 1 0 1]
     19          RenderMathMLRow {mstyle} at (1,0) size 15x23
     20            RenderMathMLUnderOver {mover} at (0,0) size 15x23
     21              RenderMathMLOperator {mo} at (-6,1) size 27x22
    2222                RenderMathMLBlock (anonymous, flex) at (2,0) size 21x4
    2323                  RenderBlock (anonymous) at (0,0) size 1x4
    2424                    RenderText at (0,-3) size 1x0
    2525                      text run at (0,-3) width 1: "\x{219C}"
    26               RenderMathMLSpace {mspace} at (5,0) size 16x1
     26              RenderMathMLSpace {mspace} at (0,0) size 15x1
    2727        RenderText {#text} at (0,0) size 0x0
    2828      RenderBlock {P} at (0,82) size 784x43
    29         RenderMathMLMath {math} at (0,0) size 158x43 [padding: 0 1 0 1]
    30           RenderMathMLRow {mstyle} at (1,0) size 156x43
    31             RenderMathMLUnderOver {mover} at (0,0) size 156x43
    32               RenderMathMLOperator {mo} at (0,1) size 156x42
     29        RenderMathMLMath {math} at (0,0) size 152x43 [padding: 0 1 0 1]
     30          RenderMathMLRow {mstyle} at (1,0) size 150x43
     31            RenderMathMLUnderOver {mover} at (0,0) size 150x43
     32              RenderMathMLOperator {mo} at (-3,1) size 156x42
    3333                RenderMathMLBlock (anonymous, flex) at (2,0) size 151x4
    3434                  RenderBlock (anonymous) at (0,0) size 1x4
    3535                    RenderText at (0,-3) size 1x0
    3636                      text run at (0,-3) width 1: "\x{219C}"
    37               RenderMathMLSpace {mspace} at (2,0) size 151x1
     37              RenderMathMLSpace {mspace} at (0,0) size 150x1
    3838        RenderText {#text} at (0,0) size 0x0
  • trunk/LayoutTests/platform/mac/mathml/opentype/opentype-stretchy-horizontal-expected.txt

    r191456 r198998  
    55    RenderBody {BODY} at (8,16) size 784x121
    66      RenderBlock {P} at (0,0) size 784x24
    7         RenderMathMLMath {math} at (0,3) size 18x22 [padding: 0 1 0 1]
    8           RenderMathMLRow {mstyle} at (1,0) size 16x22
    9             RenderMathMLUnderOver {mover} at (0,0) size 16x22
    10               RenderMathMLOperator {mo} at (0,1) size 16x21
     7        RenderMathMLMath {math} at (0,3) size 10x22 [padding: 0 1 0 1]
     8          RenderMathMLRow {mstyle} at (1,0) size 8x22
     9            RenderMathMLUnderOver {mover} at (0,0) size 8x22
     10              RenderMathMLOperator {mo} at (-5,1) size 17x21
    1111                RenderMathMLBlock (anonymous, flex) at (2,0) size 11x4
    1212                  RenderBlock (anonymous) at (0,0) size 2x4
    1313                    RenderText at (0,-3) size 2x0
    1414                      text run at (0,-3) width 2: "\x{219C}"
    15               RenderMathMLSpace {mspace} at (4,0) size 8x1
     15              RenderMathMLSpace {mspace} at (0,0) size 8x1
    1616        RenderText {#text} at (0,0) size 0x0
    1717      RenderBlock {P} at (0,40) size 784x24
    18         RenderMathMLMath {math} at (0,3) size 28x22 [padding: 0 1 0 1]
    19           RenderMathMLRow {mstyle} at (1,0) size 26x22
    20             RenderMathMLUnderOver {mover} at (0,0) size 26x22
    21               RenderMathMLOperator {mo} at (0,1) size 26x21
     18        RenderMathMLMath {math} at (0,3) size 17x22 [padding: 0 1 0 1]
     19          RenderMathMLRow {mstyle} at (1,0) size 15x22
     20            RenderMathMLUnderOver {mover} at (0,0) size 15x22
     21              RenderMathMLOperator {mo} at (-6,1) size 27x21
    2222                RenderMathMLBlock (anonymous, flex) at (2,0) size 22x4
    2323                  RenderBlock (anonymous) at (0,0) size 2x4
    2424                    RenderText at (0,-3) size 2x0
    2525                      text run at (0,-3) width 2: "\x{219C}"
    26               RenderMathMLSpace {mspace} at (5,0) size 16x1
     26              RenderMathMLSpace {mspace} at (0,0) size 15x1
    2727        RenderText {#text} at (0,0) size 0x0
    2828      RenderBlock {P} at (0,80) size 784x41
    29         RenderMathMLMath {math} at (0,0) size 158x42 [padding: 0 1 0 1]
    30           RenderMathMLRow {mstyle} at (1,0) size 156x42
    31             RenderMathMLUnderOver {mover} at (0,0) size 156x42
    32               RenderMathMLOperator {mo} at (0,1) size 156x41
     29        RenderMathMLMath {math} at (0,0) size 152x42 [padding: 0 1 0 1]
     30          RenderMathMLRow {mstyle} at (1,0) size 150x42
     31            RenderMathMLUnderOver {mover} at (0,0) size 150x42
     32              RenderMathMLOperator {mo} at (-3,1) size 156x41
    3333                RenderMathMLBlock (anonymous, flex) at (2,0) size 151x4
    3434                  RenderBlock (anonymous) at (0,0) size 2x4
    3535                    RenderText at (0,-3) size 2x0
    3636                      text run at (0,-3) width 2: "\x{219C}"
    37               RenderMathMLSpace {mspace} at (2,0) size 151x1
     37              RenderMathMLSpace {mspace} at (0,0) size 150x1
    3838        RenderText {#text} at (0,0) size 0x0
  • trunk/Source/WebCore/ChangeLog

    r198997 r198998  
     12016-04-04  Frederic Wang  <fwang@igalia.com>
     2
     3        Refactor RenderMathMLRow layout functions to avoid using flexbox
     4        https://bugs.webkit.org/show_bug.cgi?id=153208
     5
     6        Reviewed by Martin Robinson.
     7
     8        This is the first patch to rewrite MathML layout without relying on
     9        flexboxes or anonymous renderers.
     10        We have done some temporary changes to allow overriding of
     11        layoutBlock and to implement paintChildren, but this will be remove in a
     12        follow-up patch. We also implement firstLineBaseline,
     13        computePreferredLogicalWidths and layoutBlock of RenderMathMLRow without
     14        using any flexbox functions. We adjust a bit the MathML CSS to take into
     15        account these changes. Finally, we delete the unused helper function to
     16        create anonymous RenderMathMLRow.
     17
     18        * css/mathml.css:
     19        (ms, mtext, mi, mn, mo, annotation, mtd): Prevent linebreaking inside token elements and table cells, otherwise this cause test failures with the new implementation of RenderMathMLRow.
     20        (math, mrow, mfenced, merror, mphantom, mstyle, menclose): Deleted. We no longer rely on flexbox for baseline alignment of RenderMathMLRow.
     21        * rendering/RenderFlexibleBox.h: Allow overrider of the LayoutBlock for the moment.
     22        * rendering/RenderObject.h:
     23        (WebCore::RenderObject::isRenderMathMLMenclose): Add helper function.
     24        * rendering/mathml/RenderMathMLMenclose.h: ditto.
     25        * rendering/mathml/RenderMathMLBlock.h:
     26        (WebCore::ascentForChild): Add helper function to easily compute the ascent of a child.
     27        * rendering/mathml/RenderMathMLRow.cpp: Reimplement the class without using the flexbox layout.
     28        (WebCore::RenderMathMLRow::firstLineBaseline): Implement the function to determine the baseline.
     29        (WebCore::RenderMathMLRow::computeLineVerticalStretch): Add a function that browses non-stretchy children to determine the desired vertical stretch metrics.
     30        (WebCore::RenderMathMLRow::computePreferredLogicalWidths): Implement the function to determine the preferred widths of the RenderMathMLRow.
     31        (WebCore::RenderMathMLRow::layoutRowItems): Helper function that layouts children (stretching vertical operators if needed), calculate the exact logical width and position children.
     32        (WebCore::RenderMathMLRow::layoutBlock): Implement the function to do the actual layout, which essentially calls layoutRowItems.
     33        (WebCore::RenderMathMLRow::paintChildren): Temporarily implement this function, which just calls paintChild on each child.
     34        (WebCore::RenderMathMLRow::createAnonymousWithParentRenderer): Deleted. We actually don't create anonymous RenderMathMLRow at the moment.
     35        (WebCore::RenderMathMLRow::layout): Deleted.
     36        * rendering/mathml/RenderMathMLRow.h: Update declarations of functions.
     37
    1382016-04-04  Chris Fleizach  <cfleizach@apple.com>
    239
  • trunk/Source/WebCore/css/mathml.css

    r198952 r198998  
    4141}
    4242
    43 math, mrow, mfenced, merror, mphantom, mstyle, menclose {
    44     align-items: baseline;
     43ms, mtext, mi, mn, mo, annotation, mtd {
     44    white-space: nowrap !important;
    4545}
    4646
  • trunk/Source/WebCore/rendering/RenderFlexibleBox.h

    r197566 r198998  
    4747    bool avoidsFloats() const final { return true; }
    4848    bool canDropAnonymousBlockChild() const final { return false; }
    49     void layoutBlock(bool relayoutChildren, LayoutUnit pageLogicalHeight = 0) final;
     49    void layoutBlock(bool relayoutChildren, LayoutUnit pageLogicalHeight = 0) override;
    5050
    5151    int baselinePosition(FontBaseline, bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const override;
  • trunk/Source/WebCore/rendering/RenderObject.h

    r197616 r198998  
    389389    virtual bool isRenderMathMLRow() const { return false; }
    390390    virtual bool isRenderMathMLMath() const { return false; }
     391    virtual bool isRenderMathMLMenclose() const { return false; }
    391392    virtual bool isRenderMathMLFenced() const { return false; }
    392393    virtual bool isRenderMathMLFraction() const { return false; }
  • trunk/Source/WebCore/rendering/mathml/RenderMathMLBlock.h

    r197566 r198998  
    6565    RenderPtr<RenderMathMLBlock> createAnonymousMathMLBlock();
    6666   
     67protected:
     68    static LayoutUnit ascentForChild(const RenderBox& child)
     69    {
     70        return child.firstLineBaseline().valueOr(child.logicalHeight());
     71    }
     72
    6773private:
    6874    bool isRenderMathMLBlock() const final { return true; }
  • trunk/Source/WebCore/rendering/mathml/RenderMathMLMenclose.h

    r197563 r198998  
    3737
    3838private:
    39     const char* renderName() const override { return "RenderMathMLMenclose"; }
    40     void paint(PaintInfo&, const LayoutPoint&) override;
     39    bool isRenderMathMLMenclose() const final { return true; }
     40    const char* renderName() const final { return "RenderMathMLMenclose"; }
     41    void paint(PaintInfo&, const LayoutPoint&) final;
    4142    void updateLogicalHeight() override;
    4243    void addChild(RenderObject* newChild, RenderObject* beforeChild = nullptr) override;
    43     void computePreferredLogicalWidths() override;
     44    void computePreferredLogicalWidths() final;
    4445    bool checkNotationalValuesValidity(const Vector<String>&) const;
    4546};
     
    4748}
    4849
     50SPECIALIZE_TYPE_TRAITS_RENDER_OBJECT(RenderMathMLMenclose, isRenderMathMLMenclose())
     51
    4952#endif // ENABLE(MATHML)
    5053#endif // RenderMathMLMenclose_h
  • trunk/Source/WebCore/rendering/mathml/RenderMathMLRow.cpp

    r194496 r198998  
    11/*
    22 * Copyright (C) 2010 Alex Milowski (alex@milowski.com). All rights reserved.
     3 * Copyright (C) 2016 Igalia S.L.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    4950}
    5051
    51 RenderPtr<RenderMathMLRow> RenderMathMLRow::createAnonymousWithParentRenderer(RenderMathMLRoot& parent)
    52 {
    53     RenderPtr<RenderMathMLRow> newMRow = createRenderer<RenderMathMLRow>(parent.document(), RenderStyle::createAnonymousStyleWithDisplay(&parent.style(), FLEX));
    54     newMRow->initializeStyle();
    55     return newMRow;
    56 }
    57 
    5852void RenderMathMLRow::updateOperatorProperties()
    5953{
     
    6761}
    6862
    69 void RenderMathMLRow::layout()
    70 {
    71     int stretchHeightAboveBaseline = 0, stretchDepthBelowBaseline = 0;
    72     for (RenderObject* child = firstChild(); child; child = child->nextSibling()) {
    73         if (child->needsLayout())
    74             downcast<RenderElement>(*child).layout();
    75         if (is<RenderMathMLBlock>(*child)) {
    76             // We skip the stretchy operators as they must not be included in the computation of the stretch size.
    77             auto* renderOperator = downcast<RenderMathMLBlock>(*child).unembellishedOperator();
     63
     64Optional<int> RenderMathMLRow::firstLineBaseline() const
     65{
     66    RenderBox* baselineChild = firstChildBox();
     67    if (!baselineChild)
     68        return Optional<int>();
     69
     70    return Optional<int>(static_cast<int>(lroundf(ascentForChild(*baselineChild) + baselineChild->logicalTop())));
     71}
     72
     73void RenderMathMLRow::computeLineVerticalStretch(int& stretchHeightAboveBaseline, int& stretchDepthBelowBaseline)
     74{
     75    for (RenderBox* child = firstChildBox(); child; child = child->nextSiblingBox()) {
     76        if (is<RenderMathMLBlock>(child)) {
     77            auto* renderOperator = downcast<RenderMathMLBlock>(child)->unembellishedOperator();
    7878            if (renderOperator && renderOperator->hasOperatorFlag(MathMLOperatorDictionary::Stretchy))
    7979                continue;
    8080        }
    81         LayoutUnit childHeightAboveBaseline = 0, childDepthBelowBaseline = 0;
    82         if (is<RenderMathMLBlock>(*child)) {
    83             RenderMathMLBlock& mathmlChild = downcast<RenderMathMLBlock>(*child);
    84             childHeightAboveBaseline = mathmlChild.firstLineBaseline().valueOr(mathmlChild.logicalHeight());
    85             childDepthBelowBaseline = mathmlChild.logicalHeight() - childHeightAboveBaseline;
    86         } else if (is<RenderMathMLTable>(*child)) {
    87             RenderMathMLTable& tableChild = downcast<RenderMathMLTable>(*child);
    88             childHeightAboveBaseline = tableChild.firstLineBaseline().valueOr(-1);
    89             childDepthBelowBaseline = tableChild.logicalHeight() - childHeightAboveBaseline;
    90         } else if (is<RenderBox>(*child)) {
    91             childHeightAboveBaseline = downcast<RenderBox>(*child).logicalHeight();
    92             childDepthBelowBaseline = 0;
    93         }
     81
     82        child->layoutIfNeeded();
     83
     84        LayoutUnit childHeightAboveBaseline = ascentForChild(*child);
     85        LayoutUnit childDepthBelowBaseline = child->logicalHeight() - childHeightAboveBaseline;
     86
    9487        stretchHeightAboveBaseline = std::max<LayoutUnit>(stretchHeightAboveBaseline, childHeightAboveBaseline);
    9588        stretchDepthBelowBaseline = std::max<LayoutUnit>(stretchDepthBelowBaseline, childDepthBelowBaseline);
    9689    }
    97     if (stretchHeightAboveBaseline + stretchDepthBelowBaseline <= 0)
     90
     91    // We ensure a minimal stretch size.
     92    if (stretchHeightAboveBaseline + stretchDepthBelowBaseline <= 0) {
    9893        stretchHeightAboveBaseline = style().fontSize();
    99    
    100     // Set the sizes of (possibly embellished) stretchy operator children.
    101     for (auto& child : childrenOfType<RenderMathMLBlock>(*this)) {
    102         if (auto renderOperator = child.unembellishedOperator())
    103             renderOperator->stretchTo(stretchHeightAboveBaseline, stretchDepthBelowBaseline);
    104     }
    105 
    106     RenderMathMLBlock::layout();
     94        stretchDepthBelowBaseline = 0;
     95    }
     96}
     97
     98void RenderMathMLRow::computePreferredLogicalWidths()
     99{
     100    ASSERT(preferredLogicalWidthsDirty());
     101
     102    m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = 0;
     103
     104    LayoutUnit preferredWidth = 0;
     105    for (RenderBox* child = firstChildBox(); child; child = child->nextSiblingBox())
     106        preferredWidth += child->maxPreferredLogicalWidth() + child->marginLogicalWidth();
     107
     108    m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = preferredWidth + borderAndPaddingLogicalWidth();
     109
     110    setPreferredLogicalWidthsDirty(false);
     111}
     112
     113void RenderMathMLRow::layoutRowItems(int stretchHeightAboveBaseline, int stretchDepthBelowBaseline)
     114{
     115    // We first stretch the vertical operators.
     116    // For inline formulas, we can then calculate the logical width.
     117    LayoutUnit width = borderAndPaddingStart();
     118    for (RenderBox* child = firstChildBox(); child; child = child->nextSiblingBox()) {
     119        if (child->isOutOfFlowPositioned())
     120            continue;
     121
     122        if (is<RenderMathMLBlock>(child)) {
     123            if (auto renderOperator = downcast<RenderMathMLBlock>(child)->unembellishedOperator())
     124                renderOperator->stretchTo(stretchHeightAboveBaseline, stretchDepthBelowBaseline);
     125        }
     126
     127        child->layoutIfNeeded();
     128
     129        width += child->marginStart() + child->logicalWidth() + child->marginEnd();
     130    }
     131
     132    width += borderEnd() + paddingEnd();
     133    // FIXME: RenderMathMLRoot and RenderMathMLEnclose classes should also recalculate the exact logical width instead of using the preferred width.
     134    // See https://bugs.webkit.org/show_bug.cgi?id=130326
     135    if ((!isRenderMathMLMath() || style().display() == INLINE) && !isRenderMathMLRoot() && !isRenderMathMLMenclose())
     136        setLogicalWidth(width);
     137
     138    LayoutUnit verticalOffset = borderTop() + paddingTop();
     139    LayoutUnit maxAscent = 0, maxDescent = 0; // Used baseline alignment.
     140    LayoutUnit horizontalOffset = borderAndPaddingStart();
     141    bool shouldFlipHorizontal = !style().isLeftToRightDirection();
     142    for (RenderBox* child = firstChildBox(); child; child = child->nextSiblingBox()) {
     143        if (child->isOutOfFlowPositioned()) {
     144            child->containingBlock()->insertPositionedObject(*child);
     145            continue;
     146        }
     147        LayoutUnit childHorizontalExtent = child->logicalWidth();
     148        LayoutUnit ascent = ascentForChild(*child);
     149        LayoutUnit descent = child->verticalMarginExtent() + child->logicalHeight() - ascent;
     150        maxAscent = std::max(maxAscent, ascent);
     151        maxDescent = std::max(maxDescent, descent);
     152        LayoutUnit childVerticalMarginBoxExtent = maxAscent + maxDescent;
     153
     154        horizontalOffset += child->marginStart();
     155
     156        setLogicalHeight(std::max(logicalHeight(), verticalOffset + borderBottom() + paddingBottom() + childVerticalMarginBoxExtent + horizontalScrollbarHeight()));
     157
     158        LayoutPoint childLocation(shouldFlipHorizontal ? logicalWidth() - horizontalOffset - childHorizontalExtent : horizontalOffset, verticalOffset + child->marginTop());
     159        child->setLocation(childLocation);
     160
     161        horizontalOffset += childHorizontalExtent + child->marginEnd();
     162    }
     163
     164    LayoutUnit centerBlockOffset = 0;
     165    // FIXME: Remove the FLEX when it is not required by the css.
     166    if (style().display() == BLOCK || style().display() == FLEX)
     167        centerBlockOffset = std::max<LayoutUnit>(0, (logicalWidth() - (horizontalOffset + borderEnd() + paddingEnd())) / 2);
     168
     169    if (shouldFlipHorizontal && centerBlockOffset > 0)
     170        centerBlockOffset = -centerBlockOffset;
     171
     172    for (RenderBox* child = firstChildBox(); child; child = child->nextSiblingBox()) {
     173        LayoutUnit ascent = ascentForChild(*child);
     174        LayoutUnit startOffset = maxAscent - ascent;
     175        child->setLocation(child->location() + LayoutPoint(centerBlockOffset, startOffset));
     176    }
     177}
     178
     179void RenderMathMLRow::layoutBlock(bool relayoutChildren, LayoutUnit)
     180{
     181    ASSERT(needsLayout());
     182
     183    if (!relayoutChildren && simplifiedLayout())
     184        return;
     185
     186    int stretchHeightAboveBaseline = 0;
     187    int stretchDepthBelowBaseline = 0;
     188    computeLineVerticalStretch(stretchHeightAboveBaseline, stretchDepthBelowBaseline);
     189
     190    recomputeLogicalWidth();
     191
     192    setLogicalHeight(borderAndPaddingLogicalHeight() + scrollbarLogicalHeight());
     193
     194    layoutRowItems(stretchHeightAboveBaseline, stretchDepthBelowBaseline);
     195
     196    updateLogicalHeight();
     197
     198    clearNeedsLayout();
     199}
     200
     201void RenderMathMLRow::paintChildren(PaintInfo& paintInfo, const LayoutPoint& paintOffset, PaintInfo& paintInfoForChild, bool usePrintRect)
     202{
     203    for (RenderBox* child = firstChildBox(); child; child = child->nextSiblingBox()) {
     204        if (!paintChild(*child, paintInfo, paintOffset, paintInfoForChild, usePrintRect, PaintAsInlineBlock))
     205            return;
     206    }
    107207}
    108208
  • trunk/Source/WebCore/rendering/mathml/RenderMathMLRow.h

    r197566 r198998  
    11/*
    22 * Copyright (C) 2010 Alex Milowski (alex@milowski.com). All rights reserved.
     3 * Copyright (C) 2016 Igalia S.L.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    4041    RenderMathMLRow(Document&, Ref<RenderStyle>&&);
    4142
    42     static RenderPtr<RenderMathMLRow> createAnonymousWithParentRenderer(RenderMathMLRoot&);
    4343    void updateOperatorProperties();
    4444
    45 protected:
    46     void layout() override;
     45    void layoutBlock(bool relayoutChildren, LayoutUnit pageLogicalHeight = 0) final;
     46    void paintChildren(PaintInfo& forSelf, const LayoutPoint&, PaintInfo& forChild, bool usePrintRect) final;
     47    Optional<int> firstLineBaseline() const final;
    4748
    4849private:
    4950    bool isRenderMathMLRow() const final { return true; }
    5051    const char* renderName() const override { return isAnonymous() ? "RenderMathMLRow (anonymous)" : "RenderMathMLRow"; }
     52
     53    void layoutRowItems(int stretchHeightAboveBaseline, int stretchDepthBelowBaseline);
     54    void computeLineVerticalStretch(int& stretchHeightAboveBaseline, int& stretchDepthBelowBaseline);
     55    void computePreferredLogicalWidths() override;
    5156};
    5257
Note: See TracChangeset for help on using the changeset viewer.