mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Implement Element.matches().
This commit is contained in:
parent
0974d21bcd
commit
b6edd5318f
4 changed files with 51 additions and 0 deletions
|
@ -396,6 +396,7 @@ pub trait NodeHelpers {
|
|||
fn query_selector_all(&self, selectors: DOMString) -> Fallible<Temporary<NodeList>>;
|
||||
|
||||
fn remove_self(&self);
|
||||
fn matches(&self, selectors: DOMString) -> Fallible<bool>;
|
||||
}
|
||||
|
||||
impl<'a> NodeHelpers for JSRef<'a, Node> {
|
||||
|
@ -648,6 +649,28 @@ impl<'a> NodeHelpers for JSRef<'a, Node> {
|
|||
None => ()
|
||||
}
|
||||
}
|
||||
|
||||
// http://dom.spec.whatwg.org/#dom-element-matches
|
||||
fn matches(&self, selectors: DOMString) -> Fallible<bool> {
|
||||
assert!(self.is_element());
|
||||
// Step 1.
|
||||
let namespace = NamespaceMap::new();
|
||||
match parse_selector_list(tokenize(selectors.as_slice()).map(|(token, _)| token).collect(), &namespace) {
|
||||
// Step 2.
|
||||
None => return Err(Syntax),
|
||||
// Step 3.
|
||||
Some(ref selectors) => {
|
||||
for selector in selectors.iter() {
|
||||
assert!(selector.pseudo_element.is_none());
|
||||
let mut _shareable: bool = false;
|
||||
if matches_compound_selector(selector.compound_selectors.deref(), self, &mut _shareable) {
|
||||
return Ok(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(false)
|
||||
}
|
||||
}
|
||||
|
||||
/// If the given untrusted node address represents a valid DOM node in the given runtime,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue