Skip to content
Permalink
Browse files
[RenderTreeBuilder] Move RenderElement::insertChildInternal() to Rend…
…erTreeBuilder

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):


Canonical link: https://commits.webkit.org/198650@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@228588 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
alanbujtas committed Feb 17, 2018
1 parent 2b55c0b commit ed7c4b46148d30db39e85f9ab5c0227849ac0578
Showing 10 changed files with 69 additions and 56 deletions.
@@ -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
@@ -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);
}
}

@@ -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();
@@ -98,8 +98,6 @@ class RenderElement : public RenderObject {
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&) { }
@@ -778,6 +778,8 @@ class RenderObject : public CachedImageClient {

virtual void willBeRemovedFromTree();
void resetFragmentedFlowStateOnRemoval();
void initializeFragmentedFlowStateOnInsertion();
virtual void insertedIntoTree();

protected:
//////////////////////////////////////////
@@ -793,8 +795,6 @@ class RenderObject : public CachedImageClient {

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 @@ class RenderObject : public CachedImageClient {
virtual RenderFragmentedFlow* locateEnclosingFragmentedFlow() const;
static void calculateBorderStyleColor(const EBorderStyle&, const BoxSide&, Color&);

void initializeFragmentedFlowStateOnInsertion();
static FragmentedFlowState computedFragmentedFlowState(const RenderObject&);

private:
@@ -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));
}
}

@@ -65,6 +65,7 @@ class RenderTreeBuilder {

// 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);
@@ -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
@@ -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;
}
}
@@ -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.

0 comments on commit ed7c4b4

Please sign in to comment.