mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 13:37:44 +00:00
LibWeb: Split Length::relative_length_to_px()
by type
Length units are either relative to the font, or to the viewport, but never both. So we can save some work by not gathering font metrics for a viewport unit, and not retrieving the viewport for a font unit. Currently this is only helpful when the `to_px(Layout::Node)` method is called, but since that is 208 places according to CLion, (plus 33 indirect uses via `Length::resolved()`) it still seems worthwhile. :^)
This commit is contained in:
parent
d6e5e61ed4
commit
28ceeec435
2 changed files with 43 additions and 20 deletions
|
@ -164,8 +164,10 @@ public:
|
|||
{
|
||||
if (is_auto())
|
||||
return 0;
|
||||
if (is_relative())
|
||||
return relative_length_to_px(viewport_rect, font_metrics, root_font_metrics);
|
||||
if (is_font_relative())
|
||||
return font_relative_length_to_px(font_metrics, root_font_metrics);
|
||||
if (is_viewport_relative())
|
||||
return viewport_relative_length_to_px(viewport_rect);
|
||||
return absolute_length_to_px();
|
||||
}
|
||||
|
||||
|
@ -200,7 +202,8 @@ public:
|
|||
return m_type == other.m_type && m_value == other.m_value;
|
||||
}
|
||||
|
||||
CSSPixels relative_length_to_px(CSSPixelRect const& viewport_rect, FontMetrics const& font_metrics, FontMetrics const& root_font_metrics) const;
|
||||
CSSPixels font_relative_length_to_px(FontMetrics const& font_metrics, FontMetrics const& root_font_metrics) const;
|
||||
CSSPixels viewport_relative_length_to_px(CSSPixelRect const& viewport_rect) const;
|
||||
|
||||
// Returns empty optional if it's already absolute.
|
||||
Optional<Length> absolutize(CSSPixelRect const& viewport_rect, FontMetrics const& font_metrics, FontMetrics const& root_font_metrics) const;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue