diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index f180ab6fe5..da2c43b674 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -1160,7 +1160,7 @@ void Document::update_layout() if (needs_full_style_update || node.child_needs_style_update()) { if (node.is_element()) { - if (auto* shadow_root = static_cast(node).shadow_root_internal()) { + if (auto shadow_root = static_cast(node).shadow_root()) { if (needs_full_style_update || shadow_root->needs_style_update() || shadow_root->child_needs_style_update()) { auto subtree_invalidation = update_style_recursively(*shadow_root, style_computer); if (!is_display_none) diff --git a/Userland/Libraries/LibWeb/DOM/Element.cpp b/Userland/Libraries/LibWeb/DOM/Element.cpp index 732d3da2f5..b46fe5b828 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.cpp +++ b/Userland/Libraries/LibWeb/DOM/Element.cpp @@ -675,7 +675,6 @@ WebIDL::ExceptionOr Element::attach_a_shadow_root(Bindings::ShadowRootMode // 12. Set element’s shadow root to shadow. set_shadow_root(shadow); - return {}; } @@ -690,7 +689,7 @@ WebIDL::ExceptionOr> Element::attach_shadow(ShadowR } // https://dom.spec.whatwg.org/#dom-element-shadowroot -JS::GCPtr Element::shadow_root() const +JS::GCPtr Element::shadow_root_for_bindings() const { // 1. Let shadow be this’s shadow root. auto shadow = m_shadow_root; diff --git a/Userland/Libraries/LibWeb/DOM/Element.h b/Userland/Libraries/LibWeb/DOM/Element.h index 9ba8e0deed..eaad8bb57c 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.h +++ b/Userland/Libraries/LibWeb/DOM/Element.h @@ -129,7 +129,7 @@ public: WebIDL::ExceptionOr> attach_shadow(ShadowRootInit init); WebIDL::ExceptionOr attach_a_shadow_root(Bindings::ShadowRootMode mode, bool clonable, bool serializable, bool delegates_focus, Bindings::SlotAssignmentMode slot_assignment); - JS::GCPtr shadow_root() const; + JS::GCPtr shadow_root_for_bindings() const; WebIDL::ExceptionOr matches(StringView selectors) const; WebIDL::ExceptionOr closest(StringView selectors) const; @@ -195,8 +195,8 @@ public: JS::NonnullGCPtr get_elements_by_class_name(StringView); bool is_shadow_host() const; - ShadowRoot* shadow_root_internal() { return m_shadow_root.ptr(); } - ShadowRoot const* shadow_root_internal() const { return m_shadow_root.ptr(); } + JS::GCPtr shadow_root() { return m_shadow_root; } + JS::GCPtr shadow_root() const { return m_shadow_root; } void set_shadow_root(JS::GCPtr); void set_custom_properties(Optional, HashMap custom_properties); diff --git a/Userland/Libraries/LibWeb/DOM/Element.idl b/Userland/Libraries/LibWeb/DOM/Element.idl index 8c8d18ac7b..2ccf35f352 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.idl +++ b/Userland/Libraries/LibWeb/DOM/Element.idl @@ -54,7 +54,7 @@ interface Element : Node { [CEReactions] Attr removeAttributeNode(Attr attr); ShadowRoot attachShadow(ShadowRootInit init); - readonly attribute ShadowRoot? shadowRoot; + [ImplementedAs=shadow_root_for_bindings] readonly attribute ShadowRoot? shadowRoot; boolean matches(DOMString selectors); Element? closest(DOMString selectors); diff --git a/Userland/Libraries/LibWeb/DOM/Node.cpp b/Userland/Libraries/LibWeb/DOM/Node.cpp index fe5a37374d..27168750c0 100644 --- a/Userland/Libraries/LibWeb/DOM/Node.cpp +++ b/Userland/Libraries/LibWeb/DOM/Node.cpp @@ -275,7 +275,7 @@ void Node::invalidate_style() node.m_needs_style_update = true; if (node.has_children()) node.m_child_needs_style_update = true; - if (auto* shadow_root = node.is_element() ? static_cast(node).shadow_root_internal() : nullptr) { + if (auto shadow_root = node.is_element() ? static_cast(node).shadow_root() : nullptr) { node.m_child_needs_style_update = true; shadow_root->m_needs_style_update = true; if (shadow_root->has_children()) @@ -462,7 +462,7 @@ void Node::insert_before(JS::NonnullGCPtr node, JS::GCPtr child, boo auto& element = static_cast(*this); auto is_named_shadow_host = element.is_shadow_host() - && element.shadow_root_internal()->slot_assignment() == Bindings::SlotAssignmentMode::Named; + && element.shadow_root()->slot_assignment() == Bindings::SlotAssignmentMode::Named; if (is_named_shadow_host && node_to_insert->is_slottable()) assign_a_slot(node_to_insert->as_slottable()); @@ -914,7 +914,7 @@ WebIDL::ExceptionOr> Node::clone_node(Document* document, // 2. Run attach a shadow root with copy, node’s shadow root’s mode, true, node’s shadow root’s serializable, // node’s shadow root’s delegates focus, and node’s shadow root’s slot assignment. - auto& node_shadow_root = *static_cast(*this).shadow_root(); + auto& node_shadow_root = *static_cast(*this).shadow_root(); TRY(static_cast(*copy).attach_a_shadow_root(node_shadow_root.mode(), true, node_shadow_root.serializable(), node_shadow_root.delegates_focus(), node_shadow_root.slot_assignment())); // 3. Set copy’s shadow root’s declarative to node’s shadow root’s declarative. @@ -1260,7 +1260,7 @@ void Node::serialize_tree_as_json(JsonObjectSerializer& object) c element->serialize_pseudo_elements_as_json(children); if (element->is_shadow_host()) - add_child(*element->shadow_root_internal()); + add_child(*element->shadow_root()); } MUST(children.finish()); diff --git a/Userland/Libraries/LibWeb/DOM/ShadowRoot.h b/Userland/Libraries/LibWeb/DOM/ShadowRoot.h index f8753eaede..e7a86a7116 100644 --- a/Userland/Libraries/LibWeb/DOM/ShadowRoot.h +++ b/Userland/Libraries/LibWeb/DOM/ShadowRoot.h @@ -100,7 +100,7 @@ inline TraversalDecision Node::for_each_shadow_including_inclusive_descendant(Ca return TraversalDecision::Break; for (auto* child = first_child(); child; child = child->next_sibling()) { if (child->is_element()) { - if (JS::GCPtr shadow_root = static_cast(child)->shadow_root_internal()) { + if (auto shadow_root = static_cast(child)->shadow_root()) { if (shadow_root->for_each_shadow_including_inclusive_descendant(callback) == TraversalDecision::Break) return TraversalDecision::Break; } diff --git a/Userland/Libraries/LibWeb/DOM/Slottable.cpp b/Userland/Libraries/LibWeb/DOM/Slottable.cpp index fb4e93e3b1..5e5ce160e5 100644 --- a/Userland/Libraries/LibWeb/DOM/Slottable.cpp +++ b/Userland/Libraries/LibWeb/DOM/Slottable.cpp @@ -61,7 +61,7 @@ JS::GCPtr find_a_slot(Slottable const& slottable, OpenFla return nullptr; // 2. Let shadow be slottable’s parent’s shadow root. - auto* shadow = parent->shadow_root_internal(); + auto shadow = parent->shadow_root(); // 3. If shadow is null, then return null. if (shadow == nullptr) diff --git a/Userland/Libraries/LibWeb/Dump.cpp b/Userland/Libraries/LibWeb/Dump.cpp index 93cdc187a2..37499f5150 100644 --- a/Userland/Libraries/LibWeb/Dump.cpp +++ b/Userland/Libraries/LibWeb/Dump.cpp @@ -97,7 +97,7 @@ void dump_tree(StringBuilder& builder, DOM::Node const& node) } ++indent; if (is(node)) { - if (auto* shadow_root = static_cast(node).shadow_root_internal()) { + if (auto shadow_root = static_cast(node).shadow_root()) { dump_tree(builder, *shadow_root); } } diff --git a/Userland/Libraries/LibWeb/HTML/Focus.cpp b/Userland/Libraries/LibWeb/HTML/Focus.cpp index 6ccb25a908..20aee90cc0 100644 --- a/Userland/Libraries/LibWeb/HTML/Focus.cpp +++ b/Userland/Libraries/LibWeb/HTML/Focus.cpp @@ -241,7 +241,7 @@ void run_unfocusing_steps(DOM::Node* old_focus_target) // context's DOM anchor, then set old focus target to that currently focused area of a top-level browsing // context. if (is_shadow_host(old_focus_target)) { - auto* shadow_root = static_cast(old_focus_target)->shadow_root_internal(); + auto shadow_root = static_cast(old_focus_target)->shadow_root(); if (shadow_root->delegates_focus()) { auto top_level_traversable = old_focus_target->document().browsing_context()->top_level_traversable(); if (auto currently_focused_area = top_level_traversable->currently_focused_area()) { diff --git a/Userland/Libraries/LibWeb/HTML/HTMLDetailsElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLDetailsElement.cpp index fd2c45f35a..76b99bf9e5 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLDetailsElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLDetailsElement.cpp @@ -119,7 +119,7 @@ void HTMLDetailsElement::queue_a_details_toggle_event_task(String old_state, Str // https://html.spec.whatwg.org/#the-details-and-summary-elements WebIDL::ExceptionOr HTMLDetailsElement::create_shadow_tree_if_needed() { - if (shadow_root_internal()) + if (shadow_root()) return {}; auto& realm = this->realm(); @@ -145,7 +145,7 @@ WebIDL::ExceptionOr HTMLDetailsElement::create_shadow_tree_if_needed() void HTMLDetailsElement::update_shadow_tree_slots() { - if (!shadow_root_internal()) + if (!shadow_root()) return; Vector summary_assignment; @@ -177,7 +177,7 @@ void HTMLDetailsElement::update_shadow_tree_slots() // https://html.spec.whatwg.org/#the-details-and-summary-elements:the-details-element-6 void HTMLDetailsElement::update_shadow_tree_style() { - if (!shadow_root_internal()) + if (!shadow_root()) return; if (has_attribute(HTML::AttributeNames::open)) { diff --git a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp index 760ef99169..be3a54bbd7 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp @@ -721,7 +721,7 @@ Optional HTMLInputElement::placeholder_value() const void HTMLInputElement::create_shadow_tree_if_needed() { - if (shadow_root_internal()) + if (shadow_root()) return; switch (type_state()) { diff --git a/Userland/Libraries/LibWeb/HTML/HTMLMeterElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLMeterElement.cpp index 9493d7f1f0..290c909e67 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLMeterElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLMeterElement.cpp @@ -179,7 +179,7 @@ void HTMLMeterElement::removed_from(DOM::Node*) void HTMLMeterElement::create_shadow_tree_if_needed() { - if (shadow_root_internal()) + if (shadow_root()) return; auto shadow_root = heap().allocate(realm(), document(), *this, Bindings::ShadowRootMode::Closed); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLProgressElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLProgressElement.cpp index c5d643fa4d..2af5bed8a0 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLProgressElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLProgressElement.cpp @@ -97,7 +97,7 @@ void HTMLProgressElement::removed_from(DOM::Node*) void HTMLProgressElement::create_shadow_tree_if_needed() { - if (shadow_root_internal()) + if (shadow_root()) return; auto shadow_root = heap().allocate(realm(), document(), *this, Bindings::ShadowRootMode::Closed); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.cpp index bee35291fd..307503caef 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.cpp @@ -437,7 +437,7 @@ void HTMLSelectElement::computed_css_values_changed() void HTMLSelectElement::create_shadow_tree_if_needed() { - if (shadow_root_internal()) + if (shadow_root()) return; auto shadow_root = heap().allocate(realm(), document(), *this, Bindings::ShadowRootMode::Closed); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTextAreaElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLTextAreaElement.cpp index bdbd180d5e..01b8fca9fd 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTextAreaElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLTextAreaElement.cpp @@ -334,7 +334,7 @@ WebIDL::ExceptionOr HTMLTextAreaElement::set_rows(unsigned rows) void HTMLTextAreaElement::create_shadow_tree_if_needed() { - if (shadow_root_internal()) + if (shadow_root()) return; auto shadow_root = heap().allocate(realm(), document(), *this, Bindings::ShadowRootMode::Closed); diff --git a/Userland/Libraries/LibWeb/Layout/TreeBuilder.cpp b/Userland/Libraries/LibWeb/Layout/TreeBuilder.cpp index b1ae2434dd..d9aa1a43eb 100644 --- a/Userland/Libraries/LibWeb/Layout/TreeBuilder.cpp +++ b/Userland/Libraries/LibWeb/Layout/TreeBuilder.cpp @@ -372,7 +372,7 @@ void TreeBuilder::create_layout_tree(DOM::Node& dom_node, TreeBuilder::Context& insert_node_into_inline_or_block_ancestor(*layout_node, display, AppendOrPrepend::Append); } - auto* shadow_root = is(dom_node) ? verify_cast(dom_node).shadow_root_internal() : nullptr; + auto shadow_root = is(dom_node) ? verify_cast(dom_node).shadow_root() : nullptr; // Add node for the ::before pseudo-element. if (is(dom_node) && layout_node->can_have_children()) { diff --git a/Userland/Libraries/LibWeb/SVG/SVGUseElement.cpp b/Userland/Libraries/LibWeb/SVG/SVGUseElement.cpp index dedccee460..4ae7ff95cd 100644 --- a/Userland/Libraries/LibWeb/SVG/SVGUseElement.cpp +++ b/Userland/Libraries/LibWeb/SVG/SVGUseElement.cpp @@ -126,12 +126,12 @@ JS::GCPtr SVGUseElement::referenced_element() // https://svgwg.org/svg2-draft/struct.html#UseShadowTree void SVGUseElement::clone_element_tree_as_our_shadow_tree(Element* to_clone) const { - shadow_root()->remove_all_children(); + const_cast(*shadow_root()).remove_all_children(); if (to_clone && is_valid_reference_element(to_clone)) { // The ‘use’ element references another element, a copy of which is rendered in place of the ‘use’ in the document. auto cloned_reference_node = MUST(to_clone->clone_node(nullptr, true)); - shadow_root()->append_child(cloned_reference_node).release_value_but_fixme_should_propagate_errors(); + const_cast(*shadow_root()).append_child(cloned_reference_node).release_value_but_fixme_should_propagate_errors(); } } @@ -177,7 +177,7 @@ JS::NonnullGCPtr SVGUseElement::height() const // https://svgwg.org/svg2-draft/struct.html#TermInstanceRoot JS::GCPtr SVGUseElement::instance_root() const { - return shadow_root()->first_child_of_type(); + return const_cast(*shadow_root()).first_child_of_type(); } JS::GCPtr SVGUseElement::animated_instance_root() const diff --git a/Userland/Services/WebContent/WebDriverConnection.cpp b/Userland/Services/WebContent/WebDriverConnection.cpp index bb45e0e442..c5859cf9cf 100644 --- a/Userland/Services/WebContent/WebDriverConnection.cpp +++ b/Userland/Services/WebContent/WebDriverConnection.cpp @@ -1018,7 +1018,7 @@ Messages::WebDriverClient::GetElementShadowRootResponse WebDriverConnection::get auto* element = TRY(get_known_connected_element(element_id)); // 4. Let shadow root be element's shadow root. - auto* shadow_root = element->shadow_root_internal(); + auto shadow_root = element->shadow_root(); // 5. If shadow root is null, return error with error code no such shadow root. if (!shadow_root)