mirror of
https://github.com/servo/servo.git
synced 2025-06-24 09:04:33 +01:00
commit
b35d830999
9 changed files with 67 additions and 5 deletions
|
@ -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')
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -66,3 +66,5 @@ partial interface Document {
|
|||
readonly attribute HTMLCollection anchors;
|
||||
readonly attribute HTMLCollection applets;
|
||||
};
|
||||
|
||||
Document implements ParentNode;
|
||||
|
|
|
@ -7,3 +7,5 @@
|
|||
[Constructor]
|
||||
interface DocumentFragment : Node {
|
||||
};
|
||||
|
||||
DocumentFragment implements ParentNode;
|
||||
|
|
|
@ -65,5 +65,5 @@ partial interface Element {
|
|||
readonly attribute DOMString outerHTML;
|
||||
};
|
||||
|
||||
/*Element implements ChildNode;
|
||||
Element implements ParentNode;*/
|
||||
//Element implements ChildNode;
|
||||
Element implements ParentNode;
|
||||
|
|
25
src/components/script/dom/webidls/ParentNode.webidl
Normal file
25
src/components/script/dom/webidls/ParentNode.webidl
Normal 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);
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue