mirror of
https://github.com/RGBCube/serenity
synced 2025-07-23 20:57:41 +00:00
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.
This commit is contained in:
parent
ce0de4b2b4
commit
b54cd17c1e
3 changed files with 15 additions and 5 deletions
|
@ -4210,10 +4210,16 @@ Optional<CalculatedStyleValue::CalcValue> Parser::parse_calc_value(TokenStream<S
|
||||||
return CalculatedStyleValue::CalcValue { static_cast<float>(current_token.token().number_value()) };
|
return CalculatedStyleValue::CalcValue { static_cast<float>(current_token.token().number_value()) };
|
||||||
|
|
||||||
if (current_token.is(Token::Type::Dimension) || current_token.is(Token::Type::Percentage)) {
|
if (current_token.is(Token::Type::Dimension) || current_token.is(Token::Type::Percentage)) {
|
||||||
auto maybe_length = parse_length(current_token);
|
auto maybe_dimension = parse_dimension(current_token);
|
||||||
if (maybe_length.has_value() && !maybe_length.value().is_undefined())
|
if (!maybe_dimension.has_value())
|
||||||
return CalculatedStyleValue::CalcValue { maybe_length.value() };
|
return {};
|
||||||
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 {};
|
return {};
|
||||||
|
|
|
@ -574,6 +574,7 @@ Optional<CalculatedStyleValue::ResolvedType> CalculatedStyleValue::CalcValue::re
|
||||||
return value.visit(
|
return value.visit(
|
||||||
[](float) -> Optional<CalculatedStyleValue::ResolvedType> { return { ResolvedType::Number }; },
|
[](float) -> Optional<CalculatedStyleValue::ResolvedType> { return { ResolvedType::Number }; },
|
||||||
[](Length const&) -> Optional<CalculatedStyleValue::ResolvedType> { return { ResolvedType::Length }; },
|
[](Length const&) -> Optional<CalculatedStyleValue::ResolvedType> { return { ResolvedType::Length }; },
|
||||||
|
[](Percentage const&) -> Optional<CalculatedStyleValue::ResolvedType> { return { ResolvedType::Percentage }; },
|
||||||
[](NonnullOwnPtr<CalcSum> const& sum) { return sum->resolved_type(); });
|
[](NonnullOwnPtr<CalcSum> const& sum) { return sum->resolved_type(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -604,6 +605,9 @@ CalculatedStyleValue::CalculationResult CalculatedStyleValue::CalcValue::resolve
|
||||||
[&](Length const& length) -> CalculatedStyleValue::CalculationResult {
|
[&](Length const& length) -> CalculatedStyleValue::CalculationResult {
|
||||||
return CalculatedStyleValue::CalculationResult { length };
|
return CalculatedStyleValue::CalculationResult { length };
|
||||||
},
|
},
|
||||||
|
[&](Percentage const& percentage) -> CalculatedStyleValue::CalculationResult {
|
||||||
|
return CalculatedStyleValue::CalculationResult { percentage };
|
||||||
|
},
|
||||||
[&](NonnullOwnPtr<CalcSum> const& sum) -> CalculatedStyleValue::CalculationResult {
|
[&](NonnullOwnPtr<CalcSum> const& sum) -> CalculatedStyleValue::CalculationResult {
|
||||||
return sum->resolve(layout_node, percentage_basis);
|
return sum->resolve(layout_node, percentage_basis);
|
||||||
});
|
});
|
||||||
|
|
|
@ -707,7 +707,7 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CalcValue {
|
struct CalcValue {
|
||||||
Variant<float, CSS::Length, NonnullOwnPtr<CalcSum>> value;
|
Variant<float, Length, Percentage, NonnullOwnPtr<CalcSum>> value;
|
||||||
Optional<ResolvedType> resolved_type() const;
|
Optional<ResolvedType> resolved_type() const;
|
||||||
CalculationResult resolve(Layout::Node const*, Length const& percentage_basis) const;
|
CalculationResult resolve(Layout::Node const*, Length const& percentage_basis) const;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue