[LFC] Add support for is<> and downcast<>
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 26 Apr 2018 02:04:48 +0000 (02:04 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 26 Apr 2018 02:04:48 +0000 (02:04 +0000)
https://bugs.webkit.org/show_bug.cgi?id=185016

Reviewed by Antti Koivisto.

* layout/layouttree/LayoutBlockContainer.cpp:
(WebCore::Layout::BlockContainer::BlockContainer):
* layout/layouttree/LayoutBlockContainer.h:
* layout/layouttree/LayoutBox.cpp:
(WebCore::Layout::Box::Box):
* layout/layouttree/LayoutBox.h:
(WebCore::Layout::Box::isContainer const):
(WebCore::Layout::Box::isBlockContainer const):
(WebCore::Layout::Box::isInlineBox const):
(WebCore::Layout::Box::isInlineContainer const):
* layout/layouttree/LayoutContainer.cpp:
(WebCore::Layout::Container::Container):
* layout/layouttree/LayoutContainer.h:
* layout/layouttree/LayoutInlineBox.cpp:
(WebCore::Layout::InlineBox::InlineBox):
* layout/layouttree/LayoutInlineBox.h:
* layout/layouttree/LayoutInlineContainer.cpp:
(WebCore::Layout::InlineContainer::InlineContainer):
* layout/layouttree/LayoutInlineContainer.h:

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

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

index 5c74517..af46292 100644 (file)
@@ -1,3 +1,30 @@
+2018-04-25  Zalan Bujtas  <zalan@apple.com>
+
+        [LFC] Add support for is<> and downcast<>
+        https://bugs.webkit.org/show_bug.cgi?id=185016
+
+        Reviewed by Antti Koivisto.
+
+        * layout/layouttree/LayoutBlockContainer.cpp:
+        (WebCore::Layout::BlockContainer::BlockContainer):
+        * layout/layouttree/LayoutBlockContainer.h:
+        * layout/layouttree/LayoutBox.cpp:
+        (WebCore::Layout::Box::Box):
+        * layout/layouttree/LayoutBox.h:
+        (WebCore::Layout::Box::isContainer const):
+        (WebCore::Layout::Box::isBlockContainer const):
+        (WebCore::Layout::Box::isInlineBox const):
+        (WebCore::Layout::Box::isInlineContainer const):
+        * layout/layouttree/LayoutContainer.cpp:
+        (WebCore::Layout::Container::Container):
+        * layout/layouttree/LayoutContainer.h:
+        * layout/layouttree/LayoutInlineBox.cpp:
+        (WebCore::Layout::InlineBox::InlineBox):
+        * layout/layouttree/LayoutInlineBox.h:
+        * layout/layouttree/LayoutInlineContainer.cpp:
+        (WebCore::Layout::InlineContainer::InlineContainer):
+        * layout/layouttree/LayoutInlineContainer.h:
+
 2018-04-25  Chris Dumez  <cdumez@apple.com>
 
         window.postMessage() / focus() / blur() throw a TypeError when called on a RemoteDOMWindow
index d847cd4..7f43b37 100644 (file)
@@ -36,8 +36,8 @@ namespace Layout {
 
 WTF_MAKE_ISO_ALLOCATED_IMPL(BlockContainer);
 
-BlockContainer::BlockContainer(RenderStyle&& style)
-    : Container(WTFMove(style))
+BlockContainer::BlockContainer(RenderStyle&& style, BaseTypeFlags baseTypeFlags)
+    : Container(WTFMove(style), baseTypeFlags | BlockContainerFlag)
 {
 }
 
index 43e9fae..98c41a3 100644 (file)
@@ -39,11 +39,14 @@ namespace Layout {
 class BlockContainer : public Container {
     WTF_MAKE_ISO_ALLOCATED(BlockContainer);
 public:
-    BlockContainer(RenderStyle&&);
+    BlockContainer(RenderStyle&&, BaseTypeFlags);
 
     bool establishesInlineFormattingContext() const final;
 };
 
 }
 }
+
+SPECIALIZE_TYPE_TRAITS_LAYOUT_BOX(BlockContainer, isBlockContainer())
+
 #endif
index 7663675..dec0d35 100644 (file)
@@ -36,8 +36,10 @@ namespace Layout {
 
 WTF_MAKE_ISO_ALLOCATED_IMPL(Box);
 
-Box::Box(RenderStyle&& style)
+Box::Box(RenderStyle&& style, BaseTypeFlags baseTypeFlags)
     : m_style(WTFMove(style))
+    , m_baseTypeFlags(baseTypeFlags)
+    , m_isAnonymous(false)
 {
 }
 
index 2324fc8..d3124a5 100644 (file)
@@ -42,8 +42,9 @@ class Box {
     WTF_MAKE_ISO_ALLOCATED(Box);
 public:
     friend class TreeBuilder;
+    typedef unsigned BaseTypeFlags;
 
-    Box(RenderStyle&&);
+    Box(RenderStyle&&, BaseTypeFlags);
     virtual ~Box();
 
     bool establishesFormattingContext() const;
@@ -81,9 +82,21 @@ public:
     const Box* previousInFlowSibling() const;
     const Box* previousInFlowOrFloatingSibling() const;
 
+    bool isContainer() const { return m_baseTypeFlags & ContainerFlag; }
+    bool isBlockContainer() const { return m_baseTypeFlags & BlockContainerFlag; }
+    bool isInlineBox() const { return m_baseTypeFlags & InlineBoxFlag; }
+    bool isInlineContainer() const { return m_baseTypeFlags & InlineContainerFlag; }
+
     auto& weakPtrFactory() const { return m_weakFactory; }
 
 protected:
+    enum BaseTypeFlag {
+        ContainerFlag         = 1 << 0,
+        BlockContainerFlag    = 1 << 1,
+        InlineBoxFlag         = 1 << 2,
+        InlineContainerFlag   = 1 << 3
+    };
+
     bool isOverflowVisible() const;
 
 private:
@@ -99,9 +112,17 @@ private:
     Box* m_previousSibling { nullptr };
     Box* m_nextSibling { nullptr };
 
-    bool m_isAnonymous { false };
+    unsigned m_baseTypeFlags : 3;
+    unsigned m_isAnonymous : 1;
+
 };
 
 }
 }
+
+#define SPECIALIZE_TYPE_TRAITS_LAYOUT_BOX(ToValueTypeName, predicate) \
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::Layout::ToValueTypeName) \
+    static bool isType(const WebCore::Layout::Box& box) { return box.predicate; } \
+SPECIALIZE_TYPE_TRAITS_END()
+
 #endif
index 76067dc..5363da3 100644 (file)
@@ -36,8 +36,8 @@ namespace Layout {
 
 WTF_MAKE_ISO_ALLOCATED_IMPL(Container);
 
-Container::Container(RenderStyle&& style)
-    : Box(WTFMove(style))
+Container::Container(RenderStyle&& style, BaseTypeFlags baseTypeFlags)
+    : Box(WTFMove(style), baseTypeFlags | ContainerFlag)
 {
 }
 
index bb9df4a..dacd6b4 100644 (file)
@@ -42,7 +42,7 @@ class Container : public Box {
 public:
     friend class TreeBuilder;
 
-    Container(RenderStyle&&);
+    Container(RenderStyle&&, BaseTypeFlags);
 
     const Box* firstChild() const { return m_firstChild; }
     const Box* firstInFlowChild() const;
@@ -69,4 +69,7 @@ private:
 
 }
 }
+
+SPECIALIZE_TYPE_TRAITS_LAYOUT_BOX(Container, isContainer())
+
 #endif
index 37550b5..8e5390b 100644 (file)
 
 #include "config.h"
 #include "LayoutInlineBox.h"
+
+#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
+
+#include "RenderStyle.h"
+#include <wtf/IsoMallocInlines.h>
+
+namespace WebCore {
+namespace Layout {
+
+WTF_MAKE_ISO_ALLOCATED_IMPL(InlineBox);
+
+InlineBox::InlineBox(RenderStyle&& style, BaseTypeFlags baseTypeFlags)
+    : Box(WTFMove(style), baseTypeFlags | InlineBoxFlag)
+{
+}
+
+}
+}
+
+#endif
index 888dcfa..d06d096 100644 (file)
@@ -39,9 +39,12 @@ namespace Layout {
 class InlineBox : public Box {
     WTF_MAKE_ISO_ALLOCATED(InlineBox);
 public:
-    InlineBox(RenderStyle&&);
+    InlineBox(RenderStyle&&, BaseTypeFlags);
 };
 
 }
 }
+
+SPECIALIZE_TYPE_TRAITS_LAYOUT_BOX(InlineBox, isInlineBox())
+
 #endif
index 5c7f624..47151db 100644 (file)
 
 #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(RenderStyle&& style, BaseTypeFlags baseTypeFlags)
+    : Container(WTFMove(style), baseTypeFlags | InlineContainerFlag)
+{
+}
+
+}
+}
+
+#endif
index e0ab052..a93a690 100644 (file)
@@ -39,9 +39,12 @@ namespace Layout {
 class InlineContainer : public Container {
     WTF_MAKE_ISO_ALLOCATED(InlineContainer);
 public:
-    InlineContainer(RenderStyle&&);
+    InlineContainer(RenderStyle&&, BaseTypeFlags);
 };
 
 }
 }
+
+SPECIALIZE_TYPE_TRAITS_LAYOUT_BOX(InlineContainer, isInlineContainer())
+
 #endif