Changeset 226654 in webkit


Ignore:
Timestamp:
Jan 9, 2018 12:15:19 PM (6 years ago)
Author:
Alan Bujtas
Message:

[RenderTreeBuilder] Move MathML addChild logic to RenderTreeBuilder
https://bugs.webkit.org/show_bug.cgi?id=181443
<rdar://problem/36380228>

Reviewed by Antti Koivisto.

This is about moving code, no cleanup and/or normalization (unfortunately it also means
some temporary changes).

No change in functionality.

  • Sources.txt:
  • WebCore.xcodeproj/project.pbxproj:
  • rendering/mathml/RenderMathMLFenced.cpp:

(WebCore::RenderMathMLFenced::addChild):
(WebCore::RenderMathMLFenced::createMathMLOperator): Deleted.
(WebCore::RenderMathMLFenced::makeFences): Deleted.

  • rendering/mathml/RenderMathMLFenced.h:
  • rendering/updating/RenderTreeBuilder.cpp:

(WebCore::RenderTreeBuilder::RenderTreeBuilder):
(WebCore::RenderTreeBuilder::insertChildToRenderMathMLFenced):

  • rendering/updating/RenderTreeBuilder.h:

(WebCore::RenderTreeBuilder::mathMLBuilder):

Location:
trunk/Source/WebCore
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r226653 r226654  
     12018-01-09  Zalan Bujtas  <zalan@apple.com>
     2
     3        [RenderTreeBuilder] Move MathML addChild logic to RenderTreeBuilder
     4        https://bugs.webkit.org/show_bug.cgi?id=181443
     5        <rdar://problem/36380228>
     6
     7        Reviewed by Antti Koivisto.
     8
     9        This is about moving code, no cleanup and/or normalization (unfortunately it also means
     10        some temporary changes). 
     11
     12        No change in functionality.
     13
     14        * Sources.txt:
     15        * WebCore.xcodeproj/project.pbxproj:
     16        * rendering/mathml/RenderMathMLFenced.cpp:
     17        (WebCore::RenderMathMLFenced::addChild):
     18        (WebCore::RenderMathMLFenced::createMathMLOperator): Deleted.
     19        (WebCore::RenderMathMLFenced::makeFences): Deleted.
     20        * rendering/mathml/RenderMathMLFenced.h:
     21        * rendering/updating/RenderTreeBuilder.cpp:
     22        (WebCore::RenderTreeBuilder::RenderTreeBuilder):
     23        (WebCore::RenderTreeBuilder::insertChildToRenderMathMLFenced):
     24        * rendering/updating/RenderTreeBuilder.h:
     25        (WebCore::RenderTreeBuilder::mathMLBuilder):
     26
    1272018-01-09  Antti Koivisto  <antti@apple.com>
    228
  • trunk/Source/WebCore/Sources.txt

    r226613 r226654  
    19901990rendering/updating/RenderTreeBuilderInline.cpp
    19911991rendering/updating/RenderTreeBuilderList.cpp
     1992rendering/updating/RenderTreeBuilderMathML.cpp
    19921993rendering/updating/RenderTreeBuilderMultiColumn.cpp
    19931994rendering/updating/RenderTreeBuilderRuby.cpp
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r226613 r226654  
    55985598                11C5F12A2004231D0001AE60 /* RenderTreeBuilderSVG.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderTreeBuilderSVG.h; sourceTree = "<group>"; };
    55995599                11C5F12C2004231E0001AE60 /* RenderTreeBuilderSVG.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RenderTreeBuilderSVG.cpp; sourceTree = "<group>"; };
     5600                11C5F132200527F80001AE60 /* RenderTreeBuilderMathML.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RenderTreeBuilderMathML.cpp; sourceTree = "<group>"; };
     5601                11C5F134200527F90001AE60 /* RenderTreeBuilderMathML.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderTreeBuilderMathML.h; sourceTree = "<group>"; };
    56005602                11E067EB1E62461300162D16 /* SimpleLineLayoutCoverage.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SimpleLineLayoutCoverage.cpp; sourceTree = "<group>"; };
    56015603                11E067ED1E6246E500162D16 /* SimpleLineLayoutCoverage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SimpleLineLayoutCoverage.h; sourceTree = "<group>"; };
     
    2464624648                                E47C392B1FE6E0DF00BBBC6B /* RenderTreeBuilderList.cpp */,
    2464724649                                E47C39281FE6E0DD00BBBC6B /* RenderTreeBuilderList.h */,
     24650                                11C5F132200527F80001AE60 /* RenderTreeBuilderMathML.cpp */,
     24651                                11C5F134200527F90001AE60 /* RenderTreeBuilderMathML.h */,
    2464824652                                E47C39231FE6E0DA00BBBC6B /* RenderTreeBuilderMultiColumn.cpp */,
    2464924653                                E47C39271FE6E0DC00BBBC6B /* RenderTreeBuilderMultiColumn.h */,
  • trunk/Source/WebCore/rendering/mathml/RenderMathMLFenced.cpp

    r226007 r226654  
    3535#include "RenderMathMLFencedOperator.h"
    3636#include "RenderText.h"
     37#include "RenderTreeBuilder.h"
    3738#include <wtf/IsoMallocInlines.h>
    3839#include <wtf/text/StringBuilder.h>
     
    8586}
    8687
    87 RenderPtr<RenderMathMLFencedOperator> RenderMathMLFenced::createMathMLOperator(const String& operatorString, MathMLOperatorDictionary::Form form, MathMLOperatorDictionary::Flag flag)
    88 {
    89     RenderPtr<RenderMathMLFencedOperator> newOperator = createRenderer<RenderMathMLFencedOperator>(document(), RenderStyle::createAnonymousStyleWithDisplay(style(), BLOCK), operatorString, form, flag);
    90     newOperator->initializeStyle();
    91     return newOperator;
    92 }
    93 
    94 void RenderMathMLFenced::makeFences(RenderTreeBuilder& builder)
    95 {
    96     auto openFence = createMathMLOperator(m_open, MathMLOperatorDictionary::Prefix, MathMLOperatorDictionary::Fence);
    97     RenderMathMLRow::addChild(builder, WTFMove(openFence), firstChild());
    98 
    99     auto closeFence = createMathMLOperator(m_close, MathMLOperatorDictionary::Postfix, MathMLOperatorDictionary::Fence);
    100     m_closeFenceRenderer = makeWeakPtr(*closeFence);
    101     RenderMathMLRow::addChild(builder, WTFMove(closeFence));
    102 }
    103 
    10488void RenderMathMLFenced::addChild(RenderTreeBuilder& builder, RenderPtr<RenderObject> child, RenderObject* beforeChild)
    10589{
    10690    // make the fences if the render object is empty
    107     if (!firstChild()) {
     91    if (!firstChild())
    10892        updateFromElement();
    109         makeFences(builder);
    110     }
    111 
    112     // FIXME: Adding or removing a child should possibly cause all later separators to shift places if they're different, as later child positions change by +1 or -1. This should also handle surrogate pairs. See https://bugs.webkit.org/show_bug.cgi?id=125938.
    113 
    114     RenderPtr<RenderMathMLFencedOperator> separatorRenderer;
    115     if (m_separators.get()) {
    116         unsigned int count = 0;
    117         for (Node* position = child->node(); position; position = position->previousSibling()) {
    118             if (position->isElementNode())
    119                 count++;
    120         }
    121         if (!beforeChild) {
    122             // We're adding at the end (before the closing fence), so a new separator would go before the new child, not after it.
    123             --count;
    124         }
    125         // |count| is now the number of element children that will be before our new separator, i.e. it's the 1-based index of the separator.
    126 
    127         if (count > 0) {
    128             UChar separator;
    129 
    130             // Use the last separator if we've run out of specified separators.
    131             if (count > m_separators.get()->length())
    132                 separator = (*m_separators.get())[m_separators.get()->length() - 1];
    133             else
    134                 separator = (*m_separators.get())[count - 1];
    135 
    136             StringBuilder stringBuilder;
    137             stringBuilder.append(separator);
    138             separatorRenderer = createMathMLOperator(stringBuilder.toString(), MathMLOperatorDictionary::Infix, MathMLOperatorDictionary::Separator);
    139         }
    140     }
    141 
    142     if (beforeChild) {
    143         // Adding |x| before an existing |y| e.g. in element (y) - first insert our new child |x|, then its separator, to get (x, y).
    144         RenderMathMLRow::addChild(builder, WTFMove(child), beforeChild);
    145         if (separatorRenderer)
    146             RenderMathMLRow::addChild(builder, WTFMove(separatorRenderer), beforeChild);
    147     } else {
    148         // Adding |y| at the end of an existing element e.g. (x) - insert the separator first before the closing fence, then |y|, to get (x, y).
    149         if (separatorRenderer)
    150             RenderMathMLRow::addChild(builder, WTFMove(separatorRenderer), m_closeFenceRenderer.get());
    151         RenderMathMLRow::addChild(builder, WTFMove(child), m_closeFenceRenderer.get());
    152     }
     93    builder.insertChildToRenderMathMLFenced(*this, WTFMove(child), beforeChild);
    15394}
    15495
  • trunk/Source/WebCore/rendering/mathml/RenderMathMLFenced.h

    r226007 r226654  
    4040    RenderMathMLFenced(MathMLRowElement&, RenderStyle&&);
    4141
     42    StringImpl* separators() const { return m_separators.get(); }
     43    String openingBrace() const { return m_open; }
     44    String closingBrace() const { return m_close; }
     45
     46    RenderMathMLFencedOperator* closeFenceRenderer() const { return m_closeFenceRenderer.get(); }
     47    void setCloseFenceRenderer(RenderMathMLFencedOperator& renderer) { m_closeFenceRenderer = makeWeakPtr(renderer); }
     48
    4249private:
    4350    bool isRenderMathMLFenced() const final { return true; }
     
    4552    void addChild(RenderTreeBuilder&, RenderPtr<RenderObject> child, RenderObject* beforeChild) final;
    4653    void updateFromElement();
    47 
    48     RenderPtr<RenderMathMLFencedOperator> createMathMLOperator(const String& operatorString, MathMLOperatorDictionary::Form, MathMLOperatorDictionary::Flag);
    49     void makeFences(RenderTreeBuilder&);
    5054
    5155    String m_open;
  • trunk/Source/WebCore/rendering/updating/RenderTreeBuilder.cpp

    r226634 r226654  
    4242#include "RenderTreeBuilderInline.h"
    4343#include "RenderTreeBuilderList.h"
     44#include "RenderTreeBuilderMathML.h"
    4445#include "RenderTreeBuilderMultiColumn.h"
    4546#include "RenderTreeBuilderRuby.h"
     
    115116    , m_inlineBuilder(std::make_unique<Inline>(*this))
    116117    , m_svgBuilder(std::make_unique<SVG>(*this))
     118    , m_mathMLBuilder(std::make_unique<MathML>(*this))
    117119{
    118120    RELEASE_ASSERT(!s_current || &m_view != &s_current->m_view);
     
    335337}
    336338
     339void RenderTreeBuilder::insertChildToRenderMathMLFenced(RenderMathMLFenced& parent, RenderPtr<RenderObject> child, RenderObject* beforeChild)
     340{
     341    mathMLBuilder().insertChild(parent, WTFMove(child), beforeChild);
     342}
     343
    337344void RenderTreeBuilder::updateAfterDescendants(RenderElement& renderer)
    338345{
  • trunk/Source/WebCore/rendering/updating/RenderTreeBuilder.h

    r226634 r226654  
    3030namespace WebCore {
    3131
     32class RenderMathMLFenced;
    3233class RenderRubyRun;
    3334class RenderSVGContainer;
     
    6768    void insertChildToRenderTableSection(RenderTableSection& parent, RenderPtr<RenderObject> child, RenderObject* beforeChild = nullptr);
    6869    void insertChildToRenderTableRow(RenderTableRow& parent, RenderPtr<RenderObject> child, RenderObject* beforeChild = nullptr);
     70    void insertChildToRenderMathMLFenced(RenderMathMLFenced& parent, RenderPtr<RenderObject> child, RenderObject* beforeChild = nullptr);
    6971
    7072    void makeChildrenNonInline(RenderBlock& parent, RenderObject* insertionPoint = nullptr);
     
    8385    class Inline;
    8486    class SVG;
     87    class MathML;
    8588
    8689    FirstLetter& firstLetterBuilder() { return *m_firstLetterBuilder; }
     
    9497    Inline& inlineBuilder() { return *m_inlineBuilder; }
    9598    SVG& svgBuilder() { return *m_svgBuilder; }
     99    MathML& mathMLBuilder() { return *m_mathMLBuilder; }
    96100
    97101    RenderView& m_view;
     
    110114    std::unique_ptr<Inline> m_inlineBuilder;
    111115    std::unique_ptr<SVG> m_svgBuilder;
     116    std::unique_ptr<MathML> m_mathMLBuilder;
    112117};
    113118
Note: See TracChangeset for help on using the changeset viewer.