Skip to content
Permalink
Browse files
[RenderTreeBuilder] Introduce RenderTreeBuilder to moveChild(ren)To()…
… functions

https://bugs.webkit.org/show_bug.cgi?id=182596
<rdar://problem/37340553>

Reviewed by Sam Weinig.

This is in preparation for moving mutation code out of moveChildTo/moveChildrenTo.

No change in functionality.

* rendering/RenderBlock.cpp:
(WebCore::RenderBlock::dropAnonymousBoxChild):
(WebCore::RenderBlock::takeChild):
* rendering/RenderBlock.h:
(WebCore::RenderBlock::moveAllChildrenIncludingFloatsTo):
* rendering/RenderBlockFlow.cpp:
(WebCore::RenderBlockFlow::styleDidChange):
(WebCore::RenderBlockFlow::moveAllChildrenIncludingFloatsTo):
* rendering/RenderBlockFlow.h:
* rendering/RenderBoxModelObject.cpp:
(WebCore::RenderBoxModelObject::moveChildTo):
(WebCore::RenderBoxModelObject::moveChildrenTo):
* rendering/RenderBoxModelObject.h:
(WebCore::RenderBoxModelObject::moveChildTo):
(WebCore::RenderBoxModelObject::moveAllChildrenTo):
(WebCore::RenderBoxModelObject::moveChildrenTo):
* rendering/RenderElement.cpp:
(WebCore::RenderElement::styleDidChange):
(WebCore::RenderElement::removeAnonymousWrappersForInlinesIfNecessary): Deleted.
* rendering/RenderElement.h:
* rendering/RenderRubyRun.cpp:
(WebCore::RenderRubyRun::takeChild):
* rendering/updating/RenderTreeBuilder.cpp:
(WebCore::RenderTreeBuilder::makeChildrenNonInline):
(WebCore::RenderTreeBuilder::splitAnonymousBoxesAroundChild):
(WebCore::RenderTreeBuilder::removeAnonymousWrappersForInlineChildrenIfNeeded):
(WebCore::RenderTreeBuilder::childFlowStateChangesAndNoLongerAffectsParentBlock):
(WebCore::RenderTreeBuilder::removeFromParentAndDestroyCleaningUpAnonymousWrappers):
* rendering/updating/RenderTreeBuilder.h:
* rendering/updating/RenderTreeBuilderMultiColumn.cpp:
(WebCore::RenderTreeBuilder::MultiColumn::createFragmentedFlow):
(WebCore::RenderTreeBuilder::MultiColumn::destroyFragmentedFlow):
* rendering/updating/RenderTreeBuilderRuby.cpp:
(WebCore::RenderTreeBuilder::Ruby::moveInlineChildren):
(WebCore::RenderTreeBuilder::Ruby::moveBlockChildren):
* rendering/updating/RenderTreeBuilderTable.cpp:
(WebCore::RenderTreeBuilder::Table::collapseAndDestroyAnonymousSiblingRows):


Canonical link: https://commits.webkit.org/198418@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@228284 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
alanbujtas committed Feb 8, 2018
1 parent cf3daf2 commit e90e6d93380c998bf71aa9cb44dadfe9061753ed
@@ -1,3 +1,53 @@
2018-02-08 Zalan Bujtas <zalan@apple.com>

[RenderTreeBuilder] Introduce RenderTreeBuilder to moveChild(ren)To() functions
https://bugs.webkit.org/show_bug.cgi?id=182596
<rdar://problem/37340553>

Reviewed by Sam Weinig.

This is in preparation for moving mutation code out of moveChildTo/moveChildrenTo.

No change in functionality.

* rendering/RenderBlock.cpp:
(WebCore::RenderBlock::dropAnonymousBoxChild):
(WebCore::RenderBlock::takeChild):
* rendering/RenderBlock.h:
(WebCore::RenderBlock::moveAllChildrenIncludingFloatsTo):
* rendering/RenderBlockFlow.cpp:
(WebCore::RenderBlockFlow::styleDidChange):
(WebCore::RenderBlockFlow::moveAllChildrenIncludingFloatsTo):
* rendering/RenderBlockFlow.h:
* rendering/RenderBoxModelObject.cpp:
(WebCore::RenderBoxModelObject::moveChildTo):
(WebCore::RenderBoxModelObject::moveChildrenTo):
* rendering/RenderBoxModelObject.h:
(WebCore::RenderBoxModelObject::moveChildTo):
(WebCore::RenderBoxModelObject::moveAllChildrenTo):
(WebCore::RenderBoxModelObject::moveChildrenTo):
* rendering/RenderElement.cpp:
(WebCore::RenderElement::styleDidChange):
(WebCore::RenderElement::removeAnonymousWrappersForInlinesIfNecessary): Deleted.
* rendering/RenderElement.h:
* rendering/RenderRubyRun.cpp:
(WebCore::RenderRubyRun::takeChild):
* rendering/updating/RenderTreeBuilder.cpp:
(WebCore::RenderTreeBuilder::makeChildrenNonInline):
(WebCore::RenderTreeBuilder::splitAnonymousBoxesAroundChild):
(WebCore::RenderTreeBuilder::removeAnonymousWrappersForInlineChildrenIfNeeded):
(WebCore::RenderTreeBuilder::childFlowStateChangesAndNoLongerAffectsParentBlock):
(WebCore::RenderTreeBuilder::removeFromParentAndDestroyCleaningUpAnonymousWrappers):
* rendering/updating/RenderTreeBuilder.h:
* rendering/updating/RenderTreeBuilderMultiColumn.cpp:
(WebCore::RenderTreeBuilder::MultiColumn::createFragmentedFlow):
(WebCore::RenderTreeBuilder::MultiColumn::destroyFragmentedFlow):
* rendering/updating/RenderTreeBuilderRuby.cpp:
(WebCore::RenderTreeBuilder::Ruby::moveInlineChildren):
(WebCore::RenderTreeBuilder::Ruby::moveBlockChildren):
* rendering/updating/RenderTreeBuilderTable.cpp:
(WebCore::RenderTreeBuilder::Table::collapseAndDestroyAnonymousSiblingRows):

2018-02-08 Matt Lewis <jlewis3@apple.com>

Unreviewed, rolling out r228261.
@@ -518,14 +518,14 @@ static bool canMergeContiguousAnonymousBlocks(RenderObject& oldChild, RenderObje
return true;
}

void RenderBlock::dropAnonymousBoxChild(RenderBlock& child)
void RenderBlock::dropAnonymousBoxChild(RenderTreeBuilder& builder, RenderBlock& child)
{
setNeedsLayoutAndPrefWidthsRecalc();
setChildrenInline(child.childrenInline());
RenderObject* nextSibling = child.nextSibling();

auto toBeDeleted = takeChildInternal(child);
child.moveAllChildrenTo(this, nextSibling, RenderBoxModelObject::NormalizeAfterInsertion::No);
child.moveAllChildrenTo(builder, this, nextSibling, RenderBoxModelObject::NormalizeAfterInsertion::No);
// Delete the now-empty block's lines and nuke it.
child.deleteLines();
}
@@ -574,7 +574,7 @@ RenderPtr<RenderObject> RenderBlock::takeChild(RenderTreeBuilder& builder, Rende
} else {
// Take all the children out of the |next| block and put them in
// the |prev| block.
nextBlock.moveAllChildrenIncludingFloatsTo(prevBlock, RenderBoxModelObject::NormalizeAfterInsertion::No);
nextBlock.moveAllChildrenIncludingFloatsTo(builder, prevBlock, RenderBoxModelObject::NormalizeAfterInsertion::No);

// Delete the now-empty block's lines and nuke it.
nextBlock.deleteLines();
@@ -591,7 +591,7 @@ RenderPtr<RenderObject> RenderBlock::takeChild(RenderTreeBuilder& builder, Rende
if (canMergeAnonymousBlocks && child && !child->previousSibling() && !child->nextSibling() && canDropAnonymousBlockChild()) {
// The removal has knocked us down to containing only a single anonymous
// box. We can pull the content right back up into our box.
dropAnonymousBoxChild(downcast<RenderBlock>(*child));
dropAnonymousBoxChild(builder, downcast<RenderBlock>(*child));
} else if (((prev && prev->isAnonymousBlock()) || (next && next->isAnonymousBlock())) && canDropAnonymousBlockChild()) {
// It's possible that the removal has knocked us down to a single anonymous
// block with floating siblings.
@@ -607,7 +607,7 @@ RenderPtr<RenderObject> RenderBlock::takeChild(RenderTreeBuilder& builder, Rende
}
}
if (dropAnonymousBlock)
dropAnonymousBoxChild(anonBlock);
dropAnonymousBoxChild(builder, anonBlock);
}
}

@@ -191,7 +191,7 @@ class RenderBlock : public RenderBox {

static RenderPtr<RenderBlock> createAnonymousWithParentRendererAndDisplay(const RenderBox& parent, EDisplay = BLOCK);
RenderPtr<RenderBlock> createAnonymousBlock(EDisplay = BLOCK) const;
void dropAnonymousBoxChild(RenderBlock& child);
void dropAnonymousBoxChild(RenderTreeBuilder&, RenderBlock& child);

RenderPtr<RenderBox> createAnonymousBoxWithSameTypeAs(const RenderBox&) const override;

@@ -435,7 +435,7 @@ class RenderBlock : public RenderBox {
const char* renderName() const override;

// FIXME-BLOCKFLOW: Remove virtualizaion when all callers have moved to RenderBlockFlow
virtual void moveAllChildrenIncludingFloatsTo(RenderBlock& toBlock, RenderBoxModelObject::NormalizeAfterInsertion normalizeAfterInsertion) { moveAllChildrenTo(&toBlock, normalizeAfterInsertion); }
virtual void moveAllChildrenIncludingFloatsTo(RenderTreeBuilder& builder, RenderBlock& toBlock, RenderBoxModelObject::NormalizeAfterInsertion normalizeAfterInsertion) { moveAllChildrenTo(builder, &toBlock, normalizeAfterInsertion); }

bool isSelfCollapsingBlock() const override;
virtual bool childrenPreventSelfCollapsing() const;
@@ -2023,7 +2023,7 @@ void RenderBlockFlow::styleDidChange(StyleDifference diff, const RenderStyle* ol
// Fresh floats need to be reparented if they actually belong to the previous anonymous block.
// It copies the logic of RenderBlock::addChildIgnoringContinuation
if (noLongerAffectsParentBlock() && style().isFloating() && previousSibling() && previousSibling()->isAnonymousBlock())
downcast<RenderBoxModelObject>(*parent()).moveChildTo(&downcast<RenderBoxModelObject>(*previousSibling()), this, RenderBoxModelObject::NormalizeAfterInsertion::No);
downcast<RenderBoxModelObject>(*parent()).moveChildTo(*RenderTreeBuilder::current(), &downcast<RenderBoxModelObject>(*previousSibling()), this, RenderBoxModelObject::NormalizeAfterInsertion::No);

if (diff >= StyleDifferenceRepaint) {
// FIXME: This could use a cheaper style-only test instead of SimpleLineLayout::canUseFor.
@@ -2105,10 +2105,10 @@ void RenderBlockFlow::addFloatsToNewParent(RenderBlockFlow& toBlockFlow) const
}
}

void RenderBlockFlow::moveAllChildrenIncludingFloatsTo(RenderBlock& toBlock, RenderBoxModelObject::NormalizeAfterInsertion normalizeAfterInsertion)
void RenderBlockFlow::moveAllChildrenIncludingFloatsTo(RenderTreeBuilder& builder, RenderBlock& toBlock, RenderBoxModelObject::NormalizeAfterInsertion normalizeAfterInsertion)
{
auto& toBlockFlow = downcast<RenderBlockFlow>(toBlock);
moveAllChildrenTo(&toBlockFlow, normalizeAfterInsertion);
moveAllChildrenTo(builder, &toBlockFlow, normalizeAfterInsertion);
addFloatsToNewParent(toBlockFlow);
}

@@ -476,7 +476,7 @@ class RenderBlockFlow : public RenderBlock {
void paintInlineChildren(PaintInfo&, const LayoutPoint&) override;
void paintFloats(PaintInfo&, const LayoutPoint&, bool preservePhase = false) override;

void moveAllChildrenIncludingFloatsTo(RenderBlock& toBlock, RenderBoxModelObject::NormalizeAfterInsertion) override;
void moveAllChildrenIncludingFloatsTo(RenderTreeBuilder&, RenderBlock& toBlock, RenderBoxModelObject::NormalizeAfterInsertion) override;
void repaintOverhangingFloats(bool paintAllDescendants) final;
void clipOutFloatingObjects(RenderBlock&, const PaintInfo*, const LayoutPoint&, const LayoutSize&) override;

@@ -2685,7 +2685,7 @@ void RenderBoxModelObject::mapAbsoluteToLocalPoint(MapCoordinatesFlags mode, Tra
transformState.move(containerOffset.width(), containerOffset.height(), preserve3D ? TransformState::AccumulateTransform : TransformState::FlattenTransform);
}

void RenderBoxModelObject::moveChildTo(RenderBoxModelObject* toBoxModelObject, RenderObject* child, RenderObject* beforeChild, NormalizeAfterInsertion normalizeAfterInsertion)
void RenderBoxModelObject::moveChildTo(RenderTreeBuilder& builder, RenderBoxModelObject* toBoxModelObject, RenderObject* child, RenderObject* beforeChild, NormalizeAfterInsertion normalizeAfterInsertion)
{
// We assume that callers have cleared their positioned objects list for child moves so the
// positioned renderer maps don't become stale. It would be too slow to do the map lookup on each call.
@@ -2697,14 +2697,14 @@ void RenderBoxModelObject::moveChildTo(RenderBoxModelObject* toBoxModelObject, R
// Takes care of adding the new child correctly if toBlock and fromBlock
// have different kind of children (block vs inline).
auto childToMove = takeChildInternal(*child);
RenderTreeBuilder::current()->insertChild(*toBoxModelObject, WTFMove(childToMove), beforeChild);
builder.insertChild(*toBoxModelObject, WTFMove(childToMove), beforeChild);
} else {
auto childToMove = takeChildInternal(*child);
toBoxModelObject->insertChildInternal(WTFMove(childToMove), beforeChild);
}
}

void RenderBoxModelObject::moveChildrenTo(RenderBoxModelObject* toBoxModelObject, RenderObject* startChild, RenderObject* endChild, RenderObject* beforeChild, NormalizeAfterInsertion normalizeAfterInsertion)
void RenderBoxModelObject::moveChildrenTo(RenderTreeBuilder& builder, RenderBoxModelObject* toBoxModelObject, RenderObject* startChild, RenderObject* endChild, RenderObject* beforeChild, NormalizeAfterInsertion normalizeAfterInsertion)
{
// This condition is rarely hit since this function is usually called on
// anonymous blocks which can no longer carry positioned objects (see r120761)
@@ -2737,7 +2737,7 @@ void RenderBoxModelObject::moveChildrenTo(RenderBoxModelObject* toBoxModelObject
nextSibling = nextSibling->nextSibling();
}

moveChildTo(toBoxModelObject, child, beforeChild, normalizeAfterInsertion);
moveChildTo(builder, toBoxModelObject, child, beforeChild, normalizeAfterInsertion);
child = nextSibling;
}
}
@@ -277,27 +277,27 @@ class RenderBoxModelObject : public RenderLayerModelObject {

// NormalizeAfterInsertion::Yes ensures that the destination subtree is consistent after the insertion (anonymous wrappers etc).
enum class NormalizeAfterInsertion { No, Yes };
void moveChildTo(RenderBoxModelObject* toBoxModelObject, RenderObject* child, RenderObject* beforeChild, NormalizeAfterInsertion);
void moveChildTo(RenderBoxModelObject* toBoxModelObject, RenderObject* child, NormalizeAfterInsertion normalizeAfterInsertion)
void moveChildTo(RenderTreeBuilder&, RenderBoxModelObject* toBoxModelObject, RenderObject* child, RenderObject* beforeChild, NormalizeAfterInsertion);
void moveChildTo(RenderTreeBuilder& builder, RenderBoxModelObject* toBoxModelObject, RenderObject* child, NormalizeAfterInsertion normalizeAfterInsertion)
{
moveChildTo(toBoxModelObject, child, nullptr, normalizeAfterInsertion);
moveChildTo(builder, toBoxModelObject, child, nullptr, normalizeAfterInsertion);
}
void moveAllChildrenTo(RenderBoxModelObject* toBoxModelObject, NormalizeAfterInsertion normalizeAfterInsertion)
void moveAllChildrenTo(RenderTreeBuilder& builder, RenderBoxModelObject* toBoxModelObject, NormalizeAfterInsertion normalizeAfterInsertion)
{
moveAllChildrenTo(toBoxModelObject, nullptr, normalizeAfterInsertion);
moveAllChildrenTo(builder, toBoxModelObject, nullptr, normalizeAfterInsertion);
}
void moveAllChildrenTo(RenderBoxModelObject* toBoxModelObject, RenderObject* beforeChild, NormalizeAfterInsertion normalizeAfterInsertion)
void moveAllChildrenTo(RenderTreeBuilder& builder, RenderBoxModelObject* toBoxModelObject, RenderObject* beforeChild, NormalizeAfterInsertion normalizeAfterInsertion)
{
moveChildrenTo(toBoxModelObject, firstChild(), nullptr, beforeChild, normalizeAfterInsertion);
moveChildrenTo(builder, toBoxModelObject, firstChild(), nullptr, beforeChild, normalizeAfterInsertion);
}
void moveAllChildrenToInternal(RenderElement& newParent);
// Move all of the kids from |startChild| up to but excluding |endChild|. 0 can be passed as the |endChild| to denote
// that all the kids from |startChild| onwards should be moved.
void moveChildrenTo(RenderBoxModelObject* toBoxModelObject, RenderObject* startChild, RenderObject* endChild, NormalizeAfterInsertion normalizeAfterInsertion)
void moveChildrenTo(RenderTreeBuilder& builder, RenderBoxModelObject* toBoxModelObject, RenderObject* startChild, RenderObject* endChild, NormalizeAfterInsertion normalizeAfterInsertion)
{
moveChildrenTo(toBoxModelObject, startChild, endChild, nullptr, normalizeAfterInsertion);
moveChildrenTo(builder, toBoxModelObject, startChild, endChild, nullptr, normalizeAfterInsertion);
}
void moveChildrenTo(RenderBoxModelObject* toBoxModelObject, RenderObject* startChild, RenderObject* endChild, RenderObject* beforeChild, NormalizeAfterInsertion);
void moveChildrenTo(RenderTreeBuilder&, RenderBoxModelObject* toBoxModelObject, RenderObject* startChild, RenderObject* endChild, RenderObject* beforeChild, NormalizeAfterInsertion);

enum ScaleByEffectiveZoomOrNot { ScaleByEffectiveZoom, DoNotScaleByEffectiveZoom };
LayoutSize calculateImageIntrinsicDimensions(StyleImage*, const LayoutSize& scaledPositioningAreaSize, ScaleByEffectiveZoomOrNot) const;
@@ -111,8 +111,8 @@ RenderPtr<RenderObject> RenderRubyRun::takeChild(RenderTreeBuilder& builder, Ren
RenderRubyBase* rightBase = rightRun.rubyBase();
// Collect all children in a single base, then swap the bases.
RenderTreeBuilder::current()->moveRubyChildren(*rightBase, *base);
moveChildTo(&rightRun, base, RenderBoxModelObject::NormalizeAfterInsertion::No);
rightRun.moveChildTo(this, rightBase, RenderBoxModelObject::NormalizeAfterInsertion::No);
moveChildTo(builder, &rightRun, base, RenderBoxModelObject::NormalizeAfterInsertion::No);
rightRun.moveChildTo(builder, this, rightBase, RenderBoxModelObject::NormalizeAfterInsertion::No);
// The now empty ruby base will be removed below.
ASSERT(!rubyBase()->firstChild());
}
@@ -254,7 +254,7 @@ void RenderTreeBuilder::makeChildrenNonInline(RenderBlock& parent, RenderObject*
auto newBlock = parent.createAnonymousBlock();
auto& block = *newBlock;
parent.insertChildInternal(WTFMove(newBlock), inlineRunStart);
parent.moveChildrenTo(&block, inlineRunStart, child, RenderBoxModelObject::NormalizeAfterInsertion::No);
parent.moveChildrenTo(*this, &block, inlineRunStart, child, RenderBoxModelObject::NormalizeAfterInsertion::No);
}
#ifndef NDEBUG
for (RenderObject* c = parent.firstChild(); c; c = c->nextSibling())
@@ -283,7 +283,7 @@ RenderObject* RenderTreeBuilder::splitAnonymousBoxesAroundChild(RenderBox& paren
// See for example RenderTableCell:clippedOverflowRectForRepaint.
markBoxForRelayoutAfterSplit(*parentBox);
parentBox->insertChildInternal(WTFMove(newPostBox), boxToSplit.nextSibling());
boxToSplit.moveChildrenTo(&postBox, beforeChild, nullptr, RenderBoxModelObject::NormalizeAfterInsertion::Yes);
boxToSplit.moveChildrenTo(*this, &postBox, beforeChild, nullptr, RenderBoxModelObject::NormalizeAfterInsertion::Yes);

markBoxForRelayoutAfterSplit(boxToSplit);
markBoxForRelayoutAfterSplit(postBox);
@@ -342,7 +342,7 @@ void RenderTreeBuilder::removeAnonymousWrappersForInlineChildrenIfNeeded(RenderE
for (current = blockParent.firstChild(); current; current = next) {
next = current->nextSibling();
if (current->isAnonymousBlock())
blockParent.dropAnonymousBoxChild(downcast<RenderBlock>(*current));
blockParent.dropAnonymousBoxChild(*this, downcast<RenderBlock>(*current));
}
}

@@ -90,20 +90,20 @@ void RenderTreeBuilder::MultiColumn::createFragmentedFlow(RenderBlockFlow& flow)
m_builder.insertChildToRenderBlock(flow, WTFMove(newFragmentedFlow));

// Reparent children preceding the fragmented flow into the fragmented flow.
flow.moveChildrenTo(&fragmentedFlow, flow.firstChild(), &fragmentedFlow, RenderBoxModelObject::NormalizeAfterInsertion::Yes);
flow.moveChildrenTo(m_builder, &fragmentedFlow, flow.firstChild(), &fragmentedFlow, RenderBoxModelObject::NormalizeAfterInsertion::Yes);
if (flow.isFieldset()) {
// Keep legends out of the flow thread.
for (auto& box : childrenOfType<RenderBox>(fragmentedFlow)) {
if (box.isLegend())
fragmentedFlow.moveChildTo(&flow, &box, RenderBoxModelObject::NormalizeAfterInsertion::Yes);
fragmentedFlow.moveChildTo(m_builder, &flow, &box, RenderBoxModelObject::NormalizeAfterInsertion::Yes);
}
}

if (flow.style().hasLinesClamp()) {
// Keep the middle block out of the flow thread.
for (auto& element : childrenOfType<RenderElement>(fragmentedFlow)) {
if (!downcast<RenderLinesClampFlow>(fragmentedFlow).isChildAllowedInFragmentedFlow(flow, element))
fragmentedFlow.moveChildTo(&flow, &element, RenderBoxModelObject::NormalizeAfterInsertion::Yes);
fragmentedFlow.moveChildTo(m_builder, &flow, &element, RenderBoxModelObject::NormalizeAfterInsertion::Yes);
}
}

@@ -133,7 +133,7 @@ void RenderTreeBuilder::MultiColumn::destroyFragmentedFlow(RenderBlockFlow& flow
columnSet->removeFromParentAndDestroy();

flow.clearMultiColumnFlow();
multiColumnFlow.moveAllChildrenTo(&flow, RenderBoxModelObject::NormalizeAfterInsertion::Yes);
multiColumnFlow.moveAllChildrenTo(m_builder, &flow, RenderBoxModelObject::NormalizeAfterInsertion::Yes);
multiColumnFlow.removeFromParentAndDestroy();
for (auto& parentAndSpanner : parentAndSpannerList)
m_builder.insertChild(*parentAndSpanner.first, WTFMove(parentAndSpanner.second));

0 comments on commit e90e6d9

Please sign in to comment.