diff options
author | Simon Sapin <simon.sapin@exyr.org> | 2015-06-26 07:06:39 -0700 |
---|---|---|
committer | Simon Sapin <simon.sapin@exyr.org> | 2015-06-26 12:35:08 -0700 |
commit | 9e1a674b169b93e6b365d913fdc45008094abbf4 (patch) | |
tree | 3910dd6e55ed3a41842d28f8262527474df115bf /components/script/dom/node.rs | |
parent | 9eb3cc2a241dff4df57d644fa5257fcf3a52325f (diff) | |
download | servo-9e1a674b169b93e6b365d913fdc45008094abbf4.tar.gz servo-9e1a674b169b93e6b365d913fdc45008094abbf4.zip |
Update rust-selectors
Diffstat (limited to 'components/script/dom/node.rs')
-rw-r--r-- | components/script/dom/node.rs | 65 |
1 files changed, 10 insertions, 55 deletions
diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index 919136a4afd..b8282ce1de0 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -54,7 +54,7 @@ use util::geometry::Au; use util::namespace; use util::str::DOMString; use util::task_state; -use selectors::parser::{Selector, AttrSelector, NamespaceConstraint}; +use selectors::parser::Selector; use selectors::parser::parse_author_origin_selector_list_from_str; use selectors::matching::matches; use style::properties::ComputedValues; @@ -423,7 +423,11 @@ impl<'a> Iterator for QuerySelectorIterator { // TODO(cgaebel): Is it worth it to build a bloom filter here // (instead of passing `None`)? Probably. self.iterator.find(|node| { - node.r().is_element() && matches(selectors, &node.r(), &mut None) + if let Some(element) = ElementCast::to_ref(node.r()) { + matches(selectors, &element, &mut None) + } else { + false + } }) } } @@ -896,7 +900,7 @@ impl<'a> NodeHelpers for &'a Node { let root = self.ancestors().last(); let root = root.r().unwrap_or(self.clone()); Ok(root.traverse_preorder().filter_map(ElementCast::to_root).find(|element| { - matches(selectors, &NodeCast::from_ref(element.r()), &mut None) + matches(selectors, &element.r(), &mut None) })) } } @@ -2506,9 +2510,7 @@ impl<'a> VirtualMethods for &'a Node { } } -impl<'a> style::node::TNode for &'a Node { - type Element = &'a Element; - +impl<'a> ::selectors::Node<&'a Element> for &'a Node { fn parent_node(&self) -> Option<&'a Node> { (*self).parent_node.get() .map(|node| node.root().get_unsound_ref_forever()) @@ -2544,55 +2546,8 @@ impl<'a> style::node::TNode for &'a Node { is_document(*self) } - fn is_element(&self) -> bool { - // FIXME(zwarich): Remove this when UFCS lands and there is a better way - // of disambiguating methods. - fn is_element<'a, T: ElementDerived>(this: &T) -> bool { - this.is_element() - } - - is_element(*self) - } - - fn as_element(&self) -> &'a Element { - ElementCast::to_ref(*self).unwrap() - } - - fn match_attr<F>(&self, attr: &AttrSelector, test: F) -> bool - where F: Fn(&str) -> bool - { - let local_name = { - if self.is_html_element_in_html_document() { - &attr.lower_name - } else { - &attr.name - } - }; - match attr.namespace { - NamespaceConstraint::Specific(ref ns) => { - self.as_element().get_attribute(ns, local_name) - .map_or(false, |attr| { - // FIXME(https://github.com/rust-lang/rust/issues/23338) - let attr = attr.r(); - let value = attr.value(); - test(&value) - }) - }, - NamespaceConstraint::Any => { - let mut attributes: RootedVec<JS<Attr>> = RootedVec::new(); - self.as_element().get_attributes(local_name, &mut attributes); - attributes.iter().any(|attr| { - // FIXME(https://github.com/rust-lang/rust/issues/23338) - let attr = attr.root(); - let value = attr.r().value(); - test(&value) - }) - } - } - } - - fn is_html_element_in_html_document(&self) -> bool { - self.as_element().html_element_in_html_document() + fn as_element(&self) -> Option<&'a Element> { + ElementCast::to_ref(*self) } } |