mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 12:38:12 +00:00
LibWeb: Make absolutized_length()
helper a Length method
There were a mix of users between those who want to know if the Length changed, and those that just want an absolute Length. So, we now have two methods: Length::absolutize() returns an empty Optional if nothing changed, and Length::absolutized() always returns a value.
This commit is contained in:
parent
7d29262b8b
commit
16e3a86393
7 changed files with 27 additions and 20 deletions
|
@ -193,4 +193,20 @@ Optional<Length::Type> Length::unit_from_name(StringView name)
|
|||
return {};
|
||||
}
|
||||
|
||||
Optional<Length> Length::absolutize(CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size, CSSPixels line_height, CSSPixels root_line_height) const
|
||||
{
|
||||
if (is_px())
|
||||
return {};
|
||||
if (is_absolute() || is_relative()) {
|
||||
auto px = to_px(viewport_rect, font_metrics, font_size, root_font_size, line_height, root_line_height);
|
||||
return CSS::Length::make_px(px);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
Length Length::absolutized(CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size, CSSPixels line_height, CSSPixels root_line_height) const
|
||||
{
|
||||
return absolutize(viewport_rect, font_metrics, font_size, root_font_size, line_height, root_line_height).value_or(*this);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue