Autogenerate DOM bindings for Document.

This commit is contained in:
Josh Matthews 2013-07-26 12:58:01 -04:00
parent 07267c634a
commit 09d50147f7
10 changed files with 581 additions and 217 deletions

View file

@ -2,16 +2,26 @@
* 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::document;
use dom::bindings::utils::{DOMString, WrapperCache};
use dom::bindings::codegen::DocumentBinding;
use dom::bindings::codegen::DocumentBinding::VisibilityState;
use dom::bindings::codegen::DocumentBinding::VisibilityStateValues::Visible;
use dom::bindings::utils::{DOMString, WrapperCache, ErrorResult, null_string};
use dom::bindings::utils::{BindingObject, CacheableWrapper};
use dom::element::{HTMLHtmlElement, HTMLHtmlElementTypeId, Element};
use dom::event::Event_;
use dom::htmlcollection::HTMLCollection;
use dom::node::{AbstractNode, ScriptView};
use dom::node::{AbstractNode, ScriptView, Node};
use dom::window::Window;
use dom::windowproxy::WindowProxy;
use script_task::global_script_context;
use js::jsapi::{JS_AddObjectRoot, JS_RemoveObjectRoot};
use js::JSPROP_ENUMERATE;
use js::glue::*;
use js::jsapi::{JS_AddObjectRoot, JS_RemoveObjectRoot, JSObject, JSContext};
use servo_util::tree::{TreeNodeRef, TreeUtils};
use std::cast;
use std::ptr;
use std::str::eq_slice;
pub struct Document {
@ -33,13 +43,81 @@ pub fn Document(root: AbstractNode<ScriptView>, window: Option<@mut Window>) ->
let rootable = base.wrapper.get_rootable();
JS_AddObjectRoot(compartment.cx.ptr, rootable);
}
document::create(compartment, doc);
let cx = global_script_context().js_compartment.cx.ptr;
doc.wrap_object_shared(cx, ptr::null()); //XXXjdm a proper scope would be nice
match window {
Some(win) => {
//FIXME: This is a hack until Window is autogenerated
let compartment = (*win.script_task).js_compartment;
compartment.define_property(~"document",
RUST_OBJECT_TO_JSVAL(doc.wrapper.wrapper),
GetJSClassHookStubPointer(PROPERTY_STUB) as *u8,
GetJSClassHookStubPointer(STRICT_PROPERTY_STUB) as *u8,
JSPROP_ENUMERATE);
}
None => ()
}
doc
}
}
impl CacheableWrapper for Document {
fn get_wrappercache(&mut self) -> &mut WrapperCache {
unsafe { cast::transmute(&self.wrapper) }
}
fn wrap_object_shared(@mut self, cx: *JSContext, scope: *JSObject) -> *JSObject {
let mut unused = false;
DocumentBinding::Wrap(cx, scope, self, &mut unused)
}
}
impl BindingObject for Document {
fn GetParentObject(&self, _cx: *JSContext) -> @mut CacheableWrapper {
match self.window {
Some(win) => win as @mut CacheableWrapper,
None => fail!("whoops")
}
}
}
impl Document {
pub fn getElementsByTagName(&self, tag: DOMString) -> Option<@mut HTMLCollection> {
pub fn Constructor(_owner: @mut Window, _rv: &mut ErrorResult) -> @mut Document {
let root = ~HTMLHtmlElement {
parent: Element::new(HTMLHtmlElementTypeId, ~"html")
};
let root = unsafe { Node::as_abstract_node(root) };
Document(root, None)
}
pub fn URL(&self) -> DOMString {
null_string
}
pub fn DocumentURI(&self) -> DOMString {
null_string
}
pub fn CompatMode(&self) -> DOMString {
null_string
}
pub fn CharacterSet(&self) -> DOMString {
null_string
}
pub fn ContentType(&self) -> DOMString {
null_string
}
pub fn GetDocumentElement(&self) -> Option<AbstractNode<ScriptView>> {
Some(self.root)
}
pub fn GetElementsByTagName(&self, tag: DOMString) -> @mut HTMLCollection {
let mut elements = ~[];
let tag = tag.to_str();
let _ = for self.root.traverse_preorder |child| {
@ -51,10 +129,141 @@ impl Document {
}
}
};
Some(HTMLCollection::new(elements))
HTMLCollection::new(elements)
}
pub fn getElementsByName(&self, name: DOMString) -> Option<@mut HTMLCollection> {
pub fn GetElementsByTagNameNS(&self, _ns: DOMString, _tag: DOMString) -> @mut HTMLCollection {
HTMLCollection::new(~[])
}
pub fn GetElementsByClassName(&self, _class: DOMString) -> @mut HTMLCollection {
HTMLCollection::new(~[])
}
pub fn GetElementById(&self, _id: DOMString) -> Option<AbstractNode<ScriptView>> {
None
}
pub fn CreateElement(&self, _local_name: DOMString, _rv: &mut ErrorResult) -> AbstractNode<ScriptView> {
fail!("stub")
}
pub fn CreateElementNS(&self, _namespace: DOMString, _qualified_name: DOMString, _rv: &mut ErrorResult) -> AbstractNode<ScriptView> {
fail!("stub")
}
pub fn CreateEvent(&self, _interface: DOMString, _rv: &mut ErrorResult) -> @mut Event_ {
fail!("stub")
}
pub fn GetInputEncoding(&self) -> DOMString {
null_string
}
pub fn Referrer(&self) -> DOMString {
null_string
}
pub fn LastModified(&self) -> DOMString {
null_string
}
pub fn ReadyState(&self) -> DOMString {
null_string
}
pub fn Title(&self) -> DOMString {
null_string
}
pub fn SetTitle(&self, _title: DOMString, _rv: &mut ErrorResult) {
}
pub fn Dir(&self) -> DOMString {
null_string
}
pub fn SetDir(&self, _dir: DOMString) {
}
pub fn GetDefaultView(&self) -> Option<@mut WindowProxy> {
None
}
pub fn GetActiveElement(&self) -> Option<AbstractNode<ScriptView>> {
None
}
pub fn HasFocus(&self, _rv: &mut ErrorResult) -> bool {
false
}
pub fn GetCurrentScript(&self) -> Option<AbstractNode<ScriptView>> {
None
}
pub fn ReleaseCapture(&self) {
}
pub fn MozFullScreenEnabled(&self) -> bool {
false
}
pub fn GetMozFullScreenElement(&self, _rv: &mut ErrorResult) -> Option<AbstractNode<ScriptView>> {
None
}
pub fn GetMozPointerLockElement(&self) -> Option<AbstractNode<ScriptView>> {
None
}
pub fn MozExitPointerLock(&self) {
}
pub fn Hidden(&self) -> bool {
false
}
pub fn MozHidden(&self) -> bool {
self.Hidden()
}
pub fn VisibilityState(&self) -> VisibilityState {
Visible
}
pub fn MozVisibilityState(&self) -> VisibilityState {
self.VisibilityState()
}
pub fn GetSelectedStyleSheetSet(&self) -> DOMString {
null_string
}
pub fn SetSelectedStyleSheetSet(&self, _sheet: DOMString) {
}
pub fn GetLastStyleSheetSet(&self) -> DOMString {
null_string
}
pub fn GetPreferredStyleSheetSet(&self) -> DOMString {
null_string
}
pub fn EnableStyleSheetsForSet(&self, _name: DOMString) {
}
pub fn ElementFromPoint(&self, _x: f32, _y: f32) -> Option<AbstractNode<ScriptView>> {
None
}
pub fn QuerySelector(&self, _selectors: DOMString, _rv: &mut ErrorResult) -> Option<AbstractNode<ScriptView>> {
None
}
pub fn GetElementsByName(&self, name: DOMString) -> @mut HTMLCollection {
let mut elements = ~[];
let name = name.to_str();
let _ = for self.root.traverse_preorder |child| {
@ -67,7 +276,7 @@ impl Document {
}
}
};
Some(HTMLCollection::new(elements))
HTMLCollection::new(elements)
}
pub fn content_changed(&self) {