mirror of
https://github.com/servo/servo.git
synced 2025-09-30 08:39:16 +01:00
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:
parent
dcd25072d3
commit
04dd74dddb
20 changed files with 209 additions and 152 deletions
|
@ -1325,6 +1325,9 @@ pub(crate) trait LayoutElementHelpers<'dom> {
|
|||
) -> Option<&'dom AttrValue>;
|
||||
fn get_attr_val_for_layout(self, namespace: &Namespace, name: &LocalName) -> Option<&'dom str>;
|
||||
fn get_attr_vals_for_layout(self, name: &LocalName) -> Vec<&'dom AttrValue>;
|
||||
fn each_custom_state<F>(self, callback: F)
|
||||
where
|
||||
F: FnMut(&AtomIdent);
|
||||
}
|
||||
|
||||
impl LayoutDom<'_, Element> {
|
||||
|
@ -1819,6 +1822,13 @@ impl<'dom> LayoutElementHelpers<'dom> for LayoutDom<'dom, Element> {
|
|||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn each_custom_state<F>(self, callback: F)
|
||||
where
|
||||
F: FnMut(&AtomIdent),
|
||||
{
|
||||
self.unsafe_get().each_custom_state(callback)
|
||||
}
|
||||
}
|
||||
|
||||
impl Element {
|
||||
|
@ -5196,12 +5206,24 @@ impl SelectorsElement for SelectorWrapper<'_> {
|
|||
true
|
||||
}
|
||||
|
||||
fn has_custom_state(&self, _name: &AtomIdent) -> bool {
|
||||
false
|
||||
fn has_custom_state(&self, name: &AtomIdent) -> bool {
|
||||
let mut has_state = false;
|
||||
self.each_custom_state(|state| has_state |= state == name);
|
||||
|
||||
has_state
|
||||
}
|
||||
}
|
||||
|
||||
impl Element {
|
||||
fn each_custom_state<F>(&self, callback: F)
|
||||
where
|
||||
F: FnMut(&AtomIdent),
|
||||
{
|
||||
self.get_element_internals()
|
||||
.and_then(|internals| internals.custom_states())
|
||||
.inspect(|states| states.for_each_state(callback));
|
||||
}
|
||||
|
||||
fn client_rect(&self) -> Rect<i32> {
|
||||
let doc = self.node.owner_doc();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue