diff options
author | Andreas Kling <kling@serenityos.org> | 2021-10-15 01:25:12 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-10-17 22:18:59 +0200 |
commit | f2d0e8d0ee5377a38df448d3333179f8e99cb790 (patch) | |
tree | dec422f952c83fae39e55e3fcd6f37b19e3bdd78 /Userland/Libraries | |
parent | b77dad5ba3a95426fcde13e3a0d34075a3e70e2c (diff) | |
download | serenity-f2d0e8d0ee5377a38df448d3333179f8e99cb790.zip |
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.
Diffstat (limited to 'Userland/Libraries')
6 files changed, 21 insertions, 8 deletions
diff --git a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp index d872bc6f71..97668287ea 100644 --- a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp @@ -18,7 +18,7 @@ namespace Web::Layout { BlockFormattingContext::BlockFormattingContext(BlockContainer& root, FormattingContext* parent) - : FormattingContext(root, parent) + : FormattingContext(Type::Block, root, parent) { } diff --git a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp index adbf921de5..1f74a9c37c 100644 --- a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp +++ b/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) - : FormattingContext(flex_container, parent) + : FormattingContext(Type::Flex, flex_container, parent) , m_flex_direction(flex_container.computed_values().flex_direction()) { } diff --git a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp index 7aba5486e8..d65bd03556 100644 --- a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp @@ -19,8 +19,9 @@ 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) { } diff --git a/Userland/Libraries/LibWeb/Layout/FormattingContext.h b/Userland/Libraries/LibWeb/Layout/FormattingContext.h index 5dd6660860..e652a302cb 100644 --- a/Userland/Libraries/LibWeb/Layout/FormattingContext.h +++ b/Userland/Libraries/LibWeb/Layout/FormattingContext.h @@ -12,6 +12,14 @@ namespace Web::Layout { class FormattingContext { public: + enum class Type { + Block, + Inline, + Flex, + Table, + SVG, + }; + virtual void run(Box&, LayoutMode) = 0; Box& context_box() { return *m_context_box; } @@ -20,7 +28,9 @@ public: FormattingContext* parent() { 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; } static bool creates_block_formatting_context(const Box&); @@ -29,7 +39,7 @@ public: static float compute_height_for_replaced_element(const ReplacedBox&); protected: - FormattingContext(Box&, FormattingContext* parent = nullptr); + FormattingContext(Type, Box&, FormattingContext* parent = nullptr); virtual ~FormattingContext(); 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_replaced_element(ReplacedBox&); + Type m_type {}; + FormattingContext* m_parent { nullptr }; Box* m_context_box { nullptr }; }; diff --git a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp index 09fd2b063c..6cbedac7ff 100644 --- a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp @@ -16,7 +16,7 @@ namespace Web::Layout { InlineFormattingContext::InlineFormattingContext(BlockContainer& containing_block, FormattingContext* parent) - : FormattingContext(containing_block, parent) + : FormattingContext(Type::Inline, containing_block, parent) { } diff --git a/Userland/Libraries/LibWeb/Layout/SVGFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/SVGFormattingContext.cpp index 992e95415b..fbf5621575 100644 --- a/Userland/Libraries/LibWeb/Layout/SVGFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/SVGFormattingContext.cpp @@ -12,7 +12,7 @@ namespace Web::Layout { SVGFormattingContext::SVGFormattingContext(Box& box, FormattingContext* parent) - : FormattingContext(box, parent) + : FormattingContext(Type::SVG, box, parent) { } |