mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-11 18:20:43 +09:00
LibWeb: Add a way to resolve calc() values without a layout node
Instead of a layout node, you can pass a new Length::ResolutionContext struct which contains everything needed to resolve calc() lengths.
This commit is contained in:
parent
2ade229f27
commit
df8a96ee00
Notes:
sideshowbarker
2024-07-17 05:41:34 +09:00
Author: https://github.com/awesomekling
Commit: df8a96ee00
Pull-request: https://github.com/SerenityOS/serenity/pull/19227
Reviewed-by: https://github.com/AtkinsSJ ✅
5 changed files with 107 additions and 75 deletions
|
@ -144,6 +144,23 @@ CSSPixels Length::viewport_relative_length_to_px(CSSPixelRect const& viewport_re
|
|||
}
|
||||
}
|
||||
|
||||
Length::ResolutionContext Length::ResolutionContext::for_layout_node(Layout::Node const& node)
|
||||
{
|
||||
auto const* root_element = node.document().document_element();
|
||||
VERIFY(root_element);
|
||||
VERIFY(root_element->layout_node());
|
||||
return Length::ResolutionContext {
|
||||
.viewport_rect = node.browsing_context().viewport_rect(),
|
||||
.font_metrics = { node.computed_values().font_size(), node.font().pixel_metrics(), node.line_height() },
|
||||
.root_font_metrics = { root_element->layout_node()->computed_values().font_size(), root_element->layout_node()->font().pixel_metrics(), root_element->layout_node()->line_height() },
|
||||
};
|
||||
}
|
||||
|
||||
CSSPixels Length::to_px(ResolutionContext const& context) const
|
||||
{
|
||||
return to_px(context.viewport_rect, context.font_metrics, context.root_font_metrics);
|
||||
}
|
||||
|
||||
CSSPixels Length::to_px(Layout::Node const& layout_node) const
|
||||
{
|
||||
if (is_auto()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue