Truly independent web browser
LibWeb: Paint the root background only for the document element
sideshowbarkerd3c7355ce7d1
diff --git a/Libraries/LibWeb/Rust/src/painting/style_queries.rs b/Libraries/LibWeb/Rust/src/painting/style_queries.rsindex 2cbeff6d72a..0ac8e3983b4 100644--- a/Libraries/LibWeb/Rust/src/painting/style_queries.rs+++ b/Libraries/LibWeb/Rust/src/painting/style_queries.rs@@ -244,7 +244,11 @@ pub(crate) fn document_element_box_under(arena: &impl PaintRead, parent: NodeSlopub(crate) fn node_is_root_element(arena: &impl PaintRead, node: NodeSlotId) -> bool {let flags = arena.node_flags_if_live(node);- flags & NodeFlag::Anonymous as u32 == 0 && flags & NodeFlag::IsHtmlHtmlElement as u32 != 0+ // NB: Only the document element is the root: An html element anywhere else, e.g. in a shadow tree, is an+ // ordinary element.+ flags & NodeFlag::Anonymous as u32 == 0+ && flags & NodeFlag::IsHtmlHtmlElement as u32 != 0+ && flags & NodeFlag::IsDocumentElement as u32 != 0}fn style_establishes_fixed_positioning_containing_block(diff --git a/Tests/LibWeb/Ref/expected/nested-html-element-does-not-paint-root-background-ref.html b/Tests/LibWeb/Ref/expected/nested-html-element-does-not-paint-root-background-ref.htmlnew file mode 100644index 00000000000..ab21dbe9a18--- /dev/null+++ b/Tests/LibWeb/Ref/expected/nested-html-element-does-not-paint-root-background-ref.html@@ -0,0 +1,6 @@+<!DOCTYPE html>+<style>+ body { margin: 0; background: #fd0; }+ main { height: 100px; margin: 20px; background: #39c; }+</style>+<main></main>diff --git a/Tests/LibWeb/Ref/input/nested-html-element-does-not-paint-root-background.html b/Tests/LibWeb/Ref/input/nested-html-element-does-not-paint-root-background.htmlnew file mode 100644index 00000000000..fe37fa38386--- /dev/null+++ b/Tests/LibWeb/Ref/input/nested-html-element-does-not-paint-root-background.html@@ -0,0 +1,17 @@+<!DOCTYPE html>+<link rel="match" href="../expected/nested-html-element-does-not-paint-root-background-ref.html">+<style>+ body { margin: 0; background: #fd0; }+ main { height: 100px; margin: 20px; background: #39c; }+</style>+<main></main>+<div id="light"></div>+<div id="host"></div>+<script>+ // Neither html element is the document element, so neither paints the body's background over the canvas.+ document.getElementById("light").append(document.createElement("html"));+ const root = document.getElementById("host").attachShadow({ mode: "open" });+ const html = document.createElement("html");+ html.append(document.createElement("body"));+ root.append(html);+</script>