mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
Autogenerate DOM bindings for Document.
This commit is contained in:
parent
07267c634a
commit
09d50147f7
10 changed files with 581 additions and 217 deletions
|
@ -134,6 +134,9 @@ DOMInterfaces = {
|
|||
'prefable': True
|
||||
},
|
||||
|
||||
'Document': {
|
||||
},
|
||||
|
||||
'DOMParser': {
|
||||
'nativeType': 'DOMParser',
|
||||
},
|
||||
|
@ -521,7 +524,6 @@ addExternalIface('CanvasGradient', headerFile='nsIDOMCanvasRenderingContext2D.h'
|
|||
addExternalIface('CanvasPattern', headerFile='nsIDOMCanvasRenderingContext2D.h')
|
||||
addExternalIface('CSSRule')
|
||||
addExternalIface('CSSValue')
|
||||
addExternalIface('Document', nativeType='Document', pointerType='@mut ')
|
||||
addExternalIface('DOMStringList', nativeType='nsDOMStringList',
|
||||
headerFile='nsDOMLists.h')
|
||||
addExternalIface('Element', nativeType='AbstractNode<ScriptView>', pointerType='')
|
||||
|
|
|
@ -1573,15 +1573,15 @@ for (uint32_t i = 0; i < length; ++i) {
|
|||
if type.nullable():
|
||||
raise TypeError("We don't support nullable enumerated return types "
|
||||
"yet")
|
||||
return ("""MOZ_ASSERT(uint32_t(%(result)s) < ArrayLength(%(strings)s));
|
||||
JSString* %(resultStr)s = JS_NewStringCopyN(cx, %(strings)s[uint32_t(%(result)s)].value, %(strings)s[uint32_t(%(result)s)].length);
|
||||
if (!%(resultStr)s) {
|
||||
return false;
|
||||
return ("""assert!((%(result)s as uint) < %(strings)s.len());
|
||||
let %(resultStr)s: *JSString = JS_NewStringCopyN(cx, ptr::to_unsafe_ptr(&%(strings)s[%(result)s as u32].value[0]) as *i8, %(strings)s[%(result)s as u32].length as u64);
|
||||
if %(resultStr)s.is_null() {
|
||||
return 0;
|
||||
}
|
||||
""" % { "result" : result,
|
||||
"resultStr" : result + "_str",
|
||||
"strings" : type.inner.identifier.name + "Values::strings" } +
|
||||
setValue("JS::StringValue(%s_str)" % result), False)
|
||||
setValue("RUST_STRING_TO_JSVAL(%s_str)" % result), False)
|
||||
|
||||
if type.isCallback():
|
||||
assert not type.isInterface()
|
||||
|
@ -2924,7 +2924,7 @@ class CGCallGenerator(CGThing):
|
|||
call = CGList([call, CGWrapper(args, pre="(", post=");")])
|
||||
if result is not None:
|
||||
if declareResult:
|
||||
result = CGWrapper(result, pre="let result: ", post=";")
|
||||
result = CGWrapper(result, pre="let mut result: ", post=";")
|
||||
self.cgRoot.prepend(result)
|
||||
if not resultOutParam:
|
||||
call = CGWrapper(call, pre="result = ")
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
/*interface Principal;
|
||||
interface URI;
|
||||
interface InputStream;*/
|
||||
interface Document;
|
||||
|
||||
enum SupportedType {
|
||||
"text/html",
|
||||
|
|
337
src/components/script/dom/bindings/codegen/Document.webidl
Normal file
337
src/components/script/dom/bindings/codegen/Document.webidl
Normal file
|
@ -0,0 +1,337 @@
|
|||
/* -*- 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-document
|
||||
* http://www.whatwg.org/specs/web-apps/current-work/#the-document-object
|
||||
* http://dvcs.w3.org/hg/fullscreen/raw-file/tip/Overview.html#api
|
||||
* http://dvcs.w3.org/hg/pointerlock/raw-file/default/index.html#extensions-to-the-document-interface
|
||||
* http://dvcs.w3.org/hg/webperf/raw-file/tip/specs/PageVisibility/Overview.html#sec-document-interface
|
||||
* http://dev.w3.org/csswg/cssom/#extensions-to-the-document-interface
|
||||
* http://dev.w3.org/csswg/cssom-view/#extensions-to-the-document-interface
|
||||
*
|
||||
* http://mxr.mozilla.org/mozilla-central/source/dom/interfaces/core/nsIDOMDocument.idl
|
||||
*/
|
||||
|
||||
/*interface StyleSheetList;
|
||||
interface WindowProxy;
|
||||
interface nsISupports;
|
||||
interface URI;*/
|
||||
|
||||
enum VisibilityState { "hidden", "visible" };
|
||||
|
||||
/* http://dom.spec.whatwg.org/#interface-document */
|
||||
[Constructor]
|
||||
interface Document /*: Node*/ { //XXXjdm Requires servo/#623
|
||||
/*[Throws]
|
||||
readonly attribute DOMImplementation implementation;*/
|
||||
readonly attribute DOMString URL;
|
||||
readonly attribute DOMString documentURI;
|
||||
readonly attribute DOMString compatMode;
|
||||
readonly attribute DOMString characterSet;
|
||||
readonly attribute DOMString contentType;
|
||||
|
||||
//readonly attribute DocumentType? doctype;
|
||||
readonly attribute Element? documentElement;
|
||||
HTMLCollection getElementsByTagName(DOMString localName);
|
||||
HTMLCollection getElementsByTagNameNS(DOMString? namespace, DOMString localName);
|
||||
HTMLCollection getElementsByClassName(DOMString classNames);
|
||||
Element? getElementById(DOMString elementId);
|
||||
|
||||
[Creator, Throws]
|
||||
Element createElement(DOMString localName);
|
||||
[Creator, Throws]
|
||||
Element createElementNS(DOMString? namespace, DOMString qualifiedName);
|
||||
/*[Creator]
|
||||
DocumentFragment createDocumentFragment();
|
||||
[Creator]
|
||||
Text createTextNode(DOMString data);
|
||||
[Creator]
|
||||
Comment createComment(DOMString data);
|
||||
[Creator, Throws]
|
||||
ProcessingInstruction createProcessingInstruction(DOMString target, DOMString data);*/
|
||||
|
||||
/*[Throws]
|
||||
Node importNode(Node node, optional boolean deep = true);
|
||||
[Throws]
|
||||
Node adoptNode(Node node);*/
|
||||
|
||||
[Creator, Throws]
|
||||
Event createEvent(DOMString interface_);
|
||||
|
||||
/*[Creator, Throws]
|
||||
Range createRange();*/
|
||||
|
||||
// NodeFilter.SHOW_ALL = 0xFFFFFFFF
|
||||
/*[Creator, Throws]
|
||||
NodeIterator createNodeIterator(Node root, optional unsigned long whatToShow = 0xFFFFFFFF, optional NodeFilter? filter = null);
|
||||
[Creator, Throws]
|
||||
TreeWalker createTreeWalker(Node root, optional unsigned long whatToShow = 0xFFFFFFFF, optional NodeFilter? filter = null);*/
|
||||
|
||||
// NEW
|
||||
// No support for prepend/append yet
|
||||
// void prepend((Node or DOMString)... nodes);
|
||||
// void append((Node or DOMString)... nodes);
|
||||
|
||||
// These are not in the spec, but leave them for now for backwards compat.
|
||||
// So sort of like Gecko extensions
|
||||
/*[Creator, Throws]
|
||||
CDATASection createCDATASection(DOMString data);
|
||||
[Creator, Throws]
|
||||
Attr createAttribute(DOMString name);
|
||||
[Creator, Throws]
|
||||
Attr createAttributeNS(DOMString? namespace, DOMString name);*/
|
||||
readonly attribute DOMString? inputEncoding;
|
||||
};
|
||||
|
||||
// http://www.whatwg.org/specs/web-apps/current-work/#the-document-object
|
||||
partial interface Document {
|
||||
//[PutForwards=href, Unforgeable] readonly attribute Location? location;
|
||||
//(HTML only) attribute DOMString domain;
|
||||
readonly attribute DOMString referrer;
|
||||
//(HTML only) attribute DOMString cookie;
|
||||
readonly attribute DOMString lastModified;
|
||||
readonly attribute DOMString readyState;
|
||||
|
||||
// DOM tree accessors
|
||||
//(Not proxy yet)getter object (DOMString name);
|
||||
[SetterThrows]
|
||||
attribute DOMString title;
|
||||
attribute DOMString dir;
|
||||
//(HTML only) attribute HTMLElement? body;
|
||||
//(HTML only)readonly attribute HTMLHeadElement? head;
|
||||
//(HTML only)readonly attribute HTMLCollection images;
|
||||
//(HTML only)readonly attribute HTMLCollection embeds;
|
||||
//(HTML only)readonly attribute HTMLCollection plugins;
|
||||
//(HTML only)readonly attribute HTMLCollection links;
|
||||
//(HTML only)readonly attribute HTMLCollection forms;
|
||||
//(HTML only)readonly attribute HTMLCollection scripts;
|
||||
/*NodeList*/ HTMLCollection getElementsByName(DOMString elementName); ////(HTML only)
|
||||
//(HTML only)NodeList getItems(optional DOMString typeNames); // microdata
|
||||
//(Not implemented)readonly attribute DOMElementMap cssElementMap;
|
||||
|
||||
// dynamic markup insertion
|
||||
//(HTML only)Document open(optional DOMString type, optional DOMString replace);
|
||||
//(HTML only)WindowProxy open(DOMString url, DOMString name, DOMString features, optional boolean replace);
|
||||
//(HTML only)void close();
|
||||
//(HTML only)void write(DOMString... text);
|
||||
//(HTML only)void writeln(DOMString... text);
|
||||
|
||||
// user interaction
|
||||
readonly attribute WindowProxy? defaultView;
|
||||
readonly attribute Element? activeElement;
|
||||
[Throws]
|
||||
boolean hasFocus();
|
||||
//(HTML only) attribute DOMString designMode;
|
||||
//(HTML only)boolean execCommand(DOMString commandId);
|
||||
//(HTML only)boolean execCommand(DOMString commandId, boolean showUI);
|
||||
//(HTML only)boolean execCommand(DOMString commandId, boolean showUI, DOMString value);
|
||||
//(HTML only)boolean queryCommandEnabled(DOMString commandId);
|
||||
//(HTML only)boolean queryCommandIndeterm(DOMString commandId);
|
||||
//(HTML only)boolean queryCommandState(DOMString commandId);
|
||||
//(HTML only)boolean queryCommandSupported(DOMString commandId);
|
||||
//(HTML only)DOMString queryCommandValue(DOMString commandId);
|
||||
//(Not implemented)readonly attribute HTMLCollection commands;
|
||||
|
||||
// special event handler IDL attributes that only apply to Document objects
|
||||
//[LenientThis, SetterThrows] attribute EventHandler onreadystatechange;
|
||||
|
||||
// Gecko extensions?
|
||||
/*[LenientThis, SetterThrows] attribute EventHandler onmouseenter;
|
||||
[LenientThis, SetterThrows] attribute EventHandler onmouseleave;
|
||||
[SetterThrows] attribute EventHandler onwheel;
|
||||
[SetterThrows] attribute EventHandler oncopy;
|
||||
[SetterThrows] attribute EventHandler oncut;
|
||||
[SetterThrows] attribute EventHandler onpaste;
|
||||
[SetterThrows] attribute EventHandler onbeforescriptexecute;
|
||||
[SetterThrows] attribute EventHandler onafterscriptexecute;*/
|
||||
/**
|
||||
* True if this document is synthetic : stand alone image, video, audio file,
|
||||
* etc.
|
||||
*/
|
||||
//[ChromeOnly] readonly attribute boolean mozSyntheticDocument;
|
||||
/**
|
||||
* Returns the script element whose script is currently being processed.
|
||||
*
|
||||
* @see <https://developer.mozilla.org/en/DOM/document.currentScript>
|
||||
*/
|
||||
readonly attribute Element? currentScript;
|
||||
/**
|
||||
* Release the current mouse capture if it is on an element within this
|
||||
* document.
|
||||
*
|
||||
* @see <https://developer.mozilla.org/en/DOM/document.releaseCapture>
|
||||
*/
|
||||
void releaseCapture();
|
||||
/**
|
||||
* Use the given DOM element as the source image of target |-moz-element()|.
|
||||
*
|
||||
* This function introduces a new special ID (called "image element ID"),
|
||||
* which is only used by |-moz-element()|, and associates it with the given
|
||||
* DOM element. Image elements ID's have the higher precedence than general
|
||||
* HTML id's, so if |document.mozSetImageElement(<id>, <element>)| is called,
|
||||
* |-moz-element(#<id>)| uses |<element>| as the source image even if there
|
||||
* is another element with id attribute = |<id>|. To unregister an image
|
||||
* element ID |<id>|, call |document.mozSetImageElement(<id>, null)|.
|
||||
*
|
||||
* Example:
|
||||
* <script>
|
||||
* canvas = document.createElement("canvas");
|
||||
* canvas.setAttribute("width", 100);
|
||||
* canvas.setAttribute("height", 100);
|
||||
* // draw to canvas
|
||||
* document.mozSetImageElement("canvasbg", canvas);
|
||||
* </script>
|
||||
* <div style="background-image: -moz-element(#canvasbg);"></div>
|
||||
*
|
||||
* @param aImageElementId an image element ID to associate with
|
||||
* |aImageElement|
|
||||
* @param aImageElement a DOM element to be used as the source image of
|
||||
* |-moz-element(#aImageElementId)|. If this is null, the function will
|
||||
* unregister the image element ID |aImageElementId|.
|
||||
*
|
||||
* @see <https://developer.mozilla.org/en/DOM/document.mozSetImageElement>
|
||||
*/
|
||||
/*void mozSetImageElement(DOMString aImageElementId,
|
||||
Element? aImageElement);*/
|
||||
|
||||
/*[ChromeOnly]
|
||||
readonly attribute URI? documentURIObject;*/
|
||||
|
||||
};
|
||||
|
||||
// http://dvcs.w3.org/hg/fullscreen/raw-file/tip/Overview.html#api
|
||||
partial interface Document {
|
||||
// Note: Per spec the 'S' in these two is lowercase, but the "Moz"
|
||||
// versions hve it uppercase.
|
||||
readonly attribute boolean mozFullScreenEnabled;
|
||||
[Throws]
|
||||
readonly attribute Element? mozFullScreenElement;
|
||||
|
||||
//(Renamed?)void exitFullscreen();
|
||||
|
||||
// Gecko-specific fullscreen bits
|
||||
/*readonly attribute boolean mozFullScreen;
|
||||
void mozCancelFullScreen();*/
|
||||
};
|
||||
|
||||
// http://dvcs.w3.org/hg/pointerlock/raw-file/default/index.html#extensions-to-the-document-interface
|
||||
partial interface Document {
|
||||
readonly attribute Element? mozPointerLockElement;
|
||||
void mozExitPointerLock ();
|
||||
};
|
||||
|
||||
//http://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/custom/index.html#dfn-document-register
|
||||
/*partial interface Document {
|
||||
[Throws, Pref="dom.webcomponents.enabled"]
|
||||
object register(DOMString name, optional ElementRegistrationOptions options);
|
||||
};*/
|
||||
|
||||
// http://dvcs.w3.org/hg/webperf/raw-file/tip/specs/PageVisibility/Overview.html#sec-document-interface
|
||||
partial interface Document {
|
||||
readonly attribute boolean hidden;
|
||||
readonly attribute boolean mozHidden;
|
||||
readonly attribute VisibilityState visibilityState;
|
||||
readonly attribute VisibilityState mozVisibilityState;
|
||||
};
|
||||
|
||||
// http://dev.w3.org/csswg/cssom/#extensions-to-the-document-interface
|
||||
partial interface Document {
|
||||
/*[Constant]
|
||||
readonly attribute StyleSheetList styleSheets;*/
|
||||
attribute DOMString? selectedStyleSheetSet;
|
||||
readonly attribute DOMString? lastStyleSheetSet;
|
||||
readonly attribute DOMString? preferredStyleSheetSet;
|
||||
/*[Constant]
|
||||
readonly attribute DOMStringList styleSheetSets;*/
|
||||
void enableStyleSheetsForSet (DOMString? name);
|
||||
};
|
||||
|
||||
// http://dev.w3.org/csswg/cssom-view/#extensions-to-the-document-interface
|
||||
partial interface Document {
|
||||
Element? elementFromPoint (float x, float y);
|
||||
|
||||
//CaretPosition? caretPositionFromPoint (float x, float y);
|
||||
};
|
||||
|
||||
// http://dvcs.w3.org/hg/undomanager/raw-file/tip/undomanager.html
|
||||
/*partial interface Document {
|
||||
[Pref="dom.undo_manager.enabled"]
|
||||
readonly attribute UndoManager? undoManager;
|
||||
};*/
|
||||
|
||||
// http://dev.w3.org/2006/webapi/selectors-api2/#interface-definitions
|
||||
partial interface Document {
|
||||
[Throws]
|
||||
Element? querySelector(DOMString selectors);
|
||||
/*[Throws]
|
||||
NodeList querySelectorAll(DOMString selectors);*/
|
||||
|
||||
//(Not implemented)Element? find(DOMString selectors, optional (Element or sequence<Node>)? refNodes);
|
||||
//(Not implemented)NodeList findAll(DOMString selectors, optional (Element or sequence<Node>)? refNodes);
|
||||
};
|
||||
|
||||
// Mozilla extensions of various sorts
|
||||
/*partial interface Document {
|
||||
// nsIDOMDocumentXBL. Wish we could make these [ChromeOnly], but
|
||||
// that would likely break bindings running with the page principal.
|
||||
NodeList? getAnonymousNodes(Element elt);
|
||||
Element? getAnonymousElementByAttribute(Element elt, DOMString attrName,
|
||||
DOMString attrValue);
|
||||
Element? getBindingParent(Node node);
|
||||
[Throws]
|
||||
void loadBindingDocument(DOMString documentURL);
|
||||
|
||||
// nsIDOMDocumentTouch
|
||||
// XXXbz I can't find the sane spec for this stuff, so just cribbing
|
||||
// from our xpidl for now.
|
||||
[Creator, Func="nsGenericHTMLElement::TouchEventsEnabled"]
|
||||
Touch createTouch(optional Window? view = null,
|
||||
optional EventTarget? target = null,
|
||||
optional long identifier = 0,
|
||||
optional long pageX = 0,
|
||||
optional long pageY = 0,
|
||||
optional long screenX = 0,
|
||||
optional long screenY = 0,
|
||||
optional long clientX = 0,
|
||||
optional long clientY = 0,
|
||||
optional long radiusX = 0,
|
||||
optional long radiusY = 0,
|
||||
optional float rotationAngle = 0,
|
||||
optional float force = 0);
|
||||
// XXXbz a hack to get around the fact that we don't support variadics as
|
||||
// distinguishing arguments yet. Once this hack is removed. we can also
|
||||
// remove the corresponding overload on nsIDocument, since Touch... and
|
||||
// sequence<Touch> look the same in the C++.
|
||||
[Creator, Func="nsGenericHTMLElement::TouchEventsEnabled"]
|
||||
TouchList createTouchList(Touch touch, Touch... touches);
|
||||
// XXXbz and another hack for the fact that we can't usefully have optional
|
||||
// distinguishing arguments but need a working zero-arg form of
|
||||
// createTouchList().
|
||||
[Creator, Func="nsGenericHTMLElement::TouchEventsEnabled"]
|
||||
TouchList createTouchList();
|
||||
[Creator, Func="nsGenericHTMLElement::TouchEventsEnabled"]
|
||||
TouchList createTouchList(sequence<Touch> touches);
|
||||
|
||||
[ChromeOnly]
|
||||
attribute boolean styleSheetChangeEventsEnabled;
|
||||
|
||||
[ChromeOnly, Throws]
|
||||
void obsoleteSheet(URI sheetURI);
|
||||
[ChromeOnly, Throws]
|
||||
void obsoleteSheet(DOMString sheetURI);
|
||||
};
|
||||
|
||||
// Extension to give chrome JS the ability to determine when a document was
|
||||
// created to satisfy an iframe with srcdoc attribute.
|
||||
partial interface Document {
|
||||
[ChromeOnly] readonly attribute boolean isSrcdocDocument;
|
||||
};
|
||||
|
||||
Document implements XPathEvaluator;
|
||||
Document implements GlobalEventHandlers;
|
||||
Document implements NodeEventHandlers;
|
||||
Document implements TouchEventHandlers;
|
||||
Document implements ParentNode;*/
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
use js::jsapi::JSVal;
|
||||
use js::{JSVAL_FALSE, JSVAL_TRUE};
|
||||
use js::glue::{RUST_UINT_TO_JSVAL, RUST_JSVAL_TO_INT};
|
||||
use js::glue::{RUST_UINT_TO_JSVAL, RUST_JSVAL_TO_INT, RUST_DOUBLE_TO_JSVAL, RUST_JSVAL_TO_DOUBLE};
|
||||
|
||||
pub trait JSValConvertible {
|
||||
fn to_jsval(&self) -> JSVal;
|
||||
|
@ -71,4 +71,18 @@ impl JSValConvertible for bool {
|
|||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl JSValConvertible for f32 {
|
||||
fn to_jsval(&self) -> JSVal {
|
||||
unsafe {
|
||||
RUST_DOUBLE_TO_JSVAL(*self as f64)
|
||||
}
|
||||
}
|
||||
|
||||
fn from_jsval(val: JSVal) -> Option<f32> {
|
||||
unsafe {
|
||||
Some(RUST_JSVAL_TO_DOUBLE(val) as f32)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,196 +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 std::cast;
|
||||
use std::libc;
|
||||
use std::ptr;
|
||||
use std::result;
|
||||
use dom::bindings::utils::{DOMString, rust_box, squirrel_away, str};
|
||||
use dom::bindings::utils::{WrapperCache, DerivedWrapper};
|
||||
use dom::bindings::utils::{jsval_to_str, WrapNewBindingObject, CacheableWrapper};
|
||||
use dom::bindings::utils;
|
||||
use dom::document::Document;
|
||||
use dom::htmlcollection::HTMLCollection;
|
||||
use js::glue::*;
|
||||
use js::glue::{PROPERTY_STUB, STRICT_PROPERTY_STUB};
|
||||
use js::jsapi::{JS_DefineProperties};
|
||||
use js::jsapi::{JS_GetReservedSlot, JS_SetReservedSlot, JS_DefineFunctions};
|
||||
use js::jsapi::{JSContext, JSVal, JSObject, JSBool, JSFreeOp, JSPropertySpec, JSPropertyOpWrapper};
|
||||
use js::jsapi::{JSStrictPropertyOpWrapper, JSNativeWrapper, JSFunctionSpec};
|
||||
use js::rust::{Compartment, jsobj};
|
||||
use js::{JSPROP_NATIVE_ACCESSORS};
|
||||
use js::{JS_ARGV, JSPROP_ENUMERATE, JSPROP_SHARED, JSVAL_NULL, JS_THIS_OBJECT, JS_SET_RVAL};
|
||||
use script_task::task_from_context;
|
||||
|
||||
use std::libc::c_uint;
|
||||
use std::ptr::null;
|
||||
|
||||
extern fn getDocumentElement(cx: *JSContext, _argc: c_uint, vp: *mut JSVal) -> JSBool {
|
||||
unsafe {
|
||||
let obj = JS_THIS_OBJECT(cx, cast::transmute(vp));
|
||||
if obj.is_null() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
let doc = &mut (*unwrap(obj)).payload;
|
||||
let root = &mut doc.root;
|
||||
assert!(root.is_element());
|
||||
root.wrap(cx, ptr::null(), vp); //XXXjdm proper scope at some point
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
extern fn getElementsByTagName(cx: *JSContext, _argc: c_uint, vp: *JSVal) -> JSBool {
|
||||
unsafe {
|
||||
let obj = JS_THIS_OBJECT(cx, vp);
|
||||
|
||||
let argv = JS_ARGV(cx, cast::transmute(vp));
|
||||
|
||||
let arg0: DOMString;
|
||||
let strval = jsval_to_str(cx, (*argv.offset(0)));
|
||||
if strval.is_err() {
|
||||
return 0;
|
||||
}
|
||||
arg0 = str(strval.get());
|
||||
|
||||
let doc = &mut (*unwrap(obj)).payload;
|
||||
let rval: Option<@mut HTMLCollection>;
|
||||
rval = doc.getElementsByTagName(arg0);
|
||||
if rval.is_none() {
|
||||
JS_SET_RVAL(cx, vp, JSVAL_NULL);
|
||||
} else {
|
||||
let cache = doc.get_wrappercache();
|
||||
let rval = rval.get() as @mut CacheableWrapper;
|
||||
assert!(WrapNewBindingObject(cx, cache.get_wrapper(),
|
||||
rval,
|
||||
cast::transmute(vp)));
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
extern fn getElementsByName(cx: *JSContext, _argc: c_uint, vp: *JSVal) -> JSBool {
|
||||
unsafe {
|
||||
let obj = JS_THIS_OBJECT(cx, vp);
|
||||
|
||||
let argv = JS_ARGV(cx, cast::transmute(vp));
|
||||
|
||||
let arg0: DOMString;
|
||||
let strval = jsval_to_str(cx, (*argv.offset(0)));
|
||||
if strval.is_err() {
|
||||
return 0;
|
||||
}
|
||||
arg0 = str(strval.get());
|
||||
|
||||
let doc = &mut (*unwrap(obj)).payload;
|
||||
let rval: Option<@mut HTMLCollection>;
|
||||
rval = doc.getElementsByName(arg0);
|
||||
if rval.is_none() {
|
||||
JS_SET_RVAL(cx, vp, JSVAL_NULL);
|
||||
} else {
|
||||
let cache = doc.get_wrappercache();
|
||||
let rval = rval.get() as @mut CacheableWrapper;
|
||||
assert!(WrapNewBindingObject(cx, cache.get_wrapper(),
|
||||
rval,
|
||||
cast::transmute(vp)));
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
unsafe fn unwrap(obj: *JSObject) -> *mut rust_box<Document> {
|
||||
//TODO: some kind of check if this is a Document object
|
||||
let val = JS_GetReservedSlot(obj, 0);
|
||||
RUST_JSVAL_TO_PRIVATE(val) as *mut rust_box<Document>
|
||||
}
|
||||
|
||||
extern fn finalize(_fop: *JSFreeOp, obj: *JSObject) {
|
||||
debug!("document finalize!");
|
||||
unsafe {
|
||||
let val = JS_GetReservedSlot(obj, 0);
|
||||
let _doc: @Document = cast::transmute(RUST_JSVAL_TO_PRIVATE(val));
|
||||
}
|
||||
}
|
||||
|
||||
pub fn init(compartment: @mut Compartment) {
|
||||
let obj = utils::define_empty_prototype(~"Document", None, compartment);
|
||||
|
||||
let attrs = @~[
|
||||
JSPropertySpec {
|
||||
name: compartment.add_name(~"documentElement"),
|
||||
tinyid: 0,
|
||||
flags: (JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_NATIVE_ACCESSORS) as u8,
|
||||
getter: JSPropertyOpWrapper {op: getDocumentElement, info: null()},
|
||||
setter: JSStrictPropertyOpWrapper {op: null(), info: null()}},
|
||||
JSPropertySpec {
|
||||
name: null(),
|
||||
tinyid: 0,
|
||||
flags: (JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_NATIVE_ACCESSORS) as u8,
|
||||
getter: JSPropertyOpWrapper {op: null(), info: null()},
|
||||
setter: JSStrictPropertyOpWrapper {op: null(), info: null()}}];
|
||||
compartment.global_props.push(attrs);
|
||||
do attrs.as_imm_buf |specs, _len| {
|
||||
unsafe {
|
||||
assert!(JS_DefineProperties(compartment.cx.ptr, obj.ptr, specs) == 1);
|
||||
}
|
||||
}
|
||||
|
||||
let methods = @~[JSFunctionSpec {name: compartment.add_name(~"getElementsByTagName"),
|
||||
call: JSNativeWrapper {op: getElementsByTagName, info: null()},
|
||||
nargs: 0,
|
||||
flags: 0,
|
||||
selfHostedName: null()},
|
||||
JSFunctionSpec {name: compartment.add_name(~"getElementsByName"),
|
||||
call: JSNativeWrapper {op: getElementsByName, info: null()},
|
||||
nargs: 0,
|
||||
flags: 0,
|
||||
selfHostedName: null()},
|
||||
JSFunctionSpec {name: null(),
|
||||
call: JSNativeWrapper {op: null(), info: null()},
|
||||
nargs: 0,
|
||||
flags: 0,
|
||||
selfHostedName: null()}];
|
||||
do methods.as_imm_buf |fns, _len| {
|
||||
unsafe {
|
||||
JS_DefineFunctions(compartment.cx.ptr, obj.ptr, fns);
|
||||
}
|
||||
}
|
||||
|
||||
compartment.register_class(utils::instance_jsclass(~"DocumentInstance",
|
||||
finalize,
|
||||
ptr::null()));
|
||||
}
|
||||
|
||||
pub fn create(compartment: @mut Compartment, doc: @mut Document) -> *JSObject {
|
||||
let instance : jsobj = result::unwrap(
|
||||
compartment.new_object_with_proto(~"DocumentInstance", ~"Document",
|
||||
compartment.global_obj.ptr));
|
||||
doc.wrapper.set_wrapper(instance.ptr);
|
||||
|
||||
unsafe {
|
||||
let raw_ptr: *libc::c_void = cast::transmute(squirrel_away(doc));
|
||||
JS_SetReservedSlot(instance.ptr, 0, RUST_PRIVATE_TO_JSVAL(raw_ptr));
|
||||
|
||||
compartment.define_property(~"document", RUST_OBJECT_TO_JSVAL(instance.ptr),
|
||||
GetJSClassHookStubPointer(PROPERTY_STUB) as *u8,
|
||||
GetJSClassHookStubPointer(STRICT_PROPERTY_STUB) as *u8,
|
||||
JSPROP_ENUMERATE);
|
||||
}
|
||||
|
||||
instance.ptr
|
||||
}
|
||||
|
||||
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 script_context = task_from_context(cx);
|
||||
unsafe {
|
||||
create((*script_context).js_compartment, self)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -615,7 +615,7 @@ pub extern fn ThrowingConstructor(_cx: *JSContext, _argc: uint, _vp: *JSVal) ->
|
|||
}
|
||||
|
||||
pub fn initialize_global(global: *JSObject) {
|
||||
let protoArray = @mut ([0 as *JSObject, ..22]); //XXXjdm PrototyepList::id::_ID_Count
|
||||
let protoArray = @mut ([0 as *JSObject, ..23]); //XXXjdm PrototyepList::id::_ID_Count
|
||||
unsafe {
|
||||
//XXXjdm we should be storing the box pointer instead of the inner
|
||||
let box = squirrel_away(protoArray);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -514,7 +514,6 @@ impl VoidPtrLike for AbstractNode<LayoutView> {
|
|||
|
||||
pub fn define_bindings(compartment: @mut Compartment) {
|
||||
bindings::window::init(compartment);
|
||||
bindings::document::init(compartment);
|
||||
bindings::node::init(compartment);
|
||||
bindings::element::init(compartment);
|
||||
bindings::text::init(compartment);
|
||||
|
|
|
@ -24,7 +24,6 @@ extern mod extra;
|
|||
|
||||
pub mod dom {
|
||||
pub mod bindings {
|
||||
pub mod document;
|
||||
pub mod element;
|
||||
pub mod node;
|
||||
pub mod text;
|
||||
|
@ -37,6 +36,7 @@ pub mod dom {
|
|||
pub mod BlobBinding;
|
||||
pub mod ClientRectBinding;
|
||||
pub mod ClientRectListBinding;
|
||||
pub mod DocumentBinding;
|
||||
pub mod DOMParserBinding;
|
||||
pub mod EventBinding;
|
||||
pub mod EventTargetBinding;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue