diff options
-rw-r--r-- | Libraries/LibWeb/CSS/Parser/CSSParser.cpp | 10 | ||||
-rw-r--r-- | Libraries/LibWeb/CSS/StyleProperties.cpp | 29 | ||||
-rw-r--r-- | Libraries/LibWeb/CSS/StyleProperties.h | 2 | ||||
-rw-r--r-- | Libraries/LibWeb/CSS/StyleValue.h | 5 | ||||
-rw-r--r-- | Libraries/LibWeb/Layout/LayoutStyle.h | 3 | ||||
-rw-r--r-- | Libraries/LibWeb/Layout/Node.cpp | 4 |
6 files changed, 38 insertions, 15 deletions
diff --git a/Libraries/LibWeb/CSS/Parser/CSSParser.cpp b/Libraries/LibWeb/CSS/Parser/CSSParser.cpp index e2e4f9a158..9e770d3856 100644 --- a/Libraries/LibWeb/CSS/Parser/CSSParser.cpp +++ b/Libraries/LibWeb/CSS/Parser/CSSParser.cpp @@ -386,6 +386,16 @@ static Optional<CSS::ValueID> value_id_from_string(const String& string) return CSS::ValueID::VendorSpecificCenter; if (string.equals_ignoring_case("-libweb-link")) return CSS::ValueID::VendorSpecificLink; + if (string.equals_ignoring_case("static")) + return CSS::ValueID::Static; + if (string.equals_ignoring_case("relative")) + return CSS::ValueID::Relative; + if (string.equals_ignoring_case("absolute")) + return CSS::ValueID::Absolute; + if (string.equals_ignoring_case("fixed")) + return CSS::ValueID::Fixed; + if (string.equals_ignoring_case("sticky")) + return CSS::ValueID::Sticky; if (string.starts_with("-libweb-palette-", CaseSensitivity::CaseInsensitive)) return value_id_for_palette_string(string.substring_view(16, string.length() - 16)); return {}; diff --git a/Libraries/LibWeb/CSS/StyleProperties.cpp b/Libraries/LibWeb/CSS/StyleProperties.cpp index 0ce6f5e119..dde0eeaea7 100644 --- a/Libraries/LibWeb/CSS/StyleProperties.cpp +++ b/Libraries/LibWeb/CSS/StyleProperties.cpp @@ -225,20 +225,25 @@ Optional<int> StyleProperties::z_index() const return static_cast<int>(value.value()->to_length().raw_value()); } -CSS::Position StyleProperties::position() const +Optional<CSS::Position> StyleProperties::position() const { - if (property(CSS::PropertyID::Position).has_value()) { - String position_string = string_or_fallback(CSS::PropertyID::Position, "static"); - if (position_string == "relative") - return CSS::Position::Relative; - if (position_string == "absolute") - return CSS::Position::Absolute; - if (position_string == "sticky") - return CSS::Position::Sticky; - if (position_string == "fixed") - return CSS::Position::Fixed; + auto value = property(CSS::PropertyID::Position); + if (!value.has_value() || !value.value()->is_identifier()) + return {}; + switch (static_cast<const IdentifierStyleValue&>(*value.value()).id()) { + case CSS::ValueID::Static: + return CSS::Position::Static; + case CSS::ValueID::Relative: + return CSS::Position::Relative; + case CSS::ValueID::Absolute: + return CSS::Position::Absolute; + case CSS::ValueID::Fixed: + return CSS::Position::Fixed; + case CSS::ValueID::Sticky: + return CSS::Position::Sticky; + default: + return {}; } - return CSS::Position::Static; } bool StyleProperties::operator==(const StyleProperties& other) const diff --git a/Libraries/LibWeb/CSS/StyleProperties.h b/Libraries/LibWeb/CSS/StyleProperties.h index 282098986e..f23dbef7dd 100644 --- a/Libraries/LibWeb/CSS/StyleProperties.h +++ b/Libraries/LibWeb/CSS/StyleProperties.h @@ -79,7 +79,7 @@ public: bool operator==(const StyleProperties&) const; bool operator!=(const StyleProperties& other) const { return !(*this == other); } - CSS::Position position() const; + Optional<CSS::Position> position() const; Optional<int> z_index() const; private: diff --git a/Libraries/LibWeb/CSS/StyleValue.h b/Libraries/LibWeb/CSS/StyleValue.h index 79b6b87dbd..c3964d95d3 100644 --- a/Libraries/LibWeb/CSS/StyleValue.h +++ b/Libraries/LibWeb/CSS/StyleValue.h @@ -117,6 +117,11 @@ enum class ValueID { XxLarge, XxSmall, XxxLarge, + Static, + Relative, + Absolute, + Fixed, + Sticky, }; enum class Position { diff --git a/Libraries/LibWeb/Layout/LayoutStyle.h b/Libraries/LibWeb/Layout/LayoutStyle.h index 7073f9a8cc..f8f9ee8b6c 100644 --- a/Libraries/LibWeb/Layout/LayoutStyle.h +++ b/Libraries/LibWeb/Layout/LayoutStyle.h @@ -38,6 +38,7 @@ public: static CSS::Clear clear() { return CSS::Clear::None; } static CSS::WhiteSpace white_space() { return CSS::WhiteSpace::Normal; } static CSS::TextAlign text_align() { return CSS::TextAlign::Left; } + static CSS::Position position() { return CSS::Position::Static; } }; struct BorderData { @@ -76,7 +77,7 @@ protected: CSS::Clear m_clear { InitialValues::clear() }; Optional<int> m_z_index; CSS::TextAlign m_text_align { InitialValues::text_align() }; - CSS::Position m_position; + CSS::Position m_position { InitialValues::position() }; CSS::WhiteSpace m_white_space { InitialValues::white_space() }; CSS::Length m_width; CSS::Length m_min_width; diff --git a/Libraries/LibWeb/Layout/Node.cpp b/Libraries/LibWeb/Layout/Node.cpp index afb600bfca..ff7105a742 100644 --- a/Libraries/LibWeb/Layout/Node.cpp +++ b/Libraries/LibWeb/Layout/Node.cpp @@ -219,7 +219,9 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& specified_style) { auto& style = static_cast<MutableLayoutStyle&>(m_style); - style.set_position(specified_style.position()); + auto position = specified_style.position(); + if (position.has_value()) + style.set_position(position.value()); auto text_align = specified_style.text_align(); if (text_align.has_value()) |