diff options
author | Sam Atkins <atkinssj@gmail.com> | 2021-08-06 11:02:42 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-08-14 12:45:01 +0200 |
commit | 21c9825cafd25cf90084651c1ace42551f10b6b3 (patch) | |
tree | 2645c52cd76eed6c2bb6e95623fb55f9308a227b /Userland/Libraries/LibWeb/CSS/StyleValue.h | |
parent | 81527f5eba1268333e359749433e35b791dfdfc4 (diff) | |
download | serenity-21c9825cafd25cf90084651c1ace42551f10b6b3.zip |
LibWeb: Implement new StyleValueList
StyleValueList is a list of StyleValues of the same type, for use in
properties like `margin` which accept a variable number of arguments.
I had originally hoped to simply swap the old ValueListStyleValue from
being a list of ComponentValues to one of StyleValues, but I can see now
that I will need to have both for a little while, so renamed the old
is_value_list() to is_component_value_list() temporarily.
Diffstat (limited to 'Userland/Libraries/LibWeb/CSS/StyleValue.h')
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/StyleValue.h | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValue.h index 3ca4d66d77..1e6e7c250b 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValue.h +++ b/Userland/Libraries/LibWeb/CSS/StyleValue.h @@ -227,6 +227,7 @@ public: CustomProperty, Numeric, ValueList, + ComponentValueList, Calculated, BoxShadow, }; @@ -243,8 +244,9 @@ public: bool is_custom_property() const { return type() == Type::CustomProperty; } bool is_numeric() const { return type() == Type::Numeric; } bool is_value_list() const { return type() == Type::ValueList; } - bool is_box_shadow() const { return type() == Type::BoxShadow; } + bool is_component_value_list() const { return type() == Type::ComponentValueList; } bool is_calculated() const { return type() == Type::Calculated; } + bool is_box_shadow() const { return type() == Type::BoxShadow; } bool is_builtin() const { return is_inherit() || is_initial(); } @@ -621,6 +623,35 @@ private: RefPtr<Gfx::Bitmap> m_bitmap; }; +class StyleValueList final : public StyleValue { +public: + static NonnullRefPtr<StyleValueList> create(NonnullRefPtrVector<StyleValue>&& values) { return adopt_ref(*new StyleValueList(move(values))); } + + NonnullRefPtrVector<StyleValue> const& values() const { return m_values; } + + virtual String to_string() const + { + StringBuilder builder; + builder.appendff("List[{}](", m_values.size()); + for (size_t i = 0; i < m_values.size(); ++i) { + if (i) + builder.append(','); + builder.append(m_values[i].to_string()); + } + builder.append(')'); + return builder.to_string(); + } + +private: + StyleValueList(NonnullRefPtrVector<StyleValue>&& values) + : StyleValue(Type::ValueList) + , m_values(move(values)) + { + } + + NonnullRefPtrVector<StyleValue> m_values; +}; + class ValueListStyleValue final : public StyleValue { public: static NonnullRefPtr<ValueListStyleValue> create(Vector<StyleComponentValueRule>&& values) { return adopt_ref(*new ValueListStyleValue(move(values))); } |