diff --git a/Libraries/LibWeb/CSS/StyleProperties.cpp b/Libraries/LibWeb/CSS/StyleProperties.cpp index 4b57e0928f..d241ac2dae 100644 --- a/Libraries/LibWeb/CSS/StyleProperties.cpp +++ b/Libraries/LibWeb/CSS/StyleProperties.cpp @@ -263,6 +263,21 @@ Optional StyleProperties::white_space() const return {}; } +Optional StyleProperties::float_() const +{ + auto value = property(CSS::PropertyID::Float); + if (!value.has_value() || !value.value()->is_string()) + return {}; + auto string = value.value()->to_string(); + if (string == "none") + return CSS::Float::None; + if (string == "left") + return CSS::Float::Left; + if (string == "right") + return CSS::Float::Right; + return {}; +} + CSS::Display StyleProperties::display() const { auto display = string_or_fallback(CSS::PropertyID::Display, "inline"); diff --git a/Libraries/LibWeb/CSS/StyleProperties.h b/Libraries/LibWeb/CSS/StyleProperties.h index 13d3a3c84e..b95684a0bf 100644 --- a/Libraries/LibWeb/CSS/StyleProperties.h +++ b/Libraries/LibWeb/CSS/StyleProperties.h @@ -62,6 +62,7 @@ public: Color color_or_fallback(CSS::PropertyID, const Document&, Color fallback) const; CSS::TextAlign text_align() const; CSS::Display display() const; + Optional float_() const; Optional white_space() const; const Gfx::Font& font() const diff --git a/Libraries/LibWeb/CSS/StyleValue.h b/Libraries/LibWeb/CSS/StyleValue.h index 3b44181d26..257cb29c64 100644 --- a/Libraries/LibWeb/CSS/StyleValue.h +++ b/Libraries/LibWeb/CSS/StyleValue.h @@ -143,6 +143,12 @@ enum class WhiteSpace { PreWrap, }; +enum class Float { + None, + Left, + Right, +}; + } class StyleValue : public RefCounted { diff --git a/Libraries/LibWeb/Layout/LayoutNode.cpp b/Libraries/LibWeb/Layout/LayoutNode.cpp index 3c6ab3313e..a410c930a5 100644 --- a/Libraries/LibWeb/Layout/LayoutNode.cpp +++ b/Libraries/LibWeb/Layout/LayoutNode.cpp @@ -181,6 +181,13 @@ Gfx::FloatPoint LayoutNode::box_type_agnostic_position() const return position; } +bool LayoutNode::is_floating() const +{ + if (!has_style()) + return false; + return style().float_() != CSS::Float::None; +} + bool LayoutNode::is_absolutely_positioned() const { if (!has_style()) @@ -216,6 +223,10 @@ void LayoutNodeWithStyle::apply_style(const StyleProperties& specified_style) if (white_space.has_value()) style.set_white_space(white_space.value()); + auto float_ = specified_style.float_(); + if (float_.has_value()) + style.set_float(float_.value()); + style.set_z_index(specified_style.z_index()); style.set_width(specified_style.length_or_fallback(CSS::PropertyID::Width, {})); style.set_min_width(specified_style.length_or_fallback(CSS::PropertyID::MinWidth, {})); diff --git a/Libraries/LibWeb/Layout/LayoutNode.h b/Libraries/LibWeb/Layout/LayoutNode.h index d48a7ddb7b..cb5ccc08e6 100644 --- a/Libraries/LibWeb/Layout/LayoutNode.h +++ b/Libraries/LibWeb/Layout/LayoutNode.h @@ -181,6 +181,7 @@ public: }; virtual void paint(PaintContext&, PaintPhase); + bool is_floating() const; bool is_absolutely_positioned() const; bool is_fixed_position() const; diff --git a/Libraries/LibWeb/Layout/LayoutStyle.h b/Libraries/LibWeb/Layout/LayoutStyle.h index 3dfe08ae4b..5fb42325e1 100644 --- a/Libraries/LibWeb/Layout/LayoutStyle.h +++ b/Libraries/LibWeb/Layout/LayoutStyle.h @@ -34,6 +34,7 @@ namespace Web { class InitialValues { public: + static CSS::Float float_() { return CSS::Float::None; } static CSS::WhiteSpace white_space() { return CSS::WhiteSpace::Normal; } }; @@ -45,6 +46,7 @@ public: class LayoutStyle { public: + CSS::Float float_() const { return m_float; } Optional z_index() const { return m_z_index; } CSS::TextAlign text_align() const { return m_text_align; } CSS::Position position() const { return m_position; } @@ -66,6 +68,7 @@ public: const BorderData& border_bottom() const { return m_border_bottom; } protected: + CSS::Float m_float { InitialValues::float_() }; Optional m_z_index; CSS::TextAlign m_text_align; CSS::Position m_position; @@ -90,6 +93,7 @@ class ImmutableLayoutStyle final : public LayoutStyle { class MutableLayoutStyle final : public LayoutStyle { public: + void set_float(CSS::Float value) { m_float = value; } void set_z_index(Optional value) { m_z_index = value; } void set_text_align(CSS::TextAlign text_align) { m_text_align = text_align; } void set_position(CSS::Position position) { m_position = position; }