Diff
Modified: trunk/Source/WebCore/ChangeLog (226180 => 226181)
--- trunk/Source/WebCore/ChangeLog 2017-12-20 16:34:43 UTC (rev 226180)
+++ trunk/Source/WebCore/ChangeLog 2017-12-20 16:52:59 UTC (rev 226181)
@@ -1,3 +1,25 @@
+2017-12-20 Zalan Bujtas <[email protected]>
+
+ [RenderTreeBuilder] Move finding-the-parent/creating-wrapper logic from RenderTable::addChild to RenderTreeBuilder
+ https://bugs.webkit.org/show_bug.cgi?id=181018
+ <rdar://problem/36148601>
+
+ Reviewed by Antti Koivisto.
+
+ This is in preparation for removing all tree mutation from renderering code.
+
+ Covered by existing tests.
+
+ * rendering/RenderBlock.cpp:
+ (WebCore::RenderBlock::addChildIgnoringContinuation):
+ * rendering/RenderTable.cpp:
+ (WebCore::RenderTable::addChild):
+ * rendering/updating/RenderTreeBuilder.cpp:
+ (WebCore::RenderTreeBuilder::insertChild):
+ * rendering/updating/RenderTreeBuilderTable.cpp:
+ (WebCore::RenderTreeBuilder::Table::findOrCreateParentForChild):
+ * rendering/updating/RenderTreeBuilderTable.h:
+
2017-12-20 Frederic Wang <[email protected]>
Split layout of RenderMathMLRow into smaller steps
Modified: trunk/Source/WebCore/rendering/RenderBlock.cpp (226180 => 226181)
--- trunk/Source/WebCore/rendering/RenderBlock.cpp 2017-12-20 16:34:43 UTC (rev 226180)
+++ trunk/Source/WebCore/rendering/RenderBlock.cpp 2017-12-20 16:52:59 UTC (rev 226181)
@@ -572,7 +572,7 @@
if (newChild->isTablePart()) {
// Insert into the anonymous table.
- beforeChildAnonymousContainer->addChild(builder, WTFMove(newChild), beforeChild);
+ builder.insertChild(*beforeChildAnonymousContainer, WTFMove(newChild), beforeChild);
return;
}
Modified: trunk/Source/WebCore/rendering/RenderTable.cpp (226180 => 226181)
--- trunk/Source/WebCore/rendering/RenderTable.cpp 2017-12-20 16:34:43 UTC (rev 226180)
+++ trunk/Source/WebCore/rendering/RenderTable.cpp 2017-12-20 16:52:59 UTC (rev 226181)
@@ -135,13 +135,8 @@
void RenderTable::addChild(RenderTreeBuilder& builder, RenderPtr<RenderObject> child, RenderObject* beforeChild)
{
- bool wrapInAnonymousSection = !child->isOutOfFlowPositioned();
-
- if (is<RenderTableCaption>(*child))
- wrapInAnonymousSection = false;
- else if (is<RenderTableCol>(*child)) {
+ if (is<RenderTableCol>(*child)) {
m_hasColElements = true;
- wrapInAnonymousSection = false;
} else if (is<RenderTableSection>(*child)) {
switch (child->style().display()) {
case TABLE_HEADER_GROUP:
@@ -153,13 +148,11 @@
if (!m_firstBody)
m_firstBody = makeWeakPtr(downcast<RenderTableSection>(child.get()));
}
- wrapInAnonymousSection = false;
break;
case TABLE_FOOTER_GROUP:
resetSectionPointerIfNotBefore(m_foot, beforeChild);
if (!m_foot) {
m_foot = makeWeakPtr(downcast<RenderTableSection>(child.get()));
- wrapInAnonymousSection = false;
break;
}
FALLTHROUGH;
@@ -167,58 +160,19 @@
resetSectionPointerIfNotBefore(m_firstBody, beforeChild);
if (!m_firstBody)
m_firstBody = makeWeakPtr(downcast<RenderTableSection>(child.get()));
- wrapInAnonymousSection = false;
break;
default:
ASSERT_NOT_REACHED();
}
- } else if (is<RenderTableCell>(*child) || is<RenderTableRow>(*child))
- wrapInAnonymousSection = true;
- else
- wrapInAnonymousSection = true;
+ }
if (is<RenderTableSection>(*child))
setNeedsSectionRecalc();
- if (!wrapInAnonymousSection) {
- if (beforeChild && beforeChild->parent() != this)
- beforeChild = splitAnonymousBoxesAroundChild(beforeChild);
+ if (beforeChild && beforeChild->parent() != this)
+ beforeChild = splitAnonymousBoxesAroundChild(beforeChild);
- RenderBox::addChild(builder, WTFMove(child), beforeChild);
- return;
- }
-
- if (!beforeChild && is<RenderTableSection>(lastChild()) && lastChild()->isAnonymous() && !lastChild()->isBeforeContent()) {
- builder.insertChild(downcast<RenderTableSection>(*lastChild()), WTFMove(child));
- return;
- }
-
- if (beforeChild && !beforeChild->isAnonymous() && beforeChild->parent() == this) {
- RenderObject* section = beforeChild->previousSibling();
- if (is<RenderTableSection>(section) && section->isAnonymous()) {
- builder.insertChild(downcast<RenderTableSection>(*section), WTFMove(child));
- return;
- }
- }
-
- RenderObject* lastBox = beforeChild;
- while (lastBox && lastBox->parent()->isAnonymous() && !is<RenderTableSection>(*lastBox) && lastBox->style().display() != TABLE_CAPTION && lastBox->style().display() != TABLE_COLUMN_GROUP)
- lastBox = lastBox->parent();
- if (lastBox && lastBox->isAnonymous() && !isAfterContent(lastBox) && lastBox->isTableSection()) {
- RenderTableSection& section = downcast<RenderTableSection>(*lastBox);
- if (beforeChild == §ion)
- beforeChild = section.firstRow();
- builder.insertChild(section, WTFMove(child), beforeChild);
- return;
- }
-
- if (beforeChild && !is<RenderTableSection>(*beforeChild) && beforeChild->style().display() != TABLE_CAPTION && beforeChild->style().display() != TABLE_COLUMN_GROUP)
- beforeChild = nullptr;
-
- auto newSection = RenderTableSection::createAnonymousWithParentRenderer(*this);
- auto& section = *newSection;
- builder.insertChild(*this, WTFMove(newSection), beforeChild);
- builder.insertChild(section, WTFMove(child));
+ RenderBox::addChild(builder, WTFMove(child), beforeChild);
}
void RenderTable::addCaption(RenderTableCaption& caption)
Modified: trunk/Source/WebCore/rendering/updating/RenderTreeBuilder.cpp (226180 => 226181)
--- trunk/Source/WebCore/rendering/updating/RenderTreeBuilder.cpp 2017-12-20 16:34:43 UTC (rev 226180)
+++ trunk/Source/WebCore/rendering/updating/RenderTreeBuilder.cpp 2017-12-20 16:52:59 UTC (rev 226181)
@@ -68,7 +68,12 @@
}
if (is<RenderTableRow>(parent)) {
- tableBuilder().findOrCreateParentForChild(downcast<RenderTableRow>(parent), *child, beforeChild).addChild(*this, WTFMove(child), beforeChild);
+ auto& parentCandidate = tableBuilder().findOrCreateParentForChild(downcast<RenderTableRow>(parent), *child, beforeChild);
+ if (&parent != &parentCandidate) {
+ insertChild(parentCandidate, WTFMove(child), beforeChild);
+ return;
+ }
+ parent.addChild(*this, WTFMove(child), beforeChild);
return;
}
@@ -82,6 +87,16 @@
return;
}
+ if (is<RenderTable>(parent)) {
+ auto& parentCandidate = tableBuilder().findOrCreateParentForChild(downcast<RenderTable>(parent), *child, beforeChild);
+ if (&parent != &parentCandidate) {
+ insertChild(parentCandidate, WTFMove(child), beforeChild);
+ return;
+ }
+ parent.addChild(*this, WTFMove(child), beforeChild);
+ return;
+ }
+
if (is<RenderRubyRun>(parent)) {
rubyRunInsertChild(downcast<RenderRubyRun>(parent), WTFMove(child), beforeChild);
return;
Modified: trunk/Source/WebCore/rendering/updating/RenderTreeBuilderTable.cpp (226180 => 226181)
--- trunk/Source/WebCore/rendering/updating/RenderTreeBuilderTable.cpp 2017-12-20 16:34:43 UTC (rev 226180)
+++ trunk/Source/WebCore/rendering/updating/RenderTreeBuilderTable.cpp 2017-12-20 16:52:59 UTC (rev 226181)
@@ -26,7 +26,9 @@
#include "config.h"
#include "RenderTreeBuilderTable.h"
+#include "RenderTableCaption.h"
#include "RenderTableCell.h"
+#include "RenderTableCol.h"
#include "RenderTableRow.h"
#include "RenderTreeBuilder.h"
@@ -117,4 +119,46 @@
return row;
}
+RenderElement& RenderTreeBuilder::Table::findOrCreateParentForChild(RenderTable& parent, const RenderObject& child, RenderObject*& beforeChild)
+{
+ if (is<RenderTableCaption>(child) || is<RenderTableCol>(child) || is<RenderTableSection>(child))
+ return parent;
+
+ auto* lastChild = parent.lastChild();
+ if (!beforeChild && is<RenderTableSection>(lastChild) && lastChild->isAnonymous() && !lastChild->isBeforeContent())
+ return downcast<RenderElement>(*lastChild);
+
+ if (beforeChild && !beforeChild->isAnonymous() && beforeChild->parent() == &parent) {
+ auto* section = beforeChild->previousSibling();
+ if (is<RenderTableSection>(section) && section->isAnonymous()) {
+ beforeChild = nullptr;
+ return downcast<RenderElement>(*section);
+ }
+ }
+
+ auto* parentCandidate = beforeChild;
+ while (parentCandidate && parentCandidate->parent()->isAnonymous()
+ && !is<RenderTableSection>(*parentCandidate)
+ && parentCandidate->style().display() != TABLE_CAPTION
+ && parentCandidate->style().display() != TABLE_COLUMN_GROUP)
+ parentCandidate = parentCandidate->parent();
+
+ if (parentCandidate && is<RenderTableSection>(*parentCandidate) && parentCandidate->isAnonymous() && !parent.isAfterContent(parentCandidate)) {
+ if (beforeChild == parentCandidate)
+ beforeChild = downcast<RenderTableSection>(*parentCandidate).firstRow();
+ return downcast<RenderElement>(*parentCandidate);
+ }
+
+ if (beforeChild && !is<RenderTableSection>(*beforeChild)
+ && beforeChild->style().display() != TABLE_CAPTION
+ && beforeChild->style().display() != TABLE_COLUMN_GROUP)
+ beforeChild = nullptr;
+
+ auto newSection = RenderTableSection::createAnonymousWithParentRenderer(parent);
+ auto& section = *newSection;
+ m_builder.insertChild(parent, WTFMove(newSection), beforeChild);
+ beforeChild = nullptr;
+ return section;
}
+
+}
Modified: trunk/Source/WebCore/rendering/updating/RenderTreeBuilderTable.h (226180 => 226181)
--- trunk/Source/WebCore/rendering/updating/RenderTreeBuilderTable.h 2017-12-20 16:34:43 UTC (rev 226180)
+++ trunk/Source/WebCore/rendering/updating/RenderTreeBuilderTable.h 2017-12-20 16:52:59 UTC (rev 226181)
@@ -40,6 +40,7 @@
RenderElement& findOrCreateParentForChild(RenderTableRow& parent, const RenderObject& child, RenderObject*& beforeChild);
RenderElement& findOrCreateParentForChild(RenderTableSection& parent, const RenderObject& child, RenderObject*& beforeChild);
+ RenderElement& findOrCreateParentForChild(RenderTable& parent, const RenderObject& child, RenderObject*& beforeChild);
private:
RenderTreeBuilder& m_builder;