[LFC] Remove formatting context type container classes.
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 3 Aug 2019 14:01:20 +0000 (14:01 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 3 Aug 2019 14:01:20 +0000 (14:01 +0000)
https://bugs.webkit.org/show_bug.cgi?id=200202

Reviewed by Antti Koivisto.

These are formatting context specific classes. Let's try to have a layout tree without such types.

* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* layout/blockformatting/BlockFormattingContext.cpp:
(WebCore::Layout::BlockFormattingContext::computeIntrinsicWidthConstraints const):
* layout/inlineformatting/InlineFormattingContext.cpp:
(WebCore::Layout::InlineFormattingContext::layout const):
(WebCore::Layout::InlineFormattingContext::computeMarginBorderAndPaddingForInlineContainer const):
* layout/inlineformatting/InlineFormattingContext.h:
* layout/inlineformatting/InlineFormattingContextLineLayout.cpp:
(WebCore::Layout::InlineFormattingContext::InlineLayout::layout const):
* layout/inlineformatting/InlineLine.cpp:
(WebCore::Layout::Line::appendTextContent):
* layout/layouttree/LayoutBlockContainer.cpp: Removed.
* layout/layouttree/LayoutBlockContainer.h: Removed.
* layout/layouttree/LayoutBox.cpp:
(WebCore::Layout::Box::establishesInlineFormattingContext const):
(WebCore::Layout::Box::establishesInlineFormattingContextOnly const):
(WebCore::Layout::Box::formattingContextRoot const):
* layout/layouttree/LayoutBox.h:
(WebCore::Layout::Box::isBlockContainer const):
(WebCore::Layout::Box::isInlineContainer const):
(WebCore::Layout::Box::isInlineBox const):
(WebCore::Layout::Box::establishesInlineFormattingContext const): Deleted.
(WebCore::Layout::Box::establishesInlineFormattingContextOnly const): Deleted.
* layout/layouttree/LayoutInlineContainer.cpp: Removed.
* layout/layouttree/LayoutInlineContainer.h: Removed.
* layout/layouttree/LayoutIterator.h:
(WebCore::Layout::LayoutBoxTraversal::firstChild):
* layout/layouttree/LayoutTreeBuilder.cpp:
(WebCore::Layout::TreeBuilder::createLayoutTree):
(WebCore::Layout::TreeBuilder::createLayoutBox):
(WebCore::Layout::TreeBuilder::createTableStructure):
(WebCore::Layout::outputLayoutBox):
* layout/layouttree/LayoutTreeBuilder.h:
* page/FrameViewLayoutContext.cpp:
(WebCore::layoutUsingFormattingContext):

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

17 files changed:
Source/WebCore/ChangeLog
Source/WebCore/Sources.txt
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp
Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp
Source/WebCore/layout/inlineformatting/InlineFormattingContext.h
Source/WebCore/layout/inlineformatting/InlineFormattingContextLineLayout.cpp
Source/WebCore/layout/inlineformatting/InlineLine.cpp
Source/WebCore/layout/layouttree/LayoutBlockContainer.cpp [deleted file]
Source/WebCore/layout/layouttree/LayoutBlockContainer.h [deleted file]
Source/WebCore/layout/layouttree/LayoutBox.cpp
Source/WebCore/layout/layouttree/LayoutBox.h
Source/WebCore/layout/layouttree/LayoutInlineContainer.cpp [deleted file]
Source/WebCore/layout/layouttree/LayoutInlineContainer.h [deleted file]
Source/WebCore/layout/layouttree/LayoutIterator.h
Source/WebCore/layout/layouttree/LayoutTreeBuilder.cpp
Source/WebCore/layout/layouttree/LayoutTreeBuilder.h

index 3001aed..1df4a20 100644 (file)
@@ -1,3 +1,49 @@
+2019-08-03  Zalan Bujtas  <zalan@apple.com>
+
+        [LFC] Remove formatting context type container classes.
+        https://bugs.webkit.org/show_bug.cgi?id=200202
+
+        Reviewed by Antti Koivisto.
+
+        These are formatting context specific classes. Let's try to have a layout tree without such types.
+
+        * Sources.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * layout/blockformatting/BlockFormattingContext.cpp:
+        (WebCore::Layout::BlockFormattingContext::computeIntrinsicWidthConstraints const):
+        * layout/inlineformatting/InlineFormattingContext.cpp:
+        (WebCore::Layout::InlineFormattingContext::layout const):
+        (WebCore::Layout::InlineFormattingContext::computeMarginBorderAndPaddingForInlineContainer const):
+        * layout/inlineformatting/InlineFormattingContext.h:
+        * layout/inlineformatting/InlineFormattingContextLineLayout.cpp:
+        (WebCore::Layout::InlineFormattingContext::InlineLayout::layout const):
+        * layout/inlineformatting/InlineLine.cpp:
+        (WebCore::Layout::Line::appendTextContent):
+        * layout/layouttree/LayoutBlockContainer.cpp: Removed.
+        * layout/layouttree/LayoutBlockContainer.h: Removed.
+        * layout/layouttree/LayoutBox.cpp:
+        (WebCore::Layout::Box::establishesInlineFormattingContext const):
+        (WebCore::Layout::Box::establishesInlineFormattingContextOnly const):
+        (WebCore::Layout::Box::formattingContextRoot const):
+        * layout/layouttree/LayoutBox.h:
+        (WebCore::Layout::Box::isBlockContainer const):
+        (WebCore::Layout::Box::isInlineContainer const):
+        (WebCore::Layout::Box::isInlineBox const):
+        (WebCore::Layout::Box::establishesInlineFormattingContext const): Deleted.
+        (WebCore::Layout::Box::establishesInlineFormattingContextOnly const): Deleted.
+        * layout/layouttree/LayoutInlineContainer.cpp: Removed.
+        * layout/layouttree/LayoutInlineContainer.h: Removed.
+        * layout/layouttree/LayoutIterator.h:
+        (WebCore::Layout::LayoutBoxTraversal::firstChild):
+        * layout/layouttree/LayoutTreeBuilder.cpp:
+        (WebCore::Layout::TreeBuilder::createLayoutTree):
+        (WebCore::Layout::TreeBuilder::createLayoutBox):
+        (WebCore::Layout::TreeBuilder::createTableStructure):
+        (WebCore::Layout::outputLayoutBox):
+        * layout/layouttree/LayoutTreeBuilder.h:
+        * page/FrameViewLayoutContext.cpp:
+        (WebCore::layoutUsingFormattingContext):
+
 2019-08-02  Robin Morisset  <rmorisset@apple.com>
 
         [WHLSL] Avoid visiting the full AST in computeDimensions
index 97e3aa7..3f88b83 100644 (file)
@@ -1409,11 +1409,9 @@ layout/inlineformatting/InlineLine.cpp
 layout/inlineformatting/InlineLineBreaker.cpp
 layout/inlineformatting/InlineTextItem.cpp
 layout/inlineformatting/text/TextUtil.cpp
-layout/layouttree/LayoutBlockContainer.cpp
 layout/layouttree/LayoutBox.cpp
 layout/layouttree/LayoutContainer.cpp
 layout/layouttree/LayoutInlineBox.cpp
-layout/layouttree/LayoutInlineContainer.cpp
 layout/layouttree/LayoutLineBreakBox.cpp
 layout/layouttree/LayoutReplaced.cpp
 layout/layouttree/LayoutTreeBuilder.cpp
index 91a9614..f9bd014 100644 (file)
                119340971FED715500935F1E /* RenderTreeBuilderFormControls.h in Headers */ = {isa = PBXBuildFile; fileRef = 119340951FED715500935F1E /* RenderTreeBuilderFormControls.h */; };
                119340A31FEE024000935F1E /* RenderTreeBuilderBlock.h in Headers */ = {isa = PBXBuildFile; fileRef = 119340A11FEE024000935F1E /* RenderTreeBuilderBlock.h */; };
                1199FA46208E35A3002358CC /* LayoutContainer.h in Headers */ = {isa = PBXBuildFile; fileRef = 1199FA44208E35A3002358CC /* LayoutContainer.h */; settings = {ATTRIBUTES = (Private, ); }; };
-               1199FA4B208E37B6002358CC /* LayoutBlockContainer.h in Headers */ = {isa = PBXBuildFile; fileRef = 1199FA49208E37B6002358CC /* LayoutBlockContainer.h */; settings = {ATTRIBUTES = (Private, ); }; };
-               1199FA4F208E3899002358CC /* LayoutInlineContainer.h in Headers */ = {isa = PBXBuildFile; fileRef = 1199FA4D208E3899002358CC /* LayoutInlineContainer.h */; settings = {ATTRIBUTES = (Private, ); }; };
                1199FA53208E38D3002358CC /* LayoutInlineBox.h in Headers */ = {isa = PBXBuildFile; fileRef = 1199FA51208E38D3002358CC /* LayoutInlineBox.h */; settings = {ATTRIBUTES = (Private, ); }; };
                1199FA5B208E3C7F002358CC /* DisplayBox.h in Headers */ = {isa = PBXBuildFile; fileRef = 1199FA59208E3C7F002358CC /* DisplayBox.h */; settings = {ATTRIBUTES = (Private, ); }; };
                11CB2789203BA570004A1DC9 /* RenderTreeBuilderFullScreen.h in Headers */ = {isa = PBXBuildFile; fileRef = 11CB2787203BA570004A1DC9 /* RenderTreeBuilderFullScreen.h */; };
                119340A11FEE024000935F1E /* RenderTreeBuilderBlock.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RenderTreeBuilderBlock.h; sourceTree = "<group>"; };
                1199FA44208E35A3002358CC /* LayoutContainer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LayoutContainer.h; sourceTree = "<group>"; };
                1199FA45208E35A3002358CC /* LayoutContainer.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = LayoutContainer.cpp; sourceTree = "<group>"; };
-               1199FA49208E37B6002358CC /* LayoutBlockContainer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LayoutBlockContainer.h; sourceTree = "<group>"; };
-               1199FA4A208E37B6002358CC /* LayoutBlockContainer.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = LayoutBlockContainer.cpp; sourceTree = "<group>"; };
-               1199FA4D208E3899002358CC /* LayoutInlineContainer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LayoutInlineContainer.h; sourceTree = "<group>"; };
-               1199FA4E208E3899002358CC /* LayoutInlineContainer.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = LayoutInlineContainer.cpp; sourceTree = "<group>"; };
                1199FA51208E38D3002358CC /* LayoutInlineBox.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LayoutInlineBox.h; sourceTree = "<group>"; };
                1199FA52208E38D3002358CC /* LayoutInlineBox.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = LayoutInlineBox.cpp; sourceTree = "<group>"; };
                1199FA59208E3C7F002358CC /* DisplayBox.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DisplayBox.h; sourceTree = "<group>"; };
                        isa = PBXGroup;
                        children = (
                                11100FCA2092868D0081AA6C /* LayoutAncestorIterator.h */,
-                               1199FA4A208E37B6002358CC /* LayoutBlockContainer.cpp */,
-                               1199FA49208E37B6002358CC /* LayoutBlockContainer.h */,
                                115CFA96208B952B001E6991 /* LayoutBox.cpp */,
                                115CFA95208B952B001E6991 /* LayoutBox.h */,
                                11100FC920927CBC0081AA6C /* LayoutChildIterator.h */,
                                11B042FB20B0E21400828A6B /* LayoutDescendantIterator.h */,
                                1199FA52208E38D3002358CC /* LayoutInlineBox.cpp */,
                                1199FA51208E38D3002358CC /* LayoutInlineBox.h */,
-                               1199FA4E208E3899002358CC /* LayoutInlineContainer.cpp */,
-                               1199FA4D208E3899002358CC /* LayoutInlineContainer.h */,
                                11100FC72092764C0081AA6C /* LayoutIterator.h */,
                                6FE7CFA52177F069005B1573 /* LayoutLineBreakBox.cpp */,
                                6FE7CFA32177EF10005B1573 /* LayoutLineBreakBox.h */,
                                580371641A66F1D300BAF519 /* LayerFragment.h in Headers */,
                                7AA3A6A0194B59B6001CBD24 /* LayerPool.h in Headers */,
                                11310CF720BA4A620065A8D0 /* LayoutAncestorIterator.h in Headers */,
-                               1199FA4B208E37B6002358CC /* LayoutBlockContainer.h in Headers */,
                                115CFA97208B952B001E6991 /* LayoutBox.h in Headers */,
                                11310CF620BA4A560065A8D0 /* LayoutChildIterator.h in Headers */,
                                1199FA46208E35A3002358CC /* LayoutContainer.h in Headers */,
                                11310CF520BA4A4C0065A8D0 /* LayoutDescendantIterator.h in Headers */,
                                1199FA53208E38D3002358CC /* LayoutInlineBox.h in Headers */,
-                               1199FA4F208E3899002358CC /* LayoutInlineContainer.h in Headers */,
                                11310CF420BA4A3D0065A8D0 /* LayoutIterator.h in Headers */,
                                6FE7CFA42177EF10005B1573 /* LayoutLineBreakBox.h in Headers */,
                                931D72F615FE695300C4C07E /* LayoutMilestone.h in Headers */,
index 42c6fd8..5b5f931 100644 (file)
@@ -496,6 +496,9 @@ void BlockFormattingContext::computeIntrinsicWidthConstraints() const
                 // Skip descendants
                 continue;
             }
+            if (!is<Container>(childBox) || !downcast<Container>(childBox).hasInFlowOrFloatingChild())
+                break;
+            queue.append(downcast<Container>(childBox).firstInFlowOrFloatingChild());
         }
 
         // Compute min/max intrinsic width bottom up.
@@ -503,9 +506,10 @@ void BlockFormattingContext::computeIntrinsicWidthConstraints() const
             auto& childBox = *queue.takeLast();
             formattingState.setIntrinsicWidthConstraints(childBox, Geometry::intrinsicWidthConstraints(layoutState, childBox)); 
             // Move over to the next sibling or take the next box in the queue.
-            if (!is<Container>(childBox) || !downcast<Container>(childBox).nextInFlowOrFloatingSibling())
-                continue;
-            queue.append(downcast<Container>(childBox).nextInFlowOrFloatingSibling());
+            if (auto* nextSibling = childBox.nextInFlowOrFloatingSibling()) {
+                queue.append(nextSibling);
+                break;
+            }
         }
     }
     formattingStateForRoot.setIntrinsicWidthConstraints(formattingRoot, Geometry::intrinsicWidthConstraints(layoutState, formattingRoot));
index 46c9fac..ca1f0ca 100644 (file)
@@ -34,7 +34,6 @@
 #include "LayoutBox.h"
 #include "LayoutContainer.h"
 #include "LayoutInlineBox.h"
-#include "LayoutInlineContainer.h"
 #include "LayoutState.h"
 #include "Logging.h"
 #include "Textutil.h"
@@ -79,7 +78,7 @@ void InlineFormattingContext::layout() const
         if (layoutBox->establishesFormattingContext())
             layoutFormattingContextRoot(*layoutBox, usedValues);
         else if (is<Container>(*layoutBox))
-            computeMarginBorderAndPaddingForInlineContainer(downcast<InlineContainer>(*layoutBox), usedValues);
+            computeMarginBorderAndPaddingForInlineContainer(downcast<Container>(*layoutBox), usedValues);
         else if (layoutBox->isReplaced())
             computeWidthAndHeightForReplacedInlineBox(*layoutBox, usedValues);
         else if (is<InlineBox>(*layoutBox))
@@ -159,7 +158,7 @@ void InlineFormattingContext::initializeMarginBorderAndPaddingForGenericInlineBo
     displayBox.setPadding({ });
 }
 
-void InlineFormattingContext::computeMarginBorderAndPaddingForInlineContainer(const InlineContainer& container, UsedHorizontalValues usedValues) const
+void InlineFormattingContext::computeMarginBorderAndPaddingForInlineContainer(const Container& container, UsedHorizontalValues usedValues) const
 {
     computeHorizontalMargin(container, usedValues);
     computeBorderAndPadding(container, usedValues);
index be6f915..ed3a92f 100644 (file)
@@ -37,7 +37,6 @@ namespace WebCore {
 namespace Layout {
 
 class FloatingState;
-class InlineContainer;
 struct LineContent;
 struct LineInput;
 
@@ -83,7 +82,7 @@ private:
 
     void layoutFormattingContextRoot(const Box&, UsedHorizontalValues) const;
     void computeIntrinsicWidthForFloatBox(const Box&) const;
-    void computeMarginBorderAndPaddingForInlineContainer(const InlineContainer&, UsedHorizontalValues) const;
+    void computeMarginBorderAndPaddingForInlineContainer(const Container&, UsedHorizontalValues) const;
     void initializeMarginBorderAndPaddingForGenericInlineBox(const InlineBox&) const;
     void computeIntrinsicWidthForInlineBlock(const Box&) const;
     void computeWidthAndHeightForReplacedInlineBox(const Box&, UsedHorizontalValues) const;
index 8fc06f0..0c2fa04 100644 (file)
@@ -279,8 +279,6 @@ InlineFormattingContext::InlineLayout::InlineLayout(const InlineFormattingContex
 
 void InlineFormattingContext::InlineLayout::layout(const InlineItems& inlineItems, LayoutUnit widthConstraint) const
 {
-    ASSERT(!inlineItems.isEmpty());
-
     auto& formattingRootDisplayBox = layoutState().displayBoxForLayoutBox(m_formattingRoot);
     auto& floatingState = layoutState().establishedFormattingState(m_formattingRoot).floatingState();
 
index c945bc9..1801a8e 100644 (file)
@@ -279,7 +279,7 @@ void Line::appendTextContent(const InlineTextItem& inlineItem, LayoutUnit logica
         adjustBaselineAndLineHeight(inlineItem, runHeight);
     }
 
-    auto textContext = Content::Run::TextContext { inlineItem.start(), inlineItem.isCollapsed() ? 1 : inlineItem.length(), isCompletelyCollapsed, canBeExtended, inlineItem.isWhitespace() };
+    auto textContext = Content::Run::TextContext { inlineItem.start(), inlineItem.isCollapsed() ? 1 : inlineItem.length(), isCompletelyCollapsed, inlineItem.isWhitespace(), canBeExtended };
     auto lineItem = std::make_unique<Content::Run>(inlineItem, textContext, logicalRect);
     if (isTrimmable && !isCompletelyCollapsed)
         m_trimmableContent.add(lineItem.get());
diff --git a/Source/WebCore/layout/layouttree/LayoutBlockContainer.cpp b/Source/WebCore/layout/layouttree/LayoutBlockContainer.cpp
deleted file mode 100644 (file)
index 8f8ecca..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright (C) 2018 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 "LayoutBlockContainer.h"
-
-#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
-
-#include "RenderStyle.h"
-#include <wtf/IsoMallocInlines.h>
-
-namespace WebCore {
-namespace Layout {
-
-WTF_MAKE_ISO_ALLOCATED_IMPL(BlockContainer);
-
-BlockContainer::BlockContainer(Optional<ElementAttributes> attributes, RenderStyle&& style, BaseTypeFlags baseTypeFlags)
-    : Container(attributes, WTFMove(style), baseTypeFlags | BlockContainerFlag)
-{
-}
-
-bool BlockContainer::establishesInlineFormattingContext() const
-{
-    // 9.4.2 Inline formatting contexts
-    // An inline formatting context is established by a block container box that contains no block-level boxes.
-
-    // It's enough to check the first in-flow child since we can't have both block and inline level sibling boxes.
-    if (auto* firstInFlowChild = this->firstInFlowChild())
-        return firstInFlowChild->isInlineLevelBox();
-
-    return false;
-}
-
-bool BlockContainer::establishesInlineFormattingContextOnly() const
-{
-    return establishesInlineFormattingContext() && !establishesBlockFormattingContext();
-}
-
-}
-}
-
-#endif
diff --git a/Source/WebCore/layout/layouttree/LayoutBlockContainer.h b/Source/WebCore/layout/layouttree/LayoutBlockContainer.h
deleted file mode 100644 (file)
index a77f4fc..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (C) 2018 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
-
-#include "LayoutContainer.h"
-#include <wtf/IsoMalloc.h>
-
-#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
-
-namespace WebCore {
-
-class RenderStyle;
-
-namespace Layout {
-
-class BlockContainer : public Container {
-    WTF_MAKE_ISO_ALLOCATED(BlockContainer);
-public:
-    BlockContainer(Optional<ElementAttributes>, RenderStyle&&, BaseTypeFlags = BlockContainerFlag);
-
-    bool establishesInlineFormattingContext() const final;
-    bool establishesInlineFormattingContextOnly() const final;
-};
-
-}
-}
-
-SPECIALIZE_TYPE_TRAITS_LAYOUT_BOX(BlockContainer, isBlockContainer())
-
-#endif
index 853060a..4d47f14 100644 (file)
@@ -82,6 +82,29 @@ bool Box::establishesBlockFormattingContext() const
     return false;
 }
 
+bool Box::establishesInlineFormattingContext() const
+{
+    // 9.4.2 Inline formatting contexts
+    // An inline formatting context is established by a block container box that contains no block-level boxes.
+    if (!isBlockContainerBox())
+        return false;
+
+    if (!isContainer())
+        return false;
+
+    // FIXME ???
+    if (!downcast<Container>(*this).firstInFlowChild())
+        return false;
+
+    // It's enough to check the first in-flow child since we can't have both block and inline level sibling boxes.
+    return downcast<Container>(*this).firstInFlowChild()->isInlineLevelBox();
+}
+
+bool Box::establishesInlineFormattingContextOnly() const
+{
+    return establishesInlineFormattingContext() && !establishesBlockFormattingContext();
+}
+
 bool Box::establishesTableFormattingContext() const
 {
     return isTableBox();
@@ -182,10 +205,21 @@ const Container& Box::formattingContextRoot() const
     // We should never need to ask this question on the ICB.
     ASSERT(!isInitialContainingBlock());
     // A box lives in the same formatting context as its containing block unless the containing block establishes a formatting context.
-    auto& containingBlock = *this->containingBlock();
-    if (containingBlock.establishesFormattingContext())
-        return containingBlock;
-    return containingBlock.formattingContextRoot();
+    // However relatively positioned (inflow) inline container lives in the formatting context where its parent lives unless
+    // the parent establishes a formatting context.
+    //
+    // <div id=outer style="position: absolute"><div id=inner><span style="position: relative">content</span></div></div>
+    // While the relatively positioned inline container (span) is placed relative to its containing block "outer", it lives in the inline
+    // formatting context established by "inner".
+    const Container* ancestor = nullptr;
+    if (isInlineBox() && isInFlowPositioned())
+        ancestor = parent();
+    else
+        ancestor = containingBlock();
+    ASSERT(ancestor);
+    if (ancestor->establishesFormattingContext())
+        return *ancestor;
+    return ancestor->formattingContextRoot();
 }
 
 const Container& Box::initialContainingBlock() const
index 373e819..56e5fc9 100644 (file)
@@ -65,9 +65,7 @@ public:
     enum BaseTypeFlag {
         BoxFlag               = 1 << 0,
         ContainerFlag         = 1 << 1,
-        BlockContainerFlag    = 1 << 2,
         InlineBoxFlag         = 1 << 3,
-        InlineContainerFlag   = 1 << 4,
         LineBreakBoxFlag      = 1 << 5
     };
     typedef unsigned BaseTypeFlags;
@@ -79,8 +77,8 @@ public:
     bool establishesBlockFormattingContext() const;
     bool establishesTableFormattingContext() const;
     bool establishesBlockFormattingContextOnly() const;
-    virtual bool establishesInlineFormattingContext() const { return false; }
-    virtual bool establishesInlineFormattingContextOnly() const { return false; }
+    bool establishesInlineFormattingContext() const;
+    bool establishesInlineFormattingContextOnly() const;
 
     bool isInFlow() const { return !isFloatingOrOutOfFlowPositioned(); }
     bool isPositioned() const { return isInFlowPositioned() || isOutOfFlowPositioned(); }
@@ -133,9 +131,10 @@ public:
     const Box* previousInFlowOrFloatingSibling() const;
 
     bool isContainer() const { return m_baseTypeFlags & ContainerFlag; }
-    bool isBlockContainer() const { return m_baseTypeFlags & BlockContainerFlag; }
+    bool isBlockContainer() const { return isBlockLevelBox() && isContainer(); }
+    bool isInlineContainer() const { return isInlineLevelBox() && isContainer(); }
+
     bool isInlineBox() const { return m_baseTypeFlags & InlineBoxFlag; }
-    bool isInlineContainer() const { return m_baseTypeFlags & InlineContainerFlag; }
     bool isLineBreakBox() const { return m_baseTypeFlags & LineBreakBoxFlag; }
 
     bool isPaddingApplicable() const;
diff --git a/Source/WebCore/layout/layouttree/LayoutInlineContainer.cpp b/Source/WebCore/layout/layouttree/LayoutInlineContainer.cpp
deleted file mode 100644 (file)
index 4018990..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright (C) 2018 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 "LayoutInlineContainer.h"
-
-#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
-
-#include "RenderStyle.h"
-#include <wtf/IsoMallocInlines.h>
-
-namespace WebCore {
-namespace Layout {
-
-WTF_MAKE_ISO_ALLOCATED_IMPL(InlineContainer);
-
-InlineContainer::InlineContainer(Optional<ElementAttributes> attributes, RenderStyle&& style, BaseTypeFlags baseTypeFlags)
-    : Container(attributes, WTFMove(style), baseTypeFlags | InlineContainerFlag)
-{
-}
-
-bool InlineContainer::establishesInlineFormattingContext() const
-{
-    if (!isInlineBlockBox())
-        return false;
-
-    // 9.4.2 Inline formatting contexts
-    // An inline formatting context is established by a block container box that contains no block-level boxes.
-    if (auto* firstInFlowChild = this->firstInFlowChild())
-        return firstInFlowChild->isInlineLevelBox();
-
-    return false;
-}
-
-const Container& InlineContainer::formattingContextRoot() const
-{
-    // Relatively positioned (inflow) inline container lives in the formatting context where its parent lives unless
-    // the parent establishes a formatting context. This is slightly different from the usual behavior which is containing block driven.
-    //
-    // <div id=outer style="position: absolute">><div id=inner><span style="position: relative">content</span></div></div>
-    // While the relatively positioned inline container (span) is placed relative to its containing block "outer", it lives in the inline
-    // formatting context established by "inner".
-    auto& ancestor = isInFlowPositioned() ? *parent() : *containingBlock();
-    if (ancestor.establishesFormattingContext())
-        return ancestor;
-    return ancestor.formattingContextRoot();
-}
-
-}
-}
-
-#endif
diff --git a/Source/WebCore/layout/layouttree/LayoutInlineContainer.h b/Source/WebCore/layout/layouttree/LayoutInlineContainer.h
deleted file mode 100644 (file)
index ef69695..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (C) 2018 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
-
-#include "LayoutContainer.h"
-#include <wtf/IsoMalloc.h>
-
-#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
-
-namespace WebCore {
-
-class RenderStyle;
-
-namespace Layout {
-
-class InlineContainer : public Container {
-    WTF_MAKE_ISO_ALLOCATED(InlineContainer);
-public:
-    InlineContainer(Optional<ElementAttributes>, RenderStyle&&, BaseTypeFlags = InlineContainerFlag);
-
-    bool establishesInlineFormattingContext() const final;
-    const Container& formattingContextRoot() const final;
-};
-
-}
-}
-
-SPECIALIZE_TYPE_TRAITS_LAYOUT_BOX(InlineContainer, isInlineContainer())
-
-#endif
index ebbcb63..3314911 100644 (file)
@@ -64,8 +64,10 @@ inline const Box* firstChild(U& object)
     return object.firstChild();
 }
 
-inline const Box* firstChild(const Box&)
+inline const Box* firstChild(const Box& box)
 {
+    if (is<Container>(box))
+        return downcast<Container>(box).firstChild();
     return nullptr;
 }
 
index cd39626..34a3402 100644 (file)
 #include "DisplayBox.h"
 #include "DisplayRun.h"
 #include "InlineFormattingState.h"
-#include "LayoutBlockContainer.h"
 #include "LayoutBox.h"
 #include "LayoutChildIterator.h"
 #include "LayoutContainer.h"
+#include "LayoutDescendantIterator.h"
 #include "LayoutInlineBox.h"
-#include "LayoutInlineContainer.h"
 #include "LayoutState.h"
 #include "RenderBlock.h"
 #include "RenderChildIterator.h"
@@ -75,8 +74,17 @@ std::unique_ptr<Container> TreeBuilder::createLayoutTree(const RenderView& rende
     style.setLogicalWidth(Length(renderView.width(), Fixed));
     style.setLogicalHeight(Length(renderView.height(), Fixed));
 
-    std::unique_ptr<Container> initialContainingBlock(new BlockContainer(WTF::nullopt, WTFMove(style)));
+    std::unique_ptr<Container> initialContainingBlock(new Container(WTF::nullopt, WTFMove(style)));
     TreeBuilder::createSubTree(renderView, *initialContainingBlock);
+
+    // Not efficient, but this is temporary anyway.
+    // Collect the out-of-flow descendants at the formatting root level (as opposed to at the containing block level, though they might be the same).
+    for (auto& descendant : descendantsOfType<Box>(*initialContainingBlock)) {
+        if (!descendant.isOutOfFlowPositioned())
+            continue;
+        const_cast<Container&>(descendant.formattingContextRoot()).addOutOfFlowDescendant(descendant);
+    }
+
     return initialContainingBlock;
 }
 
@@ -138,12 +146,7 @@ std::unique_ptr<Box> TreeBuilder::createLayoutBox(const RenderElement& parentRen
 
     if (is<RenderTable>(renderer)) {
         // Construct the principal table wrapper box (and not the table box itself).
-        if (displayType == DisplayType::Table)
-            childLayoutBox = std::make_unique<BlockContainer>(Box::ElementAttributes { Box::ElementType::TableWrapperBox }, RenderStyle::clone(renderer.style()));
-        else {
-            ASSERT(displayType == DisplayType::InlineTable);
-            childLayoutBox = std::make_unique<InlineContainer>(Box::ElementAttributes { Box::ElementType::TableWrapperBox }, RenderStyle::clone(renderer.style()));
-        }
+        childLayoutBox = std::make_unique<Container>(Box::ElementAttributes { Box::ElementType::TableWrapperBox }, RenderStyle::clone(renderer.style()));
     } else if (is<RenderReplaced>(renderer)) {
         if (displayType == DisplayType::Block)
             childLayoutBox = std::make_unique<Box>(elementAttributes(renderer), RenderStyle::clone(renderer.style()));
@@ -163,15 +166,15 @@ std::unique_ptr<Box> TreeBuilder::createLayoutBox(const RenderElement& parentRen
                 auto style = RenderStyle::clonePtr(renderer.style());
                 style->setTop({ offset->height(), Fixed });
                 style->setLeft({ offset->width(), Fixed });
-                childLayoutBox = std::make_unique<BlockContainer>(elementAttributes(renderer), WTFMove(*style));
+                childLayoutBox = std::make_unique<Container>(elementAttributes(renderer), WTFMove(*style));
             } else
-                childLayoutBox = std::make_unique<BlockContainer>(elementAttributes(renderer), RenderStyle::clone(renderer.style()));
+                childLayoutBox = std::make_unique<Container>(elementAttributes(renderer), RenderStyle::clone(renderer.style()));
         } else if (displayType == DisplayType::Inline)
-            childLayoutBox = std::make_unique<InlineContainer>(elementAttributes(renderer), RenderStyle::clone(renderer.style()));
+            childLayoutBox = std::make_unique<Container>(elementAttributes(renderer), RenderStyle::clone(renderer.style()));
         else if (displayType == DisplayType::InlineBlock)
-            childLayoutBox = std::make_unique<InlineContainer>(elementAttributes(renderer), RenderStyle::clone(renderer.style()));
+            childLayoutBox = std::make_unique<Container>(elementAttributes(renderer), RenderStyle::clone(renderer.style()));
         else if (displayType == DisplayType::TableCaption || displayType == DisplayType::TableCell) {
-            childLayoutBox = std::make_unique<BlockContainer>(elementAttributes(renderer), RenderStyle::clone(renderer.style()));
+            childLayoutBox = std::make_unique<Container>(elementAttributes(renderer), RenderStyle::clone(renderer.style()));
         } else if (displayType == DisplayType::TableRowGroup || displayType == DisplayType::TableHeaderGroup || displayType == DisplayType::TableFooterGroup
             || displayType == DisplayType::TableRow || displayType == DisplayType::TableColumnGroup || displayType == DisplayType::TableColumn) {
             childLayoutBox = std::make_unique<Container>(elementAttributes(renderer), RenderStyle::clone(renderer.style()));
@@ -180,12 +183,6 @@ std::unique_ptr<Box> TreeBuilder::createLayoutBox(const RenderElement& parentRen
             return { };
         }
     }
-
-    if (childLayoutBox->isOutOfFlowPositioned()) {
-        // Not efficient, but this is temporary anyway.
-        // Collect the out-of-flow descendants at the formatting root level (as opposed to at the containing block level, though they might be the same).
-        const_cast<Container&>(childLayoutBox->formattingContextRoot()).addOutOfFlowDescendant(*childLayoutBox);
-    }
     return childLayoutBox;
 }
 
@@ -204,7 +201,7 @@ void TreeBuilder::createTableStructure(const RenderTable& tableRenderer, Contain
         tableChild = tableChild->nextSibling();
     }
 
-    auto tableBox = std::make_unique<BlockContainer>(Box::ElementAttributes { Box::ElementType::TableBox }, RenderStyle::clone(tableRenderer.style()));
+    auto tableBox = std::make_unique<Container>(Box::ElementAttributes { Box::ElementType::TableBox }, RenderStyle::clone(tableRenderer.style()));
     appendChild(tableWrapperBox, *tableBox);
     while (tableChild) {
         TreeBuilder::createSubTree(downcast<RenderElement>(*tableChild), *tableBox);
@@ -268,40 +265,28 @@ static void outputLayoutBox(TextStream& stream, const Box& layoutBox, const Disp
     if (layoutBox.isFloatingPositioned())
         stream << "[float] ";
 
-    if (is<Container>(layoutBox)) {
-        if (layoutBox.isTableWrapperBox())
-            stream << "TABLE principal";
-        else if (is<InlineContainer>(layoutBox)) {
-            // FIXME: fix names
-            if (layoutBox.isInlineBlockBox())
-                stream << "DIV inline-block container";
-            else
-                stream << "SPAN inline container";
-        } else if (is<BlockContainer>(layoutBox)) {
-            if (layoutBox.isInitialContainingBlock())
-                stream << "Initial containing block";
-            else if (layoutBox.isDocumentBox())
-                stream << "HTML";
-            else if (layoutBox.isBodyBox())
-                stream << "BODY";
-            else if (layoutBox.isTableBox())
-                stream << "TABLE";
-            else if (layoutBox.isTableCaption())
-                stream << "CAPTION";
-            else if (layoutBox.isTableCell())
-                stream << "TD";
-            else {
-                // FIXME
-                stream << "DIV";
-            }
-        } else {
-            if (layoutBox.isTableRow())
-                stream << "TR";
-            else
-                stream << "unknown container";
-        }
-    } else if (layoutBox.isInlineLevelBox()) {
-        if (layoutBox.replaced())
+    if (layoutBox.isInitialContainingBlock())
+        stream << "Initial containing block";
+    else if (layoutBox.isDocumentBox())
+        stream << "HTML";
+    else if (layoutBox.isBodyBox())
+        stream << "BODY";
+    else if (layoutBox.isTableWrapperBox())
+        stream << "TABLE principal";
+    else if (layoutBox.isTableBox())
+        stream << "TABLE";
+    else if (layoutBox.isTableCaption())
+        stream << "CAPTION";
+    else if (layoutBox.isTableCell())
+        stream << "TD";
+    else if (layoutBox.isTableRow())
+        stream << "TR";
+    else if (layoutBox.isInlineBlockBox())
+        stream << "Inline-block container";
+    else if (layoutBox.isInlineLevelBox()) {
+        if (layoutBox.isInlineContainer())
+            stream << "SPAN inline container";
+        else if (layoutBox.replaced())
             stream << "IMG replaced inline box";
         else if (layoutBox.isAnonymous())
             stream << "anonymous inline box";
@@ -312,7 +297,7 @@ static void outputLayoutBox(TextStream& stream, const Box& layoutBox, const Disp
     } else if (layoutBox.isBlockLevelBox())
         stream << "block box";
     else
-        stream << "box";
+        stream << "unknown box";
 
     // FIXME: Inline text runs don't create display boxes yet.
     if (displayBox)
index 794874b..cbcd730 100644 (file)
@@ -30,6 +30,7 @@
 namespace WebCore {
 
 class RenderElement;
+class RenderObject;
 class RenderTable;
 class RenderView;