aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/components/script/dom/bindings/codegen/Bindings.conf4
-rw-r--r--src/components/script/dom/document.rs6
-rw-r--r--src/components/script/dom/documentfragment.rs11
-rw-r--r--src/components/script/dom/element.rs6
-rw-r--r--src/components/script/dom/htmlcollection.rs12
-rw-r--r--src/components/script/dom/webidls/Document.webidl2
-rw-r--r--src/components/script/dom/webidls/DocumentFragment.webidl2
-rw-r--r--src/components/script/dom/webidls/Element.webidl4
-rw-r--r--src/components/script/dom/webidls/ParentNode.webidl25
9 files changed, 67 insertions, 5 deletions
diff --git a/src/components/script/dom/bindings/codegen/Bindings.conf b/src/components/script/dom/bindings/codegen/Bindings.conf
index 56469cfafb8..b80cda36b59 100644
--- a/src/components/script/dom/bindings/codegen/Bindings.conf
+++ b/src/components/script/dom/bindings/codegen/Bindings.conf
@@ -32,6 +32,7 @@ DOMInterfaces = {
'anchors',
'applets',
'body',
+ 'children',
'createComment',
'createDocumentFragment',
'createElement',
@@ -58,6 +59,7 @@ DOMInterfaces = {
'Element': {
'needsAbstract': [
'attributes',
+ 'children',
'className',
'getAttribute',
'getAttributeNS',
@@ -137,7 +139,7 @@ def addHTMLElement(element, concrete=None, needsAbstract=[]):
}
addHTMLElement('Comment')
-addHTMLElement('DocumentFragment', concrete='DocumentFragment')
+addHTMLElement('DocumentFragment', concrete='DocumentFragment', needsAbstract=['children'])
addHTMLElement('DocumentType')
addHTMLElement('Text')
addHTMLElement('ProcessingInstruction')
diff --git a/src/components/script/dom/document.rs b/src/components/script/dom/document.rs
index 95298eef358..e611a6190ea 100644
--- a/src/components/script/dom/document.rs
+++ b/src/components/script/dom/document.rs
@@ -603,6 +603,12 @@ impl Document {
self.window.get_mut().Location(&abstract_self.get().window)
}
+ pub fn Children(&self, abstract_self: &JS<Document>) -> JS<HTMLCollection> {
+ let doc = self.node.owner_doc();
+ let doc = doc.get();
+ HTMLCollection::children(&doc.window, &NodeCast::from(abstract_self))
+ }
+
pub fn createNodeList(&self, callback: |node: &JS<Node>| -> bool) -> JS<NodeList> {
let mut nodes: ~[JS<Node>] = ~[];
match self.GetDocumentElement() {
diff --git a/src/components/script/dom/documentfragment.rs b/src/components/script/dom/documentfragment.rs
index 13fe9b9c80e..bd9afa7d97f 100644
--- a/src/components/script/dom/documentfragment.rs
+++ b/src/components/script/dom/documentfragment.rs
@@ -2,12 +2,13 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-use dom::bindings::codegen::InheritTypes::DocumentFragmentDerived;
+use dom::bindings::codegen::InheritTypes::{DocumentFragmentDerived, NodeCast};
use dom::bindings::codegen::DocumentFragmentBinding;
use dom::bindings::js::JS;
use dom::bindings::error::Fallible;
use dom::document::Document;
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
+use dom::htmlcollection::HTMLCollection;
use dom::node::{DocumentFragmentNodeTypeId, Node};
use dom::window::Window;
@@ -44,3 +45,11 @@ impl DocumentFragment {
Ok(DocumentFragment::new(&owner.get().Document()))
}
}
+
+impl DocumentFragment {
+ pub fn Children(&self, abstract_self: &JS<DocumentFragment>) -> JS<HTMLCollection> {
+ let doc = self.node.owner_doc();
+ let doc = doc.get();
+ HTMLCollection::children(&doc.window, &NodeCast::from(abstract_self))
+ }
+}
diff --git a/src/components/script/dom/element.rs b/src/components/script/dom/element.rs
index d60181f5349..c94c9b01ae1 100644
--- a/src/components/script/dom/element.rs
+++ b/src/components/script/dom/element.rs
@@ -640,6 +640,12 @@ impl Element {
pub fn GetOuterHTML(&self, abstract_self: &JS<Element>) -> Fallible<DOMString> {
Ok(serialize(&mut NodeIterator::new(NodeCast::from(abstract_self), true, false)))
}
+
+ pub fn Children(&self, abstract_self: &JS<Element>) -> JS<HTMLCollection> {
+ let doc = self.node.owner_doc();
+ let doc = doc.get();
+ HTMLCollection::children(&doc.window, &NodeCast::from(abstract_self))
+ }
}
pub fn get_attribute_parts(name: DOMString) -> (Option<~str>, ~str) {
diff --git a/src/components/script/dom/htmlcollection.rs b/src/components/script/dom/htmlcollection.rs
index e88aedd02db..95637f9db1a 100644
--- a/src/components/script/dom/htmlcollection.rs
+++ b/src/components/script/dom/htmlcollection.rs
@@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-use dom::bindings::codegen::InheritTypes::{ElementCast};
+use dom::bindings::codegen::InheritTypes::{ElementCast, NodeCast};
use dom::bindings::codegen::HTMLCollectionBinding;
use dom::bindings::js::JS;
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
@@ -104,6 +104,16 @@ impl HTMLCollection {
};
HTMLCollection::create(window, root, ~filter)
}
+
+ pub fn children(window: &JS<Window>, root: &JS<Node>) -> JS<HTMLCollection> {
+ struct ElementChildFilter;
+ impl CollectionFilter for ElementChildFilter {
+ fn filter(&self, elem: &JS<Element>, root: &JS<Node>) -> bool {
+ root.is_parent_of(&NodeCast::from(elem))
+ }
+ }
+ HTMLCollection::create(window, root, ~ElementChildFilter)
+ }
}
impl HTMLCollection {
diff --git a/src/components/script/dom/webidls/Document.webidl b/src/components/script/dom/webidls/Document.webidl
index 6dd0cb658a2..d89309f1c03 100644
--- a/src/components/script/dom/webidls/Document.webidl
+++ b/src/components/script/dom/webidls/Document.webidl
@@ -66,3 +66,5 @@ partial interface Document {
readonly attribute HTMLCollection anchors;
readonly attribute HTMLCollection applets;
};
+
+Document implements ParentNode;
diff --git a/src/components/script/dom/webidls/DocumentFragment.webidl b/src/components/script/dom/webidls/DocumentFragment.webidl
index 9afc55e4aa1..4248975f768 100644
--- a/src/components/script/dom/webidls/DocumentFragment.webidl
+++ b/src/components/script/dom/webidls/DocumentFragment.webidl
@@ -7,3 +7,5 @@
[Constructor]
interface DocumentFragment : Node {
};
+
+DocumentFragment implements ParentNode;
diff --git a/src/components/script/dom/webidls/Element.webidl b/src/components/script/dom/webidls/Element.webidl
index 1874bfbe651..7acf939a1bf 100644
--- a/src/components/script/dom/webidls/Element.webidl
+++ b/src/components/script/dom/webidls/Element.webidl
@@ -65,5 +65,5 @@ partial interface Element {
readonly attribute DOMString outerHTML;
};
-/*Element implements ChildNode;
-Element implements ParentNode;*/
+//Element implements ChildNode;
+Element implements ParentNode;
diff --git a/src/components/script/dom/webidls/ParentNode.webidl b/src/components/script/dom/webidls/ParentNode.webidl
new file mode 100644
index 00000000000..54b05fbbad9
--- /dev/null
+++ b/src/components/script/dom/webidls/ParentNode.webidl
@@ -0,0 +1,25 @@
+/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * The origin of this IDL file is
+ * http://dom.spec.whatwg.org/#interface-parentnode
+ */
+
+[NoInterfaceObject]
+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);
+};