Jelajahi Sumber

LibWeb: Expose FormattingContext type

Instead of having a virtual is_block_formatting_context(), let's have a
type() that can tell you exactly which type of formatting context it is.
Andreas Kling 3 tahun lalu
induk
melakukan
f2d0e8d0ee

+ 1 - 1
Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp

@@ -18,7 +18,7 @@
 namespace Web::Layout {
 namespace Web::Layout {
 
 
 BlockFormattingContext::BlockFormattingContext(BlockContainer& root, FormattingContext* parent)
 BlockFormattingContext::BlockFormattingContext(BlockContainer& root, FormattingContext* parent)
-    : FormattingContext(root, parent)
+    : FormattingContext(Type::Block, root, parent)
 {
 {
 }
 }
 
 

+ 1 - 1
Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp

@@ -23,7 +23,7 @@ static float get_pixel_size(Box const& box, CSS::Length const& length)
 }
 }
 
 
 FlexFormattingContext::FlexFormattingContext(Box& flex_container, FormattingContext* parent)
 FlexFormattingContext::FlexFormattingContext(Box& flex_container, FormattingContext* parent)
-    : FormattingContext(flex_container, parent)
+    : FormattingContext(Type::Flex, flex_container, parent)
     , m_flex_direction(flex_container.computed_values().flex_direction())
     , m_flex_direction(flex_container.computed_values().flex_direction())
 {
 {
 }
 }

+ 3 - 2
Userland/Libraries/LibWeb/Layout/FormattingContext.cpp

@@ -19,8 +19,9 @@
 
 
 namespace Web::Layout {
 namespace Web::Layout {
 
 
-FormattingContext::FormattingContext(Box& context_box, FormattingContext* parent)
-    : m_parent(parent)
+FormattingContext::FormattingContext(Type type, Box& context_box, FormattingContext* parent)
+    : m_type(type)
+    , m_parent(parent)
     , m_context_box(&context_box)
     , m_context_box(&context_box)
 {
 {
 }
 }

+ 14 - 2
Userland/Libraries/LibWeb/Layout/FormattingContext.h

@@ -12,6 +12,14 @@ namespace Web::Layout {
 
 
 class FormattingContext {
 class FormattingContext {
 public:
 public:
+    enum class Type {
+        Block,
+        Inline,
+        Flex,
+        Table,
+        SVG,
+    };
+
     virtual void run(Box&, LayoutMode) = 0;
     virtual void run(Box&, LayoutMode) = 0;
 
 
     Box& context_box() { return *m_context_box; }
     Box& context_box() { return *m_context_box; }
@@ -20,7 +28,9 @@ public:
     FormattingContext* parent() { return m_parent; }
     FormattingContext* parent() { return m_parent; }
     const FormattingContext* parent() const { return m_parent; }
     const FormattingContext* parent() const { return m_parent; }
 
 
-    virtual bool is_block_formatting_context() const { return false; }
+    Type type() const { return m_type; }
+    bool is_block_formatting_context() const { return type() == Type::Block; }
+
     virtual bool inhibits_floating() const { return false; }
     virtual bool inhibits_floating() const { return false; }
 
 
     static bool creates_block_formatting_context(const Box&);
     static bool creates_block_formatting_context(const Box&);
@@ -29,7 +39,7 @@ public:
     static float compute_height_for_replaced_element(const ReplacedBox&);
     static float compute_height_for_replaced_element(const ReplacedBox&);
 
 
 protected:
 protected:
-    FormattingContext(Box&, FormattingContext* parent = nullptr);
+    FormattingContext(Type, Box&, FormattingContext* parent = nullptr);
     virtual ~FormattingContext();
     virtual ~FormattingContext();
 
 
     void layout_inside(Box&, LayoutMode);
     void layout_inside(Box&, LayoutMode);
@@ -52,6 +62,8 @@ protected:
     void compute_height_for_absolutely_positioned_non_replaced_element(Box&);
     void compute_height_for_absolutely_positioned_non_replaced_element(Box&);
     void compute_height_for_absolutely_positioned_replaced_element(ReplacedBox&);
     void compute_height_for_absolutely_positioned_replaced_element(ReplacedBox&);
 
 
+    Type m_type {};
+
     FormattingContext* m_parent { nullptr };
     FormattingContext* m_parent { nullptr };
     Box* m_context_box { nullptr };
     Box* m_context_box { nullptr };
 };
 };

+ 1 - 1
Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp

@@ -16,7 +16,7 @@
 namespace Web::Layout {
 namespace Web::Layout {
 
 
 InlineFormattingContext::InlineFormattingContext(BlockContainer& containing_block, FormattingContext* parent)
 InlineFormattingContext::InlineFormattingContext(BlockContainer& containing_block, FormattingContext* parent)
-    : FormattingContext(containing_block, parent)
+    : FormattingContext(Type::Inline, containing_block, parent)
 {
 {
 }
 }
 
 

+ 1 - 1
Userland/Libraries/LibWeb/Layout/SVGFormattingContext.cpp

@@ -12,7 +12,7 @@
 namespace Web::Layout {
 namespace Web::Layout {
 
 
 SVGFormattingContext::SVGFormattingContext(Box& box, FormattingContext* parent)
 SVGFormattingContext::SVGFormattingContext(Box& box, FormattingContext* parent)
-    : FormattingContext(box, parent)
+    : FormattingContext(Type::SVG, box, parent)
 {
 {
 }
 }