mirror of
https://github.com/SerenityOS/serenity
synced 2024-09-16 06:30:41 +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:
parent
3fce4f7c91
commit
7b4004d682
|
@ -96,4 +96,10 @@ Optional<Angle::Type> Angle::unit_from_name(StringView name)
|
|||
return {};
|
||||
}
|
||||
|
||||
NonnullRefPtr<CalculatedStyleValue> Angle::calculated_style_value() const
|
||||
{
|
||||
VERIFY(!m_calculated_style.is_null());
|
||||
return *m_calculated_style;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ public:
|
|||
Angle percentage_of(Percentage const&) const;
|
||||
|
||||
bool is_calculated() const { return m_type == Type::Calculated; }
|
||||
NonnullRefPtr<CalculatedStyleValue> calculated_style_value() const;
|
||||
|
||||
String to_string() const;
|
||||
float to_degrees() const;
|
||||
|
|
|
@ -83,4 +83,10 @@ Optional<Frequency::Type> Frequency::unit_from_name(StringView name)
|
|||
return {};
|
||||
}
|
||||
|
||||
NonnullRefPtr<CalculatedStyleValue> Frequency::calculated_style_value() const
|
||||
{
|
||||
VERIFY(!m_calculated_style.is_null());
|
||||
return *m_calculated_style;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ public:
|
|||
Frequency percentage_of(Percentage const&) const;
|
||||
|
||||
bool is_calculated() const { return m_type == Type::Calculated; }
|
||||
NonnullRefPtr<CalculatedStyleValue> calculated_style_value() const;
|
||||
|
||||
String to_string() const;
|
||||
float to_hertz() const;
|
||||
|
|
|
@ -198,4 +198,10 @@ Optional<Length::Type> Length::unit_from_name(StringView name)
|
|||
return {};
|
||||
}
|
||||
|
||||
NonnullRefPtr<CalculatedStyleValue> Length::calculated_style_value() const
|
||||
{
|
||||
VERIFY(!m_calculated_style.is_null());
|
||||
return *m_calculated_style;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -76,6 +76,7 @@ public:
|
|||
}
|
||||
|
||||
float raw_value() const { return m_value; }
|
||||
NonnullRefPtr<CalculatedStyleValue> calculated_style_value() const;
|
||||
|
||||
float to_px(Layout::Node const&) const;
|
||||
|
||||
|
|
|
@ -98,6 +98,8 @@ public:
|
|||
{
|
||||
return m_value.visit(
|
||||
[&](T const& t) {
|
||||
if (t.is_calculated())
|
||||
return resolve_calculated(t.calculated_style_value(), layout_node, reference_value);
|
||||
return t;
|
||||
},
|
||||
[&](Percentage const& percentage) {
|
||||
|
|
|
@ -83,4 +83,10 @@ Optional<Time::Type> Time::unit_from_name(StringView name)
|
|||
return {};
|
||||
}
|
||||
|
||||
NonnullRefPtr<CalculatedStyleValue> Time::calculated_style_value() const
|
||||
{
|
||||
VERIFY(!m_calculated_style.is_null());
|
||||
return *m_calculated_style;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ public:
|
|||
Time percentage_of(Percentage const&) const;
|
||||
|
||||
bool is_calculated() const { return m_type == Type::Calculated; }
|
||||
NonnullRefPtr<CalculatedStyleValue> calculated_style_value() const;
|
||||
|
||||
String to_string() const;
|
||||
float to_seconds() const;
|
||||
|
|
Loading…
Reference in a new issue