mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-02 14:19:48 +00:00
LibWeb: Handle calculations without a context better
This commit is contained in:
parent
c0beacbb76
commit
4408ea7c9b
Notes:
github-actions[bot]
2024-10-16 14:40:42 +00:00
Author: https://github.com/stelar7
Commit: 4408ea7c9b
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1827
4 changed files with 41 additions and 3 deletions
|
@ -40,10 +40,23 @@ static double resolve_value(CSSMathValue::CalculationResult::Value value, Option
|
|||
[](Angle const& angle) { return angle.to_degrees(); },
|
||||
[](Flex const& flex) { return flex.to_fr(); },
|
||||
[](Frequency const& frequency) { return frequency.to_hertz(); },
|
||||
[&context](Length const& length) { return length.to_px(*context).to_double(); },
|
||||
[](Percentage const& percentage) { return percentage.value(); },
|
||||
[](Resolution const& resolution) { return resolution.to_dots_per_pixel(); },
|
||||
[](Time const& time) { return time.to_seconds(); });
|
||||
[](Time const& time) { return time.to_seconds(); },
|
||||
[&context](Length const& length) {
|
||||
// Handle some common cases first, so we can resolve more without a context
|
||||
if (length.is_auto())
|
||||
return 0.0;
|
||||
|
||||
if (length.is_absolute())
|
||||
return length.absolute_length_to_px().to_double();
|
||||
|
||||
// If we dont have a context, we cant resolve the length, so return NAN
|
||||
if (!context.has_value())
|
||||
return Number(Number::Type::Number, NAN).value();
|
||||
|
||||
return length.to_px(*context).to_double();
|
||||
});
|
||||
}
|
||||
|
||||
static Optional<CSSNumericType> add_the_types(Vector<NonnullOwnPtr<CalculationNode>> const& nodes, PropertyID property_id)
|
||||
|
@ -2390,6 +2403,12 @@ void CSSMathValue::CalculationResult::add_or_subtract_internal(SumOperation op,
|
|||
}
|
||||
},
|
||||
[&](Length const& length) {
|
||||
if (!context.has_value()) {
|
||||
dbgln("CSSMathValue::CalculationResult::add_or_subtract_internal: Length without context");
|
||||
m_value = Length::make_px(0);
|
||||
return;
|
||||
}
|
||||
|
||||
auto this_px = length.to_px(*context);
|
||||
if (other.m_value.has<Length>()) {
|
||||
auto other_px = other.m_value.get<Length>().to_px(*context);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue