aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom
diff options
context:
space:
mode:
authorAnthony Ramine <n.oxyde@gmail.com>2015-09-10 01:33:13 +0200
committerAnthony Ramine <n.oxyde@gmail.com>2015-09-10 01:33:13 +0200
commitdc125f9eb16bd69cb7c816053b267d0bcaa81494 (patch)
tree6b5884d92d7515286cd6c25fd46fc6554ed6192a /components/script/dom
parent3f5b3053b92fa477555e965a8eadb147ad30d9a5 (diff)
downloadservo-dc125f9eb16bd69cb7c816053b267d0bcaa81494.tar.gz
servo-dc125f9eb16bd69cb7c816053b267d0bcaa81494.zip
Implement NonElementParentNode for DocumentFragment
Diffstat (limited to 'components/script/dom')
-rw-r--r--components/script/dom/documentfragment.rs13
-rw-r--r--components/script/dom/webidls/DocumentFragment.webidl1
2 files changed, 14 insertions, 0 deletions
diff --git a/components/script/dom/documentfragment.rs b/components/script/dom/documentfragment.rs
index 2f0ccecda5c..3eac9df6bac 100644
--- a/components/script/dom/documentfragment.rs
+++ b/components/script/dom/documentfragment.rs
@@ -17,6 +17,7 @@ use dom::eventtarget::{EventTarget, EventTargetTypeId};
use dom::htmlcollection::HTMLCollection;
use dom::node::{Node, NodeTypeId, window_from_node};
use dom::nodelist::NodeList;
+use string_cache::Atom;
use util::str::DOMString;
// https://dom.spec.whatwg.org/#documentfragment
@@ -58,6 +59,18 @@ impl DocumentFragmentMethods for DocumentFragment {
HTMLCollection::children(window.r(), NodeCast::from_ref(self))
}
+ // https://dom.spec.whatwg.org/#dom-nonelementparentnode-getelementbyid
+ fn GetElementById(&self, id: DOMString) -> Option<Root<Element>> {
+ let node = NodeCast::from_ref(self);
+ let id = Atom::from_slice(&id);
+ node.traverse_preorder().filter_map(ElementCast::to_root).find(|descendant| {
+ match descendant.get_attribute(&ns!(""), &atom!(id)) {
+ None => false,
+ Some(attr) => *attr.value().as_atom() == id,
+ }
+ })
+ }
+
// https://dom.spec.whatwg.org/#dom-parentnode-firstelementchild
fn GetFirstElementChild(&self) -> Option<Root<Element>> {
NodeCast::from_ref(self).child_elements().next()
diff --git a/components/script/dom/webidls/DocumentFragment.webidl b/components/script/dom/webidls/DocumentFragment.webidl
index 7dfbcc573df..eb2b7d6696d 100644
--- a/components/script/dom/webidls/DocumentFragment.webidl
+++ b/components/script/dom/webidls/DocumentFragment.webidl
@@ -8,4 +8,5 @@
interface DocumentFragment : Node {
};
+DocumentFragment implements NonElementParentNode;
DocumentFragment implements ParentNode;