[LFC] Introduce InitialContainingBox class
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 22 Mar 2020 17:41:12 +0000 (17:41 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 22 Mar 2020 17:41:12 +0000 (17:41 +0000)
https://bugs.webkit.org/show_bug.cgi?id=209399
<rdar://problem/60741767>

Reviewed by Antti Koivisto.

ICB is the top level containing block. This helps to make sure we don't accidentally call parent() on the ICB.
This is also a preparation for "const Box& Layout::Box::parent()".

* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* layout/integration/LayoutIntegrationBoxTree.cpp:
(WebCore::LayoutIntegration::BoxTree::BoxTree):
(): Deleted.
* layout/integration/LayoutIntegrationBoxTree.h:
(WebCore::LayoutIntegration::BoxTree::rootLayoutBox const):
(WebCore::LayoutIntegration::BoxTree::rootLayoutBox):
* layout/layouttree/LayoutBox.cpp:
(WebCore::Layout::Box::isInitialContainingBlock const): Deleted.
* layout/layouttree/LayoutBox.h:
(WebCore::Layout::Box::isInitialContainingBlock const):
* layout/layouttree/LayoutContainerBox.h:
* layout/layouttree/LayoutTreeBuilder.cpp:
(WebCore::Layout::TreeBuilder::buildLayoutTree):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@258820 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/Sources.txt
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/layout/integration/LayoutIntegrationBoxTree.cpp
Source/WebCore/layout/integration/LayoutIntegrationBoxTree.h
Source/WebCore/layout/layouttree/LayoutBox.cpp
Source/WebCore/layout/layouttree/LayoutBox.h
Source/WebCore/layout/layouttree/LayoutContainerBox.h
Source/WebCore/layout/layouttree/LayoutInitialContainingBlock.cpp [new file with mode: 0644]
Source/WebCore/layout/layouttree/LayoutInitialContainingBlock.h [new file with mode: 0644]
Source/WebCore/layout/layouttree/LayoutTreeBuilder.cpp

index b4e18df..65f25ec 100644 (file)
@@ -1,5 +1,32 @@
 2020-03-22  Zalan Bujtas  <zalan@apple.com>
 
+        [LFC] Introduce InitialContainingBox class
+        https://bugs.webkit.org/show_bug.cgi?id=209399
+        <rdar://problem/60741767>
+
+        Reviewed by Antti Koivisto.
+
+        ICB is the top level containing block. This helps to make sure we don't accidentally call parent() on the ICB.
+        This is also a preparation for "const Box& Layout::Box::parent()".
+
+        * Sources.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * layout/integration/LayoutIntegrationBoxTree.cpp:
+        (WebCore::LayoutIntegration::BoxTree::BoxTree):
+        (): Deleted.
+        * layout/integration/LayoutIntegrationBoxTree.h:
+        (WebCore::LayoutIntegration::BoxTree::rootLayoutBox const):
+        (WebCore::LayoutIntegration::BoxTree::rootLayoutBox):
+        * layout/layouttree/LayoutBox.cpp:
+        (WebCore::Layout::Box::isInitialContainingBlock const): Deleted.
+        * layout/layouttree/LayoutBox.h:
+        (WebCore::Layout::Box::isInitialContainingBlock const):
+        * layout/layouttree/LayoutContainerBox.h:
+        * layout/layouttree/LayoutTreeBuilder.cpp:
+        (WebCore::Layout::TreeBuilder::buildLayoutTree):
+
+2020-03-22  Zalan Bujtas  <zalan@apple.com>
+
         [LFC] Layout::Box::containingBlock should return a const ContainerBox&
         https://bugs.webkit.org/show_bug.cgi?id=209381
         <rdar://problem/60732278>
index cfcefb9..cf5556a 100644 (file)
@@ -1481,6 +1481,7 @@ layout/invalidation/InvalidationContext.cpp
 layout/invalidation/InvalidationState.cpp
 layout/layouttree/LayoutBox.cpp
 layout/layouttree/LayoutContainerBox.cpp
+layout/layouttree/LayoutInitialContainingBlock.cpp
 layout/layouttree/LayoutInlineTextBox.cpp
 layout/layouttree/LayoutLineBreakBox.cpp
 layout/layouttree/LayoutReplacedBox.cpp
index 753f7e4..4894de5 100644 (file)
                6F26EB48234004A5006906E2 /* LineLayoutContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 6F26EB46234004A5006906E2 /* LineLayoutContext.h */; };
                6F360E5023999421001512A7 /* InlineSoftLineBreakItem.h in Headers */ = {isa = PBXBuildFile; fileRef = 6F360E4E23999420001512A7 /* InlineSoftLineBreakItem.h */; settings = {ATTRIBUTES = (Private, ); }; };
                6F3E1F622136142000A65A08 /* FloatBox.h in Headers */ = {isa = PBXBuildFile; fileRef = 6F3E1F612136141700A65A08 /* FloatBox.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               6F6383F62427AF4A00DABA53 /* LayoutInitialContainingBlock.h in Headers */ = {isa = PBXBuildFile; fileRef = 6F6383F42427AF4900DABA53 /* LayoutInitialContainingBlock.h */; settings = {ATTRIBUTES = (Private, ); }; };
                6F77868823491AD8004D9636 /* DisplayPainter.h in Headers */ = {isa = PBXBuildFile; fileRef = 6F77868723491AD7004D9636 /* DisplayPainter.h */; settings = {ATTRIBUTES = (Private, ); }; };
                6F7CA3C6208C2957002F29AB /* LayoutState.h in Headers */ = {isa = PBXBuildFile; fileRef = 6F7CA3C4208C2956002F29AB /* LayoutState.h */; settings = {ATTRIBUTES = (Private, ); }; };
                6F7CA3CA208C2B2E002F29AB /* InlineFormattingContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 6F7CA3C8208C2B2E002F29AB /* InlineFormattingContext.h */; settings = {ATTRIBUTES = (Private, ); }; };
                6F3E1F612136141700A65A08 /* FloatBox.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FloatBox.h; sourceTree = "<group>"; };
                6F4A5BD522F9F16B00A80F25 /* LayoutPhase.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = LayoutPhase.cpp; sourceTree = "<group>"; };
                6F5B7EAA2300A79E0067D9C3 /* TableGrid.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = TableGrid.cpp; sourceTree = "<group>"; };
+               6F6383F42427AF4900DABA53 /* LayoutInitialContainingBlock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LayoutInitialContainingBlock.h; sourceTree = "<group>"; };
                6F73918C2106CEDD006AF262 /* LayoutUnits.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LayoutUnits.h; sourceTree = "<group>"; };
                6F77868523491AC6004D9636 /* DisplayPainter.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = DisplayPainter.cpp; sourceTree = "<group>"; };
                6F77868723491AD7004D9636 /* DisplayPainter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DisplayPainter.h; sourceTree = "<group>"; };
                6F995A2F1A70833700A735F4 /* JSWebGLVertexArrayObject.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSWebGLVertexArrayObject.cpp; sourceTree = "<group>"; };
                6F995A301A70833700A735F4 /* JSWebGLVertexArrayObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSWebGLVertexArrayObject.h; sourceTree = "<group>"; };
                6FAE16BA2406DE7E00A48414 /* PrecomputedBlockMarginCollapse.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = PrecomputedBlockMarginCollapse.cpp; sourceTree = "<group>"; };
+               6FB0ED112427B6C6002737E6 /* LayoutInitialContainingBlock.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = LayoutInitialContainingBlock.cpp; sourceTree = "<group>"; };
                6FB11B5921783FCF00E2A574 /* TextUtil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextUtil.h; sourceTree = "<group>"; };
                6FB11B5B21783FCF00E2A574 /* TextUtil.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TextUtil.cpp; sourceTree = "<group>"; };
                6FB22E30230097E300C20866 /* TableGrid.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TableGrid.h; sourceTree = "<group>"; };
                                1199FA45208E35A3002358CC /* LayoutContainerBox.cpp */,
                                1199FA44208E35A3002358CC /* LayoutContainerBox.h */,
                                11B042FB20B0E21400828A6B /* LayoutDescendantIterator.h */,
+                               6FB0ED112427B6C6002737E6 /* LayoutInitialContainingBlock.cpp */,
+                               6F6383F42427AF4900DABA53 /* LayoutInitialContainingBlock.h */,
                                6F0B98B623F2690600EEC2F2 /* LayoutInlineTextBox.cpp */,
                                6F0B98B323F268EB00EEC2F2 /* LayoutInlineTextBox.h */,
                                11100FC72092764C0081AA6C /* LayoutIterator.h */,
                                1199FA46208E35A3002358CC /* LayoutContainerBox.h in Headers */,
                                6F26BB6C23343E6F002F2BEA /* LayoutContext.h in Headers */,
                                11310CF520BA4A4C0065A8D0 /* LayoutDescendantIterator.h in Headers */,
+                               6F6383F62427AF4A00DABA53 /* LayoutInitialContainingBlock.h in Headers */,
                                6F0B98B523F268EC00EEC2F2 /* LayoutInlineTextBox.h in Headers */,
                                E418025523D4549B00FFB071 /* LayoutIntegrationBoxTree.h in Headers */,
                                E4ABABDD236088FE00FA4345 /* LayoutIntegrationLineLayout.h in Headers */,
index 294b78b..b0b56b0 100644 (file)
@@ -47,7 +47,7 @@ static RenderStyle rootBoxStyle(const RenderStyle& style)
 }
 
 BoxTree::BoxTree(const RenderBlockFlow& flow)
-    : m_root({ }, rootBoxStyle(flow.style()))
+    : m_root(rootBoxStyle(flow.style()))
 {
     if (flow.isAnonymous())
         m_root.setIsAnonymous();
index 88168da..822294b 100644 (file)
@@ -27,7 +27,7 @@
 
 #if ENABLE(LAYOUT_FORMATTING_CONTEXT)
 
-#include "LayoutContainerBox.h"
+#include "LayoutInitialContainingBlock.h"
 #include <wtf/HashMap.h>
 #include <wtf/Vector.h>
 
@@ -41,8 +41,8 @@ class BoxTree {
 public:
     BoxTree(const RenderBlockFlow&);
 
-    const Layout::ContainerBox& rootLayoutBox() const { return m_root; }
-    Layout::ContainerBox& rootLayoutBox() { return m_root; }
+    const Layout::InitialContainingBlock& rootLayoutBox() const { return m_root; }
+    Layout::InitialContainingBlock& rootLayoutBox() { return m_root; }
 
     const Layout::Box* layoutBoxForRenderer(const RenderObject&) const;
     const RenderObject* rendererForLayoutBox(const Layout::Box&) const;
@@ -50,7 +50,7 @@ public:
 private:
     void buildTree(const RenderBlockFlow&);
 
-    Layout::ContainerBox m_root;
+    Layout::InitialContainingBlock m_root;
     struct BoxAndRenderer {
         std::unique_ptr<const Layout::Box> box;
         const RenderObject* renderer { nullptr };
index 118cc53..2e66ac3 100644 (file)
@@ -311,11 +311,6 @@ bool Box::isBlockContainerBox() const
     return display == DisplayType::Block || display == DisplayType::ListItem || isInlineBlockBox() || isTableWrapperBox() || isTableCell() || isTableCaption(); // TODO && !replaced element
 }
 
-bool Box::isInitialContainingBlock() const
-{
-    return !parent();
-}
-
 const Box* Box::nextInFlowSibling() const
 {
     auto* nextSibling = this->nextSibling();
index fe348ea..fd8799f 100644 (file)
@@ -65,7 +65,8 @@ public:
         InlineTextBox          = 1 << 1,
         LineBreakBox           = 1 << 2,
         ReplacedBox            = 1 << 3,
-        ContainerBoxFlag       = 1 << 4
+        InitialContainingBlock = 1 << 4,
+        ContainerBoxFlag       = 1 << 5
     };
     typedef unsigned BaseTypeFlags;
 
@@ -108,7 +109,7 @@ public:
     bool isInlineBlockBox() const;
     bool isInlineTableBox() const;
     bool isBlockContainerBox() const;
-    bool isInitialContainingBlock() const;
+    bool isInitialContainingBlock() const { return m_baseTypeFlags & InitialContainingBlock; }
 
     bool isDocumentBox() const { return m_elementAttributes && m_elementAttributes.value().elementType == ElementType::Document; }
     bool isBodyBox() const { return m_elementAttributes && m_elementAttributes.value().elementType == ElementType::Body; }
index 0083095..13f10d0 100644 (file)
@@ -36,7 +36,7 @@ class RenderStyle;
 
 namespace Layout {
 
-class ContainerBox final : public Box {
+class ContainerBox : public Box {
     WTF_MAKE_ISO_ALLOCATED(ContainerBox);
 public:
     ContainerBox(Optional<ElementAttributes>, RenderStyle&&, BaseTypeFlags = Box::ContainerBoxFlag);
diff --git a/Source/WebCore/layout/layouttree/LayoutInitialContainingBlock.cpp b/Source/WebCore/layout/layouttree/LayoutInitialContainingBlock.cpp
new file mode 100644 (file)
index 0000000..c0349bc
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2020 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "LayoutInitialContainingBlock.h"
+
+#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
+
+#include "RenderStyle.h"
+#include <wtf/IsoMallocInlines.h>
+
+namespace WebCore {
+namespace Layout {
+
+WTF_MAKE_ISO_ALLOCATED_IMPL(InitialContainingBlock);
+
+InitialContainingBlock::InitialContainingBlock(RenderStyle&& style)
+    : ContainerBox({ }, WTFMove(style), Box::InitialContainingBlock)
+{
+}
+
+}
+}
+
+#endif
diff --git a/Source/WebCore/layout/layouttree/LayoutInitialContainingBlock.h b/Source/WebCore/layout/layouttree/LayoutInitialContainingBlock.h
new file mode 100644 (file)
index 0000000..a99ec95
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2018-2020 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
+
+#include "LayoutContainerBox.h"
+#include <wtf/IsoMalloc.h>
+
+namespace WebCore {
+namespace Layout {
+
+class InitialContainingBlock final : public ContainerBox {
+    WTF_MAKE_ISO_ALLOCATED(InitialContainingBlock);
+public:
+    InitialContainingBlock(RenderStyle&&);
+    virtual ~InitialContainingBlock() = default;
+
+private:
+    const ContainerBox* parent() const = delete;
+    const Box* nextSibling() const = delete;
+    const Box* nextInFlowSibling() const = delete;
+    const Box* nextInFlowOrFloatingSibling() const = delete;
+    const Box* previousSibling() const = delete;
+    const Box* previousInFlowSibling() const = delete;
+    const Box* previousInFlowOrFloatingSibling() const = delete;
+    Box* nextSibling() = delete;
+};
+
+}
+}
+
+SPECIALIZE_TYPE_TRAITS_LAYOUT_BOX(InitialContainingBlock, isInitialContainingBlock())
+
+#endif
index deadc17..5245bc4 100644 (file)
@@ -42,6 +42,7 @@
 #include "LayoutContainerBox.h"
 #include "LayoutContext.h"
 #include "LayoutDescendantIterator.h"
+#include "LayoutInitialContainingBlock.h"
 #include "LayoutInlineTextBox.h"
 #include "LayoutLineBreakBox.h"
 #include "LayoutPhase.h"
@@ -130,7 +131,7 @@ std::unique_ptr<Layout::LayoutTreeContent> TreeBuilder::buildLayoutTree(const Re
     style.setLogicalWidth(Length(renderView.width(), Fixed));
     style.setLogicalHeight(Length(renderView.height(), Fixed));
 
-    auto layoutTreeContent = makeUnique<LayoutTreeContent>(renderView, makeUnique<ContainerBox>(WTF::nullopt, WTFMove(style)));
+    auto layoutTreeContent = makeUnique<LayoutTreeContent>(renderView, makeUnique<InitialContainingBlock>(WTFMove(style)));
     TreeBuilder(*layoutTreeContent).buildTree();
     return layoutTreeContent;
 }