summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@serenityos.org>2021-09-22 12:42:54 +0100
committerAndreas Kling <kling@serenityos.org>2021-09-23 17:47:40 +0200
commit4a1dbb4f36c1289f6af9caaeb9d8d0a29d5d136c (patch)
tree2102736a0efc05bf92086de193d1598a2a9cb0e9 /Userland/Libraries
parenta1bc89b814df123e07e4208d35552bea1a59e75f (diff)
downloadserenity-4a1dbb4f36c1289f6af9caaeb9d8d0a29d5d136c.zip
LibWeb: Move color identifier checking to StyleValue::is_color()
This allows us to perform this check outside of the CSS Parser.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp75
-rw-r--r--Userland/Libraries/LibWeb/CSS/StyleValue.cpp72
-rw-r--r--Userland/Libraries/LibWeb/CSS/StyleValue.h2
3 files changed, 76 insertions, 73 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
index 4b5ecf53c3..d2640a7826 100644
--- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
+++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
@@ -1369,75 +1369,6 @@ Optional<float> Parser::try_parse_float(StringView string)
return is_negative ? -value : value;
}
-static bool is_color(StyleValue& style_value)
-{
- if (style_value.is_color())
- return true;
- switch (style_value.to_identifier()) {
- case ValueID::Currentcolor:
- case ValueID::LibwebLink:
- case ValueID::LibwebPaletteActiveLink:
- case ValueID::LibwebPaletteActiveWindowBorder1:
- case ValueID::LibwebPaletteActiveWindowBorder2:
- case ValueID::LibwebPaletteActiveWindowTitle:
- case ValueID::LibwebPaletteBase:
- case ValueID::LibwebPaletteBaseText:
- case ValueID::LibwebPaletteButton:
- case ValueID::LibwebPaletteButtonText:
- case ValueID::LibwebPaletteDesktopBackground:
- case ValueID::LibwebPaletteFocusOutline:
- case ValueID::LibwebPaletteHighlightWindowBorder1:
- case ValueID::LibwebPaletteHighlightWindowBorder2:
- case ValueID::LibwebPaletteHighlightWindowTitle:
- case ValueID::LibwebPaletteHoverHighlight:
- case ValueID::LibwebPaletteInactiveSelection:
- case ValueID::LibwebPaletteInactiveSelectionText:
- case ValueID::LibwebPaletteInactiveWindowBorder1:
- case ValueID::LibwebPaletteInactiveWindowBorder2:
- case ValueID::LibwebPaletteInactiveWindowTitle:
- case ValueID::LibwebPaletteLink:
- case ValueID::LibwebPaletteMenuBase:
- case ValueID::LibwebPaletteMenuBaseText:
- case ValueID::LibwebPaletteMenuSelection:
- case ValueID::LibwebPaletteMenuSelectionText:
- case ValueID::LibwebPaletteMenuStripe:
- case ValueID::LibwebPaletteMovingWindowBorder1:
- case ValueID::LibwebPaletteMovingWindowBorder2:
- case ValueID::LibwebPaletteMovingWindowTitle:
- case ValueID::LibwebPaletteRubberBandBorder:
- case ValueID::LibwebPaletteRubberBandFill:
- case ValueID::LibwebPaletteRuler:
- case ValueID::LibwebPaletteRulerActiveText:
- case ValueID::LibwebPaletteRulerBorder:
- case ValueID::LibwebPaletteRulerInactiveText:
- case ValueID::LibwebPaletteSelection:
- case ValueID::LibwebPaletteSelectionText:
- case ValueID::LibwebPaletteSyntaxComment:
- case ValueID::LibwebPaletteSyntaxControlKeyword:
- case ValueID::LibwebPaletteSyntaxIdentifier:
- case ValueID::LibwebPaletteSyntaxKeyword:
- case ValueID::LibwebPaletteSyntaxNumber:
- case ValueID::LibwebPaletteSyntaxOperator:
- case ValueID::LibwebPaletteSyntaxPreprocessorStatement:
- case ValueID::LibwebPaletteSyntaxPreprocessorValue:
- case ValueID::LibwebPaletteSyntaxPunctuation:
- case ValueID::LibwebPaletteSyntaxString:
- case ValueID::LibwebPaletteSyntaxType:
- case ValueID::LibwebPaletteTextCursor:
- case ValueID::LibwebPaletteThreedHighlight:
- case ValueID::LibwebPaletteThreedShadow1:
- case ValueID::LibwebPaletteThreedShadow2:
- case ValueID::LibwebPaletteVisitedLink:
- case ValueID::LibwebPaletteWindow:
- case ValueID::LibwebPaletteWindowText:
- return true;
- default:
- break;
- }
-
- return false;
-}
-
RefPtr<StyleValue> Parser::parse_builtin_value(ParsingContext const&, StyleComponentValueRule const& component_value)
{
if (component_value.is(Token::Type::Ident)) {
@@ -1848,7 +1779,7 @@ RefPtr<StyleValue> Parser::parse_background_value(ParsingContext const& context,
return nullptr;
}
- if (is_color(*value)) {
+ if (value->is_color()) {
if (background_color)
return nullptr;
background_color = value.release_nonnull();
@@ -2014,7 +1945,7 @@ RefPtr<StyleValue> Parser::parse_border_value(ParsingContext const& context, Vec
border_width = value.release_nonnull();
continue;
}
- if (is_color(*value)) {
+ if (value->is_color()) {
if (border_color)
return nullptr;
border_color = value.release_nonnull();
@@ -2756,7 +2687,7 @@ RefPtr<StyleValue> Parser::parse_text_decoration_value(ParsingContext const& con
if (!value)
return nullptr;
- if (is_color(*value)) {
+ if (value->is_color()) {
if (decoration_color)
return nullptr;
decoration_color = value.release_nonnull();
diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.cpp b/Userland/Libraries/LibWeb/CSS/StyleValue.cpp
index 8f4cda260b..ff33190d19 100644
--- a/Userland/Libraries/LibWeb/CSS/StyleValue.cpp
+++ b/Userland/Libraries/LibWeb/CSS/StyleValue.cpp
@@ -26,6 +26,78 @@ StyleValue::~StyleValue()
{
}
+bool StyleValue::is_color() const
+{
+ if (type() == Type::Color)
+ return true;
+ if (type() != Type::Identifier)
+ return false;
+
+ switch (to_identifier()) {
+ case ValueID::Currentcolor:
+ case ValueID::LibwebLink:
+ case ValueID::LibwebPaletteActiveLink:
+ case ValueID::LibwebPaletteActiveWindowBorder1:
+ case ValueID::LibwebPaletteActiveWindowBorder2:
+ case ValueID::LibwebPaletteActiveWindowTitle:
+ case ValueID::LibwebPaletteBase:
+ case ValueID::LibwebPaletteBaseText:
+ case ValueID::LibwebPaletteButton:
+ case ValueID::LibwebPaletteButtonText:
+ case ValueID::LibwebPaletteDesktopBackground:
+ case ValueID::LibwebPaletteFocusOutline:
+ case ValueID::LibwebPaletteHighlightWindowBorder1:
+ case ValueID::LibwebPaletteHighlightWindowBorder2:
+ case ValueID::LibwebPaletteHighlightWindowTitle:
+ case ValueID::LibwebPaletteHoverHighlight:
+ case ValueID::LibwebPaletteInactiveSelection:
+ case ValueID::LibwebPaletteInactiveSelectionText:
+ case ValueID::LibwebPaletteInactiveWindowBorder1:
+ case ValueID::LibwebPaletteInactiveWindowBorder2:
+ case ValueID::LibwebPaletteInactiveWindowTitle:
+ case ValueID::LibwebPaletteLink:
+ case ValueID::LibwebPaletteMenuBase:
+ case ValueID::LibwebPaletteMenuBaseText:
+ case ValueID::LibwebPaletteMenuSelection:
+ case ValueID::LibwebPaletteMenuSelectionText:
+ case ValueID::LibwebPaletteMenuStripe:
+ case ValueID::LibwebPaletteMovingWindowBorder1:
+ case ValueID::LibwebPaletteMovingWindowBorder2:
+ case ValueID::LibwebPaletteMovingWindowTitle:
+ case ValueID::LibwebPaletteRubberBandBorder:
+ case ValueID::LibwebPaletteRubberBandFill:
+ case ValueID::LibwebPaletteRuler:
+ case ValueID::LibwebPaletteRulerActiveText:
+ case ValueID::LibwebPaletteRulerBorder:
+ case ValueID::LibwebPaletteRulerInactiveText:
+ case ValueID::LibwebPaletteSelection:
+ case ValueID::LibwebPaletteSelectionText:
+ case ValueID::LibwebPaletteSyntaxComment:
+ case ValueID::LibwebPaletteSyntaxControlKeyword:
+ case ValueID::LibwebPaletteSyntaxIdentifier:
+ case ValueID::LibwebPaletteSyntaxKeyword:
+ case ValueID::LibwebPaletteSyntaxNumber:
+ case ValueID::LibwebPaletteSyntaxOperator:
+ case ValueID::LibwebPaletteSyntaxPreprocessorStatement:
+ case ValueID::LibwebPaletteSyntaxPreprocessorValue:
+ case ValueID::LibwebPaletteSyntaxPunctuation:
+ case ValueID::LibwebPaletteSyntaxString:
+ case ValueID::LibwebPaletteSyntaxType:
+ case ValueID::LibwebPaletteTextCursor:
+ case ValueID::LibwebPaletteThreedHighlight:
+ case ValueID::LibwebPaletteThreedShadow1:
+ case ValueID::LibwebPaletteThreedShadow2:
+ case ValueID::LibwebPaletteVisitedLink:
+ case ValueID::LibwebPaletteWindow:
+ case ValueID::LibwebPaletteWindowText:
+ return true;
+ default:
+ break;
+ }
+
+ return false;
+}
+
String IdentifierStyleValue::to_string() const
{
return CSS::string_from_value_id(m_id);
diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValue.h
index 367d1f8111..537b72a774 100644
--- a/Userland/Libraries/LibWeb/CSS/StyleValue.h
+++ b/Userland/Libraries/LibWeb/CSS/StyleValue.h
@@ -261,7 +261,7 @@ public:
bool is_inherit() const { return type() == Type::Inherit; }
bool is_initial() const { return type() == Type::Initial; }
bool is_unset() const { return type() == Type::Unset; }
- bool is_color() const { return type() == Type::Color; }
+ bool is_color() const;
bool is_identifier() const { return type() == Type::Identifier || is_auto(); }
bool is_image() const { return type() == Type::Image; }
bool is_string() const { return type() == Type::String; }