Changeset 203108 in webkit


Ignore:
Timestamp:
Jul 11, 2016, 10:59:55 PM (9 years ago)
Author:
fred.wang@free.fr
Message:

Move parsing of mspace attributes to a MathMLSpaceElement class
https://bugs.webkit.org/show_bug.cgi?id=156795

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

No new tests, already covered by existing tests.

  • CMakeLists.txt: Add MathMLSpaceElement to the build system.
  • WebCore.xcodeproj/project.pbxproj: Ditto.
  • mathml/MathMLElement.cpp:

(WebCore::MathMLElement::cachedMathMLLength): Helper function to returned the cached parsed
value of a MathML length and parsing the corresponding attribute value if the cache is dirty.

  • mathml/MathMLElement.h: Add a dirty boolean to MathML Length structure. Declare cachedMathMLLength.
  • mathml/MathMLSpaceElement.cpp: New class for the <mspace> element.

(WebCore::MathMLSpaceElement::MathMLSpaceElement):
(WebCore::MathMLSpaceElement::create):
(WebCore::MathMLSpaceElement::parseAttribute): Make width, height, depth attributes dirty.
(WebCore::MathMLSpaceElement::createElementRenderer):

  • mathml/MathMLSpaceElement.h: New class for the <mspace> element.

We define MathML lengths for width, height and depth attributes are on the class and expose
with the corresponding helper functions via memoization.

  • mathml/MathMLTextElement.cpp: Remove handling of mspace from this class.

(WebCore::MathMLTextElement::createElementRenderer):

  • mathml/mathtags.in: Change the interface for mspace to use the new class.
  • rendering/mathml/RenderMathMLSpace.cpp: Do not store width/height/depth values on the

renderer and instead just use the corresponding MathML lengths on the element class.
(WebCore::RenderMathMLSpace::RenderMathMLSpace): Use MathMLSpaceElement and remove member
initialization.
(WebCore::RenderMathMLSpace::computePreferredLogicalWidths): Use spaceWidth().
(WebCore::RenderMathMLSpace::spaceWidth): Helper function to resolve the width attribute value.
(WebCore::RenderMathMLSpace::getSpaceHeightAndDepth): Ditto for height and depth.
(WebCore::RenderMathMLSpace::layoutBlock): Use the helper functions to get the mspace metrics.
(WebCore::RenderMathMLSpace::firstLineBaseline): Ditto.
(WebCore::RenderMathMLSpace::updateFromElement): Deleted.
(WebCore::RenderMathMLSpace::styleDidChange): Deleted.

  • rendering/mathml/RenderMathMLSpace.h: Use MathMLSpaceElement, replace members with helper

functions and and make element() usable from a const instance.

Location:
trunk/Source/WebCore
Files:
1 added
9 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/CMakeLists.txt

    r203038 r203108  
    19881988    mathml/MathMLMencloseElement.cpp
    19891989    mathml/MathMLSelectElement.cpp
     1990    mathml/MathMLSpaceElement.cpp
    19901991    mathml/MathMLTextElement.cpp
    19911992
  • trunk/Source/WebCore/ChangeLog

    r203106 r203108  
     12016-07-11  Frederic Wang  <fwang@igalia.org>
     2
     3        Move parsing of mspace attributes to a MathMLSpaceElement class
     4        https://bugs.webkit.org/show_bug.cgi?id=156795
     5
     6        Reviewed by Brent Fulgham.
     7
     8        No new tests, already covered by existing tests.
     9
     10        * CMakeLists.txt: Add MathMLSpaceElement to the build system.
     11        * WebCore.xcodeproj/project.pbxproj: Ditto.
     12        * mathml/MathMLElement.cpp:
     13        (WebCore::MathMLElement::cachedMathMLLength): Helper function to returned the cached parsed
     14        value of a MathML length and parsing the corresponding attribute value if the cache is dirty.
     15        * mathml/MathMLElement.h: Add a dirty boolean to MathML Length structure. Declare cachedMathMLLength.
     16        * mathml/MathMLSpaceElement.cpp: New class for the <mspace> element.
     17        (WebCore::MathMLSpaceElement::MathMLSpaceElement):
     18        (WebCore::MathMLSpaceElement::create):
     19        (WebCore::MathMLSpaceElement::parseAttribute): Make width, height, depth attributes dirty.
     20        (WebCore::MathMLSpaceElement::createElementRenderer):
     21        * mathml/MathMLSpaceElement.h: New class for the <mspace> element.
     22        We define MathML lengths for width, height and depth attributes are on the class and expose
     23        with the corresponding helper functions via memoization.
     24        * mathml/MathMLTextElement.cpp: Remove handling of mspace from this class.
     25        (WebCore::MathMLTextElement::createElementRenderer):
     26        * mathml/mathtags.in: Change the interface for mspace to use the new class.
     27        * rendering/mathml/RenderMathMLSpace.cpp: Do not store width/height/depth values on the
     28        renderer and instead just use the corresponding MathML lengths on the element class.
     29        (WebCore::RenderMathMLSpace::RenderMathMLSpace): Use MathMLSpaceElement and remove member
     30        initialization.
     31        (WebCore::RenderMathMLSpace::computePreferredLogicalWidths): Use spaceWidth().
     32        (WebCore::RenderMathMLSpace::spaceWidth): Helper function to resolve the width attribute value.
     33        (WebCore::RenderMathMLSpace::getSpaceHeightAndDepth): Ditto for height and depth.
     34        (WebCore::RenderMathMLSpace::layoutBlock): Use the helper functions to get the mspace metrics.
     35        (WebCore::RenderMathMLSpace::firstLineBaseline): Ditto.
     36        (WebCore::RenderMathMLSpace::updateFromElement): Deleted.
     37        (WebCore::RenderMathMLSpace::styleDidChange): Deleted.
     38        * rendering/mathml/RenderMathMLSpace.h: Use MathMLSpaceElement, replace members with helper
     39        functions and and make element() usable from a const instance.
     40
    1412016-07-11  Frederic Wang  <fwang@igalia.org>
    242
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r203038 r203108  
    68946894                F98FFF4511A2676200F548E8 /* CSSOMUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = F98FFF4311A2676200F548E8 /* CSSOMUtils.h */; };
    68956895                F9F0ED7A0DB50CA200D16DB9 /* XMLHttpRequestProgressEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = F9F0ED770DB50CA200D16DB9 /* XMLHttpRequestProgressEvent.h */; };
     6896                4FA65A6B1108ABED002615E0 /* MathMLSpaceElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4FA65A691108ABED002615E0 /* MathMLSpaceElement.cpp */; };
     6897                4FA65A6C1108ABED002615E0 /* MathMLSpaceElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 4FA65A6A1108ABED002615E0 /* MathMLSpaceElement.h */; };
    68966898                FA654A6B1108ABED002615E0 /* MathMLTextElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA654A691108ABED002615E0 /* MathMLTextElement.cpp */; };
    68976899                FA654A6C1108ABED002615E0 /* MathMLTextElement.h in Headers */ = {isa = PBXBuildFile; fileRef = FA654A6A1108ABED002615E0 /* MathMLTextElement.h */; };
     
    1505615058                FA654A631108ABB7002615E0 /* mathml.css */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.css; path = mathml.css; sourceTree = "<group>"; };
    1505715059                FA654A671108ABE2002615E0 /* mathattrs.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = mathattrs.in; sourceTree = "<group>"; };
     15060                4FA65A691108ABED002615E0 /* MathMLSpaceElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MathMLSpaceElement.cpp; sourceTree = "<group>"; };
     15061                4FA65A6A1108ABED002615E0 /* MathMLSpaceElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MathMLSpaceElement.h; sourceTree = "<group>"; };
    1505815062                FA654A691108ABED002615E0 /* MathMLTextElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MathMLTextElement.cpp; sourceTree = "<group>"; };
    1505915063                FA654A6A1108ABED002615E0 /* MathMLTextElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MathMLTextElement.h; sourceTree = "<group>"; };
     
    2486324867                                F75A059AF170D8FAA5B8CABE /* MathMLSelectElement.cpp */,
    2486424868                                59780849D41E6F65D81198BC /* MathMLSelectElement.h */,
     24869                                4FA65A691108ABED002615E0 /* MathMLSpaceElement.cpp */,
     24870                                4FA65A6A1108ABED002615E0 /* MathMLSpaceElement.h */,
    2486524871                                FA654A691108ABED002615E0 /* MathMLTextElement.cpp */,
    2486624872                                FA654A6A1108ABED002615E0 /* MathMLTextElement.h */,
     
    2739927405                                439046E012DA25E17BAF80A2 /* MathMLOperatorDictionary.h in Headers */,
    2740027406                                439176E012DA25E17BAF80A2 /* MathMLStyle.h in Headers */,
     27407                                4FA65A6C1108ABED002615E0 /* MathMLSpaceElement.h in Headers */,
    2740127408                                FA654A6C1108ABED002615E0 /* MathMLTextElement.h in Headers */,
    2740227409                                439046EA12DA25E812AF80AC /* MathOperator.h in Headers */,
     
    3122231229                                439176DF12DA25E17BAF80A2 /* MathMLStyle.cpp in Sources */,
    3122331230                                FED48390CED66C3255F72C59 /* MathMLSelectElement.cpp in Sources */,
     31231                                4FA65A6B1108ABED002615E0 /* MathMLSpaceElement.cpp in Sources */,
    3122431232                                FA654A6B1108ABED002615E0 /* MathMLTextElement.cpp in Sources */,
    3122531233                                439046E912DA25E812AF80AC /* MathOperator.cpp in Sources */,
  • trunk/Source/WebCore/mathml/MathMLElement.cpp

    r203106 r203108  
    517517}
    518518
     519const MathMLElement::Length& MathMLElement::cachedMathMLLength(const QualifiedName& name, Length& length)
     520{
     521    if (length.dirty) {
     522        length = parseMathMLLength(fastGetAttribute(name));
     523        length.dirty = false;
     524    }
     525    return length;
     526}
     527
    519528}
    520529
  • trunk/Source/WebCore/mathml/MathMLElement.h

    r203106 r203108  
    6464        LengthType type { LengthType::ParsingFailed };
    6565        float value { 0 };
     66        bool dirty { true };
    6667    };
    6768    static Length parseMathMLLength(const String&);
     
    8283    bool willRespondToMouseClickEvents() override;
    8384    void defaultEventHandler(Event*) override;
     85
     86    const Length& cachedMathMLLength(const QualifiedName&, Length&);
    8487
    8588private:
  • trunk/Source/WebCore/mathml/MathMLSpaceElement.h

    r203107 r203108  
    11/*
    2  * Copyright (C) 2013 The MathJax Consortium. All rights reserved.
     2 * Copyright (C) 2016 Igalia S.L. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2424 */
    2525
    26 #ifndef RenderMathMLSpace_h
    27 #define RenderMathMLSpace_h
     26#ifndef MathMLSpaceElement_h
     27#define MathMLSpaceElement_h
    2828
    2929#if ENABLE(MATHML)
    30 
    31 #include "MathMLTextElement.h"
    32 #include "RenderMathMLBlock.h"
     30#include "MathMLElement.h"
    3331
    3432namespace WebCore {
    3533
    36 class RenderMathMLSpace final : public RenderMathMLBlock {
     34class MathMLSpaceElement final : public MathMLElement {
    3735public:
    38     RenderMathMLSpace(MathMLTextElement&, RenderStyle&&);
    39     MathMLTextElement& element() { return static_cast<MathMLTextElement&>(nodeForNonAnonymous()); }
     36    static Ref<MathMLSpaceElement> create(const QualifiedName& tagName, Document&);
     37    const Length& width();
     38    const Length& height();
     39    const Length& depth();
     40private:
     41    MathMLSpaceElement(const QualifiedName& tagName, Document&);
     42    bool isPresentationMathML() const final { return true; }
     43    RenderPtr<RenderElement> createElementRenderer(RenderStyle&&, const RenderTreePosition&) final;
     44    void parseAttribute(const QualifiedName&, const AtomicString&) final;
    4045
    41 private:
    42     const char* renderName() const final { return "RenderMathMLSpace"; }
    43     bool isRenderMathMLSpace() const final { return true; }
    44     void styleDidChange(StyleDifference, const RenderStyle* oldStyle) final;
    45     bool isChildAllowed(const RenderObject&, const RenderStyle&) const final { return false; }
    46     void updateFromElement() final;
    47     void computePreferredLogicalWidths() final;
    48     void layoutBlock(bool relayoutChildren, LayoutUnit pageLogicalHeight = 0) final;
    49     Optional<int> firstLineBaseline() const final;
    50 
    51     LayoutUnit m_width;
    52     LayoutUnit m_height;
    53     LayoutUnit m_depth;
     46    Length m_width;
     47    Length m_height;
     48    Length m_depth;
    5449};
    5550
    56 } // namespace WebCore
    57 
    58 SPECIALIZE_TYPE_TRAITS_RENDER_OBJECT(RenderMathMLSpace, isRenderMathMLSpace())
     51}
    5952
    6053#endif // ENABLE(MATHML)
    61 #endif // RenderMathMLSpace_h
     54#endif // MathMLSpaceElement_h
  • trunk/Source/WebCore/mathml/MathMLTextElement.cpp

    r203072 r203108  
    3333#include "MathMLNames.h"
    3434#include "RenderMathMLOperator.h"
    35 #include "RenderMathMLSpace.h"
    3635#include "RenderMathMLToken.h"
    3736
     
    8382    if (hasTagName(MathMLNames::moTag))
    8483        return createRenderer<RenderMathMLOperator>(*this, WTFMove(style));
    85     if (hasTagName(MathMLNames::mspaceTag))
    86         return createRenderer<RenderMathMLSpace>(*this, WTFMove(style));
    8784    if (hasTagName(MathMLNames::annotationTag))
    8885        return MathMLElement::createElementRenderer(WTFMove(style), insertionPosition);
  • trunk/Source/WebCore/mathml/mathtags.in

    r202962 r203108  
    2626mtext interfaceName=MathMLTextElement
    2727ms interfaceName=MathMLTextElement
    28 mspace interfaceName=MathMLTextElement
     28mspace interfaceName=MathMLSpaceElement
    2929msub interfaceName=MathMLInlineContainerElement
    3030msup interfaceName=MathMLInlineContainerElement
  • trunk/Source/WebCore/rendering/mathml/RenderMathMLSpace.cpp

    r202727 r203108  
    3737using namespace MathMLNames;
    3838
    39 RenderMathMLSpace::RenderMathMLSpace(MathMLTextElement& element, RenderStyle&& style)
     39RenderMathMLSpace::RenderMathMLSpace(MathMLSpaceElement& element, RenderStyle&& style)
    4040    : RenderMathMLBlock(element, WTFMove(style))
    41     , m_width(0)
    42     , m_height(0)
    43     , m_depth(0)
    4441{
    4542}
     
    4946    ASSERT(preferredLogicalWidthsDirty());
    5047
    51     m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = m_width;
     48    m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = spaceWidth();
    5249
    5350    setPreferredLogicalWidthsDirty(false);
    5451}
    5552
    56 void RenderMathMLSpace::updateFromElement()
     53LayoutUnit RenderMathMLSpace::spaceWidth() const
    5754{
    58     const auto& spaceElement = element();
     55    auto& spaceElement = element();
     56    // FIXME: Negative width values are not supported yet.
     57    return std::max<LayoutUnit>(0, toUserUnits(spaceElement.width(), style(), 0));
     58}
    5959
    60     // This parses the mspace attributes, using 0 as the default values.
    61     m_width = 0;
    62     m_height = 0;
    63     m_depth = 0;
    64     parseMathMLLength(spaceElement.getAttribute(MathMLNames::widthAttr), m_width, &style());
    65     parseMathMLLength(spaceElement.getAttribute(MathMLNames::heightAttr), m_height, &style());
    66     parseMathMLLength(spaceElement.getAttribute(MathMLNames::depthAttr), m_depth, &style());
    67 
    68     // FIXME: Negative width values should be accepted.
    69     if (m_width < 0)
    70         m_width = 0;
     60void RenderMathMLSpace::getSpaceHeightAndDepth(LayoutUnit& height, LayoutUnit& depth) const
     61{
     62    auto& spaceElement = element();
     63    height = toUserUnits(spaceElement.height(), style(), 0);
     64    depth = toUserUnits(spaceElement.depth(), style(), 0);
    7165
    7266    // If the total height is negative, set vertical dimensions to 0.
    73     if (m_height + m_depth < 0) {
    74         m_height = 0;
    75         m_depth = 0;
     67    if (height + depth < 0) {
     68        height = 0;
     69        depth = 0;
    7670    }
    77 
    78     setNeedsLayoutAndPrefWidthsRecalc();
    7971}
    8072
     
    8678        return;
    8779
    88     setLogicalWidth(m_width);
    89     setLogicalHeight(m_height + m_depth);
     80    setLogicalWidth(spaceWidth());
     81    LayoutUnit height, depth;
     82    getSpaceHeightAndDepth(height, depth);
     83    setLogicalHeight(height + depth);
    9084
    9185    clearNeedsLayout();
    9286}
    9387
    94 void RenderMathMLSpace::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
    95 {
    96     RenderMathMLBlock::styleDidChange(diff, oldStyle);
    97     updateFromElement();
    98 }
    99 
    10088Optional<int> RenderMathMLSpace::firstLineBaseline() const
    10189{
    102     return Optional<int>(m_height);
     90    LayoutUnit height, depth;
     91    getSpaceHeightAndDepth(height, depth);
     92    return Optional<int>(height);
    10393}
    10494
  • trunk/Source/WebCore/rendering/mathml/RenderMathMLSpace.h

    r202727 r203108  
    2929#if ENABLE(MATHML)
    3030
    31 #include "MathMLTextElement.h"
     31#include "MathMLSpaceElement.h"
    3232#include "RenderMathMLBlock.h"
    3333
     
    3636class RenderMathMLSpace final : public RenderMathMLBlock {
    3737public:
    38     RenderMathMLSpace(MathMLTextElement&, RenderStyle&&);
    39     MathMLTextElement& element() { return static_cast<MathMLTextElement&>(nodeForNonAnonymous()); }
     38    RenderMathMLSpace(MathMLSpaceElement&, RenderStyle&&);
     39    MathMLSpaceElement& element() const { return static_cast<MathMLSpaceElement&>(nodeForNonAnonymous()); }
    4040
    4141private:
    4242    const char* renderName() const final { return "RenderMathMLSpace"; }
    4343    bool isRenderMathMLSpace() const final { return true; }
    44     void styleDidChange(StyleDifference, const RenderStyle* oldStyle) final;
    4544    bool isChildAllowed(const RenderObject&, const RenderStyle&) const final { return false; }
    46     void updateFromElement() final;
    4745    void computePreferredLogicalWidths() final;
    4846    void layoutBlock(bool relayoutChildren, LayoutUnit pageLogicalHeight = 0) final;
    4947    Optional<int> firstLineBaseline() const final;
    5048
    51     LayoutUnit m_width;
    52     LayoutUnit m_height;
    53     LayoutUnit m_depth;
     49    LayoutUnit spaceWidth() const;
     50    void getSpaceHeightAndDepth(LayoutUnit& height, LayoutUnit& depth) const;
    5451};
    5552
Note: See TracChangeset for help on using the changeset viewer.