summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@serenityos.org>2022-02-12 14:53:59 +0000
committerLinus Groh <mail@linusgroh.de>2022-02-12 16:13:27 +0000
commita99d02e14d791ffe4f3ac2d7a3d25af5c0be70be (patch)
tree98d96368780a1779322be60df98545da12733599 /Userland/Libraries
parentc08a52dd9751a5e95628027c205887a136868fdd (diff)
downloadserenity-a99d02e14d791ffe4f3ac2d7a3d25af5c0be70be.zip
LibWeb: Add an enum for !important
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp6
-rw-r--r--Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.h7
-rw-r--r--Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp2
-rw-r--r--Userland/Libraries/LibWeb/CSS/Parser/StyleDeclarationRule.h3
-rw-r--r--Userland/Libraries/LibWeb/CSS/Parser/StyleRules.cpp2
-rw-r--r--Userland/Libraries/LibWeb/CSS/StyleComputer.cpp10
-rw-r--r--Userland/Libraries/LibWeb/CSS/StyleComputer.h2
-rw-r--r--Userland/Libraries/LibWeb/Dump.cpp4
8 files changed, 21 insertions, 15 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp b/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp
index 01c2a9a37d..726e4f6c0c 100644
--- a/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp
+++ b/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp
@@ -87,7 +87,7 @@ bool PropertyOwningCSSStyleDeclaration::set_property(PropertyID property_id, Str
}
m_properties.append(CSS::StyleProperty {
- .important = false,
+ .important = Important::No,
.property_id = property_id,
.value = new_value.release_nonnull(),
});
@@ -125,7 +125,7 @@ void CSSStyleDeclaration::set_css_text(StringView)
}
// https://www.w3.org/TR/cssom/#serialize-a-css-declaration
-static String serialize_a_css_declaration(CSS::PropertyID property, String value, bool important)
+static String serialize_a_css_declaration(CSS::PropertyID property, String value, Important important)
{
StringBuilder builder;
@@ -140,7 +140,7 @@ static String serialize_a_css_declaration(CSS::PropertyID property, String value
builder.append(value);
// 5. If the important flag is set, append " !important" (U+0020 U+0021 U+0069 U+006D U+0070 U+006F U+0072 U+0074 U+0061 U+006E U+0074) to s.
- if (important)
+ if (important == Important::Yes)
builder.append(" !important"sv);
// 6. Append ";" (U+003B) to s.
diff --git a/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.h b/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.h
index c0c0d153b0..5c047e09f9 100644
--- a/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.h
+++ b/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.h
@@ -13,8 +13,13 @@
namespace Web::CSS {
+enum class Important {
+ No,
+ Yes,
+};
+
struct StyleProperty {
- bool important { false };
+ Important important { Important::No };
CSS::PropertyID property_id;
NonnullRefPtr<StyleValue> value;
String custom_name {};
diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
index b23473ff95..8d7cd47703 100644
--- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
+++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
@@ -1611,7 +1611,7 @@ Optional<StyleDeclarationRule> Parser::consume_a_declaration(TokenStream<T>& tok
if (bang_index.has_value()) {
declaration.m_values.remove(important_index.value());
declaration.m_values.remove(bang_index.value());
- declaration.m_important = true;
+ declaration.m_important = Important::Yes;
}
}
}
diff --git a/Userland/Libraries/LibWeb/CSS/Parser/StyleDeclarationRule.h b/Userland/Libraries/LibWeb/CSS/Parser/StyleDeclarationRule.h
index 968307a8de..105002f2d6 100644
--- a/Userland/Libraries/LibWeb/CSS/Parser/StyleDeclarationRule.h
+++ b/Userland/Libraries/LibWeb/CSS/Parser/StyleDeclarationRule.h
@@ -8,6 +8,7 @@
#include <AK/String.h>
#include <AK/Vector.h>
+#include <LibWeb/CSS/CSSStyleDeclaration.h>
#include <LibWeb/CSS/Parser/StyleComponentValueRule.h>
namespace Web::CSS {
@@ -24,7 +25,7 @@ public:
private:
String m_name;
Vector<StyleComponentValueRule> m_values;
- bool m_important { false };
+ Important m_important { Important::No };
};
}
diff --git a/Userland/Libraries/LibWeb/CSS/Parser/StyleRules.cpp b/Userland/Libraries/LibWeb/CSS/Parser/StyleRules.cpp
index 9b67b058de..fe574b7d30 100644
--- a/Userland/Libraries/LibWeb/CSS/Parser/StyleRules.cpp
+++ b/Userland/Libraries/LibWeb/CSS/Parser/StyleRules.cpp
@@ -171,7 +171,7 @@ String StyleDeclarationRule::to_string() const
builder.append(": ");
append_with_to_string(builder, " ", m_values);
- if (m_important)
+ if (m_important == Important::Yes)
builder.append(" !important");
return builder.to_string();
diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp
index 6dfd4783a3..4d2fd3a4e2 100644
--- a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp
+++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp
@@ -543,7 +543,7 @@ RefPtr<StyleValue> StyleComputer::resolve_unresolved_style_value(DOM::Element& e
return {};
}
-void StyleComputer::cascade_declarations(StyleProperties& style, DOM::Element& element, Vector<MatchingRule> const& matching_rules, CascadeOrigin cascade_origin, bool important, HashMap<String, StyleProperty const*> const& custom_properties) const
+void StyleComputer::cascade_declarations(StyleProperties& style, DOM::Element& element, Vector<MatchingRule> const& matching_rules, CascadeOrigin cascade_origin, Important important, HashMap<String, StyleProperty const*> const& custom_properties) const
{
for (auto const& match : matching_rules) {
for (auto const& property : verify_cast<PropertyOwningCSSStyleDeclaration>(match.rule->declaration()).properties()) {
@@ -607,12 +607,12 @@ void StyleComputer::compute_cascaded_values(StyleProperties& style, DOM::Element
// Then we apply the declarations from the matched rules in cascade order:
// Normal user agent declarations
- cascade_declarations(style, element, matching_rule_set.user_agent_rules, CascadeOrigin::UserAgent, false, custom_properties);
+ cascade_declarations(style, element, matching_rule_set.user_agent_rules, CascadeOrigin::UserAgent, Important::No, custom_properties);
// FIXME: Normal user declarations
// Normal author declarations
- cascade_declarations(style, element, matching_rule_set.author_rules, CascadeOrigin::Author, false, custom_properties);
+ cascade_declarations(style, element, matching_rule_set.author_rules, CascadeOrigin::Author, Important::No, custom_properties);
// Author presentational hints (NOTE: The spec doesn't say exactly how to prioritize these.)
element.apply_presentational_hints(style);
@@ -620,12 +620,12 @@ void StyleComputer::compute_cascaded_values(StyleProperties& style, DOM::Element
// FIXME: Animation declarations [css-animations-1]
// Important author declarations
- cascade_declarations(style, element, matching_rule_set.author_rules, CascadeOrigin::Author, true, custom_properties);
+ cascade_declarations(style, element, matching_rule_set.author_rules, CascadeOrigin::Author, Important::Yes, custom_properties);
// FIXME: Important user declarations
// Important user agent declarations
- cascade_declarations(style, element, matching_rule_set.user_agent_rules, CascadeOrigin::UserAgent, true, custom_properties);
+ cascade_declarations(style, element, matching_rule_set.user_agent_rules, CascadeOrigin::UserAgent, Important::Yes, custom_properties);
// FIXME: Transition declarations [css-transitions-1]
}
diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.h b/Userland/Libraries/LibWeb/CSS/StyleComputer.h
index ac99e63bdb..f7bfcddd6f 100644
--- a/Userland/Libraries/LibWeb/CSS/StyleComputer.h
+++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.h
@@ -87,7 +87,7 @@ private:
Vector<MatchingRule> author_rules;
};
- void cascade_declarations(StyleProperties&, DOM::Element&, Vector<MatchingRule> const&, CascadeOrigin, bool important, HashMap<String, StyleProperty const*> const&) const;
+ void cascade_declarations(StyleProperties&, DOM::Element&, Vector<MatchingRule> const&, CascadeOrigin, Important important, HashMap<String, StyleProperty const*> const&) const;
void build_rule_cache();
void build_rule_cache_if_needed() const;
diff --git a/Userland/Libraries/LibWeb/Dump.cpp b/Userland/Libraries/LibWeb/Dump.cpp
index 36d28c86ef..ce4764b603 100644
--- a/Userland/Libraries/LibWeb/Dump.cpp
+++ b/Userland/Libraries/LibWeb/Dump.cpp
@@ -562,14 +562,14 @@ void dump_style_rule(StringBuilder& builder, CSS::CSSStyleRule const& rule, int
for (auto& property : style_declaration.properties()) {
indent(builder, indent_levels);
builder.appendff(" {}: '{}'", CSS::string_from_property_id(property.property_id), property.value->to_string());
- if (property.important)
+ if (property.important == CSS::Important::Yes)
builder.append(" \033[31;1m!important\033[0m");
builder.append('\n');
}
for (auto& property : style_declaration.custom_properties()) {
indent(builder, indent_levels);
builder.appendff(" {}: '{}'", property.key, property.value.value->to_string());
- if (property.value.important)
+ if (property.value.important == CSS::Important::Yes)
builder.append(" \033[31;1m!important\033[0m");
builder.append('\n');
}