Changeset 203679 in webkit


Ignore:
Timestamp:
Jul 25, 2016 12:18:47 AM (8 years ago)
Author:
fred.wang@free.fr
Message:

Move parsing of display, displaystyle and mathvariant attributes into MathML element classes
https://bugs.webkit.org/show_bug.cgi?id=159623

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

No new tests, already covered by existing tests.

  • mathml/MathMLElement.cpp:

(WebCore::MathMLElement::parseMathVariantAttribute): Move helper function to parse the
mathvariant attribute.
(WebCore::MathMLElement::getSpecifiedDisplayStyle): Helper function to set the displaystyle
value from the attribute specified on the MathML element.
(WebCore::MathMLElement::getSpecifiedMathVariant): Helper function to set the mathvariant
value from the attribute specified on the MathML element.

  • mathml/MathMLElement.h: Move the enum for mathvariant values and declare new members.

(WebCore::MathMLElement::acceptsDisplayStyleAttribute): Indicate whether the element accepts
displaystyle attribute (false for most of them).
(WebCore::MathMLElement::acceptsMathVariantAttribute): Indicate whether the element accepts
mathvariant attribute (false for most of them).

  • mathml/MathMLInlineContainerElement.cpp:

(WebCore::MathMLInlineContainerElement::acceptsDisplayStyleAttribute): Add mstyle and mtable
to the list of elements accepting the displaystyle attribute.
(WebCore::MathMLInlineContainerElement::acceptsMathVariantAttribute): Add mstyle to the list
of elements accepting the mathvariant attribute.
(WebCore::MathMLInlineContainerElement::parseAttribute): Mark displaystyle and mathvariant
dirty if necessary. Also use the new accepts*Attribute function.

  • mathml/MathMLInlineContainerElement.h: Declare overridden accepts*Attribute members.
  • mathml/MathMLMathElement.cpp:

(WebCore::MathMLMathElement::getSpecifiedDisplayStyle): Override acceptsDisplayStyleAttribute
so that the display attribute is also used to set the default value if the displaystyle
attribute is absent.
(WebCore::MathMLMathElement::parseAttribute): Mark displaystyle and mathvariant dirty if
necessary. We directly MathMLElement::parseAttribute to avoid duplicate work.

  • mathml/MathMLMathElement.h: Add the math tag to the list of elements accepting the

displaystyle and mathvariant attributes. Declare overridden getSpecifiedDisplayStyle.

  • mathml/MathMLTextElement.cpp:

(WebCore::MathMLTextElement::parseAttribute): Mark mathvariant as dirty.

  • mathml/MathMLTextElement.h: Add token elements to the list of elements accepting the

mathvariant attribute.

  • rendering/mathml/MathMLStyle.cpp:

(WebCore::MathMLStyle::updateStyleIfNeeded): Use the new MathMLElement::MathVariant enum.
(WebCore::MathMLStyle::resolveMathMLStyle): We no longer parse the display value to
initialize the default value on the math tag, because this is handled in
getSpecifiedDisplayStyle. In general, we also just call getSpecifiedDisplayStyle and
getSpecifiedMathVariant on the MathML elements instead of parsing the displaystyle and
mathvariant attributes here.
(WebCore::MathMLStyle::parseMathVariant): Deleted. This is moved into MathMLElement.

  • rendering/mathml/MathMLStyle.h: Use the new MathMLElement::MathVariant enum.
  • rendering/mathml/RenderMathMLToken.cpp: Ditto.

(WebCore::mathVariant): Ditto.
(WebCore::RenderMathMLToken::updateMathVariantGlyph): Ditto.

Location:
trunk/Source/WebCore
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r203678 r203679  
     12016-07-24  Frederic Wang  <fwang@igalia.com>
     2
     3        Move parsing of display, displaystyle and mathvariant attributes into MathML element classes
     4        https://bugs.webkit.org/show_bug.cgi?id=159623
     5
     6        Reviewed by Brent Fulgham.
     7
     8        No new tests, already covered by existing tests.
     9
     10        * mathml/MathMLElement.cpp:
     11        (WebCore::MathMLElement::parseMathVariantAttribute): Move helper function to parse the
     12        mathvariant attribute.
     13        (WebCore::MathMLElement::getSpecifiedDisplayStyle): Helper function to set the displaystyle
     14        value from the attribute specified on the MathML element.
     15        (WebCore::MathMLElement::getSpecifiedMathVariant): Helper function to set the mathvariant
     16        value from the attribute specified on the MathML element.
     17        * mathml/MathMLElement.h: Move the enum for mathvariant values and declare new members.
     18        (WebCore::MathMLElement::acceptsDisplayStyleAttribute): Indicate whether the element accepts
     19        displaystyle attribute (false for most of them).
     20        (WebCore::MathMLElement::acceptsMathVariantAttribute): Indicate whether the element accepts
     21        mathvariant attribute (false for most of them).
     22        * mathml/MathMLInlineContainerElement.cpp:
     23        (WebCore::MathMLInlineContainerElement::acceptsDisplayStyleAttribute): Add mstyle and mtable
     24        to the list of elements accepting the displaystyle attribute.
     25        (WebCore::MathMLInlineContainerElement::acceptsMathVariantAttribute): Add mstyle to the list
     26        of elements accepting the mathvariant attribute.
     27        (WebCore::MathMLInlineContainerElement::parseAttribute): Mark displaystyle and mathvariant
     28        dirty if necessary. Also use the new accepts*Attribute function.
     29        * mathml/MathMLInlineContainerElement.h: Declare overridden accepts*Attribute members.
     30        * mathml/MathMLMathElement.cpp:
     31        (WebCore::MathMLMathElement::getSpecifiedDisplayStyle): Override acceptsDisplayStyleAttribute
     32        so that the display attribute is also used to set the default value if the displaystyle
     33        attribute is absent.
     34        (WebCore::MathMLMathElement::parseAttribute): Mark displaystyle and mathvariant dirty if
     35        necessary. We directly MathMLElement::parseAttribute to avoid duplicate work.
     36        * mathml/MathMLMathElement.h: Add the math tag to the list of elements accepting the
     37        displaystyle and mathvariant attributes. Declare overridden getSpecifiedDisplayStyle.
     38        * mathml/MathMLTextElement.cpp:
     39        (WebCore::MathMLTextElement::parseAttribute): Mark mathvariant as dirty.
     40        * mathml/MathMLTextElement.h: Add token elements to the list of elements accepting the
     41        mathvariant attribute.
     42        * rendering/mathml/MathMLStyle.cpp:
     43        (WebCore::MathMLStyle::updateStyleIfNeeded): Use the new MathMLElement::MathVariant enum.
     44        (WebCore::MathMLStyle::resolveMathMLStyle):  We no longer parse the display value to
     45        initialize the default value on the math tag, because this is handled in
     46        getSpecifiedDisplayStyle. In general, we also just call getSpecifiedDisplayStyle and
     47        getSpecifiedMathVariant on the MathML elements instead of parsing the displaystyle and
     48        mathvariant attributes here.
     49        (WebCore::MathMLStyle::parseMathVariant): Deleted. This is moved into MathMLElement.
     50        * rendering/mathml/MathMLStyle.h: Use the new MathMLElement::MathVariant enum.
     51        * rendering/mathml/RenderMathMLToken.cpp: Ditto.
     52        (WebCore::mathVariant): Ditto.
     53        (WebCore::RenderMathMLToken::updateMathVariantGlyph): Ditto.
     54
    1552016-07-25  Carlos Garcia Campos  <cgarcia@igalia.com>
    256
  • trunk/Source/WebCore/mathml/MathMLElement.cpp

    r203667 r203679  
    33 * Copyright (C) 2010 Apple Inc. All rights reserved.
    44 * Copyright (C) 2010 François Sausset (sausset@gmail.com). All rights reserved.
     5 * Copyright (C) 2016 Igalia S.L.
    56 *
    67 * Redistribution and use in source and binary forms, with or without
     
    544545}
    545546
     547MathMLElement::MathVariant MathMLElement::parseMathVariantAttribute(const AtomicString& attributeValue)
     548{
     549    // The mathvariant attribute values is case-sensitive.
     550    if (attributeValue == "normal")
     551        return MathVariant::Normal;
     552    if (attributeValue == "bold")
     553        return MathVariant::Bold;
     554    if (attributeValue == "italic")
     555        return MathVariant::Italic;
     556    if (attributeValue == "bold-italic")
     557        return MathVariant::BoldItalic;
     558    if (attributeValue == "double-struck")
     559        return MathVariant::DoubleStruck;
     560    if (attributeValue == "bold-fraktur")
     561        return MathVariant::BoldFraktur;
     562    if (attributeValue == "script")
     563        return MathVariant::Script;
     564    if (attributeValue == "bold-script")
     565        return MathVariant::BoldScript;
     566    if (attributeValue == "fraktur")
     567        return MathVariant::Fraktur;
     568    if (attributeValue == "sans-serif")
     569        return MathVariant::SansSerif;
     570    if (attributeValue == "bold-sans-serif")
     571        return MathVariant::BoldSansSerif;
     572    if (attributeValue == "sans-serif-italic")
     573        return MathVariant::SansSerifItalic;
     574    if (attributeValue == "sans-serif-bold-italic")
     575        return MathVariant::SansSerifBoldItalic;
     576    if (attributeValue == "monospace")
     577        return MathVariant::Monospace;
     578    if (attributeValue == "initial")
     579        return MathVariant::Initial;
     580    if (attributeValue == "tailed")
     581        return MathVariant::Tailed;
     582    if (attributeValue == "looped")
     583        return MathVariant::Looped;
     584    if (attributeValue == "stretched")
     585        return MathVariant::Stretched;
     586    return MathVariant::None;
     587}
     588
     589Optional<bool> MathMLElement::specifiedDisplayStyle()
     590{
     591    if (!acceptsDisplayStyleAttribute())
     592        return Optional<bool>();
     593    const MathMLElement::BooleanValue& specifiedDisplayStyle = cachedBooleanAttribute(displaystyleAttr, m_displayStyle);
     594    return specifiedDisplayStyle == BooleanValue::Default ? Optional<bool>() : Optional<bool>(specifiedDisplayStyle == BooleanValue::True);
     595}
     596
     597Optional<MathMLElement::MathVariant> MathMLElement::specifiedMathVariant()
     598{
     599    if (!acceptsMathVariantAttribute())
     600        return Optional<MathVariant>();
     601    if (m_mathVariant.dirty) {
     602        m_mathVariant.value = parseMathVariantAttribute(attributeWithoutSynchronization(mathvariantAttr));
     603        m_mathVariant.dirty = false;
     604    }
     605    return m_mathVariant.value == MathVariant::None ? Optional<MathVariant>() : Optional<MathVariant>(m_mathVariant.value);
     606}
     607
    546608}
    547609
  • trunk/Source/WebCore/mathml/MathMLElement.h

    r203553 r203679  
    33 * Copyright (C) 2010 Apple Inc. All rights reserved.
    44 * Copyright (C) 2010 François Sausset (sausset@gmail.com). All rights reserved.
     5 * Copyright (C) 2016 Igalia S.L.
    56 *
    67 * Redistribution and use in source and binary forms, with or without
     
    7374    };
    7475
     76    // These are the mathvariant values from the MathML recommendation.
     77    // The special value none means that no explicit mathvariant value has been specified.
     78    // Note that the numeral values are important for the computation performed in the mathVariant function of RenderMathMLToken, do not change them!
     79    enum class MathVariant {
     80        None = 0,
     81        Normal = 1,
     82        Bold = 2,
     83        Italic = 3,
     84        BoldItalic = 4,
     85        Script = 5,
     86        BoldScript = 6,
     87        Fraktur = 7,
     88        DoubleStruck = 8,
     89        BoldFraktur = 9,
     90        SansSerif = 10,
     91        BoldSansSerif = 11,
     92        SansSerifItalic = 12,
     93        SansSerifBoldItalic = 13,
     94        Monospace = 14,
     95        Initial = 15,
     96        Tailed = 16,
     97        Looped = 17,
     98        Stretched = 18
     99    };
     100    struct MathVariantAttribute {
     101        MathVariant value { MathVariant::None };
     102        bool dirty { true };
     103    };
     104
     105    virtual Optional<bool> specifiedDisplayStyle();
     106    Optional<MathMLElement::MathVariant> specifiedMathVariant();
     107
    75108protected:
    76109    MathMLElement(const QualifiedName& tagName, Document&);
     
    92125    const BooleanValue& cachedBooleanAttribute(const QualifiedName&, BooleanAttribute&);
    93126
     127    virtual bool acceptsDisplayStyleAttribute() { return false; }
     128    virtual bool acceptsMathVariantAttribute() { return false; }
     129
     130    BooleanAttribute m_displayStyle;
     131    MathVariantAttribute m_mathVariant;
     132
    94133private:
    95134    virtual void updateSelectedChild() { }
    96135    static Length parseNumberAndUnit(const StringView&);
    97136    static Length parseNamedSpace(const StringView&);
     137    static MathVariant parseMathVariantAttribute(const AtomicString& attributeValue);
    98138
    99139    bool canStartSelection() const final;
  • trunk/Source/WebCore/mathml/MathMLInlineContainerElement.cpp

    r203553 r203679  
    22 * Copyright (C) 2009 Alex Milowski (alex@milowski.com). All rights reserved.
    33 * Copyright (C) 2010 Apple Inc. All rights reserved.
     4 * Copyright (C) 2016 Igalia S.L.
    45 *
    56 * Redistribution and use in source and binary forms, with or without
     
    7576}
    7677
     78bool MathMLInlineContainerElement::acceptsDisplayStyleAttribute()
     79{
     80    return hasTagName(mstyleTag) || hasTagName(mtableTag);
     81}
     82
     83bool MathMLInlineContainerElement::acceptsMathVariantAttribute()
     84{
     85    return hasTagName(mstyleTag);
     86}
     87
    7788void MathMLInlineContainerElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
    7889{
    79     bool displayStyleAttribute = (name == displaystyleAttr && (hasTagName(mstyleTag) || hasTagName(mtableTag)));
    80     bool mathVariantAttribute = (name == mathvariantAttr && (hasTagName(mathTag) || hasTagName(mstyleTag)));
     90    bool displayStyleAttribute = name == displaystyleAttr && acceptsDisplayStyleAttribute();
     91    bool mathVariantAttribute = name == mathvariantAttr && acceptsMathVariantAttribute();
     92    if (displayStyleAttribute)
     93        m_displayStyle.dirty = true;
     94    if (mathVariantAttribute)
     95        m_mathVariant.dirty = true;
    8196    if ((displayStyleAttribute || mathVariantAttribute) && renderer())
    8297        MathMLStyle::resolveMathMLStyleTree(renderer());
  • trunk/Source/WebCore/mathml/MathMLInlineContainerElement.h

    r203228 r203679  
    22 * Copyright (C) 2009 Alex Milowski (alex@milowski.com). All rights reserved.
    33 * Copyright (C) 2010 Apple Inc. All rights reserved.
     4 * Copyright (C) 2016 Igalia S.L.
    45 *
    56 * Redistribution and use in source and binary forms, with or without
     
    4142    void parseAttribute(const QualifiedName&, const AtomicString&) override;
    4243
     44    bool acceptsDisplayStyleAttribute() override;
     45    bool acceptsMathVariantAttribute() override;
     46
    4347private:
    4448    RenderPtr<RenderElement> createElementRenderer(RenderStyle&&, const RenderTreePosition&) override;
  • trunk/Source/WebCore/mathml/MathMLMathElement.cpp

    r203072 r203679  
    22 * Copyright (C) 2009 Alex Milowski (alex@milowski.com). All rights reserved.
    33 * Copyright (C) 2010 Apple Inc. All rights reserved.
     4 * Copyright (C) 2016 Igalia S.L.
    45 *
    56 * Redistribution and use in source and binary forms, with or without
     
    5455}
    5556
     57Optional<bool> MathMLMathElement::specifiedDisplayStyle()
     58{
     59    if (cachedBooleanAttribute(displaystyleAttr, m_displayStyle) == BooleanValue::Default) {
     60        // The default displaystyle value of the <math> depends on the display attribute, so we parse it here.
     61        const AtomicString& value = attributeWithoutSynchronization(displayAttr);
     62        if (value == "block")
     63            m_displayStyle.value = BooleanValue::True;
     64        else if (value == "inline")
     65            m_displayStyle.value = BooleanValue::False;
     66    }
     67    return m_displayStyle.value == BooleanValue::Default ? Optional<bool>() : Optional<bool>(m_displayStyle.value == BooleanValue::True);
     68}
     69
    5670void MathMLMathElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
    5771{
    58     if ((name == displaystyleAttr || name == displayAttr || name == mathvariantAttr) && renderer())
     72    bool displayStyleAttribute = (name == displaystyleAttr || name == displayAttr);
     73    bool mathVariantAttribute = name == mathvariantAttr;
     74    if (displayStyleAttribute)
     75        m_displayStyle.dirty = true;
     76    if (mathVariantAttribute)
     77        m_mathVariant.dirty = true;
     78    if ((displayStyleAttribute || mathVariantAttribute) && renderer())
    5979        MathMLStyle::resolveMathMLStyleTree(renderer());
    6080
    61     MathMLInlineContainerElement::parseAttribute(name, value);
     81    MathMLElement::parseAttribute(name, value);
    6282}
    6383
  • trunk/Source/WebCore/mathml/MathMLMathElement.h

    r203228 r203679  
    22 * Copyright (C) 2009 Alex Milowski (alex@milowski.com). All rights reserved.
    33 * Copyright (C) 2010 Apple Inc. All rights reserved.
     4 * Copyright (C) 2016 Igalia S.L.
    45 *
    56 * Redistribution and use in source and binary forms, with or without
     
    4142    void didAttachRenderers() final;
    4243
     44    bool acceptsDisplayStyleAttribute() final { return true; }
     45    bool acceptsMathVariantAttribute() final { return true; }
     46    Optional<bool> specifiedDisplayStyle() final;
     47
    4348    RenderPtr<RenderElement> createElementRenderer(RenderStyle&&, const RenderTreePosition&) final;
    4449};
  • trunk/Source/WebCore/mathml/MathMLTextElement.cpp

    r203108 r203679  
    7272    }
    7373
    74     if (name == mathvariantAttr && renderer())
    75         MathMLStyle::resolveMathMLStyleTree(renderer());
     74    if (name == mathvariantAttr) {
     75        m_mathVariant.dirty = true;
     76        if (renderer())
     77            MathMLStyle::resolveMathMLStyleTree(renderer());
     78    }
    7679
    7780    MathMLElement::parseAttribute(name, value);
  • trunk/Source/WebCore/mathml/MathMLTextElement.h

    r203228 r203679  
    22 * Copyright (C) 2009 Alex Milowski (alex@milowski.com). All rights reserved.
    33 * Copyright (C) 2010 Apple Inc. All rights reserved.
     4 * Copyright (C) 2016 Igalia S.L.
    45 *
    56 * Redistribution and use in source and binary forms, with or without
     
    3536public:
    3637    static Ref<MathMLTextElement> create(const QualifiedName& tagName, Document&);
     38    bool acceptsMathVariantAttribute() final { return true; }
    3739
    3840private:
  • trunk/Source/WebCore/rendering/mathml/MathMLStyle.cpp

    r203324 r203679  
    8282}
    8383
    84 void MathMLStyle::updateStyleIfNeeded(RenderObject* renderer, bool oldDisplayStyle, MathVariant oldMathVariant)
     84void MathMLStyle::updateStyleIfNeeded(RenderObject* renderer, bool oldDisplayStyle, MathMLElement::MathVariant oldMathVariant)
    8585{
    8686    if (oldDisplayStyle != m_displayStyle) {
     
    9999}
    100100
    101 MathMLStyle::MathVariant MathMLStyle::parseMathVariant(const AtomicString& attributeValue)
    102 {
    103     if (attributeValue == "normal")
    104         return Normal;
    105     if (attributeValue == "bold")
    106         return Bold;
    107     if (attributeValue == "italic")
    108         return Italic;
    109     if (attributeValue == "bold-italic")
    110         return BoldItalic;
    111     if (attributeValue == "double-struck")
    112         return DoubleStruck;
    113     if (attributeValue == "bold-fraktur")
    114         return BoldFraktur;
    115     if (attributeValue == "script")
    116         return Script;
    117     if (attributeValue == "bold-script")
    118         return BoldScript;
    119     if (attributeValue == "fraktur")
    120         return Fraktur;
    121     if (attributeValue == "sans-serif")
    122         return SansSerif;
    123     if (attributeValue == "bold-sans-serif")
    124         return BoldSansSerif;
    125     if (attributeValue == "sans-serif-italic")
    126         return SansSerifItalic;
    127     if (attributeValue == "sans-serif-bold-italic")
    128         return SansSerifBoldItalic;
    129     if (attributeValue == "monospace")
    130         return Monospace;
    131     if (attributeValue == "initial")
    132         return Initial;
    133     if (attributeValue == "tailed")
    134         return Tailed;
    135     if (attributeValue == "looped")
    136         return Looped;
    137     if (attributeValue == "stretched")
    138         return Stretched;
    139     return None;
    140 }
    141 
    142101void MathMLStyle::resolveMathMLStyle(RenderObject* renderer)
    143102{
     
    145104
    146105    bool oldDisplayStyle = m_displayStyle;
    147     MathVariant oldMathVariant = m_mathVariant;
     106    MathMLElement::MathVariant oldMathVariant = m_mathVariant;
    148107    auto* parentRenderer = getMathMLParentNode(renderer);
    149108    const MathMLStyle* parentStyle = getMathMLStyle(parentRenderer);
     
    151110    // By default, we just inherit the style from our parent.
    152111    m_displayStyle = false;
    153     m_mathVariant = None;
     112    m_mathVariant = MathMLElement::MathVariant::None;
    154113    if (parentStyle) {
    155114        setDisplayStyle(parentStyle->displayStyle());
     
    163122    }
    164123
    165     if (is<RenderMathMLMath>(renderer))
    166         m_displayStyle = downcast<RenderElement>(renderer)->element()->attributeWithoutSynchronization(displayAttr) == "block"; // The default displaystyle of the <math> element depends on its display attribute.
    167     else if (is<RenderMathMLTable>(renderer))
    168         m_displayStyle = false; // The default displaystyle of <mtable> is false.
     124    if (is<RenderMathMLMath>(renderer) || is<RenderMathMLTable>(renderer))
     125        m_displayStyle = false; // The default displaystyle of <math> and <mtable> is false.
    169126    else if (parentRenderer) {
    170127        if (is<RenderMathMLFraction>(parentRenderer))
     
    178135    }
    179136
    180     // The displaystyle attribute on the <math>, <mtable> or <mstyle> elements override the default behavior.
    181     const auto* element = downcast<RenderElement>(renderer)->element();
    182     const QualifiedName& tagName = element->tagQName();
    183     if (tagName == mathTag || tagName == mtableTag || tagName == mstyleTag) {
    184         // We only modify the value of displaystyle if there is an explicit and valid attribute.
    185         const AtomicString& attributeValue = element->attributeWithoutSynchronization(displaystyleAttr);
    186         if (attributeValue == "true")
    187             m_displayStyle = true;
    188         else if (attributeValue == "false")
    189             m_displayStyle = false;
     137    // The displaystyle and mathvariant attributes override the default behavior.
     138    auto* element = downcast<RenderElement>(renderer)->element();
     139    if (is<MathMLElement>(element)) {
     140        Optional<bool> displayStyle = downcast<MathMLElement>(element)->specifiedDisplayStyle();
     141        if (displayStyle)
     142            m_displayStyle = displayStyle.value();
     143        Optional<MathMLElement::MathVariant> mathVariant = downcast<MathMLElement>(element)->specifiedMathVariant();
     144        if (mathVariant)
     145            m_mathVariant = mathVariant.value();
    190146    }
    191 
    192     // The mathvariant attribute on the <math>, <mstyle> or token elements overrides the default behavior.
    193     if (is<RenderMathMLMath>(renderer) || is<RenderMathMLToken>(renderer) || tagName == mstyleTag) {
    194         MathVariant mathvariant = parseMathVariant(element->attributeWithoutSynchronization(mathvariantAttr));
    195         if (mathvariant != None)
    196             m_mathVariant = mathvariant;
    197     }
    198 
    199147    updateStyleIfNeeded(renderer, oldDisplayStyle, oldMathVariant);
    200148}
  • trunk/Source/WebCore/rendering/mathml/MathMLStyle.h

    r203228 r203679  
    2929
    3030#include "Element.h"
     31#include "MathMLElement.h"
    3132#include <wtf/RefCounted.h>
    3233
     
    4142    void setDisplayStyle(bool displayStyle) { m_displayStyle = displayStyle; }
    4243
    43     // These are the mathvariant values from the MathML recommendation.
    44     // The special value none means that no explicit mathvariant value has been specified.
    45     // Note that the numeral values are important for the computation performed in the mathVariant function of RenderMathMLToken, do not change them!
    46     enum MathVariant {
    47         None = 0,
    48         Normal = 1,
    49         Bold = 2,
    50         Italic = 3,
    51         BoldItalic = 4,
    52         Script = 5,
    53         BoldScript = 6,
    54         Fraktur = 7,
    55         DoubleStruck = 8,
    56         BoldFraktur = 9,
    57         SansSerif = 10,
    58         BoldSansSerif = 11,
    59         SansSerifItalic = 12,
    60         SansSerifBoldItalic = 13,
    61         Monospace = 14,
    62         Initial = 15,
    63         Tailed = 16,
    64         Looped = 17,
    65         Stretched = 18
    66     };
    67     MathVariant mathVariant() const { return m_mathVariant; }
    68     void setMathVariant(MathVariant mathvariant) { m_mathVariant = mathvariant; }
     44    MathMLElement::MathVariant mathVariant() const { return m_mathVariant; }
     45    void setMathVariant(MathMLElement::MathVariant mathvariant) { m_mathVariant = mathvariant; }
    6946
    7047    void resolveMathMLStyle(RenderObject*);
     
    7552    const MathMLStyle* getMathMLStyle(RenderObject* renderer);
    7653    RenderObject* getMathMLParentNode(RenderObject*);
    77     void updateStyleIfNeeded(RenderObject*, bool, MathVariant);
    78     MathVariant parseMathVariant(const AtomicString& attributeValue);
     54    void updateStyleIfNeeded(RenderObject*, bool, MathMLElement::MathVariant);
    7955
    8056    bool m_displayStyle { false };
    81     MathVariant m_mathVariant { None };
     57    MathMLElement::MathVariant m_mathVariant { MathMLElement::MathVariant::None };
    8258};
    8359
  • trunk/Source/WebCore/rendering/mathml/RenderMathMLToken.cpp

    r203280 r203679  
    3030#if ENABLE(MATHML)
    3131
     32#include "MathMLElement.h"
    3233#include "MathMLNames.h"
    3334#include "PaintInfo.h"
     
    282283// unaltered.
    283284// Characters already in the mathematical blocks (or are one of the exceptions) are never transformed.
    284 // Acceptable values for mathvariant are specified in MathMLStyle.h
     285// Acceptable values for mathvariant are specified in MathMLElement.h
    285286// The transformable characters can be found at:
    286287// http://lists.w3.org/Archives/Public/www-math/2013Sep/0012.html and
    287288// https://en.wikipedia.org/wiki/Mathematical_Alphanumeric_Symbols
    288 static UChar32 mathVariant(UChar32 codePoint, MathMLStyle::MathVariant mathvariant)
    289 {
    290     ASSERT(mathvariant >= MathMLStyle::Normal && mathvariant <= MathMLStyle::Stretched);
    291 
    292     if (mathvariant == MathMLStyle::Normal)
     289static UChar32 mathVariant(UChar32 codePoint, MathMLElement::MathVariant mathvariant)
     290{
     291    ASSERT(mathvariant >= MathMLElement::MathVariant::Normal && mathvariant <= MathMLElement::MathVariant::Stretched);
     292
     293    if (mathvariant == MathMLElement::MathVariant::Normal)
    293294        return codePoint; // Nothing to do here.
    294295
     
    297298        return codePoint; // Nothing at this code point is transformed
    298299    if (codePoint == greekLetterDigamma) {
    299         if (mathvariant == MathMLStyle::Bold)
     300        if (mathvariant == MathMLElement::MathVariant::Bold)
    300301            return mathBoldCapitalDigamma;
    301302        return codePoint;
    302303    }
    303304    if (codePoint == greekSmallLetterDigamma) {
    304         if (mathvariant == MathMLStyle::Bold)
     305        if (mathvariant == MathMLElement::MathVariant::Bold)
    305306            return mathBoldSmallDigamma;
    306307        return codePoint;
    307308    }
    308309    if (codePoint == latinSmallLetterDotlessI) {
    309         if (mathvariant == MathMLStyle::Italic)
     310        if (mathvariant == MathMLElement::MathVariant::Italic)
    310311            return mathItalicSmallDotlessI;
    311312        return codePoint;
    312313    }
    313314    if (codePoint == latinSmallLetterDotlessJ) {
    314         if (mathvariant == MathMLStyle::Italic)
     315        if (mathvariant == MathMLElement::MathVariant::Italic)
    315316            return mathItalicSmallDotlessJ;
    316317        return codePoint;
     
    390391        // multiplier represents the order of the sequences relative to the first one.
    391392        switch (mathvariant) {
    392         case MathMLStyle::Bold:
     393        case MathMLElement::MathVariant::Bold:
    393394            multiplier = 0;
    394395            break;
    395         case MathMLStyle::DoubleStruck:
     396        case MathMLElement::MathVariant::DoubleStruck:
    396397            multiplier = 1;
    397398            break;
    398         case MathMLStyle::SansSerif:
     399        case MathMLElement::MathVariant::SansSerif:
    399400            multiplier = 2;
    400401            break;
    401         case MathMLStyle::BoldSansSerif:
     402        case MathMLElement::MathVariant::BoldSansSerif:
    402403            multiplier = 3;
    403404            break;
    404         case MathMLStyle::Monospace:
     405        case MathMLElement::MathVariant::Monospace:
    405406            multiplier = 4;
    406407            break;
     
    417418    if (varType == Greekish) {
    418419        switch (mathvariant) {
    419         case MathMLStyle::Bold:
     420        case MathMLElement::MathVariant::Bold:
    420421            multiplier = 0;
    421422            break;
    422         case MathMLStyle::Italic:
     423        case MathMLElement::MathVariant::Italic:
    423424            multiplier = 1;
    424425            break;
    425         case MathMLStyle::BoldItalic:
     426        case MathMLElement::MathVariant::BoldItalic:
    426427            multiplier = 2;
    427428            break;
    428         case MathMLStyle::BoldSansSerif:
     429        case MathMLElement::MathVariant::BoldSansSerif:
    429430            multiplier = 3;
    430431            break;
    431         case MathMLStyle::SansSerifBoldItalic:
     432        case MathMLElement::MathVariant::SansSerifBoldItalic:
    432433            multiplier = 4;
    433434            break;
     
    447448        size_t tableLength;
    448449        switch (mathvariant) {
    449         case MathMLStyle::Initial:
     450        case MathMLElement::MathVariant::Initial:
    450451            mapTable = arabicInitialMapTable;
    451452            tableLength = WTF_ARRAY_LENGTH(arabicInitialMapTable);
    452453            break;
    453         case MathMLStyle::Tailed:
     454        case MathMLElement::MathVariant::Tailed:
    454455            mapTable = arabicTailedMapTable;
    455456            tableLength = WTF_ARRAY_LENGTH(arabicTailedMapTable);
    456457            break;
    457         case MathMLStyle::Stretched:
     458        case MathMLElement::MathVariant::Stretched:
    458459            mapTable = arabicStretchedMapTable;
    459460            tableLength = WTF_ARRAY_LENGTH(arabicStretchedMapTable);
    460461            break;
    461         case MathMLStyle::Looped:
     462        case MathMLElement::MathVariant::Looped:
    462463            mapTable = arabicLoopedMapTable;
    463464            tableLength = WTF_ARRAY_LENGTH(arabicLoopedMapTable);
    464465            break;
    465         case MathMLStyle::DoubleStruck:
     466        case MathMLElement::MathVariant::DoubleStruck:
    466467            mapTable = arabicDoubleMapTable;
    467468            tableLength = WTF_ARRAY_LENGTH(arabicDoubleMapTable);
     
    473474    } else {
    474475        // Must be Latin
    475         if (mathvariant > MathMLStyle::Monospace)
     476        if (mathvariant > MathMLElement::MathVariant::Monospace)
    476477            return codePoint; // Latin doesn't support the Arabic mathvariants
    477         multiplier = mathvariant - 2;
     478        multiplier = static_cast<int>(mathvariant) - 2;
    478479        // This is possible because the values for NS_MATHML_MATHVARIANT_* are chosen to coincide with the order in which the encoded mathvariant characters are located within their unicode block (less an offset to avoid None and Normal variants)
    479480        // See the Number case for an explanation of the following calculation
     
    524525    if (textContent.length() == 1) {
    525526        UChar32 codePoint = textContent[0];
    526         MathMLStyle::MathVariant mathvariant = mathMLStyle()->mathVariant();
    527         if (mathvariant == MathMLStyle::None)
    528             mathvariant = tokenElement.hasTagName(MathMLNames::miTag) ? MathMLStyle::Italic : MathMLStyle::Normal;
     527        MathMLElement::MathVariant mathvariant = mathMLStyle()->mathVariant();
     528        if (mathvariant == MathMLElement::MathVariant::None)
     529            mathvariant = tokenElement.hasTagName(MathMLNames::miTag) ? MathMLElement::MathVariant::Italic : MathMLElement::MathVariant::Normal;
    529530        UChar32 transformedCodePoint = mathVariant(codePoint, mathvariant);
    530531        if (transformedCodePoint != codePoint)
Note: See TracChangeset for help on using the changeset viewer.