summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@serenityos.org>2022-01-27 14:47:39 +0000
committerAndreas Kling <kling@serenityos.org>2022-02-04 13:52:02 +0100
commitb54cd17c1ee7eb0a46af8feac66ca4180df8416d (patch)
tree63693efd5e0a7baae0e8d5e41880795ae538e032 /Userland/Libraries
parentce0de4b2b4cddf199011e4edf311580a117cc5cd (diff)
downloadserenity-b54cd17c1ee7eb0a46af8feac66ca4180df8416d.zip
LibWeb: Allow percentage tokens again when parsing calc()
I unintentionally broke this in my LengthPercentage PR, but it was not convenient to fix until now.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp14
-rw-r--r--Userland/Libraries/LibWeb/CSS/StyleValue.cpp4
-rw-r--r--Userland/Libraries/LibWeb/CSS/StyleValue.h2
3 files changed, 15 insertions, 5 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
index 0721ffacf2..2703e79558 100644
--- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
+++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
@@ -4210,10 +4210,16 @@ Optional<CalculatedStyleValue::CalcValue> Parser::parse_calc_value(TokenStream<S
return CalculatedStyleValue::CalcValue { static_cast<float>(current_token.token().number_value()) };
if (current_token.is(Token::Type::Dimension) || current_token.is(Token::Type::Percentage)) {
- auto maybe_length = parse_length(current_token);
- if (maybe_length.has_value() && !maybe_length.value().is_undefined())
- return CalculatedStyleValue::CalcValue { maybe_length.value() };
- return {};
+ auto maybe_dimension = parse_dimension(current_token);
+ if (!maybe_dimension.has_value())
+ return {};
+ auto& dimension = maybe_dimension.value();
+
+ if (dimension.is_length())
+ return CalculatedStyleValue::CalcValue { dimension.length() };
+ if (dimension.is_percentage())
+ return CalculatedStyleValue::CalcValue { dimension.percentage() };
+ VERIFY_NOT_REACHED();
}
return {};
diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.cpp b/Userland/Libraries/LibWeb/CSS/StyleValue.cpp
index c067a015ad..cd91c4ef4a 100644
--- a/Userland/Libraries/LibWeb/CSS/StyleValue.cpp
+++ b/Userland/Libraries/LibWeb/CSS/StyleValue.cpp
@@ -574,6 +574,7 @@ Optional<CalculatedStyleValue::ResolvedType> CalculatedStyleValue::CalcValue::re
return value.visit(
[](float) -> Optional<CalculatedStyleValue::ResolvedType> { return { ResolvedType::Number }; },
[](Length const&) -> Optional<CalculatedStyleValue::ResolvedType> { return { ResolvedType::Length }; },
+ [](Percentage const&) -> Optional<CalculatedStyleValue::ResolvedType> { return { ResolvedType::Percentage }; },
[](NonnullOwnPtr<CalcSum> const& sum) { return sum->resolved_type(); });
}
@@ -604,6 +605,9 @@ CalculatedStyleValue::CalculationResult CalculatedStyleValue::CalcValue::resolve
[&](Length const& length) -> CalculatedStyleValue::CalculationResult {
return CalculatedStyleValue::CalculationResult { length };
},
+ [&](Percentage const& percentage) -> CalculatedStyleValue::CalculationResult {
+ return CalculatedStyleValue::CalculationResult { percentage };
+ },
[&](NonnullOwnPtr<CalcSum> const& sum) -> CalculatedStyleValue::CalculationResult {
return sum->resolve(layout_node, percentage_basis);
});
diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValue.h
index 5c753ac4f2..be0c3bee44 100644
--- a/Userland/Libraries/LibWeb/CSS/StyleValue.h
+++ b/Userland/Libraries/LibWeb/CSS/StyleValue.h
@@ -707,7 +707,7 @@ public:
};
struct CalcValue {
- Variant<float, CSS::Length, NonnullOwnPtr<CalcSum>> value;
+ Variant<float, Length, Percentage, NonnullOwnPtr<CalcSum>> value;
Optional<ResolvedType> resolved_type() const;
CalculationResult resolve(Layout::Node const*, Length const& percentage_basis) const;
};