summaryrefslogtreecommitdiff
path: root/Libraries
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-12-03 11:43:05 +0100
committerAndreas Kling <kling@serenityos.org>2020-12-03 11:46:10 +0100
commit194d7d3471d55d81d4701649f1dfa40534b61bdb (patch)
tree443229a1d386257307afc3b1ddbdbd3675780e0e /Libraries
parent62bd1adb067bc6626f319a31a176ba94667e7c53 (diff)
downloadserenity-194d7d3471d55d81d4701649f1dfa40534b61bdb.zip
LibWeb: Hack the CSS parser to handle integer values (like z-index)
We were rejecting perfectly valid z-index values like '1000' since we were passing all CSS values through the length parser and unit-less lengths are not valid in this context. It's yet another hack for the ad-hoc CSS parser (its days are numbered) but this makes the top header links on google.com actually work. :^)
Diffstat (limited to 'Libraries')
-rw-r--r--Libraries/LibWeb/CSS/Parser/CSSParser.cpp16
-rw-r--r--Libraries/LibWeb/CSS/Parser/CSSParser.h2
2 files changed, 15 insertions, 3 deletions
diff --git a/Libraries/LibWeb/CSS/Parser/CSSParser.cpp b/Libraries/LibWeb/CSS/Parser/CSSParser.cpp
index e407c52e6f..5d4372da54 100644
--- a/Libraries/LibWeb/CSS/Parser/CSSParser.cpp
+++ b/Libraries/LibWeb/CSS/Parser/CSSParser.cpp
@@ -338,9 +338,21 @@ static CSS::Length parse_length(const CSS::ParsingContext& context, const String
return CSS::Length(value.value(), type);
}
-RefPtr<CSS::StyleValue> parse_css_value(const CSS::ParsingContext& context, const StringView& string)
+static bool takes_integer_value(CSS::PropertyID property_id)
+{
+ return property_id == CSS::PropertyID::ZIndex;
+}
+
+RefPtr<CSS::StyleValue> parse_css_value(const CSS::ParsingContext& context, const StringView& string, CSS::PropertyID property_id)
{
bool is_bad_length = false;
+
+ if (takes_integer_value(property_id)) {
+ auto integer = string.to_int();
+ if (integer.has_value())
+ return CSS::LengthStyleValue::create(CSS::Length::make_px(integer.value()));
+ }
+
auto length = parse_length(context, string, is_bad_length);
if (is_bad_length)
return nullptr;
@@ -856,7 +868,7 @@ public:
if (property_id == CSS::PropertyID::Invalid) {
dbg() << "CSSParser: Unrecognized property '" << property_name << "'";
}
- auto value = parse_css_value(m_context, property_value);
+ auto value = parse_css_value(m_context, property_value, property_id);
if (!value)
return {};
return CSS::StyleProperty { property_id, value.release_nonnull(), important };
diff --git a/Libraries/LibWeb/CSS/Parser/CSSParser.h b/Libraries/LibWeb/CSS/Parser/CSSParser.h
index c71331558d..ca9a4688e2 100644
--- a/Libraries/LibWeb/CSS/Parser/CSSParser.h
+++ b/Libraries/LibWeb/CSS/Parser/CSSParser.h
@@ -47,7 +47,7 @@ namespace Web {
RefPtr<CSS::StyleSheet> parse_css(const CSS::ParsingContext&, const StringView&);
RefPtr<CSS::StyleDeclaration> parse_css_declaration(const CSS::ParsingContext&, const StringView&);
-RefPtr<CSS::StyleValue> parse_css_value(const CSS::ParsingContext&, const StringView&);
+RefPtr<CSS::StyleValue> parse_css_value(const CSS::ParsingContext&, const StringView&, CSS::PropertyID property_id = CSS::PropertyID::Invalid);
Optional<CSS::Selector> parse_selector(const CSS::ParsingContext&, const StringView&);
RefPtr<CSS::LengthStyleValue> parse_line_width(const CSS::ParsingContext&, const StringView&);