[LFC][IFC] RenderReplaced renderer should create InlineBox
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 19 Oct 2018 17:28:13 +0000 (17:28 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 19 Oct 2018 17:28:13 +0000 (17:28 +0000)
https://bugs.webkit.org/show_bug.cgi?id=190720

Reviewed by Antti Koivisto.

* layout/layouttree/LayoutTreeBuilder.cpp:
(WebCore::Layout::TreeBuilder::createSubTree):

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

Source/WebCore/ChangeLog
Source/WebCore/layout/layouttree/LayoutBlockContainer.h
Source/WebCore/layout/layouttree/LayoutBox.h
Source/WebCore/layout/layouttree/LayoutContainer.h
Source/WebCore/layout/layouttree/LayoutInlineContainer.h
Source/WebCore/layout/layouttree/LayoutTreeBuilder.cpp

index 9e3221f..ed83d2f 100644 (file)
@@ -1,5 +1,15 @@
 2018-10-19  Zalan Bujtas  <zalan@apple.com>
 
+        [LFC][IFC] RenderReplaced renderer should create InlineBox
+        https://bugs.webkit.org/show_bug.cgi?id=190720
+
+        Reviewed by Antti Koivisto.
+
+        * layout/layouttree/LayoutTreeBuilder.cpp:
+        (WebCore::Layout::TreeBuilder::createSubTree):
+
+2018-10-19  Zalan Bujtas  <zalan@apple.com>
+
         [LFC][IFC] Inline replaced width should default to 300px only if width is auto.
         https://bugs.webkit.org/show_bug.cgi?id=190722
 
index c844844..2f74b3f 100644 (file)
@@ -39,13 +39,10 @@ namespace Layout {
 class BlockContainer : public Container {
     WTF_MAKE_ISO_ALLOCATED(BlockContainer);
 public:
-    friend class TreeBuilder;
+    BlockContainer(std::optional<ElementAttributes>, RenderStyle&&, BaseTypeFlags = BlockContainerFlag);
 
     bool establishesInlineFormattingContext() const final;
 
-protected:
-    BlockContainer(std::optional<ElementAttributes>, RenderStyle&&, BaseTypeFlags = BlockContainerFlag);
-
 };
 
 }
index c301317..abf1523 100644 (file)
@@ -42,8 +42,32 @@ class TreeBuilder;
 class Box : public CanMakeWeakPtr<Box> {
     WTF_MAKE_ISO_ALLOCATED(Box);
 public:
-    friend class TreeBuilder;
+    enum class ElementType {
+        Document,
+        Body,
+        TableColumn,
+        TableRow,
+        TableColumnGroup,
+        TableRowGroup,
+        TableHeaderGroup,
+        TableFooterGroup,
+        GenericElement
+    };
 
+    struct ElementAttributes {
+        ElementType elementType;
+    };
+
+    enum BaseTypeFlag {
+        ContainerFlag         = 1 << 0,
+        BlockContainerFlag    = 1 << 1,
+        InlineBoxFlag         = 1 << 2,
+        InlineContainerFlag   = 1 << 3,
+        LineBreakBoxFlag      = 1 << 4
+    };
+    typedef unsigned BaseTypeFlags;
+
+    Box(std::optional<ElementAttributes>, RenderStyle&&, BaseTypeFlags);
     virtual ~Box();
 
     bool establishesFormattingContext() const;
@@ -91,7 +115,6 @@ public:
     const Box* previousInFlowSibling() const;
     const Box* previousInFlowOrFloatingSibling() const;
 
-    typedef unsigned BaseTypeFlags;
     bool isContainer() const { return m_baseTypeFlags & ContainerFlag; }
     bool isBlockContainer() const { return m_baseTypeFlags & BlockContainerFlag; }
     bool isInlineBox() const { return m_baseTypeFlags & InlineBoxFlag; }
@@ -105,37 +128,11 @@ public:
 
     std::optional<const Replaced> replaced() const { return m_replaced; }
 
-protected:
-    enum class ElementType {
-        Document,
-        Body,
-        TableColumn,
-        TableRow,
-        TableColumnGroup,
-        TableRowGroup,
-        TableHeaderGroup,
-        TableFooterGroup,
-        GenericElement
-    };
-
-    struct ElementAttributes {
-        ElementType elementType;
-    };
-
-    enum BaseTypeFlag {
-        ContainerFlag         = 1 << 0,
-        BlockContainerFlag    = 1 << 1,
-        InlineBoxFlag         = 1 << 2,
-        InlineContainerFlag   = 1 << 3,
-        LineBreakBoxFlag      = 1 << 4
-    };
-    Box(std::optional<ElementAttributes>, RenderStyle&&, BaseTypeFlags);
-
-private:
     void setParent(Container& parent) { m_parent = &parent; }
     void setNextSibling(Box& nextSibling) { m_nextSibling = &nextSibling; }
     void setPreviousSibling(Box& previousSibling) { m_previousSibling = &previousSibling; }
 
+private:
     RenderStyle m_style;
     std::optional<ElementAttributes> m_elementAttributes;
 
index d6ce22b..480c7c5 100644 (file)
@@ -40,7 +40,7 @@ namespace Layout {
 class Container : public Box {
     WTF_MAKE_ISO_ALLOCATED(Container);
 public:
-    friend class TreeBuilder;
+    Container(std::optional<ElementAttributes>, RenderStyle&&, BaseTypeFlags);
 
     const Box* firstChild() const { return m_firstChild; }
     const Box* firstInFlowChild() const;
@@ -55,14 +55,11 @@ public:
 
     const Vector<WeakPtr<const Box>>& outOfFlowDescendants() const { return m_outOfFlowDescendants; }
 
-protected:
-    Container(std::optional<ElementAttributes>, RenderStyle&&, BaseTypeFlags);
-
-private:
     void setFirstChild(Box&);
     void setLastChild(Box&);
     void addOutOfFlowDescendant(const Box&);
 
+private:
     Box* m_firstChild { nullptr };
     Box* m_lastChild { nullptr };
     Vector<WeakPtr<const Box>> m_outOfFlowDescendants;
index 7373b36..5ef6c53 100644 (file)
@@ -39,9 +39,6 @@ namespace Layout {
 class InlineContainer : public Container {
     WTF_MAKE_ISO_ALLOCATED(InlineContainer);
 public:
-    friend class TreeBuilder;
-
-protected:
     InlineContainer(std::optional<ElementAttributes>, RenderStyle&&, BaseTypeFlags = InlineContainerFlag);
 };
 
index 8ee3ca3..f4fc2f9 100644 (file)
@@ -83,23 +83,25 @@ void TreeBuilder::createSubTree(const RenderElement& rootRenderer, Container& ro
     };
 
     for (auto& child : childrenOfType<RenderObject>(rootRenderer)) {
-        Box* box = nullptr;
+        std::unique_ptr<Box> box;
 
-        if (is<RenderElement>(child)) {
+        if (is<RenderText>(child)) {
+            box = std::make_unique<InlineBox>(std::optional<Box::ElementAttributes>(), RenderStyle::createAnonymousStyleWithDisplay(rootRenderer.style(), DisplayType::Inline));
+            downcast<InlineBox>(*box).setTextContent(downcast<RenderText>(child).originalText());
+        } else if (is<RenderReplaced>(child)) {
+            auto& renderer = downcast<RenderReplaced>(child);
+            box = std::make_unique<InlineBox>(elementAttributes(renderer), RenderStyle::clone(renderer.style()));
+        } else if (is<RenderElement>(child)) {
             auto& renderer = downcast<RenderElement>(child);
             auto display = renderer.style().display();
             if (display == DisplayType::Block)
-                box = new BlockContainer(elementAttributes(renderer), RenderStyle::clone(renderer.style()));
+                box = std::make_unique<BlockContainer>(elementAttributes(renderer), RenderStyle::clone(renderer.style()));
             else if (display == DisplayType::Inline)
-                box = new InlineContainer(elementAttributes(renderer), RenderStyle::clone(renderer.style()));
+                box = std::make_unique<InlineContainer>(elementAttributes(renderer), RenderStyle::clone(renderer.style()));
             else {
                 ASSERT_NOT_IMPLEMENTED_YET();
                 continue;
             }
-
-        } else if (is<RenderText>(child)) {
-            box = new InlineBox( { }, RenderStyle::createAnonymousStyleWithDisplay(rootRenderer.style(), DisplayType::Inline));
-            downcast<InlineBox>(*box).setTextContent(downcast<RenderText>(child).originalText());
         } else {
             ASSERT_NOT_IMPLEMENTED_YET();
             continue;
@@ -123,8 +125,10 @@ void TreeBuilder::createSubTree(const RenderElement& rootRenderer, Container& ro
             auto& containingBlockFormattingContextRoot = box->containingBlock()->formattingContextRoot();
             const_cast<Container&>(containingBlockFormattingContextRoot).addOutOfFlowDescendant(*box);
         }
-        if (is<RenderElement>(child))
+        if (is<Container>(*box))
             createSubTree(downcast<RenderElement>(child), downcast<Container>(*box));
+        // Temporary
+        box.release();
     }
 }