1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 20:27:45 +00:00

LibWeb: Add to_px() helpers to CSS::Size and CSS::PercentageOr<T>

Old pattern:

    foo.resolved(node, reference_value).to_px(node)

New pattern:

    foo.to_px(node, reference_value)

Also, the reference value for to_px() is a CSSPixels, which means we
don't have to synthesize a CSS::Length just for this call.
This commit is contained in:
Andreas Kling 2023-05-06 16:33:06 +02:00
parent 3e62ab996d
commit cdf0d3e905
3 changed files with 12 additions and 0 deletions

View file

@ -88,6 +88,11 @@ public:
VERIFY_NOT_REACHED();
}
CSSPixels to_px(Layout::Node const& layout_node, CSSPixels reference_value) const
{
return resolved(layout_node, Length::make_px(reference_value)).to_px(layout_node);
}
T resolved(Layout::Node const& layout_node, T const& reference_value) const
{
return m_value.visit(

View file

@ -14,6 +14,11 @@ Size::Size(Type type, LengthPercentage length_percentage)
{
}
CSSPixels Size::to_px(Layout::Node const& node, CSSPixels reference_value) const
{
return m_length_percentage.resolved(node, CSS::Length::make_px(reference_value)).to_px(node);
}
CSS::Length Size::resolved(Layout::Node const& node, Length const& reference_value) const
{
return m_length_percentage.resolved(node, reference_value);

View file

@ -47,6 +47,8 @@ public:
// FIXME: This is a stopgap API that will go away once all layout code is aware of CSS::Size.
CSS::Length resolved(Layout::Node const&, Length const& reference_value) const;
[[nodiscard]] CSSPixels to_px(Layout::Node const&, CSSPixels reference_value) const;
bool contains_percentage() const;
CalculatedStyleValue const& calculated() const