[LFC][IFC] Implement Replaced helper class.
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 22 Oct 2018 15:42:44 +0000 (15:42 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 22 Oct 2018 15:42:44 +0000 (15:42 +0000)
https://bugs.webkit.org/show_bug.cgi?id=190719

Reviewed by Antti Koivisto.

* layout/layouttree/LayoutBox.cpp:
(WebCore::Layout::Box::Box):
* layout/layouttree/LayoutBox.h:
(WebCore::Layout::Box::replaced const):
* layout/layouttree/LayoutReplaced.cpp:
(WebCore::Layout::Replaced::Replaced):
(WebCore::Layout::Replaced::hasIntrinsicWidth const):
(WebCore::Layout::Replaced::hasIntrinsicHeight const):
(WebCore::Layout::Replaced::hasIntrinsicRatio const):
(WebCore::Layout::Replaced::intrinsicWidth const):
(WebCore::Layout::Replaced::intrinsicHeight const):
(WebCore::Layout::Replaced::intrinsicRatio const):
* layout/layouttree/LayoutReplaced.h:
(WebCore::Layout::Replaced::hasIntrinsicWidth const): Deleted.
(WebCore::Layout::Replaced::hasIntrinsicHeight const): Deleted.
(WebCore::Layout::Replaced::hasIntrinsicRatio const): Deleted.
(WebCore::Layout::Replaced::intrinsicWidth const): Deleted.
(WebCore::Layout::Replaced::intrinsicHeight const): Deleted.
(WebCore::Layout::Replaced::intrinsicRatio const): Deleted.
* layout/layouttree/LayoutTreeBuilder.cpp:
(WebCore::Layout::TreeBuilder::createSubTree):

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

Source/WebCore/ChangeLog
Source/WebCore/layout/layouttree/LayoutBox.cpp
Source/WebCore/layout/layouttree/LayoutBox.h
Source/WebCore/layout/layouttree/LayoutReplaced.cpp
Source/WebCore/layout/layouttree/LayoutReplaced.h
Source/WebCore/layout/layouttree/LayoutTreeBuilder.cpp

index f3a5f20..2cfc6ad 100644 (file)
@@ -1,5 +1,34 @@
 2018-10-22  Zalan Bujtas  <zalan@apple.com>
 
+        [LFC][IFC] Implement Replaced helper class.
+        https://bugs.webkit.org/show_bug.cgi?id=190719
+
+        Reviewed by Antti Koivisto.
+
+        * layout/layouttree/LayoutBox.cpp:
+        (WebCore::Layout::Box::Box):
+        * layout/layouttree/LayoutBox.h:
+        (WebCore::Layout::Box::replaced const):
+        * layout/layouttree/LayoutReplaced.cpp:
+        (WebCore::Layout::Replaced::Replaced):
+        (WebCore::Layout::Replaced::hasIntrinsicWidth const):
+        (WebCore::Layout::Replaced::hasIntrinsicHeight const):
+        (WebCore::Layout::Replaced::hasIntrinsicRatio const):
+        (WebCore::Layout::Replaced::intrinsicWidth const):
+        (WebCore::Layout::Replaced::intrinsicHeight const):
+        (WebCore::Layout::Replaced::intrinsicRatio const):
+        * layout/layouttree/LayoutReplaced.h:
+        (WebCore::Layout::Replaced::hasIntrinsicWidth const): Deleted.
+        (WebCore::Layout::Replaced::hasIntrinsicHeight const): Deleted.
+        (WebCore::Layout::Replaced::hasIntrinsicRatio const): Deleted.
+        (WebCore::Layout::Replaced::intrinsicWidth const): Deleted.
+        (WebCore::Layout::Replaced::intrinsicHeight const): Deleted.
+        (WebCore::Layout::Replaced::intrinsicRatio const): Deleted.
+        * layout/layouttree/LayoutTreeBuilder.cpp:
+        (WebCore::Layout::TreeBuilder::createSubTree):
+
+2018-10-22  Zalan Bujtas  <zalan@apple.com>
+
         [LFC][IFC] Block formatting context roots avoid floats.
         https://bugs.webkit.org/show_bug.cgi?id=190723
 
index 05df2c8..bf5b38a 100644 (file)
@@ -42,6 +42,8 @@ Box::Box(std::optional<ElementAttributes> attributes, RenderStyle&& style, BaseT
     , m_elementAttributes(attributes)
     , m_baseTypeFlags(baseTypeFlags)
 {
+    if (m_elementAttributes && m_elementAttributes.value().elementType == ElementType::Replaced)
+        m_replaced = std::make_unique<Replaced>(*this);
 }
 
 Box::~Box()
index abf1523..ab1889e 100644 (file)
@@ -51,6 +51,7 @@ public:
         TableRowGroup,
         TableHeaderGroup,
         TableFooterGroup,
+        Replaced,
         GenericElement
     };
 
@@ -126,7 +127,7 @@ public:
 
     const RenderStyle& style() const { return m_style; }
 
-    std::optional<const Replaced> replaced() const { return m_replaced; }
+    const Replaced* replaced() const { return m_replaced.get(); }
 
     void setParent(Container& parent) { m_parent = &parent; }
     void setNextSibling(Box& nextSibling) { m_nextSibling = &nextSibling; }
@@ -140,7 +141,7 @@ private:
     Box* m_previousSibling { nullptr };
     Box* m_nextSibling { nullptr };
 
-    std::optional<const Replaced> m_replaced;
+    std::unique_ptr<const Replaced> m_replaced;
 
     unsigned m_baseTypeFlags : 4;
 };
index b9ad103..3a55517 100644 (file)
 #if ENABLE(LAYOUT_FORMATTING_CONTEXT)
 
 #include "LayoutBox.h"
+#include "RenderStyle.h"
 #include <wtf/IsoMallocInlines.h>
 
 namespace WebCore {
 namespace Layout {
 
-Replaced::Replaced(const LayoutBox&)
+WTF_MAKE_ISO_ALLOCATED_IMPL(Replaced);
+
+Replaced::Replaced(const Box& layoutBox)
+    : m_layoutBox(makeWeakPtr(layoutBox))
+{
+}
+
+bool Replaced::hasIntrinsicWidth() const
+{
+    return m_layoutBox->style().logicalWidth().isIntrinsic();
+}
+
+bool Replaced::hasIntrinsicHeight() const
+{
+    return m_layoutBox->style().logicalHeight().isIntrinsic();
+}
+
+bool Replaced::hasIntrinsicRatio() const
 {
+    return m_layoutBox->style().aspectRatioType() == AspectRatioType::FromIntrinsic;
 }
 
+LayoutUnit Replaced::intrinsicWidth() const
+{
+    ASSERT(hasIntrinsicWidth());
+    return m_layoutBox->style().logicalWidth().value();
 }
+
+LayoutUnit Replaced::intrinsicHeight() const
+{
+    ASSERT(hasIntrinsicHeight());
+    return m_layoutBox->style().logicalHeight().value();
 }
 
+LayoutUnit Replaced::intrinsicRatio() const
+{
+    ASSERT(hasIntrinsicRatio());
+    ASSERT_NOT_IMPLEMENTED_YET();
+    return 1;
+}
+
+}
+}
 #endif
index cfc18e6..0aa8d31 100644 (file)
 
 #include "LayoutUnit.h"
 #include <wtf/IsoMalloc.h>
+#include <wtf/WeakPtr.h>
 
 namespace WebCore {
-
 namespace Layout {
-class LayoutBox;
+
+class Box;
 
 // HTMLAudioElement, HTMLCanvasElement. HTMLEmbedElement, HTMLIFrameElement, HTMLImageElement, HTMLInputElement, HTMLObjectElement, HTMLVideoElement.
 class Replaced {
     WTF_MAKE_ISO_ALLOCATED(Replaced);
 public:
-    friend class LayoutBox;
+    Replaced(const Box&);
+    ~Replaced() = default;
 
-    bool hasIntrinsicWidth() const { return m_intrinsicWidth.has_value(); }
-    bool hasIntrinsicHeight() const { return m_intrinsicHeight.has_value(); }
-    bool hasIntrinsicRatio() const { return m_intrinsicRatio.has_value(); }
+    bool hasIntrinsicWidth() const;
+    bool hasIntrinsicHeight() const;
+    bool hasIntrinsicRatio() const;
     LayoutUnit intrinsicWidth() const;
     LayoutUnit intrinsicHeight() const;
     LayoutUnit intrinsicRatio() const;
 
 private:
-    Replaced(const LayoutBox&);
-
-    std::optional<LayoutUnit> m_intrinsicWidth;
-    std::optional<LayoutUnit> m_intrinsicHeight;
-    std::optional<LayoutUnit> m_intrinsicRatio;
+    WeakPtr<const Box> m_layoutBox;
 };
 
-inline LayoutUnit Replaced::intrinsicWidth() const
-{
-    ASSERT(hasIntrinsicWidth());
-    return m_intrinsicWidth.value_or(LayoutUnit::max());
-}
-
-inline LayoutUnit Replaced::intrinsicHeight() const
-{
-    ASSERT(hasIntrinsicHeight());
-    return m_intrinsicHeight.value_or(LayoutUnit::max());
 }
-
-inline LayoutUnit Replaced::intrinsicRatio() const
-{
-    ASSERT(hasIntrinsicRatio());
-    return m_intrinsicRatio.value_or(LayoutUnit::max());
-}
-
 }
-}
-
 #endif
index f4fc2f9..b06d92b 100644 (file)
@@ -77,6 +77,8 @@ void TreeBuilder::createSubTree(const RenderElement& rootRenderer, Container& ro
                 return Box::ElementAttributes { Box::ElementType::TableFooterGroup };
             if (element->hasTagName(HTMLNames::tfootTag))
                 return Box::ElementAttributes { Box::ElementType::TableFooterGroup };
+            if (element->hasTagName(HTMLNames::imgTag))
+                return Box::ElementAttributes { Box::ElementType::Replaced };
             return Box::ElementAttributes { Box::ElementType::GenericElement };
         }
         return std::nullopt;