LibWeb: Don't crash if the document element is not visible

Previously, setting the `hidden` property on the `<html>` element would
cause a crash.
This commit is contained in:
Tim Ledbetter 2024-04-22 19:36:39 +01:00 committed by Andreas Kling
parent dd73cccf8f
commit 3aea14093f
Notes: sideshowbarker 2024-07-16 21:42:29 +09:00
3 changed files with 11 additions and 3 deletions

View File

@ -0,0 +1,3 @@
Viewport <#document> at (0,0) content-size 800x600 children: not-inline
ViewportPaintable (Viewport<#document>) [0,0 800x600]

View File

@ -0,0 +1,5 @@
<html hidden>
<body>
<div>Test passes if we don't crash</div>
</body>
</html>

View File

@ -1058,13 +1058,14 @@ void Document::update_layout()
if (!navigable)
return;
auto* document_element = this->document_element();
auto viewport_rect = this->viewport_rect();
if (!m_layout_root) {
Layout::TreeBuilder tree_builder;
m_layout_root = verify_cast<Layout::Viewport>(*tree_builder.build(*this));
if (auto* document_element = this->document_element()) {
if (document_element && document_element->layout_node()) {
propagate_overflow_to_viewport(*document_element, *m_layout_root);
}
}
@ -1079,8 +1080,7 @@ void Document::update_layout()
viewport_state.set_content_width(viewport_rect.width());
viewport_state.set_content_height(viewport_rect.height());
if (auto* document_element = this->document_element()) {
VERIFY(document_element->layout_node());
if (document_element && document_element->layout_node()) {
auto& icb_state = layout_state.get_mutable(verify_cast<Layout::NodeWithStyleAndBoxModelMetrics>(*document_element->layout_node()));
icb_state.set_content_width(viewport_rect.width());
}