Truly independent web browser
LibWeb: Render object elements in shadow trees
sideshowbarker12a02828e34a
diff --git a/Libraries/LibWeb/HTML/HTMLObjectElement.cpp b/Libraries/LibWeb/HTML/HTMLObjectElement.cppindex b91c986ca43..20e0346cb9b 100644--- a/Libraries/LibWeb/HTML/HTMLObjectElement.cpp+++ b/Libraries/LibWeb/HTML/HTMLObjectElement.cpp@@ -500,7 +500,12 @@ void HTMLObjectElement::run_object_representation_handler_steps(Fetch::Infrastru}// If the object element's content navigable is null, then create a new child navigable for the element.- if (!m_content_navigable && in_a_document_tree()) {+ // AD-HOC: The spec only gets here for an element "in a document", a legacy term that its use here hasn't been+ // updated for shadow trees:+ // https://dom.spec.whatwg.org/#in-a-document+ // So an object in a shadow tree gets its navigable once it's connected, the same as one in the document+ // tree.+ if (!m_content_navigable && is_connected()) {create_new_child_navigable();}@@ -639,8 +644,9 @@ void HTMLObjectElement::update_layout_and_child_objects(Representation representCSS::record_element_box_kind(*this);CSS::record_element_replaced_content_input(*this);- if (auto parent_element = this->parent_element())- parent_element->set_needs_layout_tree_update(true, DOM::SetNeedsLayoutTreeUpdateReason::HTMLObjectElementUpdateLayoutAndChildObjects);+ // NB: The parent is a shadow root for an object at the top of a shadow tree, so it's not always an element.+ if (auto parent = this->parent())+ parent->set_needs_layout_tree_update(true, DOM::SetNeedsLayoutTreeUpdateReason::HTMLObjectElementUpdateLayoutAndChildObjects);}// https://html.spec.whatwg.org/multipage/interaction.html#dom-tabindexdiff --git a/Tests/LibWeb/TestConfig.ini b/Tests/LibWeb/TestConfig.iniindex 673c95781e2..d9715986f00 100644--- a/Tests/LibWeb/TestConfig.ini+++ b/Tests/LibWeb/TestConfig.ini@@ -14,6 +14,7 @@ Text/input/replaced/embed-window-stop-during-fetch.htmlText/input/replaced/embed-window-stop-during-body.htmlText/input/replaced/embed-removed-during-body.htmlText/input/replaced/embed-in-shadow-tree.html+Text/input/replaced/object-in-shadow-tree.htmlText/input/HTML/HTMLObjectElement-window-stop-during-fetch.htmlText/input/HTML/HTMLObjectElement-window-stop-during-body.htmlText/input/wpt-import/html/semantics/embedded-content/the-embed-element/embed-ignored-in-media-element.htmldiff --git a/Tests/LibWeb/Text/expected/replaced/object-in-shadow-tree.txt b/Tests/LibWeb/Text/expected/replaced/object-in-shadow-tree.txtnew file mode 100644index 00000000000..ab0cc302554--- /dev/null+++ b/Tests/LibWeb/Text/expected/replaced/object-in-shadow-tree.txt@@ -0,0 +1,2 @@+document object in a shadow tree: 300x150, contentDocument true+image object in a shadow tree: 16x16diff --git a/Tests/LibWeb/Text/input/replaced/object-in-shadow-tree.html b/Tests/LibWeb/Text/input/replaced/object-in-shadow-tree.htmlnew file mode 100644index 00000000000..4c2bfd503de--- /dev/null+++ b/Tests/LibWeb/Text/input/replaced/object-in-shadow-tree.html@@ -0,0 +1,21 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<div id="document-host"></div>+<div id="image-host"></div>+<script>+ promiseTest(async () => {+ const loadedObject = (host, data) => {+ const object = document.createElement("object");+ const loaded = new Promise(resolve => object.addEventListener("load", resolve, { once: true }));+ object.data = data;+ host.attachShadow({ mode: "open" }).append(object);+ return loaded.then(() => object);+ };+ const [documentObject, imageObject] = await Promise.all([+ loadedObject(document.getElementById("document-host"), "../../data/blank.html"),+ loadedObject(document.getElementById("image-host"), "../wpt-import/images/green-16x16.png"),+ ]);+ println(`document object in a shadow tree: ${documentObject.offsetWidth}x${documentObject.offsetHeight}, contentDocument ${documentObject.contentDocument !== null}`);+ println(`image object in a shadow tree: ${imageObject.offsetWidth}x${imageObject.offsetHeight}`);+ });+</script>