[RenderTreeBuilder] Move RenderElement::insertChildInternal() to RenderTreeBuilder
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 17 Feb 2018 00:05:35 +0000 (00:05 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 17 Feb 2018 00:05:35 +0000 (00:05 +0000)
https://bugs.webkit.org/show_bug.cgi?id=182885
<rdar://problem/37617371>

Reviewed by Antti Koivisto.

No change in functionality.

* rendering/RenderElement.cpp:
(WebCore::RenderElement::insertChildInternal): Deleted.
* rendering/RenderObject.h:
* rendering/updating/RenderTreeBuilder.cpp:
(WebCore::RenderTreeBuilder::insertChildToRenderElement):

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

Source/WebCore/ChangeLog
Source/WebCore/rendering/RenderBoxModelObject.cpp
Source/WebCore/rendering/RenderElement.cpp
Source/WebCore/rendering/RenderElement.h
Source/WebCore/rendering/RenderObject.h
Source/WebCore/rendering/updating/RenderTreeBuilder.cpp
Source/WebCore/rendering/updating/RenderTreeBuilder.h
Source/WebCore/rendering/updating/RenderTreeBuilderBlock.cpp
Source/WebCore/rendering/updating/RenderTreeBuilderInline.cpp
Source/WebCore/rendering/updating/RenderTreeBuilderRuby.cpp

index 4700d5a..0c4248a 100644 (file)
@@ -1,3 +1,19 @@
+2018-02-16  Zalan Bujtas  <zalan@apple.com>
+
+        [RenderTreeBuilder] Move RenderElement::insertChildInternal() to RenderTreeBuilder
+        https://bugs.webkit.org/show_bug.cgi?id=182885
+        <rdar://problem/37617371>
+
+        Reviewed by Antti Koivisto.
+
+        No change in functionality.
+
+        * rendering/RenderElement.cpp:
+        (WebCore::RenderElement::insertChildInternal): Deleted.
+        * rendering/RenderObject.h:
+        * rendering/updating/RenderTreeBuilder.cpp:
+        (WebCore::RenderTreeBuilder::insertChildToRenderElement):
+
 2018-02-16  Youenn Fablet  <youenn@apple.com>
 
         Allow specifying which plug-ins are supported
index b40bbfd..6cf9405 100644 (file)
@@ -2700,7 +2700,7 @@ void RenderBoxModelObject::moveChildTo(RenderTreeBuilder& builder, RenderBoxMode
         builder.insertChild(*toBoxModelObject, WTFMove(childToMove), beforeChild);
     } else {
         auto childToMove = builder.takeChildFromRenderElement(*this, *child);
-        toBoxModelObject->insertChildInternal(WTFMove(childToMove), beforeChild);
+        builder.insertChildToRenderElementInternal(*toBoxModelObject, WTFMove(childToMove), beforeChild);
     }
 }
 
index 1021008..9382c43 100644 (file)
@@ -532,43 +532,6 @@ RenderPtr<RenderObject> RenderElement::detachRendererInternal(RenderObject& rend
     return RenderPtr<RenderObject>(&renderer);
 }
 
-void RenderElement::insertChildInternal(RenderPtr<RenderObject> newChildPtr, RenderObject* beforeChild)
-{
-    RELEASE_ASSERT_WITH_MESSAGE(!view().frameView().layoutContext().layoutState(), "Layout must not mutate render tree");
-
-    ASSERT(canHaveChildren() || canHaveGeneratedChildren());
-    ASSERT(!newChildPtr->parent());
-    ASSERT(!isRenderBlockFlow() || (!newChildPtr->isTableSection() && !newChildPtr->isTableRow() && !newChildPtr->isTableCell()));
-
-    while (beforeChild && beforeChild->parent() && beforeChild->parent() != this)
-        beforeChild = beforeChild->parent();
-
-    ASSERT(!beforeChild || beforeChild->parent() == this);
-    ASSERT(!is<RenderText>(beforeChild) || !downcast<RenderText>(*beforeChild).inlineWrapperForDisplayContents());
-
-    // Take the ownership.
-    auto* newChild = attachRendererInternal(WTFMove(newChildPtr), beforeChild);
-
-    newChild->initializeFragmentedFlowStateOnInsertion();
-    if (!renderTreeBeingDestroyed()) {
-        newChild->insertedIntoTree();
-        if (is<RenderElement>(*newChild))
-            RenderCounter::rendererSubtreeAttached(downcast<RenderElement>(*newChild));
-    }
-
-    newChild->setNeedsLayoutAndPrefWidthsRecalc();
-    setPreferredLogicalWidthsDirty(true);
-    if (!normalChildNeedsLayout())
-        setChildNeedsLayout(); // We may supply the static position for an absolute positioned child.
-
-    if (AXObjectCache* cache = document().axObjectCache())
-        cache->childrenChanged(this, newChild);
-    if (is<RenderBlockFlow>(*this))
-        downcast<RenderBlockFlow>(*this).invalidateLineLayoutPath();
-    if (hasOutlineAutoAncestor() || outlineStyleForRepaint().outlineStyleIsAuto())
-        newChild->setHasOutlineAutoAncestor();
-}
-
 RenderBlock* RenderElement::containingBlockForFixedPosition() const
 {
     auto* renderer = parent();
index 11a96f4..97d7f26 100644 (file)
@@ -98,8 +98,6 @@ public:
     void moveLayers(RenderLayer* oldParent, RenderLayer* newParent);
     RenderLayer* findNextLayer(RenderLayer* parentLayer, RenderObject* startPoint, bool checkParent = true);
 
-    void insertChildInternal(RenderPtr<RenderObject>, RenderObject* beforeChild);
-
     virtual RenderElement* hoverAncestor() const;
 
     virtual void dirtyLinesFromChangedChild(RenderObject&) { }
index 472a594..44ec2ae 100644 (file)
@@ -778,6 +778,8 @@ public:
 
     virtual void willBeRemovedFromTree();
     void resetFragmentedFlowStateOnRemoval();
+    void initializeFragmentedFlowStateOnInsertion();
+    virtual void insertedIntoTree();
 
 protected:
     //////////////////////////////////////////
@@ -793,8 +795,6 @@ protected:
 
     virtual void willBeDestroyed(RenderTreeBuilder&);
 
-    virtual void insertedIntoTree();
-
     void setNeedsPositionedMovementLayoutBit(bool b) { m_bitfields.setNeedsPositionedMovementLayout(b); }
     void setNormalChildNeedsLayoutBit(bool b) { m_bitfields.setNormalChildNeedsLayout(b); }
     void setPosChildNeedsLayoutBit(bool b) { m_bitfields.setPosChildNeedsLayout(b); }
@@ -803,7 +803,6 @@ protected:
     virtual RenderFragmentedFlow* locateEnclosingFragmentedFlow() const;
     static void calculateBorderStyleColor(const EBorderStyle&, const BoxSide&, Color&);
 
-    void initializeFragmentedFlowStateOnInsertion();
     static FragmentedFlowState computedFragmentedFlowState(const RenderObject&);
 
 private:
index 329a8ea..cfcb407 100644 (file)
@@ -336,10 +336,46 @@ void RenderTreeBuilder::insertChildToRenderElement(RenderElement& parent, Render
         return;
     }
     auto& newChild = *child.get();
-    parent.insertChildInternal(WTFMove(child), beforeChild);
+    insertChildToRenderElementInternal(parent, WTFMove(child), beforeChild);
     parent.didInsertChild(newChild, beforeChild);
 }
 
+void RenderTreeBuilder::insertChildToRenderElementInternal(RenderElement& parent, RenderPtr<RenderObject> child, RenderObject* beforeChild)
+{
+    RELEASE_ASSERT_WITH_MESSAGE(!parent.view().frameView().layoutContext().layoutState(), "Layout must not mutate render tree");
+    ASSERT(parent.canHaveChildren() || parent.canHaveGeneratedChildren());
+    ASSERT(!child->parent());
+    ASSERT(!parent.isRenderBlockFlow() || (!child->isTableSection() && !child->isTableRow() && !child->isTableCell()));
+
+    while (beforeChild && beforeChild->parent() && beforeChild->parent() != &parent)
+    beforeChild = beforeChild->parent();
+
+    ASSERT(!beforeChild || beforeChild->parent() == &parent);
+    ASSERT(!is<RenderText>(beforeChild) || !downcast<RenderText>(*beforeChild).inlineWrapperForDisplayContents());
+
+    // Take the ownership.
+    auto* newChild = parent.attachRendererInternal(WTFMove(child), beforeChild);
+
+    newChild->initializeFragmentedFlowStateOnInsertion();
+    if (!parent.renderTreeBeingDestroyed()) {
+        newChild->insertedIntoTree();
+        if (is<RenderElement>(*newChild))
+        RenderCounter::rendererSubtreeAttached(downcast<RenderElement>(*newChild));
+    }
+
+    newChild->setNeedsLayoutAndPrefWidthsRecalc();
+    parent.setPreferredLogicalWidthsDirty(true);
+    if (!parent.normalChildNeedsLayout())
+    parent.setChildNeedsLayout(); // We may supply the static position for an absolute positioned child.
+
+    if (AXObjectCache* cache = parent.document().axObjectCache())
+    cache->childrenChanged(&parent, newChild);
+    if (is<RenderBlockFlow>(parent))
+    downcast<RenderBlockFlow>(parent).invalidateLineLayoutPath();
+    if (parent.hasOutlineAutoAncestor() || parent.outlineStyleForRepaint().outlineStyleIsAuto())
+    newChild->setHasOutlineAutoAncestor();
+}
+
 void RenderTreeBuilder::makeChildrenNonInline(RenderBlock& parent, RenderObject* insertionPoint)
 {
     // makeChildrenNonInline takes a block whose children are *all* inline and it
@@ -372,7 +408,7 @@ void RenderTreeBuilder::makeChildrenNonInline(RenderBlock& parent, RenderObject*
 
         auto newBlock = parent.createAnonymousBlock();
         auto& block = *newBlock;
-        parent.insertChildInternal(WTFMove(newBlock), inlineRunStart);
+        insertChildToRenderElementInternal(parent, WTFMove(newBlock), inlineRunStart);
         parent.moveChildrenTo(*this, &block, inlineRunStart, child, RenderBoxModelObject::NormalizeAfterInsertion::No);
     }
 #ifndef NDEBUG
@@ -401,7 +437,7 @@ RenderObject* RenderTreeBuilder::splitAnonymousBoxesAroundChild(RenderBox& paren
             // so that the table repainting logic knows the structure is dirty.
             // See for example RenderTableCell:clippedOverflowRectForRepaint.
             markBoxForRelayoutAfterSplit(*parentBox);
-            parentBox->insertChildInternal(WTFMove(newPostBox), boxToSplit.nextSibling());
+            insertChildToRenderElementInternal(*parentBox, WTFMove(newPostBox), boxToSplit.nextSibling());
             boxToSplit.moveChildrenTo(*this, &postBox, beforeChild, nullptr, RenderBoxModelObject::NormalizeAfterInsertion::Yes);
 
             markBoxForRelayoutAfterSplit(boxToSplit);
@@ -431,9 +467,9 @@ void RenderTreeBuilder::childFlowStateChangesAndAffectsParentBlock(RenderElement
         // An anonymous block must be made to wrap this inline.
         auto newBlock = downcast<RenderBlock>(*parent).createAnonymousBlock();
         auto& block = *newBlock;
-        parent->insertChildInternal(WTFMove(newBlock), &child);
+        insertChildToRenderElementInternal(*parent, WTFMove(newBlock), &child);
         auto thisToMove = takeChildFromRenderElement(*parent, child);
-        block.insertChildInternal(WTFMove(thisToMove), nullptr);
+        insertChildToRenderElementInternal(block, WTFMove(thisToMove));
     }
 }
 
index ec53d79..5712017 100644 (file)
@@ -65,6 +65,7 @@ public:
 
     // These functions are temporary until after all block/inline/continuation code is moved over.
     RenderPtr<RenderObject> takeChildFromRenderElement(RenderElement& parent, RenderObject& child) WARN_UNUSED_RETURN;
+    void insertChildToRenderElementInternal(RenderElement& parent, RenderPtr<RenderObject> child, RenderObject* beforeChild = nullptr);
 
     void childFlowStateChangesAndAffectsParentBlock(RenderElement& child);
     void childFlowStateChangesAndNoLongerAffectsParentBlock(RenderElement& child);
index d1ec942..da9e6fd 100644 (file)
@@ -297,7 +297,7 @@ RenderPtr<RenderObject> RenderTreeBuilder::Block::takeChild(RenderBlock& parent,
 
             // Now just put the inlineChildrenBlock inside the blockChildrenBlock.
             RenderObject* beforeChild = prev == &inlineChildrenBlock ? blockChildrenBlock.firstChild() : nullptr;
-            blockChildrenBlock.insertChildInternal(WTFMove(blockToMove), beforeChild);
+            m_builder.insertChildToRenderElementInternal(blockChildrenBlock, WTFMove(blockToMove), beforeChild);
             next->setNeedsLayoutAndPrefWidthsRecalc();
 
             // inlineChildrenBlock got reparented to blockChildrenBlock, so it is no longer a child
index 61346ad..2c5d269 100644 (file)
@@ -225,9 +225,9 @@ void RenderTreeBuilder::Inline::splitFlow(RenderInline& parent, RenderObject* be
 
     RenderObject* boxFirst = madeNewBeforeBlock ? block->firstChild() : pre->nextSibling();
     if (createdPre)
-        block->insertChildInternal(WTFMove(createdPre), boxFirst);
-    block->insertChildInternal(WTFMove(newBlockBox), boxFirst);
-    block->insertChildInternal(WTFMove(createdPost), boxFirst);
+        m_builder.insertChildToRenderElementInternal(*block, WTFMove(createdPre), boxFirst);
+    m_builder.insertChildToRenderElementInternal(*block, WTFMove(newBlockBox), boxFirst);
+    m_builder.insertChildToRenderElementInternal(*block, WTFMove(createdPost), boxFirst);
     block->setChildrenInline(false);
 
     if (madeNewBeforeBlock) {
@@ -236,7 +236,7 @@ void RenderTreeBuilder::Inline::splitFlow(RenderInline& parent, RenderObject* be
             RenderObject* no = o;
             o = no->nextSibling();
             auto childToMove = m_builder.takeChildFromRenderElement(*block, *no);
-            pre->insertChildInternal(WTFMove(childToMove), nullptr);
+            m_builder.insertChildToRenderElementInternal(*pre, WTFMove(childToMove));
             no->setNeedsLayoutAndPrefWidthsRecalc();
         }
     }
@@ -361,14 +361,14 @@ void RenderTreeBuilder::Inline::splitInlines(RenderInline& parent, RenderBlock*
         cloneBlockChild.resetEnclosingFragmentedFlowAndChildInfoIncludingDescendants();
 
     // Now we are at the block level. We need to put the clone into the toBlock.
-    toBlock->insertChildInternal(WTFMove(cloneInline), nullptr);
+    m_builder.insertChildToRenderElementInternal(*toBlock, WTFMove(cloneInline));
 
     // Now take all the children after currentChild and remove them from the fromBlock
     // and put them in the toBlock.
     for (auto* current = currentChild->nextSibling(); current;) {
         auto* next = current->nextSibling();
         auto childToMove = m_builder.takeChildFromRenderElement(*fromBlock, *current);
-        toBlock->insertChildInternal(WTFMove(childToMove), nullptr);
+        m_builder.insertChildToRenderElementInternal(*toBlock, WTFMove(childToMove));
         current = next;
     }
 }
index a59f709..50cf43e 100644 (file)
@@ -139,7 +139,7 @@ void RenderTreeBuilder::Ruby::moveInlineChildren(RenderRubyBase& from, RenderRub
         else {
             auto newToBlock = to.createAnonymousBlock();
             toBlock = newToBlock.get();
-            to.insertChildInternal(WTFMove(newToBlock), nullptr);
+            m_builder.insertChildToRenderElementInternal(to, WTFMove(newToBlock));
         }
     }
     // Move our inline children into the target block we determined above.