diff options
author | Tobias Christiansen <tobi@tobyase.de> | 2021-05-30 12:11:32 +0200 |
---|---|---|
committer | Ali Mohammad Pur <Ali.mpfard@gmail.com> | 2021-06-06 01:46:06 +0430 |
commit | e6545d5259f18cbc793328866d4c2e213152c9a2 (patch) | |
tree | feca2b3af1f2650043434a682fbb7b3b3b568c1c | |
parent | 72d5394b8cd5fbb15d14149ce42a6bcbb4e67b04 (diff) | |
download | serenity-e6545d5259f18cbc793328866d4c2e213152c9a2.zip |
LibWeb: Add parsing for flex-wrap property
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/ComputedValues.h | 4 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/Identifiers.json | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/Properties.json | 4 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/StyleProperties.cpp | 17 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/StyleProperties.h | 1 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/StyleValue.h | 6 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/Node.cpp | 4 |
7 files changed, 38 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/ComputedValues.h b/Userland/Libraries/LibWeb/CSS/ComputedValues.h index 10ef059362..14934a4def 100644 --- a/Userland/Libraries/LibWeb/CSS/ComputedValues.h +++ b/Userland/Libraries/LibWeb/CSS/ComputedValues.h @@ -28,6 +28,7 @@ public: static CSS::Repeat background_repeat() { return CSS::Repeat::Repeat; } static CSS::ListStyleType list_style_type() { return CSS::ListStyleType::Disc; } static CSS::FlexDirection flex_direction() { return CSS::FlexDirection::Row; } + static CSS::FlexWrap flex_wrap() { return CSS::FlexWrap::Nowrap; } static CSS::Overflow overflow() { return CSS::Overflow::Visible; } }; @@ -51,6 +52,7 @@ public: CSS::Position position() const { return m_noninherited.position; } CSS::WhiteSpace white_space() const { return m_inherited.white_space; } CSS::FlexDirection flex_direction() const { return m_noninherited.flex_direction; } + CSS::FlexWrap flex_wrap() const { return m_noninherited.flex_wrap; } const CSS::Length& width() const { return m_noninherited.width; } const CSS::Length& min_width() const { return m_noninherited.min_width; } const CSS::Length& max_width() const { return m_noninherited.max_width; } @@ -127,6 +129,7 @@ protected: CSS::Repeat background_repeat_x { InitialValues::background_repeat() }; CSS::Repeat background_repeat_y { InitialValues::background_repeat() }; CSS::FlexDirection flex_direction { InitialValues::flex_direction() }; + CSS::FlexWrap flex_wrap { InitialValues::flex_wrap() }; CSS::Overflow overflow_x { InitialValues::overflow() }; CSS::Overflow overflow_y { InitialValues::overflow() }; } m_noninherited; @@ -172,6 +175,7 @@ public: BorderData& border_right() { return m_noninherited.border_right; } BorderData& border_bottom() { return m_noninherited.border_bottom; } void set_flex_direction(CSS::FlexDirection value) { m_noninherited.flex_direction = value; } + void set_flex_wrap(CSS::FlexWrap value) { m_noninherited.flex_wrap = value; } }; } diff --git a/Userland/Libraries/LibWeb/CSS/Identifiers.json b/Userland/Libraries/LibWeb/CSS/Identifiers.json index 1bbb27730d..083f1049e2 100644 --- a/Userland/Libraries/LibWeb/CSS/Identifiers.json +++ b/Userland/Libraries/LibWeb/CSS/Identifiers.json @@ -165,6 +165,8 @@ "visible", "vertical-text", "wait", + "wrap", + "wrap-reverse", "w-resize", "x-large", "x-small", diff --git a/Userland/Libraries/LibWeb/CSS/Properties.json b/Userland/Libraries/LibWeb/CSS/Properties.json index 3ffba496e1..dbfb7d0ff5 100644 --- a/Userland/Libraries/LibWeb/CSS/Properties.json +++ b/Userland/Libraries/LibWeb/CSS/Properties.json @@ -207,6 +207,10 @@ "inherited": false, "initial": "row" }, + "flex-wrap": { + "inherited": false, + "initial": "nowrap" + }, "float": { "inherited": false, "initial": "none" diff --git a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp index f08ec06fa9..ca29bfd631 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp @@ -240,6 +240,23 @@ Optional<CSS::FlexDirection> StyleProperties::flex_direction() const } } +Optional<CSS::FlexWrap> StyleProperties::flex_wrap() const +{ + auto value = property(CSS::PropertyID::FlexWrap); + if (!value.has_value()) + return {}; + switch (value.value()->to_identifier()) { + case CSS::ValueID::Wrap: + return CSS::FlexWrap::Wrap; + case CSS::ValueID::Nowrap: + return CSS::FlexWrap::Nowrap; + case CSS::ValueID::WrapReverse: + return CSS::FlexWrap::WrapReverse; + default: + return {}; + } +} + Optional<CSS::Position> StyleProperties::position() const { auto value = property(CSS::PropertyID::Position); diff --git a/Userland/Libraries/LibWeb/CSS/StyleProperties.h b/Userland/Libraries/LibWeb/CSS/StyleProperties.h index 6cdaafcff5..3a14c745d7 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleProperties.h +++ b/Userland/Libraries/LibWeb/CSS/StyleProperties.h @@ -51,6 +51,7 @@ public: Optional<CSS::TextTransform> text_transform() const; Optional<CSS::ListStyleType> list_style_type() const; Optional<CSS::FlexDirection> flex_direction() const; + Optional<CSS::FlexWrap> flex_wrap() const; Optional<CSS::Overflow> overflow_x() const; Optional<CSS::Overflow> overflow_y() const; Optional<CSS::Repeat> background_repeat_x() const; diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValue.h index b4de7d4779..303513d250 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValue.h +++ b/Userland/Libraries/LibWeb/CSS/StyleValue.h @@ -80,6 +80,12 @@ enum class FlexDirection { ColumnReverse, }; +enum class FlexWrap { + Nowrap, + Wrap, + WrapReverse +}; + enum class WhiteSpace { Normal, Pre, diff --git a/Userland/Libraries/LibWeb/Layout/Node.cpp b/Userland/Libraries/LibWeb/Layout/Node.cpp index 0c15350a1d..6771564ff3 100644 --- a/Userland/Libraries/LibWeb/Layout/Node.cpp +++ b/Userland/Libraries/LibWeb/Layout/Node.cpp @@ -259,6 +259,10 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& specified_style) if (flex_direction.has_value()) computed_values.set_flex_direction(flex_direction.value()); + auto flex_wrap = specified_style.flex_wrap(); + if (flex_wrap.has_value()) + computed_values.set_flex_wrap(flex_wrap.value()); + auto position = specified_style.position(); if (position.has_value()) computed_values.set_position(position.value()); |