Log Message
[LFC] Layout box should own its children https://bugs.webkit.org/show_bug.cgi?id=231288
Reviewed by Alan Bujtas. Avoid the need to have a separate ownership scheme. Also make the box tree use CheckedPtrs. * layout/integration/LayoutIntegrationBoxTree.cpp: (WebCore::LayoutIntegration::BoxTree::appendChild): * layout/integration/LayoutIntegrationBoxTree.h: * layout/layouttree/LayoutBox.cpp: (WebCore::Layout::Box::setParent): (WebCore::Layout::Box::setNextSibling): (WebCore::Layout::Box::setPreviousSibling): * layout/layouttree/LayoutBox.h: (WebCore::Layout::Box::nextSibling const): (WebCore::Layout::Box::previousSibling const): (WebCore::Layout::Box::nextSibling): (WebCore::Layout::Box::setParent): Deleted. (WebCore::Layout::Box::setNextSibling): Deleted. (WebCore::Layout::Box::setPreviousSibling): Deleted. * layout/layouttree/LayoutContainerBox.cpp: (WebCore::Layout::ContainerBox::~ContainerBox): (WebCore::Layout::ContainerBox::appendChild): (WebCore::Layout::ContainerBox::destroyChildren): (WebCore::Layout::ContainerBox::setFirstChild): Deleted. (WebCore::Layout::ContainerBox::setLastChild): Deleted. * layout/layouttree/LayoutContainerBox.h: (WebCore::Layout::ContainerBox::firstChild const): (WebCore::Layout::ContainerBox::lastChild const): (WebCore::Layout::ContainerBox::firstChild): (): Deleted. * layout/layouttree/LayoutTreeBuilder.cpp: (WebCore::Layout::LayoutTree::LayoutTree): (WebCore::Layout::appendChild): (WebCore::Layout::TreeBuilder::buildLayoutTree): (WebCore::Layout::TreeBuilder::TreeBuilder): (WebCore::Layout::TreeBuilder::createReplacedBox): (WebCore::Layout::TreeBuilder::createTextBox): (WebCore::Layout::TreeBuilder::createLineBreakBox): (WebCore::Layout::TreeBuilder::createContainer): (WebCore::Layout::TreeBuilder::createLayoutBox): (WebCore::Layout::TreeBuilder::buildTableStructure): (WebCore::Layout::TreeBuilder::buildSubTree): * layout/layouttree/LayoutTreeBuilder.h: (WebCore::Layout::LayoutTree::root const): (WebCore::Layout::LayoutTree::append): Deleted.
Modified Paths
- trunk/Source/WebCore/ChangeLog
- trunk/Source/WebCore/layout/integration/LayoutIntegrationBoxTree.cpp
- trunk/Source/WebCore/layout/integration/LayoutIntegrationBoxTree.h
- trunk/Source/WebCore/layout/layouttree/LayoutBox.cpp
- trunk/Source/WebCore/layout/layouttree/LayoutBox.h
- trunk/Source/WebCore/layout/layouttree/LayoutContainerBox.cpp
- trunk/Source/WebCore/layout/layouttree/LayoutContainerBox.h
- trunk/Source/WebCore/layout/layouttree/LayoutTreeBuilder.cpp
- trunk/Source/WebCore/layout/layouttree/LayoutTreeBuilder.h
Diff
Modified: trunk/Source/WebCore/ChangeLog (283619 => 283620)
--- trunk/Source/WebCore/ChangeLog 2021-10-06 15:23:05 UTC (rev 283619)
+++ trunk/Source/WebCore/ChangeLog 2021-10-06 15:25:17 UTC (rev 283620)
@@ -1,3 +1,55 @@
+2021-10-06 Antti Koivisto <[email protected]>
+
+ [LFC] Layout box should own its children
+ https://bugs.webkit.org/show_bug.cgi?id=231288
+
+ Reviewed by Alan Bujtas.
+
+ Avoid the need to have a separate ownership scheme.
+
+ Also make the box tree use CheckedPtrs.
+
+ * layout/integration/LayoutIntegrationBoxTree.cpp:
+ (WebCore::LayoutIntegration::BoxTree::appendChild):
+ * layout/integration/LayoutIntegrationBoxTree.h:
+ * layout/layouttree/LayoutBox.cpp:
+ (WebCore::Layout::Box::setParent):
+ (WebCore::Layout::Box::setNextSibling):
+ (WebCore::Layout::Box::setPreviousSibling):
+ * layout/layouttree/LayoutBox.h:
+ (WebCore::Layout::Box::nextSibling const):
+ (WebCore::Layout::Box::previousSibling const):
+ (WebCore::Layout::Box::nextSibling):
+ (WebCore::Layout::Box::setParent): Deleted.
+ (WebCore::Layout::Box::setNextSibling): Deleted.
+ (WebCore::Layout::Box::setPreviousSibling): Deleted.
+ * layout/layouttree/LayoutContainerBox.cpp:
+ (WebCore::Layout::ContainerBox::~ContainerBox):
+ (WebCore::Layout::ContainerBox::appendChild):
+ (WebCore::Layout::ContainerBox::destroyChildren):
+ (WebCore::Layout::ContainerBox::setFirstChild): Deleted.
+ (WebCore::Layout::ContainerBox::setLastChild): Deleted.
+ * layout/layouttree/LayoutContainerBox.h:
+ (WebCore::Layout::ContainerBox::firstChild const):
+ (WebCore::Layout::ContainerBox::lastChild const):
+ (WebCore::Layout::ContainerBox::firstChild):
+ (): Deleted.
+ * layout/layouttree/LayoutTreeBuilder.cpp:
+ (WebCore::Layout::LayoutTree::LayoutTree):
+ (WebCore::Layout::appendChild):
+ (WebCore::Layout::TreeBuilder::buildLayoutTree):
+ (WebCore::Layout::TreeBuilder::TreeBuilder):
+ (WebCore::Layout::TreeBuilder::createReplacedBox):
+ (WebCore::Layout::TreeBuilder::createTextBox):
+ (WebCore::Layout::TreeBuilder::createLineBreakBox):
+ (WebCore::Layout::TreeBuilder::createContainer):
+ (WebCore::Layout::TreeBuilder::createLayoutBox):
+ (WebCore::Layout::TreeBuilder::buildTableStructure):
+ (WebCore::Layout::TreeBuilder::buildSubTree):
+ * layout/layouttree/LayoutTreeBuilder.h:
+ (WebCore::Layout::LayoutTree::root const):
+ (WebCore::Layout::LayoutTree::append): Deleted.
+
2021-10-06 Alan Bujtas <[email protected]>
Make containerForElement logic more explicit
Modified: trunk/Source/WebCore/layout/integration/LayoutIntegrationBoxTree.cpp (283619 => 283620)
--- trunk/Source/WebCore/layout/integration/LayoutIntegrationBoxTree.cpp 2021-10-06 15:23:05 UTC (rev 283619)
+++ trunk/Source/WebCore/layout/integration/LayoutIntegrationBoxTree.cpp 2021-10-06 15:25:17 UTC (rev 283620)
@@ -153,10 +153,11 @@
void BoxTree::appendChild(UniqueRef<Layout::Box> childBox, RenderObject& childRenderer)
{
auto& parentBox = downcast<Layout::ContainerBox>(layoutBoxForRenderer(*childRenderer.parent()));
- parentBox.appendChild(childBox.get());
- m_boxes.append({ WTFMove(childBox), &childRenderer });
+ m_boxes.append({ childBox.get(), &childRenderer });
+ parentBox.appendChild(WTFMove(childBox));
+
if (m_boxes.size() > smallTreeThreshold) {
if (m_rendererToBoxMap.isEmpty()) {
for (auto& entry : m_boxes)
Modified: trunk/Source/WebCore/layout/integration/LayoutIntegrationBoxTree.h (283619 => 283620)
--- trunk/Source/WebCore/layout/integration/LayoutIntegrationBoxTree.h 2021-10-06 15:23:05 UTC (rev 283619)
+++ trunk/Source/WebCore/layout/integration/LayoutIntegrationBoxTree.h 2021-10-06 15:25:17 UTC (rev 283620)
@@ -60,7 +60,7 @@
size_t boxCount() const { return m_boxes.size(); }
struct BoxAndRenderer {
- UniqueRef<Layout::Box> box;
+ CheckedRef<Layout::Box> box;
RenderObject* renderer { nullptr };
};
const auto& boxAndRendererList() const { return m_boxes; }
Modified: trunk/Source/WebCore/layout/layouttree/LayoutBox.cpp (283619 => 283620)
--- trunk/Source/WebCore/layout/layouttree/LayoutBox.cpp 2021-10-06 15:23:05 UTC (rev 283619)
+++ trunk/Source/WebCore/layout/layouttree/LayoutBox.cpp 2021-10-06 15:25:17 UTC (rev 283620)
@@ -59,6 +59,21 @@
removeRareData();
}
+void Box::setParent(ContainerBox* parent)
+{
+ m_parent = parent;
+}
+
+void Box::setNextSibling(Box* nextSibling)
+{
+ m_nextSibling = nextSibling;
+}
+
+void Box::setPreviousSibling(Box* previousSibling)
+{
+ m_previousSibling = previousSibling;
+}
+
void Box::updateStyle(const RenderStyle& newStyle, std::unique_ptr<RenderStyle>&& newFirstLineStyle)
{
m_style = RenderStyle::clone(newStyle);
Modified: trunk/Source/WebCore/layout/layouttree/LayoutBox.h (283619 => 283620)
--- trunk/Source/WebCore/layout/layouttree/LayoutBox.h 2021-10-06 15:23:05 UTC (rev 283619)
+++ trunk/Source/WebCore/layout/layouttree/LayoutBox.h 2021-10-06 15:25:17 UTC (rev 283620)
@@ -140,16 +140,16 @@
bool isInternalRubyBox() const { return false; }
const ContainerBox& parent() const { return *m_parent; }
- const Box* nextSibling() const { return m_nextSibling; }
+ const Box* nextSibling() const { return m_nextSibling.get(); }
const Box* nextInFlowSibling() const;
const Box* nextInFlowOrFloatingSibling() const;
- const Box* previousSibling() const { return m_previousSibling; }
+ const Box* previousSibling() const { return m_previousSibling.get(); }
const Box* previousInFlowSibling() const;
const Box* previousInFlowOrFloatingSibling() const;
bool isDescendantOf(const ContainerBox&) const;
// FIXME: This is currently needed for style updates.
- Box* nextSibling() { return m_nextSibling; }
+ Box* nextSibling() { return m_nextSibling.get(); }
bool isContainerBox() const { return baseTypeFlags().contains(ContainerBoxFlag); }
bool isInlineTextBox() const { return baseTypeFlags().contains(InlineTextBoxFlag); }
@@ -173,10 +173,6 @@
void setColumnWidth(LayoutUnit);
std::optional<LayoutUnit> columnWidth() const;
- void setParent(ContainerBox& parent) { m_parent = &parent; }
- void setNextSibling(Box& nextSibling) { m_nextSibling = &nextSibling; }
- void setPreviousSibling(Box& previousSibling) { m_previousSibling = &previousSibling; }
-
void setIsAnonymous() { m_isAnonymous = true; }
bool canCacheForLayoutState(const LayoutState&) const;
@@ -187,6 +183,12 @@
Box(std::optional<ElementAttributes>, RenderStyle&&, std::unique_ptr<RenderStyle>&& firstLineStyle, OptionSet<BaseTypeFlag>);
private:
+ friend class ContainerBox;
+
+ void setParent(ContainerBox*);
+ void setNextSibling(Box*);
+ void setPreviousSibling(Box*);
+
class BoxRareData {
WTF_MAKE_FAST_ALLOCATED;
public:
@@ -212,9 +214,9 @@
RenderStyle m_style;
std::optional<ElementAttributes> m_elementAttributes;
- ContainerBox* m_parent { nullptr };
- Box* m_previousSibling { nullptr };
- Box* m_nextSibling { nullptr };
+ CheckedPtr<ContainerBox> m_parent;
+ CheckedPtr<Box> m_previousSibling;
+ CheckedPtr<Box> m_nextSibling;
// First LayoutState gets a direct cache.
mutable WeakPtr<LayoutState> m_cachedLayoutState;
Modified: trunk/Source/WebCore/layout/layouttree/LayoutContainerBox.cpp (283619 => 283620)
--- trunk/Source/WebCore/layout/layouttree/LayoutContainerBox.cpp 2021-10-06 15:23:05 UTC (rev 283619)
+++ trunk/Source/WebCore/layout/layouttree/LayoutContainerBox.cpp 2021-10-06 15:25:17 UTC (rev 283620)
@@ -41,6 +41,11 @@
{
}
+ContainerBox::~ContainerBox()
+{
+ destroyChildren();
+}
+
const Box* ContainerBox::firstInFlowChild() const
{
if (auto* firstChild = this->firstChild()) {
@@ -81,27 +86,41 @@
return nullptr;
}
-void ContainerBox::setFirstChild(Box& childBox)
+void ContainerBox::appendChild(UniqueRef<Box> childRef)
{
- m_firstChild = &childBox;
-}
+ auto childBox = childRef.moveToUniquePtr();
-void ContainerBox::setLastChild(Box& childBox)
-{
- m_lastChild = &childBox;
+ childBox->setParent(this);
+
+ if (m_lastChild) {
+ m_lastChild->setNextSibling(childBox.get());
+ childBox->setPreviousSibling(m_lastChild.get());
+ } else
+ m_firstChild = childBox.get();
+
+ // Ownership has been transferred.
+ m_lastChild = childBox.release();
}
-void ContainerBox::appendChild(Box& childBox)
+void ContainerBox::destroyChildren()
{
- childBox.setParent(*this);
+ std::unique_ptr<Box> childToDestroy { m_firstChild.get() };
+
+ m_firstChild = nullptr;
+ m_lastChild = nullptr;
- if (m_lastChild) {
- m_lastChild->setNextSibling(childBox);
- childBox.setPreviousSibling(*m_lastChild);
- } else
- m_firstChild = &childBox;
+ while (childToDestroy) {
+ childToDestroy->setParent(nullptr);
- m_lastChild = &childBox;
+ std::unique_ptr<Box> nextSibling { childToDestroy->nextSibling() };
+
+ if (nextSibling) {
+ childToDestroy->setNextSibling(nullptr);
+ nextSibling->setPreviousSibling(nullptr);
+ }
+
+ childToDestroy = WTFMove(nextSibling);
+ }
}
}
Modified: trunk/Source/WebCore/layout/layouttree/LayoutContainerBox.h (283619 => 283620)
--- trunk/Source/WebCore/layout/layouttree/LayoutContainerBox.h 2021-10-06 15:23:05 UTC (rev 283619)
+++ trunk/Source/WebCore/layout/layouttree/LayoutContainerBox.h 2021-10-06 15:25:17 UTC (rev 283620)
@@ -29,6 +29,7 @@
#include "LayoutBox.h"
#include <wtf/IsoMalloc.h>
+#include <wtf/UniqueRef.h>
namespace WebCore {
@@ -40,28 +41,28 @@
WTF_MAKE_ISO_ALLOCATED(ContainerBox);
public:
ContainerBox(std::optional<ElementAttributes>, RenderStyle&&, std::unique_ptr<RenderStyle>&& firstLineStyle = nullptr, OptionSet<BaseTypeFlag> = { ContainerBoxFlag });
+ ~ContainerBox();
- const Box* firstChild() const { return m_firstChild; }
+ const Box* firstChild() const { return m_firstChild.get(); }
const Box* firstInFlowChild() const;
const Box* firstInFlowOrFloatingChild() const;
- const Box* lastChild() const { return m_lastChild; }
+ const Box* lastChild() const { return m_lastChild.get(); }
const Box* lastInFlowChild() const;
const Box* lastInFlowOrFloatingChild() const;
// FIXME: This is currently needed for style updates.
- Box* firstChild() { return m_firstChild; }
+ Box* firstChild() { return m_firstChild.get(); }
bool hasChild() const { return firstChild(); }
bool hasInFlowChild() const { return firstInFlowChild(); }
bool hasInFlowOrFloatingChild() const { return firstInFlowOrFloatingChild(); }
- void setFirstChild(Box&);
- void setLastChild(Box&);
- void appendChild(Box&);
+ void appendChild(UniqueRef<Box>);
+ void destroyChildren();
private:
- Box* m_firstChild { nullptr };
- Box* m_lastChild { nullptr };
+ CheckedPtr<Box> m_firstChild;
+ CheckedPtr<Box> m_lastChild;
};
}
Modified: trunk/Source/WebCore/layout/layouttree/LayoutTreeBuilder.cpp (283619 => 283620)
--- trunk/Source/WebCore/layout/layouttree/LayoutTreeBuilder.cpp 2021-10-06 15:23:05 UTC (rev 283619)
+++ trunk/Source/WebCore/layout/layouttree/LayoutTreeBuilder.cpp 2021-10-06 15:25:17 UTC (rev 283620)
@@ -67,24 +67,17 @@
namespace Layout {
WTF_MAKE_ISO_ALLOCATED_IMPL(LayoutTree);
-LayoutTree::LayoutTree()
+LayoutTree::LayoutTree(std::unique_ptr<ContainerBox> root)
+ : m_root(WTFMove(root))
{
}
-static void appendChild(ContainerBox& parent, Box& newChild)
+template<class BoxType>
+static BoxType& appendChild(ContainerBox& parent, std::unique_ptr<BoxType> newChild)
{
- if (!parent.hasChild()) {
- parent.setFirstChild(newChild);
- parent.setLastChild(newChild);
- newChild.setParent(parent);
- return;
- }
-
- auto& lastChild = const_cast<Box&>(*parent.lastChild());
- lastChild.setNextSibling(newChild);
- newChild.setPreviousSibling(lastChild);
- newChild.setParent(parent);
- parent.setLastChild(newChild);
+ auto& box = *newChild;
+ parent.appendChild(makeUniqueRefFromNonNullUniquePtr(WTFMove(newChild)));
+ return box;
}
static std::optional<LayoutSize> accumulatedOffsetForInFlowPositionedContinuation(const RenderBox& block)
@@ -124,51 +117,36 @@
rootStyle.setLogicalHeight(Length(renderView.height(), LengthType::Fixed));
auto rootLayoutBox = makeUnique<InitialContainingBlock>(WTFMove(rootStyle));
- auto& rootContainer = *rootLayoutBox;
- auto layoutTree = makeUnique<LayoutTree>();
- layoutTree->append(WTFMove(rootLayoutBox));
- TreeBuilder(*layoutTree).buildSubTree(renderView, rootContainer);
- return layoutTree;
+ TreeBuilder().buildSubTree(renderView, *rootLayoutBox);
+
+ return makeUnique<LayoutTree>(WTFMove(rootLayoutBox));
}
-TreeBuilder::TreeBuilder(LayoutTree& layoutTree)
- : m_layoutTree(layoutTree)
+TreeBuilder::TreeBuilder()
{
}
-Box& TreeBuilder::createReplacedBox(std::optional<Box::ElementAttributes> elementAttributes, RenderStyle&& style)
+std::unique_ptr<Box> TreeBuilder::createReplacedBox(std::optional<Box::ElementAttributes> elementAttributes, RenderStyle&& style)
{
- auto newBox = makeUnique<ReplacedBox>(elementAttributes, WTFMove(style));
- auto& box = *newBox;
- m_layoutTree.append(WTFMove(newBox));
- return box;
+ return makeUnique<ReplacedBox>(elementAttributes, WTFMove(style));
}
-Box& TreeBuilder::createTextBox(String text, bool canUseSimplifiedTextMeasuring, RenderStyle&& style)
+std::unique_ptr<Box> TreeBuilder::createTextBox(String text, bool canUseSimplifiedTextMeasuring, RenderStyle&& style)
{
- auto newBox = makeUnique<InlineTextBox>(text, canUseSimplifiedTextMeasuring, WTFMove(style));
- auto& box = *newBox;
- m_layoutTree.append(WTFMove(newBox));
- return box;
+ return makeUnique<InlineTextBox>(text, canUseSimplifiedTextMeasuring, WTFMove(style));
}
-Box& TreeBuilder::createLineBreakBox(bool isOptional, RenderStyle&& style)
+std::unique_ptr<Box> TreeBuilder::createLineBreakBox(bool isOptional, RenderStyle&& style)
{
- auto newBox = makeUnique<Layout::LineBreakBox>(isOptional, WTFMove(style));
- auto& box = *newBox;
- m_layoutTree.append(WTFMove(newBox));
- return box;
+ return makeUnique<Layout::LineBreakBox>(isOptional, WTFMove(style));
}
-ContainerBox& TreeBuilder::createContainer(std::optional<Box::ElementAttributes> elementAttributes, RenderStyle&& style)
+std::unique_ptr<ContainerBox> TreeBuilder::createContainer(std::optional<Box::ElementAttributes> elementAttributes, RenderStyle&& style)
{
- auto newContainer = makeUnique<ContainerBox>(elementAttributes, WTFMove(style));
- auto& container = *newContainer;
- m_layoutTree.append(WTFMove(newContainer));
- return container;
+ return makeUnique<ContainerBox>(elementAttributes, WTFMove(style));
}
-Box* TreeBuilder::createLayoutBox(const ContainerBox& parentContainer, const RenderObject& childRenderer)
+std::unique_ptr<Box> TreeBuilder::createLayoutBox(const ContainerBox& parentContainer, const RenderObject& childRenderer)
{
auto elementAttributes = [] (const RenderElement& renderer) -> std::optional<Box::ElementAttributes> {
if (renderer.isDocumentElementRenderer())
@@ -185,7 +163,7 @@
return std::nullopt;
};
- Box* childLayoutBox = nullptr;
+ std::unique_ptr<Box> childLayoutBox = nullptr;
if (is<RenderText>(childRenderer)) {
auto& textRenderer = downcast<RenderText>(childRenderer);
// RenderText::text() has already applied text-transform and text-security properties.
@@ -192,9 +170,9 @@
String text = textRenderer.text();
auto useSimplifiedTextMeasuring = canUseSimplifiedTextMeasuring(text, parentContainer.style().fontCascade(), parentContainer.style().collapseWhiteSpace());
if (parentContainer.style().display() == DisplayType::Inline)
- childLayoutBox = &createTextBox(text, useSimplifiedTextMeasuring, RenderStyle::clone(parentContainer.style()));
+ childLayoutBox = createTextBox(text, useSimplifiedTextMeasuring, RenderStyle::clone(parentContainer.style()));
else
- childLayoutBox = &createTextBox(text, useSimplifiedTextMeasuring, RenderStyle::createAnonymousStyleWithDisplay(parentContainer.style(), DisplayType::Inline));
+ childLayoutBox = createTextBox(text, useSimplifiedTextMeasuring, RenderStyle::createAnonymousStyleWithDisplay(parentContainer.style(), DisplayType::Inline));
} else {
auto& renderer = downcast<RenderElement>(childRenderer);
auto displayType = renderer.style().display();
@@ -205,7 +183,7 @@
clonedStyle.setDisplay(DisplayType::Inline);
clonedStyle.setFloating(Float::None);
clonedStyle.setPosition(PositionType::Static);
- childLayoutBox = &createLineBreakBox(downcast<RenderLineBreak>(childRenderer).isWBR(), WTFMove(clonedStyle));
+ childLayoutBox = createLineBreakBox(downcast<RenderLineBreak>(childRenderer).isWBR(), WTFMove(clonedStyle));
} else if (is<RenderTable>(renderer)) {
// Construct the principal table wrapper box (and not the table box itself).
// The computed values of properties 'position', 'float', 'margin-*', 'top', 'right', 'bottom', and 'left' on the table element
@@ -225,10 +203,10 @@
tableWrapperBoxStyle.setMarginBottom(Length { renderer.style().marginBottom() });
tableWrapperBoxStyle.setMarginRight(Length { renderer.style().marginRight() });
- childLayoutBox = &createContainer(Box::ElementAttributes { Box::ElementType::TableWrapperBox }, WTFMove(tableWrapperBoxStyle));
+ childLayoutBox = createContainer(Box::ElementAttributes { Box::ElementType::TableWrapperBox }, WTFMove(tableWrapperBoxStyle));
childLayoutBox->setIsAnonymous();
} else if (is<RenderReplaced>(renderer)) {
- childLayoutBox = &createReplacedBox(elementAttributes(renderer), WTFMove(clonedStyle));
+ childLayoutBox = createReplacedBox(elementAttributes(renderer), WTFMove(clonedStyle));
// FIXME: We don't yet support all replaced elements and this is temporary anyway.
downcast<ReplacedBox>(*childLayoutBox).setIntrinsicSize(downcast<RenderReplaced>(renderer).intrinsicSize());
if (is<RenderImage>(renderer)) {
@@ -243,22 +221,22 @@
if (auto offset = accumulatedOffsetForInFlowPositionedContinuation(downcast<RenderBox>(renderer))) {
clonedStyle.setTop({ offset->height(), LengthType::Fixed });
clonedStyle.setLeft({ offset->width(), LengthType::Fixed });
- childLayoutBox = &createContainer(elementAttributes(renderer), WTFMove(clonedStyle));
+ childLayoutBox = createContainer(elementAttributes(renderer), WTFMove(clonedStyle));
} else
- childLayoutBox = &createContainer(elementAttributes(renderer), WTFMove(clonedStyle));
+ childLayoutBox = createContainer(elementAttributes(renderer), WTFMove(clonedStyle));
} else if (displayType == DisplayType::Flex)
- childLayoutBox = &createContainer(elementAttributes(renderer), WTFMove(clonedStyle));
+ childLayoutBox = createContainer(elementAttributes(renderer), WTFMove(clonedStyle));
else if (displayType == DisplayType::Inline)
- childLayoutBox = &createContainer(elementAttributes(renderer), WTFMove(clonedStyle));
+ childLayoutBox = createContainer(elementAttributes(renderer), WTFMove(clonedStyle));
else if (displayType == DisplayType::InlineBlock)
- childLayoutBox = &createContainer(elementAttributes(renderer), WTFMove(clonedStyle));
+ childLayoutBox = createContainer(elementAttributes(renderer), WTFMove(clonedStyle));
else if (displayType == DisplayType::TableCaption || displayType == DisplayType::TableCell) {
- childLayoutBox = &createContainer(elementAttributes(renderer), WTFMove(clonedStyle));
+ childLayoutBox = createContainer(elementAttributes(renderer), WTFMove(clonedStyle));
} else if (displayType == DisplayType::TableRowGroup || displayType == DisplayType::TableHeaderGroup || displayType == DisplayType::TableFooterGroup
|| displayType == DisplayType::TableRow || displayType == DisplayType::TableColumnGroup) {
- childLayoutBox = &createContainer(elementAttributes(renderer), WTFMove(clonedStyle));
+ childLayoutBox = createContainer(elementAttributes(renderer), WTFMove(clonedStyle));
} else if (displayType == DisplayType::TableColumn) {
- childLayoutBox = &createContainer(elementAttributes(renderer), WTFMove(clonedStyle));
+ childLayoutBox = createContainer(elementAttributes(renderer), WTFMove(clonedStyle));
auto& tableColElement = static_cast<HTMLTableColElement&>(*renderer.element());
auto columnWidth = tableColElement.width();
if (!columnWidth.isEmpty())
@@ -269,7 +247,7 @@
ASSERT_NOT_IMPLEMENTED_YET();
// Let's fall back to a regular block level container when the renderer type is not yet supported.
clonedStyle.setDisplay(DisplayType::Block);
- childLayoutBox = &createContainer(elementAttributes(renderer), WTFMove(clonedStyle));
+ childLayoutBox = createContainer(elementAttributes(renderer), WTFMove(clonedStyle));
}
}
@@ -298,9 +276,9 @@
auto* tableChild = tableRenderer.firstChild();
while (is<RenderTableCaption>(tableChild)) {
auto& captionRenderer = *tableChild;
- auto* captionBox = createLayoutBox(tableWrapperBox, captionRenderer);
- appendChild(tableWrapperBox, *captionBox);
- auto& captionContainer = downcast<ContainerBox>(*captionBox);
+ auto newCaptionBox = createLayoutBox(tableWrapperBox, captionRenderer);
+ auto& captionBox = appendChild(tableWrapperBox, WTFMove(newCaptionBox));
+ auto& captionContainer = downcast<ContainerBox>(captionBox);
buildSubTree(downcast<RenderElement>(captionRenderer), captionContainer);
tableChild = tableChild->nextSibling();
}
@@ -312,13 +290,12 @@
// FIXME: Figure out where the spec says table width is like box-sizing: border-box;
if (is<HTMLTableElement>(tableRenderer.element()))
tableBoxStyle.setBoxSizing(BoxSizing::BorderBox);
- auto& tableBox = createContainer(Box::ElementAttributes { Box::ElementType::TableBox }, WTFMove(tableBoxStyle));
- appendChild(tableWrapperBox, tableBox);
+ auto newTableBox = createContainer(Box::ElementAttributes { Box::ElementType::TableBox }, WTFMove(tableBoxStyle));
+ auto& tableBox = appendChild(tableWrapperBox, WTFMove(newTableBox));
auto* sectionRenderer = tableChild;
while (sectionRenderer) {
- auto* sectionBox = createLayoutBox(tableBox, *sectionRenderer);
- appendChild(tableBox, *sectionBox);
- auto& sectionContainer = downcast<ContainerBox>(*sectionBox);
+ auto& sectionBox = appendChild(tableBox, createLayoutBox(tableBox, *sectionRenderer));
+ auto& sectionContainer = downcast<ContainerBox>(sectionBox);
buildSubTree(downcast<RenderElement>(*sectionRenderer), sectionContainer);
sectionRenderer = sectionRenderer->nextSibling();
}
@@ -371,12 +348,11 @@
void TreeBuilder::buildSubTree(const RenderElement& parentRenderer, ContainerBox& parentContainer)
{
for (auto& childRenderer : childrenOfType<RenderObject>(parentRenderer)) {
- auto* childLayoutBox = createLayoutBox(parentContainer, childRenderer);
- appendChild(parentContainer, *childLayoutBox);
- if (childLayoutBox->isTableWrapperBox())
- buildTableStructure(downcast<RenderTable>(childRenderer), downcast<ContainerBox>(*childLayoutBox));
- else if (is<ContainerBox>(*childLayoutBox))
- buildSubTree(downcast<RenderElement>(childRenderer), downcast<ContainerBox>(*childLayoutBox));
+ auto& childLayoutBox = appendChild(parentContainer, createLayoutBox(parentContainer, childRenderer));
+ if (childLayoutBox.isTableWrapperBox())
+ buildTableStructure(downcast<RenderTable>(childRenderer), downcast<ContainerBox>(childLayoutBox));
+ else if (is<ContainerBox>(childLayoutBox))
+ buildSubTree(downcast<RenderElement>(childRenderer), downcast<ContainerBox>(childLayoutBox));
}
}
Modified: trunk/Source/WebCore/layout/layouttree/LayoutTreeBuilder.h (283619 => 283620)
--- trunk/Source/WebCore/layout/layouttree/LayoutTreeBuilder.h 2021-10-06 15:23:05 UTC (rev 283619)
+++ trunk/Source/WebCore/layout/layouttree/LayoutTreeBuilder.h 2021-10-06 15:25:17 UTC (rev 283620)
@@ -46,14 +46,13 @@
class LayoutTree {
WTF_MAKE_ISO_ALLOCATED(LayoutTree);
public:
- LayoutTree();
+ LayoutTree(std::unique_ptr<ContainerBox>);
~LayoutTree() = default;
- const ContainerBox& root() const { return downcast<ContainerBox>(*m_layoutBoxes[0]); }
- void append(std::unique_ptr<Box> box) { m_layoutBoxes.append(WTFMove(box)); }
+ const ContainerBox& root() const { return *m_root; }
private:
- Vector<std::unique_ptr<Box>> m_layoutBoxes;
+ std::unique_ptr<ContainerBox> m_root;
};
class TreeBuilder {
@@ -61,18 +60,16 @@
static std::unique_ptr<Layout::LayoutTree> buildLayoutTree(const RenderView&);
private:
- TreeBuilder(LayoutTree&);
+ TreeBuilder();
void buildSubTree(const RenderElement& parentRenderer, ContainerBox& parentContainer);
void buildTableStructure(const RenderTable& tableRenderer, ContainerBox& tableWrapperBox);
- Box* createLayoutBox(const ContainerBox& parentContainer, const RenderObject& childRenderer);
+ std::unique_ptr<Box> createLayoutBox(const ContainerBox& parentContainer, const RenderObject& childRenderer);
- Box& createReplacedBox(std::optional<Box::ElementAttributes>, RenderStyle&&);
- Box& createTextBox(String text, bool canUseSimplifiedTextMeasuring, RenderStyle&&);
- Box& createLineBreakBox(bool isOptional, RenderStyle&&);
- ContainerBox& createContainer(std::optional<Box::ElementAttributes>, RenderStyle&&);
-
- LayoutTree& m_layoutTree;
+ std::unique_ptr<Box> createReplacedBox(std::optional<Box::ElementAttributes>, RenderStyle&&);
+ std::unique_ptr<Box> createTextBox(String text, bool canUseSimplifiedTextMeasuring, RenderStyle&&);
+ std::unique_ptr<Box> createLineBreakBox(bool isOptional, RenderStyle&&);
+ std::unique_ptr<ContainerBox> createContainer(std::optional<Box::ElementAttributes>, RenderStyle&&);
};
#if ENABLE(TREE_DEBUGGING)
_______________________________________________ webkit-changes mailing list [email protected] https://lists.webkit.org/mailman/listinfo/webkit-changes
