1
0
mirror of https://github.com/SerenityOS/serenity synced 2024-07-09 09:00:46 +00:00

LibWeb: Rename Element::shadow_root_internal() to shadow_root()

And let the old shadow_root(), which was only supposed to be used by
bindings, be called shadow_root_for_bindings() instead.

This makes it much easier to read DOM code, and we don't have to worry
about when to use shadow_root_internal() or why.

(cherry picked from commit f4bdf562127c12a7af18029777a88d4260af82d3)
This commit is contained in:
Andreas Kling 2024-06-25 11:28:58 +02:00 committed by Nico Weber
parent 1c5f0e8daf
commit c8206fa070
18 changed files with 27 additions and 28 deletions

View File

@ -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<DOM::Element&>(node).shadow_root_internal()) {
if (auto shadow_root = static_cast<DOM::Element&>(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)

View File

@ -675,7 +675,6 @@ WebIDL::ExceptionOr<void> Element::attach_a_shadow_root(Bindings::ShadowRootMode
// 12. Set elements shadow root to shadow.
set_shadow_root(shadow);
return {};
}
@ -690,7 +689,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<ShadowRoot>> Element::attach_shadow(ShadowR
}
// https://dom.spec.whatwg.org/#dom-element-shadowroot
JS::GCPtr<ShadowRoot> Element::shadow_root() const
JS::GCPtr<ShadowRoot> Element::shadow_root_for_bindings() const
{
// 1. Let shadow be thiss shadow root.
auto shadow = m_shadow_root;

View File

@ -129,7 +129,7 @@ public:
WebIDL::ExceptionOr<JS::NonnullGCPtr<ShadowRoot>> attach_shadow(ShadowRootInit init);
WebIDL::ExceptionOr<void> attach_a_shadow_root(Bindings::ShadowRootMode mode, bool clonable, bool serializable, bool delegates_focus, Bindings::SlotAssignmentMode slot_assignment);
JS::GCPtr<ShadowRoot> shadow_root() const;
JS::GCPtr<ShadowRoot> shadow_root_for_bindings() const;
WebIDL::ExceptionOr<bool> matches(StringView selectors) const;
WebIDL::ExceptionOr<DOM::Element const*> closest(StringView selectors) const;
@ -195,8 +195,8 @@ public:
JS::NonnullGCPtr<HTMLCollection> 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<ShadowRoot> shadow_root() { return m_shadow_root; }
JS::GCPtr<ShadowRoot const> shadow_root() const { return m_shadow_root; }
void set_shadow_root(JS::GCPtr<ShadowRoot>);
void set_custom_properties(Optional<CSS::Selector::PseudoElement::Type>, HashMap<FlyString, CSS::StyleProperty> custom_properties);

View File

@ -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);

View File

@ -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<DOM::Element&>(node).shadow_root_internal() : nullptr) {
if (auto shadow_root = node.is_element() ? static_cast<DOM::Element&>(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> node, JS::GCPtr<Node> child, boo
auto& element = static_cast<DOM::Element&>(*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<JS::NonnullGCPtr<Node>> Node::clone_node(Document* document,
// 2. Run attach a shadow root with copy, nodes shadow roots mode, true, nodes shadow roots serializable,
// nodes shadow roots delegates focus, and nodes shadow roots slot assignment.
auto& node_shadow_root = *static_cast<Element const&>(*this).shadow_root();
auto& node_shadow_root = *static_cast<Element&>(*this).shadow_root();
TRY(static_cast<Element&>(*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 copys shadow roots declarative to nodes shadow roots declarative.
@ -1260,7 +1260,7 @@ void Node::serialize_tree_as_json(JsonObjectSerializer<StringBuilder>& 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());

View File

@ -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<ShadowRoot> shadow_root = static_cast<Element*>(child)->shadow_root_internal()) {
if (auto shadow_root = static_cast<Element*>(child)->shadow_root()) {
if (shadow_root->for_each_shadow_including_inclusive_descendant(callback) == TraversalDecision::Break)
return TraversalDecision::Break;
}

View File

@ -61,7 +61,7 @@ JS::GCPtr<HTML::HTMLSlotElement> find_a_slot(Slottable const& slottable, OpenFla
return nullptr;
// 2. Let shadow be slottables parents shadow root.
auto* shadow = parent->shadow_root_internal();
auto shadow = parent->shadow_root();
// 3. If shadow is null, then return null.
if (shadow == nullptr)

View File

@ -97,7 +97,7 @@ void dump_tree(StringBuilder& builder, DOM::Node const& node)
}
++indent;
if (is<DOM::Element>(node)) {
if (auto* shadow_root = static_cast<DOM::Element const&>(node).shadow_root_internal()) {
if (auto shadow_root = static_cast<DOM::Element const&>(node).shadow_root()) {
dump_tree(builder, *shadow_root);
}
}

View File

@ -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<DOM::Element*>(old_focus_target)->shadow_root_internal();
auto shadow_root = static_cast<DOM::Element*>(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()) {

View File

@ -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<void> HTMLDetailsElement::create_shadow_tree_if_needed()
{
if (shadow_root_internal())
if (shadow_root())
return {};
auto& realm = this->realm();
@ -145,7 +145,7 @@ WebIDL::ExceptionOr<void> HTMLDetailsElement::create_shadow_tree_if_needed()
void HTMLDetailsElement::update_shadow_tree_slots()
{
if (!shadow_root_internal())
if (!shadow_root())
return;
Vector<HTMLSlotElement::SlottableHandle> 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)) {

View File

@ -721,7 +721,7 @@ Optional<String> HTMLInputElement::placeholder_value() const
void HTMLInputElement::create_shadow_tree_if_needed()
{
if (shadow_root_internal())
if (shadow_root())
return;
switch (type_state()) {

View File

@ -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<DOM::ShadowRoot>(realm(), document(), *this, Bindings::ShadowRootMode::Closed);

View File

@ -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<DOM::ShadowRoot>(realm(), document(), *this, Bindings::ShadowRootMode::Closed);

View File

@ -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<DOM::ShadowRoot>(realm(), document(), *this, Bindings::ShadowRootMode::Closed);

View File

@ -334,7 +334,7 @@ WebIDL::ExceptionOr<void> 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<DOM::ShadowRoot>(realm(), document(), *this, Bindings::ShadowRootMode::Closed);

View File

@ -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::Element>(dom_node) ? verify_cast<DOM::Element>(dom_node).shadow_root_internal() : nullptr;
auto shadow_root = is<DOM::Element>(dom_node) ? verify_cast<DOM::Element>(dom_node).shadow_root() : nullptr;
// Add node for the ::before pseudo-element.
if (is<DOM::Element>(dom_node) && layout_node->can_have_children()) {

View File

@ -126,12 +126,12 @@ JS::GCPtr<DOM::Element> 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<DOM::ShadowRoot&>(*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<DOM::ShadowRoot&>(*shadow_root()).append_child(cloned_reference_node).release_value_but_fixme_should_propagate_errors();
}
}
@ -177,7 +177,7 @@ JS::NonnullGCPtr<SVGAnimatedLength> SVGUseElement::height() const
// https://svgwg.org/svg2-draft/struct.html#TermInstanceRoot
JS::GCPtr<SVGElement> SVGUseElement::instance_root() const
{
return shadow_root()->first_child_of_type<SVGElement>();
return const_cast<DOM::ShadowRoot&>(*shadow_root()).first_child_of_type<SVGElement>();
}
JS::GCPtr<SVGElement> SVGUseElement::animated_instance_root() const

View File

@ -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)