diff --git a/servo/components/script/dom/document.rs b/servo/components/script/dom/document.rs index 62fdfbeb1092..dad3cf7c96a4 100644 --- a/servo/components/script/dom/document.rs +++ b/servo/components/script/dom/document.rs @@ -1378,6 +1378,21 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { HTMLCollection::children(window.r(), NodeCast::from_ref(self)) } + // https://dom.spec.whatwg.org/#dom-parentnode-firstelementchild + fn GetFirstElementChild(self) -> Option> { + NodeCast::from_ref(self).child_elements().next() + } + + // https://dom.spec.whatwg.org/#dom-parentnode-lastelementchild + fn GetLastElementChild(self) -> Option> { + NodeCast::from_ref(self).rev_children().filter_map(ElementCast::to_temporary).next() + } + + // https://dom.spec.whatwg.org/#dom-parentnode-childelementcount + fn ChildElementCount(self) -> u32 { + NodeCast::from_ref(self).child_elements().count() as u32 + } + // http://dom.spec.whatwg.org/#dom-parentnode-queryselector fn QuerySelector(self, selectors: DOMString) -> Fallible>> { let root: JSRef = NodeCast::from_ref(self); diff --git a/servo/components/script/dom/documentfragment.rs b/servo/components/script/dom/documentfragment.rs index f8e76103d7df..2a61aa98460e 100644 --- a/servo/components/script/dom/documentfragment.rs +++ b/servo/components/script/dom/documentfragment.rs @@ -5,7 +5,8 @@ use dom::bindings::codegen::Bindings::DocumentFragmentBinding; use dom::bindings::codegen::Bindings::DocumentFragmentBinding::DocumentFragmentMethods; use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; -use dom::bindings::codegen::InheritTypes::{DocumentFragmentDerived, NodeCast}; +use dom::bindings::codegen::InheritTypes::DocumentFragmentDerived; +use dom::bindings::codegen::InheritTypes::{ElementCast, NodeCast}; use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::error::Fallible; use dom::bindings::global::GlobalRef; @@ -56,6 +57,21 @@ impl<'a> DocumentFragmentMethods for JSRef<'a, DocumentFragment> { HTMLCollection::children(window.r(), NodeCast::from_ref(self)) } + // https://dom.spec.whatwg.org/#dom-parentnode-firstelementchild + fn GetFirstElementChild(self) -> Option> { + NodeCast::from_ref(self).child_elements().next() + } + + // https://dom.spec.whatwg.org/#dom-parentnode-lastelementchild + fn GetLastElementChild(self) -> Option> { + NodeCast::from_ref(self).rev_children().filter_map(ElementCast::to_temporary).next() + } + + // https://dom.spec.whatwg.org/#dom-parentnode-childelementcount + fn ChildElementCount(self) -> u32 { + NodeCast::from_ref(self).child_elements().count() as u32 + } + // http://dom.spec.whatwg.org/#dom-parentnode-queryselector fn QuerySelector(self, selectors: DOMString) -> Fallible>> { let root: JSRef = NodeCast::from_ref(self); diff --git a/servo/components/script/dom/element.rs b/servo/components/script/dom/element.rs index c3bf678a48d0..e0e5534c79e8 100644 --- a/servo/components/script/dom/element.rs +++ b/servo/components/script/dom/element.rs @@ -1223,6 +1223,21 @@ impl<'a> ElementMethods for JSRef<'a, Element> { HTMLCollection::children(window.r(), NodeCast::from_ref(self)) } + // https://dom.spec.whatwg.org/#dom-parentnode-firstelementchild + fn GetFirstElementChild(self) -> Option> { + NodeCast::from_ref(self).child_elements().next() + } + + // https://dom.spec.whatwg.org/#dom-parentnode-lastelementchild + fn GetLastElementChild(self) -> Option> { + NodeCast::from_ref(self).rev_children().filter_map(ElementCast::to_temporary).next() + } + + // https://dom.spec.whatwg.org/#dom-parentnode-childelementcount + fn ChildElementCount(self) -> u32 { + NodeCast::from_ref(self).child_elements().count() as u32 + } + // http://dom.spec.whatwg.org/#dom-parentnode-queryselector fn QuerySelector(self, selectors: DOMString) -> Fallible>> { let root: JSRef = NodeCast::from_ref(self); diff --git a/servo/components/script/dom/webidls/ParentNode.webidl b/servo/components/script/dom/webidls/ParentNode.webidl index daa4339611f2..9df1143f6257 100644 --- a/servo/components/script/dom/webidls/ParentNode.webidl +++ b/servo/components/script/dom/webidls/ParentNode.webidl @@ -11,14 +11,13 @@ interface ParentNode { [Constant] readonly attribute HTMLCollection children; - /* [Pure] readonly attribute Element? firstElementChild; [Pure] readonly attribute Element? lastElementChild; [Pure] readonly attribute unsigned long childElementCount; - */ + // Not implemented yet // void prepend((Node or DOMString)... nodes); // void append((Node or DOMString)... nodes);