aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/element.rs
diff options
context:
space:
mode:
authorbors-servo <metajack+bors@gmail.com>2015-01-18 08:09:43 -0700
committerbors-servo <metajack+bors@gmail.com>2015-01-18 08:09:43 -0700
commitea83ffdb980d290a910e78b96c3f056280487ac7 (patch)
tree99bbd28cc2b98520055285f650f72a10571a760f /components/script/dom/element.rs
parent2a9acdcb73685f2c5c14b51f33b741690b60cb23 (diff)
parent7759358e0978909986216409884b9d1d66afe87f (diff)
downloadservo-ea83ffdb980d290a910e78b96c3f056280487ac7.tar.gz
servo-ea83ffdb980d290a910e78b96c3f056280487ac7.zip
auto merge of #4621 : jimrhoskins/servo/closest, r=jdm
fixes #4603 - Add definition to the Element.webidl and implementation to element.rs. - Create inclusive_ancestors helper in NodeHelpers - Update test expectations
Diffstat (limited to 'components/script/dom/element.rs')
-rw-r--r--components/script/dom/element.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs
index 129756c1575..14f48f5f3b6 100644
--- a/components/script/dom/element.rs
+++ b/components/script/dom/element.rs
@@ -1120,6 +1120,23 @@ impl<'a> ElementMethods for JSRef<'a, Element> {
}
}
}
+
+ // https://dom.spec.whatwg.org/#dom-element-closest
+ fn Closest(self, selectors: DOMString) -> Fallible<Option<Temporary<Element>>> {
+ let parser_context = ParserContext {
+ origin: StylesheetOrigin::Author,
+ };
+ match style::parse_selector_list_from_str(&parser_context, selectors.as_slice()) {
+ Err(()) => Err(Syntax),
+ Ok(ref selectors) => {
+ let root: JSRef<Node> = NodeCast::from_ref(self);
+ Ok(root.inclusive_ancestors()
+ .filter_map(ElementCast::to_ref)
+ .find(|element| matches(selectors, &NodeCast::from_ref(*element), &mut None))
+ .map(Temporary::from_rooted))
+ }
+ }
+ }
}
pub fn get_attribute_parts<'a>(name: &'a str) -> (Option<&'a str>, &'a str) {