Changeset 203396 in webkit


Ignore:
Timestamp:
Jul 18, 2016 10:42:46 PM (8 years ago)
Author:
fred.wang@free.fr
Message:

Move parsing of subscriptshift and superscriptshift from rendering to element classes
https://bugs.webkit.org/show_bug.cgi?id=159622

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

We introduce a new MathMLScriptsElement that is used for elements msub, msup, msubsup and
mmultiscripts in order to create RenderMathMLScripts and parse and expose the values of the
subscriptshift and superscriptshift attributes. This is one more step toward moving MathML
attribute parsing to the DOM (bug 156536).

No new tests, rendering is unchanged.

  • CMakeLists.txt: Add MathMLScriptsElement files.
  • WebCore.xcodeproj/project.pbxproj: Ditto.
  • mathml/MathMLAllInOne.cpp: Ditto.
  • mathml/MathMLInlineContainerElement.cpp: Remove handling of scripts.

(WebCore::MathMLInlineContainerElement::createElementRenderer): Deleted.

  • mathml/MathMLScriptsElement.cpp: Added. New class to handle scripted elements supporting

parsing for the subscriptshift and superscriptshift MathML lengths.
(WebCore::MathMLScriptsElement::MathMLScriptsElement):
(WebCore::MathMLScriptsElement::create):
(WebCore::MathMLScriptsElement::subscriptShift): Expose the cached length for the shift,
parsing the attribute again if necessary.
(WebCore::MathMLScriptsElement::superscriptShift): Ditto.
(WebCore::MathMLScriptsElement::parseAttribute): Mark attributes dirty.
(WebCore::MathMLScriptsElement::createElementRenderer): Create RenderMathMLScripts.

  • mathml/MathMLScriptsElement.h: Ditto.
  • mathml/mathtags.in: Map msub, msup, msubsup and mmultiscripts to MathMLScriptsElement.
  • rendering/mathml/RenderMathMLScripts.cpp:

(WebCore::RenderMathMLScripts::scriptsElement): Helper function to cast the node to a
MathMLScriptsElement.
(WebCore::RenderMathMLScripts::getScriptMetricsAndLayoutIfNeeded): Resolve the attributes
using the functions from the MathMLScriptsElement class.

  • rendering/mathml/RenderMathMLScripts.h: Declare scriptsElement.
Location:
trunk/Source/WebCore
Files:
1 added
8 edited
1 copied

Legend:

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

    r203285 r203396  
    19921992    mathml/MathMLOperatorDictionary.cpp
    19931993    mathml/MathMLPaddedElement.cpp
     1994    mathml/MathMLScriptsElement.cpp
    19941995    mathml/MathMLSelectElement.cpp
    19951996    mathml/MathMLSpaceElement.cpp
  • trunk/Source/WebCore/ChangeLog

    r203395 r203396  
     12016-07-18  Frederic Wang  <fwang@igalia.com>
     2
     3        Move parsing of subscriptshift and superscriptshift from rendering to element classes
     4        https://bugs.webkit.org/show_bug.cgi?id=159622
     5
     6        Reviewed by Darin Adler.
     7
     8        We introduce a new MathMLScriptsElement that is used for elements msub, msup, msubsup and
     9        mmultiscripts in order to create RenderMathMLScripts and parse and expose the values of the
     10        subscriptshift and superscriptshift attributes. This is one more step toward moving MathML
     11        attribute parsing to the DOM (bug 156536).
     12
     13        No new tests, rendering is unchanged.
     14
     15        * CMakeLists.txt: Add MathMLScriptsElement files.
     16        * WebCore.xcodeproj/project.pbxproj: Ditto.
     17        * mathml/MathMLAllInOne.cpp: Ditto.
     18        * mathml/MathMLInlineContainerElement.cpp: Remove handling of scripts.
     19        (WebCore::MathMLInlineContainerElement::createElementRenderer): Deleted.
     20        * mathml/MathMLScriptsElement.cpp: Added. New class to handle scripted elements supporting
     21        parsing for the subscriptshift and superscriptshift MathML lengths.
     22        (WebCore::MathMLScriptsElement::MathMLScriptsElement):
     23        (WebCore::MathMLScriptsElement::create):
     24        (WebCore::MathMLScriptsElement::subscriptShift): Expose the cached length for the shift,
     25        parsing the attribute again if necessary.
     26        (WebCore::MathMLScriptsElement::superscriptShift): Ditto.
     27        (WebCore::MathMLScriptsElement::parseAttribute): Mark attributes dirty.
     28        (WebCore::MathMLScriptsElement::createElementRenderer): Create RenderMathMLScripts.
     29        * mathml/MathMLScriptsElement.h: Ditto.
     30        * mathml/mathtags.in: Map msub, msup, msubsup and mmultiscripts to MathMLScriptsElement.
     31        * rendering/mathml/RenderMathMLScripts.cpp:
     32        (WebCore::RenderMathMLScripts::scriptsElement): Helper function to cast the node to a
     33        MathMLScriptsElement.
     34        (WebCore::RenderMathMLScripts::getScriptMetricsAndLayoutIfNeeded): Resolve the attributes
     35        using the functions from the MathMLScriptsElement class.
     36        * rendering/mathml/RenderMathMLScripts.h: Declare scriptsElement.
     37
    1382016-07-18  Frederic Wang  <fwang@igalia.com>
    239
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r203381 r203396  
    54055405                B57CB52E182A3EFC0079A647 /* InlineElementBox.h in Headers */ = {isa = PBXBuildFile; fileRef = B57CB52B182A37F60079A647 /* InlineElementBox.h */; };
    54065406                B595FF471824CEE300FF51CD /* RenderIterator.h in Headers */ = {isa = PBXBuildFile; fileRef = B595FF461824CEE300FF51CD /* RenderIterator.h */; };
     5407                B59CA390CED66C3255F72B48 /* MathMLScriptsElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B59CA59AF170D8FAA5B8C9AD /* MathMLScriptsElement.cpp */; };
    54075408                B59CA390CED66C3255F72C59 /* MathMLPaddedElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B59CA59AF170D8FAA5B8CABE /* MathMLPaddedElement.cpp */; };
    54085409                B59DD699119029E5007E9684 /* JSDatabaseCallback.h in Headers */ = {isa = PBXBuildFile; fileRef = B59DD697119029E5007E9684 /* JSDatabaseCallback.h */; };
     
    1340413405                B57CB52C182A3EED0079A647 /* InlineElementBox.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InlineElementBox.cpp; sourceTree = "<group>"; };
    1340513406                B595FF461824CEE300FF51CD /* RenderIterator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderIterator.h; sourceTree = "<group>"; };
     13407                B59CA59AF170D8FAA5B8C9AD /* MathMLScriptsElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MathMLScriptsElement.cpp; sourceTree = "<group>"; };
     13408                B59CA849D41E6F65D81197AB /* MathMLScriptsElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MathMLScriptsElement.h; sourceTree = "<group>"; };
    1340613409                B59CA59AF170D8FAA5B8CABE /* MathMLPaddedElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MathMLPaddedElement.cpp; sourceTree = "<group>"; };
    1340713410                B59CA849D41E6F65D81198BC /* MathMLPaddedElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MathMLPaddedElement.h; sourceTree = "<group>"; };
     
    2489424897                                D4F72C653A64807A83E76FB8 /* MathMLOperatorDictionary.cpp */,
    2489524898                                DF7E9A294C7AACE0AD89B3DD /* MathMLOperatorDictionary.h */,
     24899                                B59CA59AF170D8FAA5B8C9AD /* MathMLScriptsElement.cpp */,
     24900                                B59CA849D41E6F65D81197AB /* MathMLScriptsElement.h */,
    2489624901                                B59CA59AF170D8FAA5B8CABE /* MathMLPaddedElement.cpp */,
    2489724902                                B59CA849D41E6F65D81198BC /* MathMLPaddedElement.h */,
     
    3126731272                                FABE72FE1059C21100D999DD /* MathMLNames.cpp in Sources */,
    3126831273                                439176DF12DA25E17BAF80A2 /* MathMLStyle.cpp in Sources */,
     31274                                B59CA390CED66C3255F72B48 /* MathMLScriptsElement.cpp in Sources */,
    3126931275                                B59CA390CED66C3255F72C59 /* MathMLPaddedElement.cpp in Sources */,
    3127031276                                FED48390CED66C3255F72C59 /* MathMLSelectElement.cpp in Sources */,
  • trunk/Source/WebCore/mathml/MathMLAllInOne.cpp

    r203285 r203396  
    3333#include "MathMLOperatorDictionary.cpp"
    3434#include "MathMLPaddedElement.cpp"
     35#include "MathMLScriptsElement.cpp"
    3536#include "MathMLSelectElement.cpp"
    3637#include "MathMLTextElement.cpp"
  • trunk/Source/WebCore/mathml/MathMLInlineContainerElement.cpp

    r203285 r203396  
    3737#include "RenderMathMLRoot.h"
    3838#include "RenderMathMLRow.h"
    39 #include "RenderMathMLScripts.h"
    4039#include "RenderMathMLUnderOver.h"
    4140
     
    6766    if (hasTagName(annotation_xmlTag) || hasTagName(merrorTag) || hasTagName(mphantomTag) || hasTagName(mrowTag) || hasTagName(mstyleTag))
    6867        return createRenderer<RenderMathMLRow>(*this, WTFMove(style));
    69     if (hasTagName(msubTag) || hasTagName(msupTag) || hasTagName(msubsupTag) || hasTagName(mmultiscriptsTag))
    70         return createRenderer<RenderMathMLScripts>(*this, WTFMove(style));
    7168    if (hasTagName(moverTag) || hasTagName(munderTag) || hasTagName(munderoverTag))
    7269        return createRenderer<RenderMathMLUnderOver>(*this, WTFMove(style));
  • trunk/Source/WebCore/mathml/MathMLScriptsElement.h

    r203395 r203396  
    11/*
    2  * Copyright (C) 2010 Alex Milowski (alex@milowski.com). All rights reserved.
    3  * Copyright (C) 2013 The MathJax Consortium.
    4  * Copyright (C) 2016 Igalia S.L.
     2 * Copyright (C) 2016 Igalia S.L. All rights reserved.
    53 *
    64 * Redistribution and use in source and binary forms, with or without
     
    2927
    3028#if ENABLE(MATHML)
    31 
    32 #include "RenderMathMLBlock.h"
     29#include "MathMLInlineContainerElement.h"
    3330
    3431namespace WebCore {
    35 // Render a base with scripts.
    36 class RenderMathMLScripts : public RenderMathMLBlock {
     32
     33class MathMLScriptsElement final : public MathMLInlineContainerElement {
    3734public:
    38     RenderMathMLScripts(Element&, RenderStyle&&);
    39     RenderMathMLOperator* unembellishedOperator() final;
    40 
    41 protected:
    42     bool isRenderMathMLScripts() const override { return true; }
    43     const char* renderName() const override { return "RenderMathMLScripts"; }
    44     void computePreferredLogicalWidths() override;
    45     void layoutBlock(bool relayoutChildren, LayoutUnit pageLogicalHeight = 0) override;
    46 
    47     enum ScriptsType { Sub, Super, SubSup, Multiscripts, Under, Over, UnderOver };
    48     ScriptsType m_scriptType;
     35    static Ref<MathMLScriptsElement> create(const QualifiedName& tagName, Document&);
     36    const Length& subscriptShift();
     37    const Length& superscriptShift();
    4938
    5039private:
    51     Optional<int> firstLineBaseline() const final;
    52     bool getBaseAndScripts(RenderBox*& base, RenderBox*& firstPostScript, RenderBox*& firstPreScript);
    53     LayoutUnit spaceAfterScript();
    54     LayoutUnit italicCorrection(RenderBox* base);
    55     void getScriptMetricsAndLayoutIfNeeded(RenderBox* base, RenderBox* script, LayoutUnit& minSubScriptShift, LayoutUnit& minSupScriptShift, LayoutUnit& maxScriptDescent, LayoutUnit& maxScriptAscent);
     40    MathMLScriptsElement(const QualifiedName& tagName, Document&);
     41    RenderPtr<RenderElement> createElementRenderer(RenderStyle&&, const RenderTreePosition&) final;
     42    void parseAttribute(const QualifiedName&, const AtomicString&) final;
     43
     44    Length m_subscriptShift;
     45    Length m_superscriptShift;
    5646};
    5747
    58 } // namespace WebCore
    59 
    60 SPECIALIZE_TYPE_TRAITS_RENDER_OBJECT(RenderMathMLScripts, isRenderMathMLScripts())
     48}
    6149
    6250#endif // ENABLE(MATHML)
  • trunk/Source/WebCore/mathml/mathtags.in

    r203285 r203396  
    1010mfrac interfaceName=MathMLFractionElement
    1111mfenced interfaceName=MathMLInlineContainerElement
    12 msubsup interfaceName=MathMLInlineContainerElement
     12msubsup interfaceName=MathMLScriptsElement
    1313merror interfaceName=MathMLInlineContainerElement
    1414mpadded interfaceName=MathMLPaddedElement
     
    2727ms interfaceName=MathMLTextElement
    2828mspace interfaceName=MathMLSpaceElement
    29 msub interfaceName=MathMLInlineContainerElement
    30 msup interfaceName=MathMLInlineContainerElement
     29msub interfaceName=MathMLScriptsElement
     30msup interfaceName=MathMLScriptsElement
    3131mtable interfaceName=MathMLInlineContainerElement
    3232mtr interfaceName=MathMLElement
    3333mtd interfaceName=MathMLElement
    34 mmultiscripts interfaceName=MathMLInlineContainerElement
     34mmultiscripts interfaceName=MathMLScriptsElement
    3535mprescripts interfaceName=MathMLInlineContainerElement
    3636menclose interfaceName=MathMLMencloseElement
  • trunk/Source/WebCore/rendering/mathml/RenderMathMLScripts.cpp

    r203324 r203396  
    3333
    3434#include "MathMLElement.h"
     35#include "MathMLScriptsElement.h"
    3536#include "RenderMathMLOperator.h"
    3637
     
    6465        m_scriptType = Multiscripts;
    6566    }
     67}
     68
     69MathMLScriptsElement& RenderMathMLScripts::scriptsElement() const
     70{
     71    ASSERT(!isRenderMathMLUnderOver());
     72    return static_cast<MathMLScriptsElement&>(nodeForNonAnonymous());
    6673}
    6774
     
    252259        minSubScriptShift = std::max(subscriptShiftDown, baseDescent + subscriptBaselineDropMin);
    253260        if (!isRenderMathMLUnderOver()) {
    254             LayoutUnit specifiedMinSubShift = 0;
    255             parseMathMLLength(element()->attributeWithoutSynchronization(MathMLNames::subscriptshiftAttr), specifiedMinSubShift, &style(), false);
     261            // It is not clear how to interpret the default shift and it is not available yet anyway.
     262            // Hence we just pass 0 as the default value used by toUserUnits.
     263            LayoutUnit specifiedMinSubShift = toUserUnits(scriptsElement().subscriptShift(), style(), 0);
    256264            minSubScriptShift = std::max(minSubScriptShift, specifiedMinSubShift);
    257265        }
     
    260268        minSupScriptShift = std::max(superscriptShiftUp, baseAscent - superScriptBaselineDropMax);
    261269        if (!isRenderMathMLUnderOver()) {
    262             LayoutUnit specifiedMinSupShift = 0;
    263             parseMathMLLength(element()->attributeWithoutSynchronization(MathMLNames::superscriptshiftAttr), specifiedMinSupShift, &style(), false);
     270            // It is not clear how to interpret the default shift and it is not available yet anyway.
     271            // Hence we just pass 0 as the default value used by toUserUnits.
     272            LayoutUnit specifiedMinSupShift = toUserUnits(scriptsElement().superscriptShift(), style(), 0);
    264273            minSupScriptShift = std::max(minSupScriptShift, specifiedMinSupShift);
    265274        }
  • trunk/Source/WebCore/rendering/mathml/RenderMathMLScripts.h

    r203228 r203396  
    3333
    3434namespace WebCore {
     35
     36class MathMLScriptsElement;
     37
    3538// Render a base with scripts.
    3639class RenderMathMLScripts : public RenderMathMLBlock {
     
    4952
    5053private:
     54    MathMLScriptsElement& scriptsElement() const;
    5155    Optional<int> firstLineBaseline() const final;
    5256    bool getBaseAndScripts(RenderBox*& base, RenderBox*& firstPostScript, RenderBox*& firstPreScript);
Note: See TracChangeset for help on using the changeset viewer.