[RenderTreeBuilder] Move RenderElement addChild mutation logic to RenderTreeBuilder
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 9 Jan 2018 23:31:57 +0000 (23:31 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 9 Jan 2018 23:31:57 +0000 (23:31 +0000)
https://bugs.webkit.org/show_bug.cgi?id=181451
<rdar://problem/36385562>

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.

* rendering/RenderElement.cpp:
(WebCore::RenderElement::addChild):
(WebCore::RenderElement::childRequiresTable const): Deleted.
* rendering/RenderElement.h:
* rendering/updating/RenderTreeBuilder.cpp:
(WebCore::RenderTreeBuilder::insertChildToRenderElement):
(WebCore::RenderTreeBuilder::childRequiresTable):
* rendering/updating/RenderTreeBuilder.h:
* rendering/updating/RenderTreeBuilderInline.cpp:
(WebCore::RenderTreeBuilder::Inline::insertChildToContinuation):
(WebCore::RenderTreeBuilder::Inline::insertChildIgnoringContinuation):
(WebCore::RenderTreeBuilder::Inline::newChildIsInline):
(WebCore::newChildIsInline): Deleted.
* rendering/updating/RenderTreeBuilderInline.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@226660 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/rendering/RenderElement.cpp
Source/WebCore/rendering/RenderElement.h
Source/WebCore/rendering/updating/RenderTreeBuilder.cpp
Source/WebCore/rendering/updating/RenderTreeBuilder.h
Source/WebCore/rendering/updating/RenderTreeBuilderInline.cpp
Source/WebCore/rendering/updating/RenderTreeBuilderInline.h
Source/WebCore/rendering/updating/RenderTreeBuilderTable.cpp
Source/WebCore/rendering/updating/RenderTreeBuilderTable.h

index 6423659..b0006dd 100644 (file)
@@ -1,3 +1,31 @@
+2018-01-09  Zalan Bujtas  <zalan@apple.com>
+
+        [RenderTreeBuilder] Move RenderElement addChild mutation logic to RenderTreeBuilder
+        https://bugs.webkit.org/show_bug.cgi?id=181451
+        <rdar://problem/36385562>
+
+        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.
+
+        * rendering/RenderElement.cpp:
+        (WebCore::RenderElement::addChild):
+        (WebCore::RenderElement::childRequiresTable const): Deleted.
+        * rendering/RenderElement.h:
+        * rendering/updating/RenderTreeBuilder.cpp:
+        (WebCore::RenderTreeBuilder::insertChildToRenderElement):
+        (WebCore::RenderTreeBuilder::childRequiresTable):
+        * rendering/updating/RenderTreeBuilder.h:
+        * rendering/updating/RenderTreeBuilderInline.cpp:
+        (WebCore::RenderTreeBuilder::Inline::insertChildToContinuation):
+        (WebCore::RenderTreeBuilder::Inline::insertChildIgnoringContinuation):
+        (WebCore::RenderTreeBuilder::Inline::newChildIsInline):
+        (WebCore::newChildIsInline): Deleted.
+        * rendering/updating/RenderTreeBuilderInline.h:
+
 2018-01-09  Matt Lewis  <jlewis3@apple.com>
 
         Unreviewed, rolling out r226531.
index 04d5840..26f89d1 100644 (file)
@@ -454,49 +454,13 @@ void RenderElement::setStyle(RenderStyle&& style, StyleDifference minimalStyleDi
     }
 }
 
-bool RenderElement::childRequiresTable(const RenderObject& child) const
-{
-    if (is<RenderTableCol>(child)) {
-        const RenderTableCol& newTableColumn = downcast<RenderTableCol>(child);
-        bool isColumnInColumnGroup = newTableColumn.isTableColumn() && is<RenderTableCol>(*this);
-        return !is<RenderTable>(*this) && !isColumnInColumnGroup;
-    }
-    if (is<RenderTableCaption>(child))
-        return !is<RenderTable>(*this);
-
-    if (is<RenderTableSection>(child))
-        return !is<RenderTable>(*this);
-
-    if (is<RenderTableRow>(child))
-        return !is<RenderTableSection>(*this);
-
-    if (is<RenderTableCell>(child))
-        return !is<RenderTableRow>(*this);
-
-    return false;
-}
-
 void RenderElement::addChild(RenderTreeBuilder& builder, RenderPtr<RenderObject> newChild, RenderObject* beforeChild)
 {
     auto& child = *newChild;
-    if (childRequiresTable(child)) {
-        RenderTable* table;
-        RenderObject* afterChild = beforeChild ? beforeChild->previousSibling() : m_lastChild;
-        if (afterChild && afterChild->isAnonymous() && is<RenderTable>(*afterChild) && !afterChild->isBeforeContent())
-            table = downcast<RenderTable>(afterChild);
-        else {
-            auto newTable = RenderTable::createAnonymousWithParentRenderer(*this);
-            table = newTable.get();
-            builder.insertChild(*this, WTFMove(newTable), beforeChild);
-        }
-
-        builder.insertChild(*table, WTFMove(newChild));
-    } else
-        insertChildInternal(WTFMove(newChild), beforeChild);
+    builder.insertChildToRenderElement(*this, WTFMove(newChild), beforeChild);
 
     if (is<RenderText>(child))
         downcast<RenderText>(child).styleDidChange(StyleDifferenceEqual, nullptr);
-
     // SVG creates renderers for <g display="none">, as SVG requires children of hidden
     // <g>s to have renderers - at least that's how our implementation works. Consider:
     // <g display="none"><foreignObject><body style="position: relative">FOO...
@@ -507,7 +471,6 @@ void RenderElement::addChild(RenderTreeBuilder& builder, RenderPtr<RenderObject>
     // and stop creating layers at all for these cases - they're not used anyways.
     if (child.hasLayer() && !layerCreationAllowedForSubtree())
         downcast<RenderLayerModelObject>(child).layer()->removeOnlyThisLayer();
-
     SVGRenderSupport::childAdded(*this, child);
 }
 
index a04168a..5b1129e 100644 (file)
@@ -204,8 +204,6 @@ public:
     const RenderElement* enclosingRendererWithTextDecoration(TextDecoration, bool firstLine) const;
     void drawLineForBoxSide(GraphicsContext&, const FloatRect&, BoxSide, Color, EBorderStyle, float adjacentWidth1, float adjacentWidth2, bool antialias = false) const;
 
-    bool childRequiresTable(const RenderObject& child) const;
-
 #if ENABLE(TEXT_AUTOSIZING)
     void adjustComputedFontSizesOnBlocks(float size, float visibleWidth);
     WEBCORE_EXPORT void resetTextAutosizing();
index 0cde2da..cbc4465 100644 (file)
@@ -192,6 +192,25 @@ void RenderTreeBuilder::insertChild(RenderTreePosition& position, RenderPtr<Rend
     insertChild(position.parent(), WTFMove(child), position.nextSibling());
 }
 
+void RenderTreeBuilder::insertChildToRenderElement(RenderElement& parent, RenderPtr<RenderObject> child, RenderObject* beforeChild)
+{
+    if (tableBuilder().childRequiresTable(parent, *child)) {
+        RenderTable* table;
+        RenderObject* afterChild = beforeChild ? beforeChild->previousSibling() : parent.lastChild();
+        if (afterChild && afterChild->isAnonymous() && is<RenderTable>(*afterChild) && !afterChild->isBeforeContent())
+            table = downcast<RenderTable>(afterChild);
+        else {
+            auto newTable = RenderTable::createAnonymousWithParentRenderer(parent);
+            table = newTable.get();
+            insertChild(parent, WTFMove(newTable), beforeChild);
+        }
+
+        insertChild(*table, WTFMove(child));
+        return;
+    }
+    parent.RenderElement::insertChildInternal(WTFMove(child), beforeChild);
+}
+
 void RenderTreeBuilder::insertChildToRenderBlock(RenderBlock& parent, RenderPtr<RenderObject> child, RenderObject* beforeChild)
 {
     blockBuilder().insertChild(parent, WTFMove(child), beforeChild);
index 19f9b66..914f192 100644 (file)
@@ -55,6 +55,7 @@ public:
     static RenderTreeBuilder* current() { return s_current; }
 
     // These functions are temporary until after all block/inline/continuation code is moved over.
+    void insertChildToRenderElement(RenderElement& parent, RenderPtr<RenderObject> child, RenderObject* beforeChild = nullptr);
     void insertChildToRenderBlock(RenderBlock& parent, RenderPtr<RenderObject>, RenderObject* beforeChild = nullptr);
     void insertChildToRenderBlockIgnoringContinuation(RenderBlock& parent, RenderPtr<RenderObject>, RenderObject* beforeChild = nullptr);
     void insertChildToRenderBlockFlow(RenderBlockFlow& parent, RenderPtr<RenderObject>, RenderObject* beforeChild = nullptr);
@@ -69,6 +70,7 @@ public:
     void insertChildToRenderTableRow(RenderTableRow& parent, RenderPtr<RenderObject> child, RenderObject* beforeChild = nullptr);
     void insertChildToRenderMathMLFenced(RenderMathMLFenced& parent, RenderPtr<RenderObject> child, RenderObject* beforeChild = nullptr);
 
+    bool childRequiresTable(const RenderElement& parent, const RenderObject& child);
     void makeChildrenNonInline(RenderBlock& parent, RenderObject* insertionPoint = nullptr);
     RenderObject* splitAnonymousBoxesAroundChild(RenderBox& parent, RenderObject* beforeChild);
     void splitFlow(RenderInline& parent, RenderObject* beforeChild, RenderPtr<RenderBlock> newBlockBox, RenderPtr<RenderObject> child, RenderBoxModelObject* oldCont);
index 33ec037..72a9447 100644 (file)
@@ -86,12 +86,6 @@ static RenderPtr<RenderInline> cloneAsContinuation(RenderInline& renderer)
     return cloneInline;
 }
 
-static bool newChildIsInline(const RenderObject& child, const RenderInline& parent)
-{
-    // inline parent generates inline-table.
-    return child.isInline() | (parent.childRequiresTable(child) && parent.style().display() == INLINE);
-}
-
 static RenderElement* inFlowPositionedInlineAncestor(RenderElement& renderer)
 {
     auto* ancestor = &renderer;
@@ -151,7 +145,7 @@ void RenderTreeBuilder::Inline::insertChildToContinuation(RenderInline& parent,
         return flow->addChildIgnoringContinuation(m_builder, WTFMove(child), beforeChild);
     // A continuation always consists of two potential candidates: an inline or an anonymous
     // block box holding block children.
-    bool childInline = newChildIsInline(*child, parent);
+    bool childInline = newChildIsInline(parent, *child);
     // The goal here is to match up if we can, so that we can coalesce and create the
     // minimal # of continuations needed for the inline.
     if (childInline == beforeChildAncestor->isInline())
@@ -167,7 +161,7 @@ void RenderTreeBuilder::Inline::insertChildIgnoringContinuation(RenderInline& pa
     if (!beforeChild && parent.isAfterContent(parent.lastChild()))
         beforeChild = parent.lastChild();
 
-    bool childInline = newChildIsInline(*child, parent);
+    bool childInline = newChildIsInline(parent, *child);
     // This code is for the old block-inside-inline model that uses continuations.
     if (!childInline && !child->isFloatingOrOutOfFlowPositioned()) {
         // We are placing a block inside an inline. We have to perform a split of this
@@ -379,5 +373,10 @@ void RenderTreeBuilder::Inline::splitInlines(RenderInline& parent, RenderBlock*
     }
 }
 
+bool RenderTreeBuilder::Inline::newChildIsInline(const RenderInline& parent, const RenderObject& child)
+{
+    // inline parent generates inline-table.
+    return child.isInline() || (m_builder.tableBuilder().childRequiresTable(parent, child) && parent.style().display() == INLINE);
 }
 
+}
index 88f38a9..79a2c8a 100644 (file)
@@ -42,6 +42,7 @@ public:
 private:
     void insertChildToContinuation(RenderInline& parent, RenderPtr<RenderObject> child, RenderObject* beforeChild);
     void splitInlines(RenderInline& parent, RenderBlock* fromBlock, RenderBlock* toBlock, RenderBlock* middleBlock, RenderObject* beforeChild, RenderBoxModelObject* oldCont);
+    bool newChildIsInline(const RenderInline& parent, const RenderObject& child);
 
     RenderTreeBuilder& m_builder;
 };
index 067dacb..100288f 100644 (file)
@@ -187,4 +187,26 @@ void RenderTreeBuilder::Table::insertChild(RenderTable& parent, RenderPtr<Render
     parent.RenderBox::addChild(m_builder, WTFMove(child), beforeChild);
 }
 
+bool RenderTreeBuilder::Table::childRequiresTable(const RenderElement& parent, const RenderObject& child)
+{
+    if (is<RenderTableCol>(child)) {
+        const RenderTableCol& newTableColumn = downcast<RenderTableCol>(child);
+        bool isColumnInColumnGroup = newTableColumn.isTableColumn() && is<RenderTableCol>(parent);
+        return !is<RenderTable>(parent) && !isColumnInColumnGroup;
+    }
+    if (is<RenderTableCaption>(child))
+        return !is<RenderTable>(parent);
+
+    if (is<RenderTableSection>(child))
+        return !is<RenderTable>(parent);
+
+    if (is<RenderTableRow>(child))
+        return !is<RenderTableSection>(parent);
+
+    if (is<RenderTableCell>(child))
+        return !is<RenderTableRow>(parent);
+
+    return false;
+}
+
 }
index dee0648..1b2b4e8 100644 (file)
@@ -48,6 +48,8 @@ public:
     void insertChild(RenderTableSection& parent, RenderPtr<RenderObject> child, RenderObject* beforeChild);
     void insertChild(RenderTableRow& parent, RenderPtr<RenderObject> child, RenderObject* beforeChild);
 
+    bool childRequiresTable(const RenderElement& parent, const RenderObject& child);
+
 private:
     RenderTreeBuilder& m_builder;
 };