Changeset 204037 in webkit


Ignore:
Timestamp:
Aug 2, 2016 12:53:57 PM (8 years ago)
Author:
fred.wang@free.fr
Message:

Move parsing of operator length attributes to MathMLOperatorElement
https://bugs.webkit.org/show_bug.cgi?id=160301

Patch by Frederic Wang <fwang@igalia.com> on 2016-08-02
Reviewed by Darin Adler.

Source/WebCore:

We move parsing of operator attributes lspace, rspace minsize, maxsize into the class
MathMLOperatorElement. We rely on the existing MathMLElement::Length structure and expand
it to handle the "infinity" case of maxsize that we always resolve as intMaxForLayoutUnit.
We also improve the resolution of a negative value for minsize and maxsize 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 default value. This is similar to r203285
for mfrac@linethickness. We also update the existing test for minsize/maxsize to take into
account that change.

No new tests, already covered by existing tests.

  • mathml/MathMLElement.h: Add an "Infinity" type for MathML Length.
  • mathml/MathMLOperatorElement.cpp:

(WebCore::MathMLOperatorElement::leadingSpace): Helper function to retrieve the cached value
for the lspace attribute, parse it if necessary.
(WebCore::MathMLOperatorElement::trailingSpace): Ditto for rspace.
(WebCore::MathMLOperatorElement::minSize): Ditto for minsize.
(WebCore::MathMLOperatorElement::maxSize): Ditto for maxsize. This attribute also accepts the
"infinity" value.
(WebCore::MathMLOperatorElement::parseAttribute): Mark attributes dirty.

  • mathml/MathMLOperatorElement.h: Declare Length members and accessors.
  • rendering/mathml/RenderMathMLBlock.cpp:

(WebCore::toUserUnits): Resolve Infinity as intMaxForLayoutUnit.

  • rendering/mathml/RenderMathMLOperator.cpp:

(WebCore::RenderMathMLOperator::setOperatorProperties): We use toUserUnits to resolve the
lengths. Negative maxsize and minsize values now fallback to 0 instead of their default
values. We also remove the !isAnonymous() check since setOperatorProperties is overriden
in the RenderMathMLFencedOperator class.

LayoutTests:

  • mathml/presentation/stretchy-minsize-maxsize-expected.html: Update the test for negative

minsize and maxsize to align on the behavior suggested in the MathML recommendation.

  • mathml/presentation/stretchy-minsize-maxsize.html: Ditto.
Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r204028 r204037  
     12016-08-02  Frederic Wang  <fwang@igalia.com>
     2
     3        Move parsing of operator length attributes to MathMLOperatorElement
     4        https://bugs.webkit.org/show_bug.cgi?id=160301
     5
     6        Reviewed by Darin Adler.
     7
     8        * mathml/presentation/stretchy-minsize-maxsize-expected.html: Update the test for negative
     9        minsize and maxsize to align on the behavior suggested in the MathML recommendation.
     10        * mathml/presentation/stretchy-minsize-maxsize.html: Ditto.
     11
    1122016-08-02  Chris Dumez  <cdumez@apple.com>
    213
  • trunk/LayoutTests/mathml/presentation/stretchy-minsize-maxsize-expected.html

    r164700 r204037  
    4444      <math>
    4545        <mrow>
    46           <mo symmetric="false">|</mo>
     46          <mo symmetric="false" minsize="0em">|</mo>
    4747          <mspace height="4em" depth="4em"/>
    4848        </mrow>
     
    5050      <math>
    5151        <mrow>
    52           <mo symmetric="false">|</mo>
     52          <mo symmetric="false" maxsize="0em">|</mo>
    5353          <mspace height="4em" depth="4em"/>
    5454        </mrow>
  • trunk/LayoutTests/mathml/presentation/stretchy-minsize-maxsize.html

    r164700 r204037  
    4646      </math>
    4747
    48       <!-- We verify that negative values are ignored. -->
     48      <!-- We verify that negative values are treated as 0. -->
    4949      <math>
    5050        <mrow>
  • trunk/Source/WebCore/ChangeLog

    r204036 r204037  
     12016-08-02  Frederic Wang  <fwang@igalia.com>
     2
     3        Move parsing of operator length attributes to MathMLOperatorElement
     4        https://bugs.webkit.org/show_bug.cgi?id=160301
     5
     6        Reviewed by Darin Adler.
     7
     8        We move parsing of operator attributes lspace, rspace minsize, maxsize into the class
     9        MathMLOperatorElement. We rely on the existing MathMLElement::Length structure and expand
     10        it to handle the "infinity" case of maxsize that we always resolve as intMaxForLayoutUnit.
     11        We also improve the resolution of a negative value for minsize and maxsize since the MathML
     12        recommendation says it should be rounded up to the nearest valid value (which is zero)
     13        instead of ignoring the attribute and using the default value. This is similar to r203285
     14        for mfrac@linethickness. We also update the existing test for minsize/maxsize to take into
     15        account that change.
     16
     17        No new tests, already covered by existing tests.
     18
     19        * mathml/MathMLElement.h: Add an "Infinity" type for MathML Length.
     20        * mathml/MathMLOperatorElement.cpp:
     21        (WebCore::MathMLOperatorElement::leadingSpace): Helper function to retrieve the cached value
     22        for the lspace attribute, parse it if necessary.
     23        (WebCore::MathMLOperatorElement::trailingSpace): Ditto for rspace.
     24        (WebCore::MathMLOperatorElement::minSize): Ditto for minsize.
     25        (WebCore::MathMLOperatorElement::maxSize): Ditto for maxsize. This attribute also accepts the
     26        "infinity" value.
     27        (WebCore::MathMLOperatorElement::parseAttribute): Mark attributes dirty.
     28        * mathml/MathMLOperatorElement.h: Declare Length members and accessors.
     29        * rendering/mathml/RenderMathMLBlock.cpp:
     30        (WebCore::toUserUnits): Resolve Infinity as intMaxForLayoutUnit.
     31        * rendering/mathml/RenderMathMLOperator.cpp:
     32        (WebCore::RenderMathMLOperator::setOperatorProperties): We use toUserUnits to resolve the
     33        lengths. Negative maxsize and minsize values now fallback to 0 instead of their default
     34        values. We also remove the !isAnonymous() check since setOperatorProperties is overriden
     35        in the RenderMathMLFencedOperator class.
     36
    1372016-08-02  Frederic Wang  <fred.wang@free.fr>
    238
  • trunk/Source/WebCore/mathml/MathMLElement.h

    r204021 r204037  
    6060    // TeX's Math Unit is used internally for named spaces (1 mu = 1/18 em).
    6161    // Unitless values are interpreted as a multiple of a reference value.
    62     enum class LengthType { Cm, Em, Ex, In, MathUnit, Mm, ParsingFailed, Pc, Percentage, Pt, Px, UnitLess };
     62    enum class LengthType { Cm, Em, Ex, In, MathUnit, Mm, ParsingFailed, Pc, Percentage, Pt, Px, UnitLess, Infinity };
    6363    struct Length {
    6464        LengthType type { LengthType::ParsingFailed };
  • trunk/Source/WebCore/mathml/MathMLOperatorElement.cpp

    r204036 r204037  
    180180}
    181181
     182const MathMLElement::Length& MathMLOperatorElement::leadingSpace()
     183{
     184    return cachedMathMLLength(MathMLNames::lspaceAttr, m_leadingSpace);
     185}
     186
     187const MathMLElement::Length& MathMLOperatorElement::trailingSpace()
     188{
     189    return cachedMathMLLength(MathMLNames::rspaceAttr, m_trailingSpace);
     190}
     191
     192const MathMLElement::Length& MathMLOperatorElement::minSize()
     193{
     194    return cachedMathMLLength(MathMLNames::minsizeAttr, m_minSize);
     195}
     196
     197const MathMLElement::Length& MathMLOperatorElement::maxSize()
     198{
     199    if (m_maxSize)
     200        return m_maxSize.value();
     201
     202    const AtomicString& value = attributeWithoutSynchronization(MathMLNames::maxsizeAttr);
     203    if (value == "infinity") {
     204        Length maxsize;
     205        maxsize.type = LengthType::Infinity;
     206        m_maxSize = maxsize;
     207    } else
     208        m_maxSize = parseMathMLLength(value);
     209
     210    return m_maxSize.value();
     211}
     212
    182213void MathMLOperatorElement::childrenChanged(const ChildChange& change)
    183214{
     
    214245    } else if (auto flag = attributeNameToPropertyFlag(name))
    215246        m_properties.dirtyFlags |= flag.value();
     247    else if (name == lspaceAttr)
     248        m_leadingSpace = Nullopt;
     249    else if (name == rspaceAttr)
     250        m_trailingSpace = Nullopt;
     251    else if (name == minsizeAttr)
     252        m_minSize = Nullopt;
     253    else if (name == maxsizeAttr)
     254        m_maxSize = Nullopt;
    216255
    217256    if ((name == stretchyAttr || name == lspaceAttr || name == rspaceAttr || name == movablelimitsAttr) && renderer()) {
  • trunk/Source/WebCore/mathml/MathMLOperatorElement.h

    r204032 r204037  
    4242    Length defaultLeadingSpace();
    4343    Length defaultTrailingSpace();
     44    const Length& leadingSpace();
     45    const Length& trailingSpace();
     46    const Length& minSize();
     47    const Length& maxSize();
    4448
    4549private:
     
    6973    OperatorProperties m_properties;
    7074    void computeOperatorFlag(MathMLOperatorDictionary::Flag);
     75
     76    Optional<Length> m_leadingSpace;
     77    Optional<Length> m_trailingSpace;
     78    Optional<Length> m_minSize;
     79    Optional<Length> m_maxSize;
    7180};
    7281
  • trunk/Source/WebCore/rendering/mathml/RenderMathMLBlock.cpp

    r203106 r204037  
    166166    case MathMLElement::LengthType::ParsingFailed:
    167167        return referenceValue;
     168    case MathMLElement::LengthType::Infinity:
     169        return intMaxForLayoutUnit;
    168170    default:
    169171        ASSERT_NOT_REACHED();
  • trunk/Source/WebCore/rendering/mathml/RenderMathMLOperator.cpp

    r204032 r204037  
    8080    m_isVertical = MathMLOperatorDictionary::isVertical(textContent());
    8181
    82     // Initialize with the default values.
     82    // FIXME: Negative leading spaces must be implemented (https://webkit.org/b/124830).
    8383    m_leadingSpace = toUserUnits(element().defaultLeadingSpace(), style(), 0);
     84    m_leadingSpace = std::max<LayoutUnit>(0, toUserUnits(element().leadingSpace(), style(), m_leadingSpace));
     85
     86    // FIXME: Negative trailing spaces must be implemented (https://webkit.org/b/124830).
    8487    m_trailingSpace = toUserUnits(element().defaultTrailingSpace(), style(), 0);
    85     m_minSize = style().fontCascade().size(); // This sets minsize to "1em".
    86     m_maxSize = intMaxForLayoutUnit; // This sets maxsize to "infinity".
    87 
    88     if (!isAnonymous()) {
    89         // Finally, we make the attribute values override the default.
    90         parseMathMLLength(element().attributeWithoutSynchronization(MathMLNames::lspaceAttr), m_leadingSpace, &style(), false); // FIXME: Negative leading space must be implemented (https://bugs.webkit.org/show_bug.cgi?id=124830).
    91         parseMathMLLength(element().attributeWithoutSynchronization(MathMLNames::rspaceAttr), m_trailingSpace, &style(), false); // FIXME: Negative trailing space must be implemented (https://bugs.webkit.org/show_bug.cgi?id=124830).
    92 
    93         parseMathMLLength(element().attributeWithoutSynchronization(MathMLNames::minsizeAttr), m_minSize, &style(), false);
    94         const AtomicString& maxsize = element().attributeWithoutSynchronization(MathMLNames::maxsizeAttr);
    95         if (maxsize != "infinity")
    96             parseMathMLLength(maxsize, m_maxSize, &style(), false);
    97     }
     88    m_trailingSpace = std::max<LayoutUnit>(0, toUserUnits(element().trailingSpace(), style(), m_trailingSpace));
     89
     90    m_minSize = style().fontCascade().size(); // Default minsize is "1em".
     91    m_minSize = std::max<LayoutUnit>(0, toUserUnits(element().minSize(), style(), m_minSize));
     92
     93    m_maxSize = intMaxForLayoutUnit; // Default maxsize is "infinity".
     94    m_maxSize = std::max<LayoutUnit>(0, toUserUnits(element().maxSize(), style(), m_maxSize));
    9895}
    9996
Note: See TracChangeset for help on using the changeset viewer.