LibWeb: Give Element a CustomStateSet, exposed by ElementInternals

This commit is contained in:
Sam Atkins 2025-07-04 14:03:44 +01:00 committed by Tim Ledbetter
commit b6ffea8990
Notes: github-actions[bot] 2025-07-04 17:11:47 +00:00
10 changed files with 209 additions and 1 deletions

View file

@ -46,6 +46,7 @@
#include <LibWeb/HTML/CustomElements/CustomElementName.h>
#include <LibWeb/HTML/CustomElements/CustomElementReactionNames.h>
#include <LibWeb/HTML/CustomElements/CustomElementRegistry.h>
#include <LibWeb/HTML/CustomElements/CustomStateSet.h>
#include <LibWeb/HTML/EventLoop/EventLoop.h>
#include <LibWeb/HTML/HTMLAnchorElement.h>
#include <LibWeb/HTML/HTMLAreaElement.h>
@ -118,6 +119,7 @@ void Element::visit_edges(Cell::Visitor& visitor)
visitor.visit(m_class_list);
visitor.visit(m_shadow_root);
visitor.visit(m_custom_element_definition);
visitor.visit(m_custom_state_set);
visitor.visit(m_cascaded_properties);
visitor.visit(m_computed_properties);
if (m_pseudo_element_data) {
@ -3824,6 +3826,13 @@ auto Element::ensure_custom_element_reaction_queue() -> CustomElementReactionQue
return *m_custom_element_reaction_queue;
}
HTML::CustomStateSet& Element::ensure_custom_state_set()
{
if (!m_custom_state_set)
m_custom_state_set = HTML::CustomStateSet::create(realm(), *this);
return *m_custom_state_set;
}
CSS::StyleSheetList& Element::document_or_shadow_root_style_sheets()
{
auto& root_node = root();

View file

@ -351,6 +351,9 @@ public:
CustomElementReactionQueue const* custom_element_reaction_queue() const { return m_custom_element_reaction_queue; }
CustomElementReactionQueue& ensure_custom_element_reaction_queue();
HTML::CustomStateSet const* custom_state_set() const { return m_custom_state_set; }
HTML::CustomStateSet& ensure_custom_state_set();
JS::ThrowCompletionOr<void> upgrade_element(GC::Ref<HTML::CustomElementDefinition> custom_element_definition);
void try_to_upgrade();
@ -587,6 +590,9 @@ private:
// https://dom.spec.whatwg.org/#concept-element-is-value
Optional<String> m_is_value;
// https://html.spec.whatwg.org/multipage/custom-elements.html#states-set
GC::Ptr<HTML::CustomStateSet> m_custom_state_set;
// https://www.w3.org/TR/intersection-observer/#dom-element-registeredintersectionobservers-slot
// Element objects have an internal [[RegisteredIntersectionObservers]] slot, which is initialized to an empty list.
OwnPtr<Vector<IntersectionObserver::IntersectionObserverRegistration>> m_registered_intersection_observers;