auto merge of #2192 : evilpie/servo/children, r=Ms2ger

Fixes #2186
This commit is contained in:
bors-servo 2014-04-22 16:52:17 -04:00
commit b35d830999
9 changed files with 67 additions and 5 deletions

View file

@ -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')

View file

@ -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() {

View file

@ -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))
}
}

View file

@ -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) {

View file

@ -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 {

View file

@ -66,3 +66,5 @@ partial interface Document {
readonly attribute HTMLCollection anchors;
readonly attribute HTMLCollection applets;
};
Document implements ParentNode;

View file

@ -7,3 +7,5 @@
[Constructor]
interface DocumentFragment : Node {
};
DocumentFragment implements ParentNode;

View file

@ -65,5 +65,5 @@ partial interface Element {
readonly attribute DOMString outerHTML;
};
/*Element implements ChildNode;
Element implements ParentNode;*/
//Element implements ChildNode;
Element implements ParentNode;

View file

@ -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);
};