summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@serenityos.org>2021-12-03 12:28:14 +0000
committerAndreas Kling <kling@serenityos.org>2021-12-09 21:30:31 +0100
commit000fb5a70d0a7683d232cdec90884224931a12c2 (patch)
treedd9a2ef6c94186720447c7ee48bfeca9e527d368 /Userland
parentd2f9d2fe51a553acfba408dd6e4be94d45f8d643 (diff)
downloadserenity-000fb5a70d0a7683d232cdec90884224931a12c2.zip
LibWeb: Add new UnresolvedStyleValue class
This represents a property value that hasn't been converted to a "proper" StyleValue yet. That is, it's either a custom property's value, or a value that includes `var()` references, (or both!) since neither of those can be fully resolved at parse time.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibWeb/CSS/StyleValue.cpp14
-rw-r--r--Userland/Libraries/LibWeb/CSS/StyleValue.h30
-rw-r--r--Userland/Libraries/LibWeb/Forward.h1
3 files changed, 45 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.cpp b/Userland/Libraries/LibWeb/CSS/StyleValue.cpp
index 114fea2ced..74e6a850cd 100644
--- a/Userland/Libraries/LibWeb/CSS/StyleValue.cpp
+++ b/Userland/Libraries/LibWeb/CSS/StyleValue.cpp
@@ -169,6 +169,12 @@ TransformationStyleValue const& StyleValue::as_transformation() const
return static_cast<TransformationStyleValue const&>(*this);
}
+UnresolvedStyleValue const& StyleValue::as_unresolved() const
+{
+ VERIFY(is_unresolved());
+ return static_cast<UnresolvedStyleValue const&>(*this);
+}
+
UnsetStyleValue const& StyleValue::as_unset() const
{
VERIFY(is_unset());
@@ -492,4 +498,12 @@ String PositionStyleValue::to_string() const
return String::formatted("{} {} {} {}", to_string(m_edge_x), m_offset_x.to_string(), to_string(m_edge_y), m_offset_y.to_string());
}
+String UnresolvedStyleValue::to_string() const
+{
+ StringBuilder builder;
+ for (auto& value : m_values)
+ builder.append(value.to_string());
+ return builder.to_string();
+}
+
}
diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValue.h
index c991b29ebf..c49c977a13 100644
--- a/Userland/Libraries/LibWeb/CSS/StyleValue.h
+++ b/Userland/Libraries/LibWeb/CSS/StyleValue.h
@@ -24,6 +24,7 @@
#include <LibGfx/Color.h>
#include <LibWeb/CSS/Display.h>
#include <LibWeb/CSS/Length.h>
+#include <LibWeb/CSS/Parser/StyleComponentValueRule.h>
#include <LibWeb/CSS/PropertyID.h>
#include <LibWeb/CSS/ValueID.h>
#include <LibWeb/Forward.h>
@@ -288,6 +289,7 @@ public:
String,
TextDecoration,
Transformation,
+ Unresolved,
Unset,
ValueList,
};
@@ -318,6 +320,7 @@ public:
bool is_string() const { return type() == Type::String; }
bool is_text_decoration() const { return type() == Type::TextDecoration; }
bool is_transformation() const { return type() == Type::Transformation; }
+ bool is_unresolved() const { return type() == Type::Unresolved; }
bool is_unset() const { return type() == Type::Unset; }
bool is_value_list() const { return type() == Type::ValueList; }
@@ -347,6 +350,7 @@ public:
StringStyleValue const& as_string() const;
TextDecorationStyleValue const& as_text_decoration() const;
TransformationStyleValue const& as_transformation() const;
+ UnresolvedStyleValue const& as_unresolved() const;
UnsetStyleValue const& as_unset() const;
StyleValueList const& as_value_list() const;
@@ -374,6 +378,7 @@ public:
StringStyleValue& as_string() { return const_cast<StringStyleValue&>(const_cast<StyleValue const&>(*this).as_string()); }
TextDecorationStyleValue& as_text_decoration() { return const_cast<TextDecorationStyleValue&>(const_cast<StyleValue const&>(*this).as_text_decoration()); }
TransformationStyleValue& as_transformation() { return const_cast<TransformationStyleValue&>(const_cast<StyleValue const&>(*this).as_transformation()); }
+ UnresolvedStyleValue& as_unresolved() { return const_cast<UnresolvedStyleValue&>(const_cast<StyleValue const&>(*this).as_unresolved()); }
UnsetStyleValue& as_unset() { return const_cast<UnsetStyleValue&>(const_cast<StyleValue const&>(*this).as_unset()); }
StyleValueList& as_value_list() { return const_cast<StyleValueList&>(const_cast<StyleValue const&>(*this).as_value_list()); }
@@ -1308,6 +1313,31 @@ private:
NonnullRefPtrVector<StyleValue> m_values;
};
+class UnresolvedStyleValue final : public StyleValue {
+public:
+ static NonnullRefPtr<UnresolvedStyleValue> create(Vector<StyleComponentValueRule>&& values, bool contains_var)
+ {
+ return adopt_ref(*new UnresolvedStyleValue(move(values), contains_var));
+ }
+ virtual ~UnresolvedStyleValue() override { }
+
+ virtual String to_string() const override;
+
+ Vector<StyleComponentValueRule> const& values() const { return m_values; }
+ bool contains_var() const { return m_contains_var; }
+
+private:
+ UnresolvedStyleValue(Vector<StyleComponentValueRule>&& values, bool contains_var)
+ : StyleValue(Type::Unresolved)
+ , m_values(move(values))
+ , m_contains_var(contains_var)
+ {
+ }
+
+ Vector<StyleComponentValueRule> m_values;
+ bool m_contains_var { false };
+};
+
class UnsetStyleValue final : public StyleValue {
public:
static NonnullRefPtr<UnsetStyleValue> the()
diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h
index 7112cae86b..0020c089ea 100644
--- a/Userland/Libraries/LibWeb/Forward.h
+++ b/Userland/Libraries/LibWeb/Forward.h
@@ -67,6 +67,7 @@ class StyleValueList;
class Supports;
class TextDecorationStyleValue;
class TransformationStyleValue;
+class UnresolvedStyleValue;
class UnsetStyleValue;
}