Truly independent web browser
LibWeb: Don't expect a parent for a root's moved custom properties
Andreas Klinga1d70de9a988
diff --git a/Libraries/LibWeb/DOM/Element.cpp b/Libraries/LibWeb/DOM/Element.cppindex 7e38d580046..916c3bc8409 100644--- a/Libraries/LibWeb/DOM/Element.cpp+++ b/Libraries/LibWeb/DOM/Element.cpp@@ -1971,16 +1971,19 @@ RefPtr<CSS::CustomPropertyData const> Element::style_custom_property_environment// NB: Where the animations of the element's parent sample custom properties, the parent holds their composition// over the environment the style engine resolved the element's over. The element inherits the composition, and// its own declarations stand over it, as when the animations move the parent's environment.+ // NB: An environment names the environment it was resolved over last, which a descendant holding the store can have+ // moved. So this also comes to the root, whose declarations stand over nothing.auto parent = DOM::AbstractElement { const_cast<Element&>(*this) }.element_to_inherit_style_from();- VERIFY(parent.has_value());auto& style_computer = document().style_computer();auto& style_engine = style_computer.style_engine();RefPtr<CSS::CustomPropertyData const> inherited_data;- if (auto parent_data = parent->custom_property_data())- inherited_data = parent_data->inheritable(read, document());- auto const parent_identity = parent->installed_style().custom_property_environment();- if (identity == CSS::StyleEngineFFI::style_engine_inheritable_custom_property_environment(style_engine.host(), &read, parent_identity))- return inherited_data;+ if (parent.has_value()) {+ if (auto parent_data = parent->custom_property_data())+ inherited_data = parent_data->inheritable(read, document());+ auto const parent_identity = parent->installed_style().custom_property_environment();+ if (identity == CSS::StyleEngineFFI::style_engine_inheritable_custom_property_environment(style_engine.host(), &read, parent_identity))+ return inherited_data;+ }auto declarations = style_computer.engine_custom_property_declarations_over(read, identity, inherited_data);VERIFY(declarations);return declarations;diff --git a/Tests/LibWeb/Text/expected/css/custom-property-store-of-root-resolved-over-descendant-parent.txt b/Tests/LibWeb/Text/expected/css/custom-property-store-of-root-resolved-over-descendant-parent.txtnew file mode 100644index 00000000000..a9f793854ab--- /dev/null+++ b/Tests/LibWeb/Text/expected/css/custom-property-store-of-root-resolved-over-descendant-parent.txt@@ -0,0 +1,3 @@+html: 0+div: 0+option: 0diff --git a/Tests/LibWeb/Text/input/css/custom-property-store-of-root-resolved-over-descendant-parent.html b/Tests/LibWeb/Text/input/css/custom-property-store-of-root-resolved-over-descendant-parent.htmlnew file mode 100644index 00000000000..ce08d863264--- /dev/null+++ b/Tests/LibWeb/Text/input/css/custom-property-store-of-root-resolved-over-descendant-parent.html@@ -0,0 +1,47 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<script>+ // The root takes a store a descendant then holds over another parent's environment, in one style update.+ asyncTest(async done => {+ const nextFrame = () => new Promise(resolve => requestAnimationFrame(resolve));+ const readStyles = () => {+ for (const element of document.querySelectorAll("html, body, body *"))+ getComputedStyle(element).getPropertyValue("--value");+ };++ const parent = document.createElement("div");+ document.body.append(parent);+ document.body.append(document.createElement("details"));+ const child = document.createElement("option");+ child.className = "marked";+ parent.append(child);++ for (const text of [+ "* { --value: 0; }",+ "@media (prefers-color-scheme: light) { :is(.marked, .other) { --value: 1; } }",+ ]) {+ const style = document.createElement("style");+ style.textContent = text;+ document.head.append(style);+ }+ await nextFrame();++ document.documentElement.classList.add("marked");+ document.head.style.display = "block";+ document.documentElement.cloneNode(true);+ readStyles();+ document.head.removeAttribute("style");++ internals.setPreferredColorScheme("dark");+ await nextFrame();+ internals.setPreferredColorScheme("light");+ await nextFrame();+ internals.setPreferredColorScheme("dark");+ await nextFrame();+ await nextFrame();++ for (const element of [document.documentElement, parent, child])+ println(`${element.localName}: ${getComputedStyle(element).getPropertyValue("--value")}`);+ done();+ });+</script>