Skip to content

Commit b54cd17

Browse files
AtkinsSJawesomekling
authored andcommitted
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.
1 parent ce0de4b commit b54cd17

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4210,10 +4210,16 @@ Optional<CalculatedStyleValue::CalcValue> Parser::parse_calc_value(TokenStream<S
42104210
return CalculatedStyleValue::CalcValue { static_cast<float>(current_token.token().number_value()) };
42114211

42124212
if (current_token.is(Token::Type::Dimension) || current_token.is(Token::Type::Percentage)) {
4213-
auto maybe_length = parse_length(current_token);
4214-
if (maybe_length.has_value() && !maybe_length.value().is_undefined())
4215-
return CalculatedStyleValue::CalcValue { maybe_length.value() };
4216-
return {};
4213+
auto maybe_dimension = parse_dimension(current_token);
4214+
if (!maybe_dimension.has_value())
4215+
return {};
4216+
auto& dimension = maybe_dimension.value();
4217+
4218+
if (dimension.is_length())
4219+
return CalculatedStyleValue::CalcValue { dimension.length() };
4220+
if (dimension.is_percentage())
4221+
return CalculatedStyleValue::CalcValue { dimension.percentage() };
4222+
VERIFY_NOT_REACHED();
42174223
}
42184224

42194225
return {};

Userland/Libraries/LibWeb/CSS/StyleValue.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,7 @@ Optional<CalculatedStyleValue::ResolvedType> CalculatedStyleValue::CalcValue::re
574574
return value.visit(
575575
[](float) -> Optional<CalculatedStyleValue::ResolvedType> { return { ResolvedType::Number }; },
576576
[](Length const&) -> Optional<CalculatedStyleValue::ResolvedType> { return { ResolvedType::Length }; },
577+
[](Percentage const&) -> Optional<CalculatedStyleValue::ResolvedType> { return { ResolvedType::Percentage }; },
577578
[](NonnullOwnPtr<CalcSum> const& sum) { return sum->resolved_type(); });
578579
}
579580

@@ -604,6 +605,9 @@ CalculatedStyleValue::CalculationResult CalculatedStyleValue::CalcValue::resolve
604605
[&](Length const& length) -> CalculatedStyleValue::CalculationResult {
605606
return CalculatedStyleValue::CalculationResult { length };
606607
},
608+
[&](Percentage const& percentage) -> CalculatedStyleValue::CalculationResult {
609+
return CalculatedStyleValue::CalculationResult { percentage };
610+
},
607611
[&](NonnullOwnPtr<CalcSum> const& sum) -> CalculatedStyleValue::CalculationResult {
608612
return sum->resolve(layout_node, percentage_basis);
609613
});

Userland/Libraries/LibWeb/CSS/StyleValue.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ class CalculatedStyleValue : public StyleValue {
707707
};
708708

709709
struct CalcValue {
710-
Variant<float, CSS::Length, NonnullOwnPtr<CalcSum>> value;
710+
Variant<float, Length, Percentage, NonnullOwnPtr<CalcSum>> value;
711711
Optional<ResolvedType> resolved_type() const;
712712
CalculationResult resolve(Layout::Node const*, Length const& percentage_basis) const;
713713
};

0 commit comments

Comments
 (0)