1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-22 22:37:40 +00:00

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.
This commit is contained in:
Andreas Kling 2021-10-15 01:25:12 +02:00
parent b77dad5ba3
commit f2d0e8d0ee
6 changed files with 21 additions and 8 deletions

View file

@ -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)
{ {
} }

View file

@ -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())
{ {
} }

View file

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

View file

@ -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 };
}; };

View file

@ -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)
{ {
} }

View file

@ -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)
{ {
} }