mirror of
https://github.com/servo/servo.git
synced 2025-07-24 15:50:21 +01:00
Implement NonElementParentNode for DocumentFragment
This commit is contained in:
parent
3f5b3053b9
commit
dc125f9eb1
3 changed files with 14 additions and 9 deletions
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue