summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/CSS/Parser
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@serenityos.org>2021-09-16 20:53:18 +0100
committerAndreas Kling <kling@serenityos.org>2021-09-17 23:06:45 +0200
commit854d6e5822e1b0e93ccc8c64ca49019b266d36ee (patch)
tree80d911862b2be321259f5cdf5f3e1ea6898ea96e /Userland/Libraries/LibWeb/CSS/Parser
parent17bb913625b58c5375a1f74646bd77477b4c7208 (diff)
downloadserenity-854d6e5822e1b0e93ccc8c64ca49019b266d36ee.zip
LibWeb: Persuade CSS Parser that idents like `currentcolor` are colors
Shorthand properties were only checking for `ColorStyleValue`s, which excludes identifier colors. Now they accept them too, including the various `-libweb-foo` colors. :^)
Diffstat (limited to 'Userland/Libraries/LibWeb/CSS/Parser')
-rw-r--r--Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp75
1 files changed, 72 insertions, 3 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
index ad11b17999..f49aca0773 100644
--- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
+++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
@@ -1369,6 +1369,75 @@ 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)) {
@@ -1779,7 +1848,7 @@ RefPtr<StyleValue> Parser::parse_background_value(ParsingContext const& context,
return nullptr;
}
- if (value->is_color()) {
+ if (is_color(*value)) {
if (background_color)
return nullptr;
background_color = value.release_nonnull();
@@ -1945,7 +2014,7 @@ RefPtr<StyleValue> Parser::parse_border_value(ParsingContext const& context, Vec
border_width = value.release_nonnull();
continue;
}
- if (value->is_color()) {
+ if (is_color(*value)) {
if (border_color)
return nullptr;
border_color = value.release_nonnull();
@@ -2688,7 +2757,7 @@ RefPtr<StyleValue> Parser::parse_text_decoration_value(ParsingContext const& con
if (!value)
return nullptr;
- if (value->is_color()) {
+ if (is_color(*value)) {
if (decoration_color)
return nullptr;
decoration_color = value.release_nonnull();