script: Support custom element states (#38564)

Also adds support for `:state`.

Testing: Covered by existing tests

---------

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
This commit is contained in:
Simon Wülker 2025-08-27 19:25:16 +02:00 committed by GitHub
parent dcd25072d3
commit 04dd74dddb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 209 additions and 152 deletions

View file

@ -560,10 +560,11 @@ impl<'dom> style::dom::TElement for ServoLayoutElement<'dom> {
.intersection(ElementSelectorFlags::RELATIVE_SELECTOR_SEARCH_DIRECTION_ANCESTOR_SIBLING)
}
fn each_custom_state<F>(&self, _callback: F)
fn each_custom_state<F>(&self, callback: F)
where
F: FnMut(&AtomIdent),
{
self.element.each_custom_state(callback);
}
/// Returns the implicit scope root for given sheet index and host.
@ -960,8 +961,12 @@ impl<'dom> ::selectors::Element for ServoLayoutElement<'dom> {
true
}
fn has_custom_state(&self, _name: &AtomIdent) -> bool {
false
fn has_custom_state(&self, name: &AtomIdent) -> bool {
let mut has_state = false;
self.element
.each_custom_state(|state| has_state |= state == name);
has_state
}
}