1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-23 18:57:35 +00:00

LibWeb: Ensure PercentageOr<T>::resolved() returns a concrete T

Which is to say, a T where `is_calculated()` is false.

As is becoming a repeating theme with CSS types, we have two states for
a FooPercentage that is a `calc()` expression: Either the FooPercentage
holds the CalculatedStyleValue directly, or it holds a Foo which itself
holds the CalculatedStyleValue. The first case was already handled to
return Foo, and with this patch, the second is too. :^)
This commit is contained in:
Sam Atkins 2022-07-27 13:45:05 +01:00 committed by Andreas Kling
parent 3fce4f7c91
commit 7b4004d682
9 changed files with 30 additions and 0 deletions

View file

@ -96,4 +96,10 @@ Optional<Angle::Type> Angle::unit_from_name(StringView name)
return {}; return {};
} }
NonnullRefPtr<CalculatedStyleValue> Angle::calculated_style_value() const
{
VERIFY(!m_calculated_style.is_null());
return *m_calculated_style;
}
} }

View file

@ -31,6 +31,7 @@ public:
Angle percentage_of(Percentage const&) const; Angle percentage_of(Percentage const&) const;
bool is_calculated() const { return m_type == Type::Calculated; } bool is_calculated() const { return m_type == Type::Calculated; }
NonnullRefPtr<CalculatedStyleValue> calculated_style_value() const;
String to_string() const; String to_string() const;
float to_degrees() const; float to_degrees() const;

View file

@ -83,4 +83,10 @@ Optional<Frequency::Type> Frequency::unit_from_name(StringView name)
return {}; return {};
} }
NonnullRefPtr<CalculatedStyleValue> Frequency::calculated_style_value() const
{
VERIFY(!m_calculated_style.is_null());
return *m_calculated_style;
}
} }

View file

@ -28,6 +28,7 @@ public:
Frequency percentage_of(Percentage const&) const; Frequency percentage_of(Percentage const&) const;
bool is_calculated() const { return m_type == Type::Calculated; } bool is_calculated() const { return m_type == Type::Calculated; }
NonnullRefPtr<CalculatedStyleValue> calculated_style_value() const;
String to_string() const; String to_string() const;
float to_hertz() const; float to_hertz() const;

View file

@ -198,4 +198,10 @@ Optional<Length::Type> Length::unit_from_name(StringView name)
return {}; return {};
} }
NonnullRefPtr<CalculatedStyleValue> Length::calculated_style_value() const
{
VERIFY(!m_calculated_style.is_null());
return *m_calculated_style;
}
} }

View file

@ -76,6 +76,7 @@ public:
} }
float raw_value() const { return m_value; } float raw_value() const { return m_value; }
NonnullRefPtr<CalculatedStyleValue> calculated_style_value() const;
float to_px(Layout::Node const&) const; float to_px(Layout::Node const&) const;

View file

@ -98,6 +98,8 @@ public:
{ {
return m_value.visit( return m_value.visit(
[&](T const& t) { [&](T const& t) {
if (t.is_calculated())
return resolve_calculated(t.calculated_style_value(), layout_node, reference_value);
return t; return t;
}, },
[&](Percentage const& percentage) { [&](Percentage const& percentage) {

View file

@ -83,4 +83,10 @@ Optional<Time::Type> Time::unit_from_name(StringView name)
return {}; return {};
} }
NonnullRefPtr<CalculatedStyleValue> Time::calculated_style_value() const
{
VERIFY(!m_calculated_style.is_null());
return *m_calculated_style;
}
} }

View file

@ -29,6 +29,7 @@ public:
Time percentage_of(Percentage const&) const; Time percentage_of(Percentage const&) const;
bool is_calculated() const { return m_type == Type::Calculated; } bool is_calculated() const { return m_type == Type::Calculated; }
NonnullRefPtr<CalculatedStyleValue> calculated_style_value() const;
String to_string() const; String to_string() const;
float to_seconds() const; float to_seconds() const;