mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Generate bindings for Comment and DocumentType.
This commit is contained in:
parent
1eb5eeb630
commit
8070f02e39
12 changed files with 147 additions and 187 deletions
|
@ -367,12 +367,6 @@ DOMInterfaces = {
|
|||
'resultNotAddRefed': [ 'getItem' ]
|
||||
}],
|
||||
|
||||
'Text': {
|
||||
'nativeType': 'AbstractNode<ScriptView>',
|
||||
'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<ScriptView>',
|
||||
'pointerType': ''
|
||||
'pointerType': '',
|
||||
'concreteType': concrete if concrete else element
|
||||
}
|
||||
|
||||
addHTMLElement('Comment')
|
||||
addHTMLElement('DocumentType', concrete='DocumentType<ScriptView>')
|
||||
addHTMLElement('Text')
|
||||
|
||||
addHTMLElement('HTMLAnchorElement')
|
||||
addHTMLElement('HTMLAppletElement')
|
||||
addHTMLElement('HTMLAreaElement')
|
||||
|
|
15
src/components/script/dom/bindings/codegen/Comment.webidl
Normal file
15
src/components/script/dom/bindings/codegen/Comment.webidl
Normal file
|
@ -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 {
|
||||
};
|
|
@ -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;
|
|
@ -311,7 +311,7 @@ pub fn create(cx: *JSContext, node: &mut AbstractNode<ScriptView>) -> 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<ScriptView>, DocumentTypeBinding::Wrap)
|
||||
generate_binding_object!(DocumentType<ScriptView>)
|
||||
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)
|
||||
|
|
|
@ -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<ScriptView>) -> *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<ScriptView>),
|
||||
TextNodeTypeId => generate_element!(Text)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<ScriptView> = 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<ScriptView> = 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<ScriptView> = unwrap(obj);
|
||||
let _elem: ~Doctype<ScriptView> = 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<ScriptView>) -> 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;
|
||||
}
|
33
src/components/script/dom/comment.rs
Normal file
33
src/components/script/dom/comment.rs
Normal file
|
@ -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<ScriptView> {
|
||||
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))
|
||||
}
|
||||
}
|
||||
}
|
50
src/components/script/dom/documenttype.rs
Normal file
50
src/components/script/dom/documenttype.rs
Normal file
|
@ -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<View> {
|
||||
parent: Node<View>,
|
||||
name: ~str,
|
||||
public_id: Option<~str>,
|
||||
system_id: Option<~str>,
|
||||
force_quirks: bool
|
||||
}
|
||||
|
||||
impl DocumentType<ScriptView> {
|
||||
/// Creates a new `DOCTYPE` tag.
|
||||
pub fn new(name: ~str,
|
||||
public_id: Option<~str>,
|
||||
system_id: Option<~str>,
|
||||
force_quirks: bool)
|
||||
-> DocumentType<ScriptView> {
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<View> {
|
||||
parent: Node<View>,
|
||||
name: ~str,
|
||||
public_id: Option<~str>,
|
||||
system_id: Option<~str>,
|
||||
force_quirks: bool
|
||||
}
|
||||
|
||||
impl Doctype<ScriptView> {
|
||||
/// Creates a new `DOCTYPE` tag.
|
||||
pub fn new(name: ~str,
|
||||
public_id: Option<~str>,
|
||||
system_id: Option<~str>,
|
||||
force_quirks: bool)
|
||||
-> Doctype<ScriptView> {
|
||||
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<View> Clone for AbstractNode<View> {
|
||||
fn clone(&self) -> AbstractNode<View> {
|
||||
*self
|
||||
|
@ -655,7 +610,6 @@ impl VoidPtrLike for AbstractNode<LayoutView> {
|
|||
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);
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue