LibWeb: Always blockify the root element

This is what the spec tells us to do:

    The root element’s display type is always blockified,
    and its principal box always establishes an independent
    formatting context.

    Additionally, a display of contents computes to block
    on the root element.

Spec link: https://drafts.csswg.org/css-display/#root

Fixes #1562
This commit is contained in:
Andreas Kling 2024-09-29 10:54:46 +02:00 committed by Andreas Kling
commit f1be662f68
Notes: github-actions[bot] 2024-09-29 09:47:03 +00:00
12 changed files with 44 additions and 12 deletions

View file

@ -2177,9 +2177,17 @@ void StyleComputer::transform_box_type_if_needed(StyleProperties& style, DOM::El
// (This has no effect on display types that generate no box at all, such as none or contents.)
auto display = style.display();
if (display.is_none() || display.is_contents())
if (display.is_none() || (display.is_contents() && !element.is_document_element()))
return;
// https://drafts.csswg.org/css-display/#root
// The root elements display type is always blockified, and its principal box always establishes an independent formatting context.
if (element.is_document_element() && !display.is_block_outside()) {
style.set_property(CSS::PropertyID::Display, DisplayStyleValue::create(Display::from_short(CSS::Display::Short::Block)));
return;
}
auto new_display = display;
if (display.is_math_inside()) {