diff --git a/src/components/script/dom/bindings/codegen/Bindings.conf b/src/components/script/dom/bindings/codegen/Bindings.conf index a0c343ca4a8..d81bb05db17 100644 --- a/src/components/script/dom/bindings/codegen/Bindings.conf +++ b/src/components/script/dom/bindings/codegen/Bindings.conf @@ -367,12 +367,6 @@ DOMInterfaces = { 'resultNotAddRefed': [ 'getItem' ] }], -'Text': { - 'nativeType': 'AbstractNode', - 'concreteType': 'Text', - 'pointerType': '' -}, - 'UIEvent': { }, @@ -548,12 +542,17 @@ def addExternalIface(iface, nativeType=None, headerFile=None, pointerType=None): domInterface['pointerType'] = pointerType DOMInterfaces[iface] = domInterface -def addHTMLElement(element): +def addHTMLElement(element, concrete=None): DOMInterfaces[element] = { 'nativeType': 'AbstractNode', - 'pointerType': '' + 'pointerType': '', + 'concreteType': concrete if concrete else element } +addHTMLElement('Comment') +addHTMLElement('DocumentType', concrete='DocumentType') +addHTMLElement('Text') + addHTMLElement('HTMLAnchorElement') addHTMLElement('HTMLAppletElement') addHTMLElement('HTMLAreaElement') diff --git a/src/components/script/dom/bindings/codegen/Comment.webidl b/src/components/script/dom/bindings/codegen/Comment.webidl new file mode 100644 index 00000000000..023335f166a --- /dev/null +++ b/src/components/script/dom/bindings/codegen/Comment.webidl @@ -0,0 +1,15 @@ +/* -*- 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/#comment + * + * Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C + * liability, trademark and document use rules apply. + */ + +[Constructor(optional DOMString data = "")] +interface Comment : CharacterData { +}; diff --git a/src/components/script/dom/bindings/codegen/DocumentType.webidl b/src/components/script/dom/bindings/codegen/DocumentType.webidl new file mode 100644 index 00000000000..9a2e9cc4042 --- /dev/null +++ b/src/components/script/dom/bindings/codegen/DocumentType.webidl @@ -0,0 +1,22 @@ +/* -*- 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/#documenttype + * + * Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C + * liability, trademark and document use rules apply. + */ + +interface DocumentType : Node { + readonly attribute DOMString name; + readonly attribute DOMString publicId; + readonly attribute DOMString systemId; + + // Mozilla extension + //readonly attribute DOMString? internalSubset; +}; + +//DocumentType implements ChildNode; diff --git a/src/components/script/dom/bindings/element.rs b/src/components/script/dom/bindings/element.rs index 6e7196b4649..3ad1b73a444 100644 --- a/src/components/script/dom/bindings/element.rs +++ b/src/components/script/dom/bindings/element.rs @@ -311,7 +311,7 @@ pub fn create(cx: *JSContext, node: &mut AbstractNode) -> jsobj { } pub macro_rules! generate_cacheable_wrapper( - ($name: ident, $wrap: path) => ( + ($name: path, $wrap: path) => ( impl CacheableWrapper for $name { fn get_wrappercache(&mut self) -> &mut WrapperCache { self.parent.get_wrappercache() @@ -326,7 +326,7 @@ pub macro_rules! generate_cacheable_wrapper( ) pub macro_rules! generate_binding_object( - ($name: ident) => ( + ($name: path) => ( impl BindingObject for $name { fn GetParentObject(&self, cx: *JSContext) -> Option<@mut CacheableWrapper> { self.parent.GetParentObject(cx) @@ -335,6 +335,12 @@ pub macro_rules! generate_binding_object( ) ) +generate_cacheable_wrapper!(Comment, CommentBinding::Wrap) +generate_binding_object!(Comment) +generate_cacheable_wrapper!(DocumentType, DocumentTypeBinding::Wrap) +generate_binding_object!(DocumentType) +generate_cacheable_wrapper!(Text, TextBinding::Wrap) +generate_binding_object!(Text) generate_cacheable_wrapper!(HTMLHeadElement, HTMLHeadElementBinding::Wrap) generate_binding_object!(HTMLHeadElement) generate_cacheable_wrapper!(HTMLAnchorElement, HTMLAnchorElementBinding::Wrap) diff --git a/src/components/script/dom/bindings/node.rs b/src/components/script/dom/bindings/node.rs index db54fb6537c..d798ef2f1f6 100644 --- a/src/components/script/dom/bindings/node.rs +++ b/src/components/script/dom/bindings/node.rs @@ -3,7 +3,6 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::bindings::element; -use dom::bindings::text; use dom::bindings::utils; use dom::bindings::utils::{CacheableWrapper, WrapperCache, DerivedWrapper}; use dom::element::*; @@ -64,7 +63,7 @@ pub fn init(compartment: @mut Compartment) { } macro_rules! generate_element( - ($name: ident) => ({ + ($name: path) => ({ let node: @mut $name = unsafe { cast::transmute(node.raw_object()) }; node.wrap_object_shared(cx, ptr::null()) }) @@ -130,12 +129,9 @@ pub fn create(cx: *JSContext, node: &mut AbstractNode) -> *JSObject ElementNodeTypeId(HTMLUListElementTypeId) => generate_element!(HTMLUListElement), ElementNodeTypeId(HTMLUnknownElementTypeId) => generate_element!(HTMLUnknownElement), ElementNodeTypeId(_) => element::create(cx, node).ptr, - CommentNodeTypeId | - DoctypeNodeTypeId => text::create(cx, node).ptr, - TextNodeTypeId => { - let node: @mut Text = unsafe { cast::transmute(node.raw_object()) }; - node.wrap_object_shared(cx, ptr::null()) - } + CommentNodeTypeId => generate_element!(Comment), + DoctypeNodeTypeId => generate_element!(DocumentType), + TextNodeTypeId => generate_element!(Text) } } diff --git a/src/components/script/dom/bindings/text.rs b/src/components/script/dom/bindings/text.rs deleted file mode 100644 index 9b231d7087d..00000000000 --- a/src/components/script/dom/bindings/text.rs +++ /dev/null @@ -1,96 +0,0 @@ -/* 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::element; -use dom::bindings::node::unwrap; -use dom::bindings::utils; -use dom::bindings::utils::{DOM_OBJECT_SLOT, CacheableWrapper}; -use dom::node::{AbstractNode, Comment, Doctype, TextNodeTypeId, CommentNodeTypeId}; -use dom::node::{DoctypeNodeTypeId, ScriptView}; -use dom::text::Text; - -use js::jsapi::{JSFreeOp, JSObject, JSContext}; -use js::jsapi::{JS_SetReservedSlot}; -use js::glue::{RUST_PRIVATE_TO_JSVAL}; -use js::rust::{Compartment, jsobj}; - -use std::cast; -use std::libc; - -extern fn finalize_text(_fop: *JSFreeOp, obj: *JSObject) { - debug!("text finalize: %?!", obj as uint); - unsafe { - let node: AbstractNode = unwrap(obj); - let _elem: ~Text = cast::transmute(node.raw_object()); - } -} - -extern fn finalize_comment(_fop: *JSFreeOp, obj: *JSObject) { - debug!("comment finalize: %?!", obj as uint); - unsafe { - let node: AbstractNode = unwrap(obj); - let _elem: ~Comment = cast::transmute(node.raw_object()); - } -} - -extern fn finalize_doctype(_fop: *JSFreeOp, obj: *JSObject) { - debug!("doctype finalize: %?!", obj as uint); - unsafe { - let node: AbstractNode = unwrap(obj); - let _elem: ~Doctype = cast::transmute(node.raw_object()); - } -} - -pub fn init(compartment: @mut Compartment) { - let _ = utils::define_empty_prototype(~"CharacterData", Some(~"Node"), compartment); - - let _ = utils::define_empty_prototype(~"TextPrototype", - Some(~"CharacterData"), - compartment); - let _ = utils::define_empty_prototype(~"CommentPrototype", - Some(~"CharacterData"), - compartment); - let _ = utils::define_empty_prototype(~"DocumentTypePrototype", - Some(~"Node"), - compartment); - - compartment.register_class(utils::instance_jsclass(~"Text", - finalize_text, - element::trace)); - compartment.register_class(utils::instance_jsclass(~"Comment", - finalize_comment, - element::trace)); - compartment.register_class(utils::instance_jsclass(~"DocumentType", - finalize_doctype, - element::trace)); - - -} - -pub fn create(cx: *JSContext, node: &mut AbstractNode) -> jsobj { - let (proto, instance) = match node.type_id() { - TextNodeTypeId => (~"TextPrototype", ~"Text"), - CommentNodeTypeId => (~"CommentPrototype", ~"Comment"), - DoctypeNodeTypeId => (~"DocumentTypePrototype", ~"DocumentType"), - _ => fail!(~"text::create only handles textual nodes") - }; - - //XXXjdm the parent should probably be the node parent instead of the global - //TODO error checking - let compartment = utils::get_compartment(cx); - let obj = compartment.new_object_with_proto(instance, - proto, - compartment.global_obj.ptr).unwrap(); - - let cache = node.get_wrappercache(); - assert!(cache.get_wrapper().is_null()); - cache.set_wrapper(obj.ptr); - - unsafe { - let raw_ptr = node.raw_object() as *libc::c_void; - JS_SetReservedSlot(obj.ptr, DOM_OBJECT_SLOT as u32, RUST_PRIVATE_TO_JSVAL(raw_ptr)); - } - - return obj; -} diff --git a/src/components/script/dom/comment.rs b/src/components/script/dom/comment.rs new file mode 100644 index 00000000000..126178ca5d0 --- /dev/null +++ b/src/components/script/dom/comment.rs @@ -0,0 +1,33 @@ +/* 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::{DOMString, str, null_string, ErrorResult}; +use dom::characterdata::CharacterData; +use dom::node::{AbstractNode, ScriptView, CommentNodeTypeId, Node}; +use dom::window::Window; + +/// An HTML comment. +pub struct Comment { + parent: CharacterData, +} + +impl Comment { + /// Creates a new HTML comment. + pub fn new(text: ~str) -> Comment { + Comment { + parent: CharacterData::new(CommentNodeTypeId, text) + } + } + + pub fn Constructor(owner: @mut Window, data: &DOMString, _rv: &mut ErrorResult) -> AbstractNode { + let s = match *data { + str(ref s) => s.clone(), + null_string => ~"" + }; + unsafe { + let compartment = (*owner.page).js_info.get_ref().js_compartment; + Node::as_abstract_node(compartment.cx.ptr, @Comment::new(s)) + } + } +} diff --git a/src/components/script/dom/documenttype.rs b/src/components/script/dom/documenttype.rs new file mode 100644 index 00000000000..3ac1d1f0db0 --- /dev/null +++ b/src/components/script/dom/documenttype.rs @@ -0,0 +1,50 @@ +/* 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::{DOMString, str, null_string}; +use dom::node::{ScriptView, Node, DoctypeNodeTypeId}; + +/// The `DOCTYPE` tag. +pub struct DocumentType { + parent: Node, + name: ~str, + public_id: Option<~str>, + system_id: Option<~str>, + force_quirks: bool +} + +impl DocumentType { + /// Creates a new `DOCTYPE` tag. + pub fn new(name: ~str, + public_id: Option<~str>, + system_id: Option<~str>, + force_quirks: bool) + -> DocumentType { + DocumentType { + parent: Node::new(DoctypeNodeTypeId), + name: name, + public_id: public_id, + system_id: system_id, + force_quirks: force_quirks, + } + } + + pub fn Name(&self) -> DOMString { + str(self.name.clone()) + } + + pub fn PublicId(&self) -> DOMString { + match self.public_id { + Some(ref s) => str(s.clone()), + None => null_string + } + } + + pub fn SystemId(&self) -> DOMString { + match self.system_id { + Some(ref s) => str(s.clone()), + None => null_string + } + } +} diff --git a/src/components/script/dom/node.rs b/src/components/script/dom/node.rs index 23d76712022..f7d01575bf6 100644 --- a/src/components/script/dom/node.rs +++ b/src/components/script/dom/node.rs @@ -8,7 +8,6 @@ use dom::bindings::node; use dom::bindings::utils::{WrapperCache, DOMString, null_string, ErrorResult}; use dom::bindings::utils::{BindingObject, CacheableWrapper, rust_box}; use dom::bindings; -use dom::characterdata::CharacterData; use dom::document::AbstractDocument; use dom::element::{Element, ElementTypeId, HTMLImageElementTypeId, HTMLIframeElementTypeId}; use dom::element::{HTMLStyleElementTypeId}; @@ -98,50 +97,6 @@ pub enum NodeTypeId { TextNodeTypeId, } -// -// Basic node types -// - -/// The `DOCTYPE` tag. -pub struct Doctype { - parent: Node, - name: ~str, - public_id: Option<~str>, - system_id: Option<~str>, - force_quirks: bool -} - -impl Doctype { - /// Creates a new `DOCTYPE` tag. - pub fn new(name: ~str, - public_id: Option<~str>, - system_id: Option<~str>, - force_quirks: bool) - -> Doctype { - Doctype { - parent: Node::new(DoctypeNodeTypeId), - name: name, - public_id: public_id, - system_id: system_id, - force_quirks: force_quirks, - } - } -} - -/// An HTML comment. -pub struct Comment { - parent: CharacterData, -} - -impl Comment { - /// Creates a new HTML comment. - pub fn new(text: ~str) -> Comment { - Comment { - parent: CharacterData::new(CommentNodeTypeId, text) - } - } -} - impl Clone for AbstractNode { fn clone(&self) -> AbstractNode { *self @@ -655,7 +610,6 @@ impl VoidPtrLike for AbstractNode { pub fn define_bindings(compartment: @mut Compartment) { bindings::node::init(compartment); bindings::element::init(compartment); - bindings::text::init(compartment); bindings::utils::initialize_global(compartment.global_obj.ptr); bindings::codegen::RegisterBindings::Register(compartment); } diff --git a/src/components/script/dom/text.rs b/src/components/script/dom/text.rs index 95926d12d92..807b1645d57 100644 --- a/src/components/script/dom/text.rs +++ b/src/components/script/dom/text.rs @@ -2,13 +2,10 @@ * 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::{DOMString, ErrorResult, null_string, CacheableWrapper}; -use dom::bindings::utils::{BindingObject, WrapperCache}; -use dom::bindings::codegen::TextBinding; +use dom::bindings::utils::{DOMString, ErrorResult, null_string}; use dom::characterdata::CharacterData; use dom::node::{AbstractNode, ScriptView, Node, TextNodeTypeId}; use dom::window::Window; -use js::jsapi::{JSContext, JSObject}; /// An HTML text node. pub struct Text { @@ -36,20 +33,3 @@ impl Text { null_string } } - -impl CacheableWrapper for Text { - fn get_wrappercache(&mut self) -> &mut WrapperCache { - self.parent.get_wrappercache() - } - - fn wrap_object_shared(@mut self, cx: *JSContext, scope: *JSObject) -> *JSObject { - let mut unused = false; - TextBinding::Wrap(cx, scope, self, &mut unused) - } -} - -impl BindingObject for Text { - fn GetParentObject(&self, cx: *JSContext) -> Option<@mut CacheableWrapper> { - self.parent.GetParentObject(cx) - } -} diff --git a/src/components/script/html/hubbub_html_parser.rs b/src/components/script/html/hubbub_html_parser.rs index 2d9803d9670..75882950351 100644 --- a/src/components/script/html/hubbub_html_parser.rs +++ b/src/components/script/html/hubbub_html_parser.rs @@ -8,7 +8,7 @@ use dom::htmlelement::HTMLElement; use dom::htmlheadingelement::{Heading1, Heading2, Heading3, Heading4, Heading5, Heading6}; use dom::htmliframeelement::IFrameSize; use dom::htmlformelement::HTMLFormElement; -use dom::node::{AbstractNode, Comment, Doctype, ElementNodeTypeId, Node, ScriptView}; +use dom::node::{AbstractNode, ElementNodeTypeId, Node, ScriptView}; use dom::types::*; use html::cssparse::{InlineProvenance, StylesheetProvenance, UrlProvenance, spawn_css_parser}; use js::jsapi::JSContext; @@ -326,10 +326,10 @@ pub fn parse_html(cx: *JSContext, public_id: public_id, system_id: system_id, force_quirks: force_quirks } = doctype; - let node = @Doctype::new(name, - public_id, - system_id, - force_quirks); + let node = @DocumentType::new(name, + public_id, + system_id, + force_quirks); unsafe { Node::as_abstract_node(cx, node).to_hubbub_node() } diff --git a/src/components/script/script.rc b/src/components/script/script.rc index af4b60910d6..21a70515c86 100644 --- a/src/components/script/script.rc +++ b/src/components/script/script.rc @@ -26,7 +26,6 @@ pub mod dom { pub mod bindings { pub mod element; pub mod node; - pub mod text; pub mod utils; pub mod conversions; pub mod proxyhandler; @@ -48,7 +47,9 @@ pub mod dom { pub mod characterdata; pub mod clientrect; pub mod clientrectlist; + pub mod comment; pub mod document; + pub mod documenttype; pub mod domparser; pub mod element; pub mod event;