mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-01 13:49:16 +00:00
LibWeb: Allow creating Length::ResolutionContext
with provided root
Previously we could not create a `Length::ResolutionContext` using the `for_layout_node` method if the provided node's document did not have a layout node. We now provide a workaround for this in the case that the provided layout is that root layout node. This is useful for instance if we want to create a length resolution context when calling `NodeWithStyle::apply_style` on the root node.
This commit is contained in:
parent
1fd0bf9feb
commit
b468923372
Notes:
github-actions[bot]
2025-07-04 12:20:21 +00:00
Author: https://github.com/Calme1709
Commit: b468923372
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5284
Reviewed-by: https://github.com/AtkinsSJ ✅
1 changed files with 12 additions and 4 deletions
|
@ -151,13 +151,21 @@ Length::ResolutionContext Length::ResolutionContext::for_window(HTML::Window con
|
|||
|
||||
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());
|
||||
Layout::Node const* root_layout_node;
|
||||
|
||||
if (is<DOM::Document>(node.dom_node())) {
|
||||
root_layout_node = &node;
|
||||
} else {
|
||||
auto const* root_element = node.document().document_element();
|
||||
VERIFY(root_element);
|
||||
VERIFY(root_element->layout_node());
|
||||
root_layout_node = root_element->layout_node();
|
||||
}
|
||||
|
||||
return Length::ResolutionContext {
|
||||
.viewport_rect = node.navigable()->viewport_rect(),
|
||||
.font_metrics = { node.computed_values().font_size(), node.first_available_font().pixel_metrics() },
|
||||
.root_font_metrics = { root_element->layout_node()->computed_values().font_size(), root_element->layout_node()->first_available_font().pixel_metrics() },
|
||||
.root_font_metrics = { root_layout_node->computed_values().font_size(), root_layout_node->first_available_font().pixel_metrics() },
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue