Skip to content
Permalink
Browse files
[RenderTreeBuilder] Introduce RenderTreebuilder::takeChild
https://bugs.webkit.org/show_bug.cgi?id=182707
<rdar://problem/37473433>

Reviewed by Antti Koivisto.

All takeChild calls should go through RenderTreeBuilder::takeChild from now on.
This patch also moves the Ruby related takeChild calls to RenderTreeBuilder.

No change in functionality.

* rendering/RenderButton.cpp:
(WebCore::RenderButton::takeChild):
* rendering/RenderElement.cpp:
(WebCore::RenderElement::removeAndDestroyChild):
* rendering/RenderFullScreen.cpp:
(WebCore::RenderFullScreen::wrapExistingRenderer):
(WebCore::RenderFullScreen::unwrapRenderer):
* rendering/RenderMenuList.cpp:
(RenderMenuList::takeChild):
* rendering/RenderRuby.cpp:
(WebCore::RenderRubyAsInline::takeChild): Deleted.
(WebCore::RenderRubyAsBlock::takeChild): Deleted.
* rendering/RenderRuby.h:
* rendering/RenderRubyRun.cpp:
(WebCore::RenderRubyRun::takeChild): Deleted.
* rendering/RenderRubyRun.h:
* rendering/updating/RenderTreeBuilder.cpp:
(WebCore::RenderTreeBuilder::takeChild):
(WebCore::RenderTreeBuilder::takeChildFromRenderRubyAsInline): Deleted.
(WebCore::RenderTreeBuilder::takeChildFromRenderRubyAsBlock): Deleted.
(WebCore::RenderTreeBuilder::takeChildFromRenderRubyRun): Deleted.
* rendering/updating/RenderTreeBuilder.h:
* rendering/updating/RenderTreeBuilderFirstLetter.cpp:
(WebCore::RenderTreeBuilder::FirstLetter::updateStyle):
* rendering/updating/RenderTreeBuilderList.cpp:
(WebCore::RenderTreeBuilder::List::updateItemMarker):
* rendering/updating/RenderTreeBuilderMultiColumn.cpp:
(WebCore::RenderTreeBuilder::MultiColumn::createFragmentedFlow):
(WebCore::RenderTreeBuilder::MultiColumn::destroyFragmentedFlow):
(WebCore::RenderTreeBuilder::MultiColumn::processPossibleSpannerDescendant):
* rendering/updating/RenderTreeBuilderRuby.cpp:
(WebCore::RenderTreeBuilder::Ruby::takeChild):
* rendering/updating/RenderTreeBuilderTable.cpp:
(WebCore::RenderTreeBuilder::Table::collapseAndDestroyAnonymousSiblingRows):


Canonical link: https://commits.webkit.org/198506@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@228400 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
alanbujtas committed Feb 12, 2018
1 parent 1b0b51d commit e559a6749ebb49c932d7b11257b21b9962767e2c
Showing 16 changed files with 79 additions and 53 deletions.
@@ -1,3 +1,51 @@
2018-02-12 Zalan Bujtas <zalan@apple.com>

[RenderTreeBuilder] Introduce RenderTreebuilder::takeChild
https://bugs.webkit.org/show_bug.cgi?id=182707
<rdar://problem/37473433>

Reviewed by Antti Koivisto.

All takeChild calls should go through RenderTreeBuilder::takeChild from now on.
This patch also moves the Ruby related takeChild calls to RenderTreeBuilder.

No change in functionality.

* rendering/RenderButton.cpp:
(WebCore::RenderButton::takeChild):
* rendering/RenderElement.cpp:
(WebCore::RenderElement::removeAndDestroyChild):
* rendering/RenderFullScreen.cpp:
(WebCore::RenderFullScreen::wrapExistingRenderer):
(WebCore::RenderFullScreen::unwrapRenderer):
* rendering/RenderMenuList.cpp:
(RenderMenuList::takeChild):
* rendering/RenderRuby.cpp:
(WebCore::RenderRubyAsInline::takeChild): Deleted.
(WebCore::RenderRubyAsBlock::takeChild): Deleted.
* rendering/RenderRuby.h:
* rendering/RenderRubyRun.cpp:
(WebCore::RenderRubyRun::takeChild): Deleted.
* rendering/RenderRubyRun.h:
* rendering/updating/RenderTreeBuilder.cpp:
(WebCore::RenderTreeBuilder::takeChild):
(WebCore::RenderTreeBuilder::takeChildFromRenderRubyAsInline): Deleted.
(WebCore::RenderTreeBuilder::takeChildFromRenderRubyAsBlock): Deleted.
(WebCore::RenderTreeBuilder::takeChildFromRenderRubyRun): Deleted.
* rendering/updating/RenderTreeBuilder.h:
* rendering/updating/RenderTreeBuilderFirstLetter.cpp:
(WebCore::RenderTreeBuilder::FirstLetter::updateStyle):
* rendering/updating/RenderTreeBuilderList.cpp:
(WebCore::RenderTreeBuilder::List::updateItemMarker):
* rendering/updating/RenderTreeBuilderMultiColumn.cpp:
(WebCore::RenderTreeBuilder::MultiColumn::createFragmentedFlow):
(WebCore::RenderTreeBuilder::MultiColumn::destroyFragmentedFlow):
(WebCore::RenderTreeBuilder::MultiColumn::processPossibleSpannerDescendant):
* rendering/updating/RenderTreeBuilderRuby.cpp:
(WebCore::RenderTreeBuilder::Ruby::takeChild):
* rendering/updating/RenderTreeBuilderTable.cpp:
(WebCore::RenderTreeBuilder::Table::collapseAndDestroyAnonymousSiblingRows):

2018-02-12 Zalan Bujtas <zalan@apple.com>

[RenderTreeBuilder] Move RenderBlock::dropAnonymousBoxChild to RenderTreeBuilder
@@ -79,7 +79,7 @@ RenderPtr<RenderObject> RenderButton::takeChild(RenderTreeBuilder& builder, Rend
ASSERT(&oldChild == m_inner || !m_inner);
return RenderFlexibleBox::takeChild(builder, oldChild);
}
return m_inner->takeChild(builder, oldChild);
return builder.takeChild(*m_inner, oldChild);
}

void RenderButton::updateAnonymousChildStyle(RenderStyle& childStyle) const
@@ -497,7 +497,7 @@ void RenderElement::removeAndDestroyChild(RenderTreeBuilder& builder, RenderObje
child.removeAndDestroyChild(builder, firstChild);
}
}
auto toDestroy = takeChild(builder, oldChild);
auto toDestroy = builder.takeChild(*this, oldChild);
}

RenderObject* RenderElement::attachRendererInternal(RenderPtr<RenderObject> child, RenderObject* beforeChild)
@@ -132,7 +132,7 @@ void RenderFullScreen::wrapExistingRenderer(RenderElement& renderer, Document& d

builder.insertChild(parent, WTFMove(newFullscreenRenderer), &renderer);

auto toMove = parent.takeChild(builder, renderer);
auto toMove = builder.takeChild(parent, renderer);

// Always just do a full layout to ensure that line boxes get deleted properly.
// Because objects moved from |parent| to |fullscreenRenderer|, we want to
@@ -178,7 +178,7 @@ void RenderFullScreen::unwrapRenderer(bool& requiresRenderTreeRebuild)
// lying around on the child.
if (is<RenderBox>(*child))
downcast<RenderBox>(*child).clearOverrideSize();
auto childToMove = child->parent()->takeChild(builder, *child);
auto childToMove = builder.takeChild(*child->parent(), *child);
builder.insertChild(*parent(), WTFMove(childToMove), this);
parent()->setNeedsLayoutAndPrefWidthsRecalc();
}
@@ -176,7 +176,7 @@ RenderPtr<RenderObject> RenderMenuList::takeChild(RenderTreeBuilder& builder, Re
{
if (!m_innerBlock || &oldChild == m_innerBlock)
return RenderFlexibleBox::takeChild(builder, oldChild);
return m_innerBlock->takeChild(builder, oldChild);
return builder.takeChild(*m_innerBlock, oldChild);
}

void RenderMenuList::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
@@ -60,11 +60,6 @@ void RenderRubyAsInline::styleDidChange(StyleDifference diff, const RenderStyle*
propagateStyleToAnonymousChildren(PropagateToAllChildren);
}

RenderPtr<RenderObject> RenderRubyAsInline::takeChild(RenderTreeBuilder& builder, RenderObject& child)
{
return builder.takeChildFromRenderRubyAsInline(*this, child);
}

//=== ruby as block object ===

RenderRubyAsBlock::RenderRubyAsBlock(Element& element, RenderStyle&& style)
@@ -80,9 +75,4 @@ void RenderRubyAsBlock::styleDidChange(StyleDifference diff, const RenderStyle*
propagateStyleToAnonymousChildren(PropagateToAllChildren);
}

RenderPtr<RenderObject> RenderRubyAsBlock::takeChild(RenderTreeBuilder& builder, RenderObject& child)
{
return builder.takeChildFromRenderRubyAsBlock(*this, child);
}

} // namespace WebCore
@@ -56,8 +56,6 @@ class RenderRubyAsInline final : public RenderInline {
RenderRubyAsInline(Element&, RenderStyle&&);
virtual ~RenderRubyAsInline();

RenderPtr<RenderObject> takeChild(RenderTreeBuilder&, RenderObject& child) override;

protected:
void styleDidChange(StyleDifference, const RenderStyle* oldStyle) override;

@@ -76,8 +74,6 @@ class RenderRubyAsBlock final : public RenderBlockFlow {

Element& element() const { return downcast<Element>(nodeForNonAnonymous()); }

RenderPtr<RenderObject> takeChild(RenderTreeBuilder&, RenderObject& child) override;

protected:
void styleDidChange(StyleDifference, const RenderStyle* oldStyle) override;

@@ -97,11 +97,6 @@ bool RenderRubyRun::isChildAllowed(const RenderObject& child, const RenderStyle&
return child.isInline() || child.isRubyText();
}

RenderPtr<RenderObject> RenderRubyRun::takeChild(RenderTreeBuilder& builder, RenderObject& child)
{
return builder.takeChildFromRenderRubyRun(*this, child);
}

RenderPtr<RenderRubyBase> RenderRubyRun::createRubyBase() const
{
auto newStyle = RenderStyle::createAnonymousStyleWithDisplay(style(), BLOCK);
@@ -56,7 +56,6 @@ class RenderRubyRun final : public RenderBlockFlow {
void layoutBlock(bool relayoutChildren, LayoutUnit pageHeight = 0) override;

bool isChildAllowed(const RenderObject&, const RenderStyle&) const override;
RenderPtr<RenderObject> takeChild(RenderTreeBuilder&, RenderObject&) override;

RenderBlock* firstLineBlock() const override;

@@ -187,6 +187,20 @@ void RenderTreeBuilder::insertChild(RenderElement& parent, RenderPtr<RenderObjec
parent.addChild(*this, WTFMove(child), beforeChild);
}

RenderPtr<RenderObject> RenderTreeBuilder::takeChild(RenderElement& parent, RenderObject& child)
{
if (is<RenderRubyAsInline>(parent))
return rubyBuilder().takeChild(downcast<RenderRubyAsInline>(parent), child);

if (is<RenderRubyAsBlock>(parent))
return rubyBuilder().takeChild(downcast<RenderRubyAsBlock>(parent), child);

if (is<RenderRubyRun>(parent))
return rubyBuilder().takeChild(downcast<RenderRubyRun>(parent), child);

return parent.takeChild(*this, child);
}

void RenderTreeBuilder::insertChild(RenderTreePosition& position, RenderPtr<RenderObject> child)
{
insertChild(position.parent(), WTFMove(child), position.nextSibling());
@@ -476,21 +490,6 @@ void RenderTreeBuilder::insertChildToRenderMathMLFenced(RenderMathMLFenced& pare
mathMLBuilder().insertChild(parent, WTFMove(child), beforeChild);
}

RenderPtr<RenderObject> RenderTreeBuilder::takeChildFromRenderRubyAsInline(RenderRubyAsInline& parent, RenderObject& child)
{
return rubyBuilder().takeChild(parent, child);
}

RenderPtr<RenderObject> RenderTreeBuilder::takeChildFromRenderRubyAsBlock(RenderRubyAsBlock& parent, RenderObject& child)
{
return rubyBuilder().takeChild(parent, child);
}

RenderPtr<RenderObject> RenderTreeBuilder::takeChildFromRenderRubyRun(RenderRubyRun& parent, RenderObject& child)
{
return rubyBuilder().takeChild(parent, child);
}

RenderPtr<RenderObject> RenderTreeBuilder::takeChildFromRenderBlock(RenderBlock& parent, RenderObject& oldChild)
{
return blockBuilder().takeChild(parent, oldChild);
@@ -51,6 +51,8 @@ class RenderTreeBuilder {
void insertChild(RenderElement& parent, RenderPtr<RenderObject>, RenderObject* beforeChild = nullptr);
void insertChild(RenderTreePosition&, RenderPtr<RenderObject>);

RenderPtr<RenderObject> takeChild(RenderElement&, RenderObject&) WARN_UNUSED_RETURN;

void updateAfterDescendants(RenderElement&);

// This avoids having to convert all sites that need RenderTreeBuilder in one go.
@@ -73,9 +75,6 @@ class RenderTreeBuilder {
void insertChildToRenderTableRow(RenderTableRow& parent, RenderPtr<RenderObject> child, RenderObject* beforeChild = nullptr);
void insertChildToRenderMathMLFenced(RenderMathMLFenced& parent, RenderPtr<RenderObject> child, RenderObject* beforeChild = nullptr);

RenderPtr<RenderObject> takeChildFromRenderRubyAsInline(RenderRubyAsInline& parent, RenderObject& child);
RenderPtr<RenderObject> takeChildFromRenderRubyAsBlock(RenderRubyAsBlock& parent, RenderObject& child);
RenderPtr<RenderObject> takeChildFromRenderRubyRun(RenderRubyRun& parent, RenderObject& child);
RenderPtr<RenderObject> takeChildFromRenderBlock(RenderBlock& parent, RenderObject& oldChild);

bool childRequiresTable(const RenderElement& parent, const RenderObject& child);
@@ -174,7 +174,7 @@ void RenderTreeBuilder::FirstLetter::updateStyle(RenderBlock& firstLetterBlock,
while (RenderObject* child = firstLetter->firstChild()) {
if (is<RenderText>(*child))
downcast<RenderText>(*child).removeAndDestroyTextBoxes();
auto toMove = firstLetter->takeChild(m_builder, *child);
auto toMove = m_builder.takeChild(*firstLetter, *child);
m_builder.insertChild(*newFirstLetter, WTFMove(toMove));
}

@@ -115,7 +115,7 @@ void RenderTreeBuilder::List::updateItemMarker(RenderListItem& listItemRenderer)
return;

if (currentParent)
m_builder.insertChild(*newParent, currentParent->takeChild(m_builder, *markerRenderer), firstNonMarkerChild(*newParent));
m_builder.insertChild(*newParent, m_builder.takeChild(*currentParent, *markerRenderer), firstNonMarkerChild(*newParent));
else
m_builder.insertChild(*newParent, WTFMove(newMarkerRenderer), firstNonMarkerChild(*newParent));

@@ -160,7 +160,7 @@ void RenderTreeBuilder::MultiColumn::createFragmentedFlow(RenderBlockFlow& flow)
// Move the spanner back to its original position.
auto& spannerOriginalParent = *placeholder->parent();
// Detaching the spanner takes care of removing the placeholder (and merges the RenderMultiColumnSets).
auto spannerToReInsert = spanner->parent()->takeChild(m_builder, *spanner);
auto spannerToReInsert = m_builder.takeChild(*spanner->parent(), *spanner);
m_builder.insertChild(spannerOriginalParent, WTFMove(spannerToReInsert));
}
}
@@ -208,7 +208,7 @@ void RenderTreeBuilder::MultiColumn::destroyFragmentedFlow(RenderBlockFlow& flow
spannerOriginalParent = &flow;
// Detaching the spanner takes care of removing the placeholder (and merges the RenderMultiColumnSets).
auto* spanner = placeholder->spanner();
parentAndSpannerList.append(std::make_pair(spannerOriginalParent, spanner->parent()->takeChild(m_builder, *spanner)));
parentAndSpannerList.append(std::make_pair(spannerOriginalParent, m_builder.takeChild(*spanner->parent(), *spanner)));
}
while (auto* columnSet = multiColumnFlow.firstMultiColumnSet())
columnSet->removeFromParentAndDestroy(m_builder);
@@ -313,7 +313,7 @@ RenderObject* RenderTreeBuilder::MultiColumn::processPossibleSpannerDescendant(R
auto newPlaceholder = RenderMultiColumnSpannerPlaceholder::createAnonymous(flow, downcast<RenderBox>(descendant), container->style());
auto& placeholder = *newPlaceholder;
m_builder.insertChild(*container, WTFMove(newPlaceholder), descendant.nextSibling());
auto takenDescendant = container->takeChild(m_builder, descendant);
auto takenDescendant = m_builder.takeChild(*container, descendant);

// This is a guard to stop an ancestor flow thread from processing the spanner.
gShiftingSpanner = true;
@@ -387,13 +387,13 @@ RenderPtr<RenderObject> RenderTreeBuilder::Ruby::takeChild(RenderRubyAsInline& p
if (isAnonymousRubyInlineBlock(child.parent())) {
ASSERT(child.isBeforeContent() || child.isAfterContent());
auto& parent = *child.parent();
auto takenChild = parent.takeChild(m_builder, child);
auto takenChild = m_builder.takeChild(parent, child);
parent.removeFromParentAndDestroy(m_builder);
return takenChild;
}

// Otherwise find the containing run and remove it from there.
return findRubyRunParent(child).takeChild(m_builder, child);
return m_builder.takeChild(findRubyRunParent(child), child);
}

RenderPtr<RenderObject> RenderTreeBuilder::Ruby::takeChild(RenderRubyAsBlock& parent, RenderObject& child)
@@ -411,13 +411,13 @@ RenderPtr<RenderObject> RenderTreeBuilder::Ruby::takeChild(RenderRubyAsBlock& pa
if (isAnonymousRubyInlineBlock(child.parent())) {
ASSERT(child.isBeforeContent() || child.isAfterContent());
auto& parent = *child.parent();
auto takenChild = parent.takeChild(m_builder, child);
auto takenChild = m_builder.takeChild(parent, child);
parent.removeFromParentAndDestroy(m_builder);
return takenChild;
}

// Otherwise find the containing run and remove it from there.
return findRubyRunParent(child).takeChild(m_builder, child);
return m_builder.takeChild(findRubyRunParent(child), child);
}

RenderPtr<RenderObject> RenderTreeBuilder::Ruby::takeChild(RenderRubyRun& parent, RenderObject& child)
@@ -236,7 +236,7 @@ void RenderTreeBuilder::Table::collapseAndDestroyAnonymousSiblingRows(RenderTabl
continue;
}
currentRow->moveAllChildrenTo(m_builder, rowToInsertInto, RenderBoxModelObject::NormalizeAfterInsertion::No);
auto toDestroy = section->takeChild(m_builder, *currentRow);
auto toDestroy = m_builder.takeChild(*section, *currentRow);
currentRow = currentRow->nextRow();
}
if (rowToInsertInto)

0 comments on commit e559a67

Please sign in to comment.