Changeset 203285 in webkit


Ignore:
Timestamp:
Jul 15, 2016 11:24:47 AM (8 years ago)
Author:
fred.wang@free.fr
Message:

Source/WebCore:
Move parsing of mfrac attributes into a MathMLFractionElement class
https://bugs.webkit.org/show_bug.cgi?id=159624

Patch by Frederic Wang <fwang@igalia.com> on 2016-07-15
Reviewed by Brent Fulgham.

We move the parsing of mfrac attributes to a MathMLFractionElement class. This allows to
minimize the updates in RenderMathMLFraction and to remove the alignment members. Many of
the members in updateLayoutParameters are actually only used in layoutBlock and could be
removed in a follow-up patch. We also improve the resolution of negative line thickness value
since the MathML recommendation says it should be rounded up to the nearest valid
value (which is zero) instead of ignoring the attribute and using the line thickness.

No new tests, already covered by existing tests.

  • CMakeLists.txt: Add MathMLFractionElement.
  • WebCore.xcodeproj/project.pbxproj: Ditto.
  • mathml/MathMLAllInOne.cpp: Ditto.
  • mathml/MathMLFractionElement.cpp: Added.

(WebCore::MathMLFractionElement::MathMLFractionElement):
(WebCore::MathMLFractionElement::create):
(WebCore::MathMLFractionElement::lineThickness): Return the cached linethickness length,
parsing it again if it is dirty. This handles the special values "thin", "medium" and "thick"
or fallback to the general parseMathMLLength for MathML lengths.
(WebCore::MathMLFractionElement::cachedFractionAlignment): Return the cached alignment value,
parsing it again if it is dirty.
(WebCore::MathMLFractionElement::numeratorAlignment): Return the cached alignment.
(WebCore::MathMLFractionElement::denominatorAlignment): Ditto.
(WebCore::MathMLFractionElement::parseAttribute): Make attributes dirty.
(WebCore::MathMLFractionElement::createElementRenderer): Create a RenderMathMLFraction.

  • mathml/MathMLFractionElement.h: Added.
  • mathml/MathMLInlineContainerElement.cpp: We no longer need to handle fraction here.

(WebCore::MathMLInlineContainerElement::createElementRenderer):

  • mathml/mathtags.in: Use MathMLFractionElement for mfrac.
  • rendering/mathml/RenderMathMLFraction.cpp:

(WebCore::RenderMathMLFraction::updateLayoutParameters): New helper function to set the
layout parameters, replacing updateFromElement. We no longer parse and store the alignment
values here. We also change the resolution of negative values.
(WebCore::RenderMathMLFraction::horizontalOffset): Use the enum from MathMLFractionElement.
(WebCore::RenderMathMLFraction::layoutBlock): We call updateLayoutParameters instead of
updateFromElement. The numerator and denominator alignments are resolved here.
(WebCore::RenderMathMLFraction::parseAlignmentAttribute): Deleted. Parsing of alignment
attribute is now handled in MathMLFractionElement.
(WebCore::RenderMathMLFraction::updateFromElement): Deleted. Attribute changes are now
handled in MathMLFractionElement.
(WebCore::RenderMathMLFraction::styleDidChange): Deleted. Font changes are properly handled.

  • rendering/mathml/RenderMathMLFraction.h: Update declarations.

LayoutTests:
Move parsing of mfrac attributes into a MathMLFractionElementClass
https://bugs.webkit.org/show_bug.cgi?id=159624

Patch by Frederic Wang <fwang@igalia.com> on 2016-07-15
Reviewed by Brent Fulgham.

We update the expectation for negative linethickness. As indicated in the MathML
recommendation, it should be rounded up to the nearest valid value, which is 0.

  • mathml/presentation/mfrac-linethickness2.html: Update the comment to reflect the new behavior.
  • mathml/presentation/mfrac-linethickness2-expected.html: Use 0px as the reference for negative values.
Location:
trunk
Files:
2 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r203283 r203285  
     12016-07-15  Frederic Wang  <fwang@igalia.com>
     2
     3        Move parsing of mfrac attributes into a MathMLFractionElementClass
     4        https://bugs.webkit.org/show_bug.cgi?id=159624
     5
     6        Reviewed by Brent Fulgham.
     7
     8        We update the expectation for negative linethickness. As indicated in the MathML
     9        recommendation, it should be rounded up to the nearest valid value, which is 0.
     10
     11        * mathml/presentation/mfrac-linethickness2.html: Update the comment to reflect the new behavior.
     12        * mathml/presentation/mfrac-linethickness2-expected.html: Use 0px as the reference for negative values.
     13
    1142016-07-15  Brent Fulgham  <bfulgham@apple.com>
    215
  • trunk/LayoutTests/mathml/presentation/mfrac-linethickness2-expected.html

    r152140 r203285  
    77
    88  <math>
    9     <mfrac>
     9    <mfrac linethickness="0px">
    1010      <mi>x</mi>
    1111      <mi>y</mi>
  • trunk/LayoutTests/mathml/presentation/mfrac-linethickness2.html

    r152140 r203285  
    66  <body>
    77
    8   <!-- The linethickness should be ignored -->
     8  <!-- Negative values are not accepted. We treat them as zero. -->
    99  <math>
    1010    <mfrac linethickness="-1.23em">
  • trunk/Source/WebCore/CMakeLists.txt

    r203244 r203285  
    19861986
    19871987    mathml/MathMLElement.cpp
     1988    mathml/MathMLFractionElement.cpp
    19881989    mathml/MathMLInlineContainerElement.cpp
    19891990    mathml/MathMLMathElement.cpp
  • trunk/Source/WebCore/ChangeLog

    r203280 r203285  
     12016-07-15  Frederic Wang  <fwang@igalia.com>
     2
     3        Move parsing of mfrac attributes into a MathMLFractionElement class
     4        https://bugs.webkit.org/show_bug.cgi?id=159624
     5
     6        Reviewed by Brent Fulgham.
     7
     8        We move the parsing of mfrac attributes to a MathMLFractionElement class. This allows to
     9        minimize the updates in RenderMathMLFraction and to remove the alignment members. Many of
     10        the members in updateLayoutParameters are actually only used in layoutBlock and could be
     11        removed in a follow-up patch. We also improve the resolution of negative line thickness value
     12        since the MathML recommendation says it should be rounded up to the nearest valid
     13        value (which is zero) instead of ignoring the attribute and using the line thickness.
     14
     15        No new tests, already covered by existing tests.
     16
     17        * CMakeLists.txt: Add MathMLFractionElement.
     18        * WebCore.xcodeproj/project.pbxproj: Ditto.
     19        * mathml/MathMLAllInOne.cpp: Ditto.
     20        * mathml/MathMLFractionElement.cpp: Added.
     21        (WebCore::MathMLFractionElement::MathMLFractionElement):
     22        (WebCore::MathMLFractionElement::create):
     23        (WebCore::MathMLFractionElement::lineThickness): Return the cached linethickness length,
     24        parsing it again if it is dirty. This handles the special values "thin", "medium" and "thick"
     25        or fallback to the general parseMathMLLength for MathML lengths.
     26        (WebCore::MathMLFractionElement::cachedFractionAlignment): Return the cached alignment value,
     27        parsing it again if it is dirty.
     28        (WebCore::MathMLFractionElement::numeratorAlignment): Return the cached alignment.
     29        (WebCore::MathMLFractionElement::denominatorAlignment): Ditto.
     30        (WebCore::MathMLFractionElement::parseAttribute): Make attributes dirty.
     31        (WebCore::MathMLFractionElement::createElementRenderer): Create a RenderMathMLFraction.
     32        * mathml/MathMLFractionElement.h: Added.
     33        * mathml/MathMLInlineContainerElement.cpp: We no longer need to handle fraction here.
     34        (WebCore::MathMLInlineContainerElement::createElementRenderer):
     35        * mathml/mathtags.in: Use MathMLFractionElement for mfrac.
     36        * rendering/mathml/RenderMathMLFraction.cpp:
     37        (WebCore::RenderMathMLFraction::updateLayoutParameters): New helper function to set the
     38        layout parameters, replacing updateFromElement. We no longer parse and store the alignment
     39        values here. We also change the resolution of negative values.
     40        (WebCore::RenderMathMLFraction::horizontalOffset): Use the enum from MathMLFractionElement.
     41        (WebCore::RenderMathMLFraction::layoutBlock): We call updateLayoutParameters instead of
     42        updateFromElement. The numerator and denominator alignments are resolved here.
     43        (WebCore::RenderMathMLFraction::parseAlignmentAttribute): Deleted. Parsing of alignment
     44        attribute is now handled in MathMLFractionElement.
     45        (WebCore::RenderMathMLFraction::updateFromElement): Deleted. Attribute changes are now
     46        handled in MathMLFractionElement.
     47        (WebCore::RenderMathMLFraction::styleDidChange): Deleted. Font changes are properly handled.
     48        * rendering/mathml/RenderMathMLFraction.h: Update declarations.
     49
    1502016-07-15  Frederic Wang  <fwang@igalia.com>
    251
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r203244 r203285  
    69046904                FABE72F41059C1EB00D999DD /* MathMLElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FABE72ED1059C1EB00D999DD /* MathMLElement.cpp */; };
    69056905                FABE72F51059C1EB00D999DD /* MathMLElement.h in Headers */ = {isa = PBXBuildFile; fileRef = FABE72EE1059C1EB00D999DD /* MathMLElement.h */; };
     6906                0BCF83F61059C1EB00D999DD /* MathMLFractionElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0BCF83EF1059C1EB00D999DD /* MathMLFractionElement.cpp */; };
     6907                0BCF83F71059C1EB00D999DD /* MathMLFractionElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 0BCF83F01059C1EB00D999DD /* MathMLFractionElement.h */; };
    69066908                FABE72F61059C1EB00D999DD /* MathMLInlineContainerElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FABE72EF1059C1EB00D999DD /* MathMLInlineContainerElement.cpp */; };
    69076909                FABE72F71059C1EB00D999DD /* MathMLInlineContainerElement.h in Headers */ = {isa = PBXBuildFile; fileRef = FABE72F01059C1EB00D999DD /* MathMLInlineContainerElement.h */; };
     
    1507515077                FABE72ED1059C1EB00D999DD /* MathMLElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MathMLElement.cpp; sourceTree = "<group>"; };
    1507615078                FABE72EE1059C1EB00D999DD /* MathMLElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MathMLElement.h; sourceTree = "<group>"; };
     15079                0BCF83EF1059C1EB00D999DD /* MathMLFractionElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MathMLFractionElement.cpp; sourceTree = "<group>"; };
     15080                0BCF83F01059C1EB00D999DD /* MathMLFractionElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MathMLFractionElement.h; sourceTree = "<group>"; };
    1507715081                FABE72EF1059C1EB00D999DD /* MathMLInlineContainerElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MathMLInlineContainerElement.cpp; sourceTree = "<group>"; };
    1507815082                FABE72F01059C1EB00D999DD /* MathMLInlineContainerElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MathMLInlineContainerElement.h; sourceTree = "<group>"; };
     
    2487124875                                FABE72ED1059C1EB00D999DD /* MathMLElement.cpp */,
    2487224876                                FABE72EE1059C1EB00D999DD /* MathMLElement.h */,
     24877                                0BCF83EF1059C1EB00D999DD /* MathMLFractionElement.cpp */,
     24878                                0BCF83F01059C1EB00D999DD /* MathMLFractionElement.h */,
    2487324879                                FABE72EF1059C1EB00D999DD /* MathMLInlineContainerElement.cpp */,
    2487424880                                FABE72F01059C1EB00D999DD /* MathMLInlineContainerElement.h */,
     
    2741727423                                FABE72F51059C1EB00D999DD /* MathMLElement.h in Headers */,
    2741827424                                44A28AAC12DFB8AC00AE923B /* MathMLElementFactory.h in Headers */,
     27425                                0BCF83F71059C1EB00D999DD /* MathMLFractionElement.h in Headers */,
    2741927426                                FABE72F71059C1EB00D999DD /* MathMLInlineContainerElement.h in Headers */,
    2742027427                                FABE72F91059C1EB00D999DD /* MathMLMathElement.h in Headers */,
     
    3124131248                                FABE72F41059C1EB00D999DD /* MathMLElement.cpp in Sources */,
    3124231249                                FABE72FD1059C21100D999DD /* MathMLElementFactory.cpp in Sources */,
     31250                                0BCF83F61059C1EB00D999DD /* MathMLFractionElement.cpp in Sources */,
    3124331251                                FABE72F61059C1EB00D999DD /* MathMLInlineContainerElement.cpp in Sources */,
    3124431252                                FABE72F81059C1EB00D999DD /* MathMLMathElement.cpp in Sources */,
  • trunk/Source/WebCore/mathml/MathMLAllInOne.cpp

    r203150 r203285  
    2727
    2828#include "MathMLElement.cpp"
     29#include "MathMLFractionElement.cpp"
    2930#include "MathMLInlineContainerElement.cpp"
    3031#include "MathMLMathElement.cpp"
  • trunk/Source/WebCore/mathml/MathMLInlineContainerElement.cpp

    r203150 r203285  
    3434#include "RenderMathMLBlock.h"
    3535#include "RenderMathMLFenced.h"
    36 #include "RenderMathMLFraction.h"
    3736#include "RenderMathMLMenclose.h"
    3837#include "RenderMathMLRoot.h"
     
    7271    if (hasTagName(moverTag) || hasTagName(munderTag) || hasTagName(munderoverTag))
    7372        return createRenderer<RenderMathMLUnderOver>(*this, WTFMove(style));
    74     if (hasTagName(mfracTag))
    75         return createRenderer<RenderMathMLFraction>(*this, WTFMove(style));
    7673    if (hasTagName(msqrtTag) || hasTagName(mrootTag))
    7774        return createRenderer<RenderMathMLRoot>(*this, WTFMove(style));
  • trunk/Source/WebCore/mathml/mathtags.in

    r203150 r203285  
    88maction interfaceName=MathMLSelectElement
    99math
    10 mfrac interfaceName=MathMLInlineContainerElement
     10mfrac interfaceName=MathMLFractionElement
    1111mfenced interfaceName=MathMLInlineContainerElement
    1212msubsup interfaceName=MathMLInlineContainerElement
  • trunk/Source/WebCore/rendering/mathml/RenderMathMLFraction.cpp

    r203073 r203285  
    4545}
    4646
    47 RenderMathMLFraction::FractionAlignment RenderMathMLFraction::parseAlignmentAttribute(const String& value)
    48 {
    49     if (equalLettersIgnoringASCIICase(value, "left"))
    50         return FractionAlignmentLeft;
    51     if (equalLettersIgnoringASCIICase(value, "right"))
    52         return FractionAlignmentRight;
    53     return FractionAlignmentCenter;
    54 }
    55 
    5647bool RenderMathMLFraction::isValid() const
    5748{
     
    7768}
    7869
    79 void RenderMathMLFraction::updateFromElement()
    80 {
    81     if (isEmpty())
    82         return;
    83 
     70void RenderMathMLFraction::updateLayoutParameters()
     71{
    8472    // We try and read constants to draw the fraction from the OpenType MATH and use fallback values otherwise.
    8573    // We also parse presentation attributes of the <mfrac> element.
     
    9381        m_defaultLineThickness = ruleThicknessFallback();
    9482
    95     // Next, we parse the linethickness attribute.
    96     // The MathML3 recommendation states that "medium" is the default thickness.
    97     // However, it only states that "thin" and "thick" are respectively thiner and thicker.
    98     // The MathML in HTML5 implementation note suggests 50% and 200% and these values are also used in Gecko.
    99     String thickness = element().getAttribute(MathMLNames::linethicknessAttr);
    100     if (equalLettersIgnoringASCIICase(thickness, "thin"))
    101         m_lineThickness = m_defaultLineThickness / 2;
    102     else if (equalLettersIgnoringASCIICase(thickness, "medium"))
    103         m_lineThickness = m_defaultLineThickness;
    104     else if (equalLettersIgnoringASCIICase(thickness, "thick"))
    105         m_lineThickness = m_defaultLineThickness * 2;
    106     else {
    107         // Parse the thickness using m_defaultLineThickness as the default value.
    108         m_lineThickness = m_defaultLineThickness;
    109         parseMathMLLength(thickness, m_lineThickness, &style(), false);
    110     }
     83    // Resolve the thickness using m_defaultLineThickness as the default value.
     84    m_lineThickness = toUserUnits(element().lineThickness(), style(), m_defaultLineThickness);
     85    if (m_lineThickness < 0)
     86        m_lineThickness = 0;
    11187
    11288    // We now know whether we should layout as a normal fraction or as a stack (fraction without bar) and so determine the relevant constants.
     
    138114        }
    139115    }
    140 
    141     // Parse alignment attributes.
    142     m_numeratorAlign = parseAlignmentAttribute(element().getAttribute(MathMLNames::numalignAttr));
    143     m_denominatorAlign = parseAlignmentAttribute(element().getAttribute(MathMLNames::denomalignAttr));
    144 }
    145 
    146 void RenderMathMLFraction::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
    147 {
    148     RenderMathMLBlock::styleDidChange(diff, oldStyle);
    149 
    150     updateFromElement();
    151116}
    152117
     
    174139}
    175140
    176 LayoutUnit RenderMathMLFraction::horizontalOffset(RenderBox& child, FractionAlignment align)
     141LayoutUnit RenderMathMLFraction::horizontalOffset(RenderBox& child, MathMLFractionElement::FractionAlignment align)
    177142{
    178143    switch (align) {
    179     case FractionAlignmentRight:
     144    case MathMLFractionElement::FractionAlignmentRight:
    180145        return LayoutUnit(logicalWidth() - child.logicalWidth());
    181     case FractionAlignmentCenter:
     146    case MathMLFractionElement::FractionAlignmentCenter:
    182147        return LayoutUnit((logicalWidth() - child.logicalWidth()) / 2);
    183     case FractionAlignmentLeft:
     148    case MathMLFractionElement::FractionAlignmentLeft:
    184149        return LayoutUnit(0);
    185150    }
     
    192157{
    193158    ASSERT(needsLayout());
    194 
    195     // FIXME: We should be able to remove this.
    196     updateFromElement();
    197159
    198160    if (!relayoutChildren && simplifiedLayout())
     
    211173    setLogicalWidth(std::max(numerator().logicalWidth(), denominator().logicalWidth()));
    212174
     175    updateLayoutParameters();
    213176    LayoutUnit verticalOffset = 0; // This is the top of the renderer.
    214     LayoutPoint numeratorLocation(horizontalOffset(numerator(), m_numeratorAlign), verticalOffset);
     177    LayoutPoint numeratorLocation(horizontalOffset(numerator(), element().numeratorAlignment()), verticalOffset);
    215178    numerator().setLocation(numeratorLocation);
    216179
     
    238201    }
    239202
    240     LayoutPoint denominatorLocation(horizontalOffset(denominator(), m_denominatorAlign), verticalOffset);
     203    LayoutPoint denominatorLocation(horizontalOffset(denominator(), element().denominatorAlignment()), verticalOffset);
    241204    denominator().setLocation(denominatorLocation);
    242205
  • trunk/Source/WebCore/rendering/mathml/RenderMathMLFraction.h

    r203228 r203285  
    3030#if ENABLE(MATHML)
    3131
     32#include "MathMLFractionElement.h"
    3233#include "MathMLInlineContainerElement.h"
    3334#include "RenderMathMLBlock.h"
     
    3940    RenderMathMLFraction(MathMLInlineContainerElement&, RenderStyle&&);
    4041
    41     MathMLInlineContainerElement& element() { return static_cast<MathMLInlineContainerElement&>(nodeForNonAnonymous()); }
    4242    float relativeLineThickness() const { return m_defaultLineThickness ? m_lineThickness / m_defaultLineThickness : LayoutUnit(0); }
    43 
    44     void updateFromElement() final;
    4543
    4644private:
     
    5351    void paint(PaintInfo&, const LayoutPoint&) final;
    5452    RenderMathMLOperator* unembellishedOperator() final;
    55     void styleDidChange(StyleDifference, const RenderStyle* oldStyle) final;
     53
     54    MathMLFractionElement& element() const { return static_cast<MathMLFractionElement&>(nodeForNonAnonymous()); }
    5655
    5756    bool isStack() const { return !m_lineThickness; }
     
    5958    RenderBox& numerator() const;
    6059    RenderBox& denominator() const;
    61     enum FractionAlignment {
    62         FractionAlignmentCenter,
    63         FractionAlignmentLeft,
    64         FractionAlignmentRight
    65     };
    66     FractionAlignment parseAlignmentAttribute(const String& value);
    67     LayoutUnit horizontalOffset(RenderBox&, FractionAlignment);
     60    LayoutUnit horizontalOffset(RenderBox&, MathMLFractionElement::FractionAlignment);
     61    void updateLayoutParameters();
    6862
    6963    LayoutUnit m_ascent;
     
    8377        LayoutUnit m_bottomShiftDown;
    8478    };
    85     FractionAlignment m_numeratorAlign { FractionAlignmentCenter };
    86     FractionAlignment m_denominatorAlign { FractionAlignmentCenter };
    8779};
    8880
Note: See TracChangeset for help on using the changeset viewer.