mirror of
https://github.com/servo/servo.git
synced 2025-06-23 16:44:33 +01:00
Implement DocumentFragment.
This commit is contained in:
parent
fc9fdf30a6
commit
438d121cd8
10 changed files with 78 additions and 15 deletions
|
@ -141,10 +141,16 @@ DOMInterfaces = {
|
|||
},
|
||||
|
||||
'Document': {
|
||||
'nativeType': 'AbstractDocument',
|
||||
'pointerType': '',
|
||||
'customTrace': 'trace',
|
||||
'needsAbstract': ['title', 'createElement', 'createTextNode', 'createComment'],
|
||||
'nativeType': 'AbstractDocument',
|
||||
'pointerType': '',
|
||||
'customTrace': 'trace',
|
||||
'needsAbstract': [
|
||||
'createComment',
|
||||
'createDocumentFragment',
|
||||
'createElement',
|
||||
'createTextNode',
|
||||
'title',
|
||||
],
|
||||
},
|
||||
|
||||
'DOMParser': {
|
||||
|
@ -568,6 +574,7 @@ def addHTMLElement(element, concrete=None, needsAbstract=[]):
|
|||
}
|
||||
|
||||
addHTMLElement('Comment')
|
||||
addHTMLElement('DocumentFragment', concrete='DocumentFragment<ScriptView>')
|
||||
addHTMLElement('DocumentType', concrete='DocumentType<ScriptView>')
|
||||
addHTMLElement('Text')
|
||||
|
||||
|
|
|
@ -44,8 +44,8 @@ interface Document /*: Node*/ { //XXXjdm Requires servo/#623
|
|||
Element createElement(DOMString localName);
|
||||
[Creator, Throws]
|
||||
Element createElementNS(DOMString? namespace, DOMString qualifiedName);
|
||||
/*[Creator]
|
||||
DocumentFragment createDocumentFragment();*/
|
||||
[Creator]
|
||||
DocumentFragment createDocumentFragment();
|
||||
[Creator]
|
||||
Text createTextNode(DOMString data);
|
||||
[Creator]
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
/* -*- 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/. */
|
||||
|
||||
// http://dom.spec.whatwg.org/#interface-documentfragment
|
||||
[Constructor]
|
||||
interface DocumentFragment : Node {
|
||||
};
|
|
@ -129,6 +129,9 @@ macro_rules! generate_traceable_node(
|
|||
generate_cacheable_wrapper!(Comment, CommentBinding::Wrap)
|
||||
generate_binding_object!(Comment)
|
||||
generate_traceable!(Comment)
|
||||
generate_cacheable_wrapper_node!(DocumentFragment<ScriptView>, DocumentFragmentBinding::Wrap)
|
||||
generate_binding_object_node!(DocumentFragment<ScriptView>)
|
||||
generate_traceable_node!(DocumentFragment<ScriptView>)
|
||||
generate_cacheable_wrapper_node!(DocumentType<ScriptView>, DocumentTypeBinding::Wrap)
|
||||
generate_binding_object_node!(DocumentType<ScriptView>)
|
||||
generate_traceable_node!(DocumentType<ScriptView>)
|
||||
|
|
|
@ -6,7 +6,7 @@ use dom::bindings::utils::{Reflectable, Reflector, Traceable};
|
|||
use dom::element::*;
|
||||
use dom::types::*;
|
||||
use dom::node::{AbstractNode, ElementNodeTypeId, TextNodeTypeId, CommentNodeTypeId};
|
||||
use dom::node::{DoctypeNodeTypeId, ScriptView};
|
||||
use dom::node::{DoctypeNodeTypeId, DocumentFragmentNodeTypeId, ScriptView};
|
||||
|
||||
use std::cast;
|
||||
use std::libc;
|
||||
|
@ -91,8 +91,9 @@ pub fn create(cx: *JSContext, node: &mut AbstractNode<ScriptView>) -> *JSObject
|
|||
ElementNodeTypeId(HTMLUnknownElementTypeId) => generate_element!(HTMLUnknownElement),
|
||||
CommentNodeTypeId => generate_element!(Comment),
|
||||
DoctypeNodeTypeId => generate_element!(DocumentType<ScriptView>),
|
||||
TextNodeTypeId => generate_element!(Text)
|
||||
}
|
||||
DocumentFragmentNodeTypeId => generate_element!(DocumentFragment<ScriptView>),
|
||||
TextNodeTypeId => generate_element!(Text),
|
||||
}
|
||||
}
|
||||
|
||||
impl Reflectable for AbstractNode<ScriptView> {
|
||||
|
|
|
@ -7,6 +7,7 @@ use dom::bindings::codegen::DocumentBinding;
|
|||
use dom::bindings::utils::{DOMString, Reflector, ErrorResult, Fallible};
|
||||
use dom::bindings::utils::{BindingObject, Reflectable, DerivedWrapper};
|
||||
use dom::bindings::utils::{is_valid_element_name, InvalidCharacter, Traceable, null_str_as_empty, null_str_as_word_null};
|
||||
use dom::documentfragment::DocumentFragment;
|
||||
use dom::element::{Element};
|
||||
use dom::element::{HTMLHtmlElementTypeId, HTMLHeadElementTypeId, HTMLTitleElementTypeId};
|
||||
use dom::event::Event;
|
||||
|
@ -283,6 +284,12 @@ impl Document {
|
|||
fail!("stub")
|
||||
}
|
||||
|
||||
pub fn CreateDocumentFragment(&self, abstract_self: AbstractDocument) -> AbstractNode<ScriptView> {
|
||||
let cx = self.get_cx();
|
||||
let fragment = @DocumentFragment::new(abstract_self);
|
||||
unsafe { Node::as_abstract_node(cx, fragment) }
|
||||
}
|
||||
|
||||
pub fn CreateTextNode(&self, abstract_self: AbstractDocument, data: &DOMString) -> AbstractNode<ScriptView> {
|
||||
let cx = self.get_cx();
|
||||
let text = @Text::new(null_str_as_empty(data), abstract_self);
|
||||
|
|
28
src/components/script/dom/documentfragment.rs
Normal file
28
src/components/script/dom/documentfragment.rs
Normal file
|
@ -0,0 +1,28 @@
|
|||
/* 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/. */
|
||||
|
||||
use dom::bindings::utils::Fallible;
|
||||
use dom::document::AbstractDocument;
|
||||
use dom::node::{ScriptView, Node, DocumentFragmentNodeTypeId};
|
||||
use dom::node::{AbstractNode};
|
||||
use dom::window::Window;
|
||||
|
||||
pub struct DocumentFragment<View> {
|
||||
node: Node<View>,
|
||||
}
|
||||
|
||||
impl DocumentFragment<ScriptView> {
|
||||
/// Creates a new DocumentFragment.
|
||||
pub fn new(document: AbstractDocument) -> DocumentFragment<ScriptView> {
|
||||
DocumentFragment {
|
||||
node: Node::new(DocumentFragmentNodeTypeId, document),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn Constructor(owner: @mut Window) -> Fallible<AbstractNode<ScriptView>> {
|
||||
let cx = (*owner.page).js_info.get_ref().js_compartment.cx.ptr;
|
||||
let fragment = @DocumentFragment::new(owner.Document());
|
||||
Ok(unsafe { Node::as_abstract_node(cx, fragment) })
|
||||
}
|
||||
}
|
|
@ -101,6 +101,7 @@ pub struct Node<View> {
|
|||
#[deriving(Eq)]
|
||||
pub enum NodeTypeId {
|
||||
DoctypeNodeTypeId,
|
||||
DocumentFragmentNodeTypeId,
|
||||
CommentNodeTypeId,
|
||||
ElementNodeTypeId(ElementTypeId),
|
||||
TextNodeTypeId,
|
||||
|
@ -531,7 +532,8 @@ impl Node<ScriptView> {
|
|||
ElementNodeTypeId(_) => 1,
|
||||
TextNodeTypeId => 3,
|
||||
CommentNodeTypeId => 8,
|
||||
DoctypeNodeTypeId => 10
|
||||
DoctypeNodeTypeId => 10,
|
||||
DocumentFragmentNodeTypeId => 11,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -548,7 +550,8 @@ impl Node<ScriptView> {
|
|||
do abstract_self.with_imm_doctype |doctype| {
|
||||
doctype.name.clone()
|
||||
}
|
||||
}
|
||||
},
|
||||
DocumentFragmentNodeTypeId => ~"#document-fragment",
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -561,7 +564,8 @@ impl Node<ScriptView> {
|
|||
ElementNodeTypeId(*) |
|
||||
CommentNodeTypeId |
|
||||
TextNodeTypeId |
|
||||
DoctypeNodeTypeId => Some(self.owner_doc),
|
||||
DoctypeNodeTypeId |
|
||||
DocumentFragmentNodeTypeId => Some(self.owner_doc),
|
||||
// DocumentNodeTypeId => None
|
||||
}
|
||||
}
|
||||
|
@ -614,7 +618,7 @@ impl Node<ScriptView> {
|
|||
|
||||
pub fn GetTextContent(&self, abstract_self: AbstractNode<ScriptView>) -> DOMString {
|
||||
match self.type_id {
|
||||
ElementNodeTypeId(*) => {
|
||||
DocumentFragmentNodeTypeId | ElementNodeTypeId(*) => {
|
||||
let mut content = ~"";
|
||||
for node in abstract_self.traverse_preorder() {
|
||||
if node.is_text() {
|
||||
|
@ -679,7 +683,7 @@ impl Node<ScriptView> {
|
|||
_ => false
|
||||
};
|
||||
match self.type_id {
|
||||
ElementNodeTypeId(*) => {
|
||||
DocumentFragmentNodeTypeId | ElementNodeTypeId(*) => {
|
||||
let node = if is_empty {
|
||||
None
|
||||
} else {
|
||||
|
|
|
@ -50,6 +50,7 @@ pub mod dom {
|
|||
pub mod clientrectlist;
|
||||
pub mod comment;
|
||||
pub mod document;
|
||||
pub mod documentfragment;
|
||||
pub mod documenttype;
|
||||
pub mod domparser;
|
||||
pub mod element;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue