From cfd26609bd15e5e4fef8c72d0abc6c929afd155b Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Wed, 27 Jun 2012 18:16:45 +0000 Subject: add window and self properties svn path=/trunk/netsurf/; revision=13989 --- javascript/jsapi/window.c | 169 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 165 insertions(+), 4 deletions(-) (limited to 'javascript/jsapi/window.c') diff --git a/javascript/jsapi/window.c b/javascript/jsapi/window.c index e9c815792..d4941d70f 100644 --- a/javascript/jsapi/window.c +++ b/javascript/jsapi/window.c @@ -22,7 +22,133 @@ #include "javascript/jsapi.h" #include "utils/log.h" -static JSBool jsalert(JSContext *cx, uintN argc, jsval *vp) +/* IDL + +[NamedPropertiesObject] +interface Window : EventTarget { + // the current browsing context + [Unforgeable] readonly attribute WindowProxy window; + [Replaceable] readonly attribute WindowProxy self; + [Unforgeable] readonly attribute Document document; + attribute DOMString name; + [PutForwards=href, Unforgeable] readonly attribute Location location; + readonly attribute History history; + + boolean find(optional DOMString aString, optional boolean aCaseSensitive, optional boolean aBackwards, optional boolean aWrapAround, optional boolean aWholeWord, optional boolean aSearchInFrames, optional boolean aShowDialog); + + [Replaceable] readonly attribute BarProp locationbar; + [Replaceable] readonly attribute BarProp menubar; + [Replaceable] readonly attribute BarProp personalbar; + [Replaceable] readonly attribute BarProp scrollbars; + [Replaceable] readonly attribute BarProp statusbar; + [Replaceable] readonly attribute BarProp toolbar; + attribute DOMString status; + void close(); + void stop(); + void focus(); + void blur(); + + // other browsing contexts + [Replaceable] readonly attribute WindowProxy frames; + [Replaceable] readonly attribute unsigned long length; + [Unforgeable] readonly attribute WindowProxy top; + attribute WindowProxy? opener; + readonly attribute WindowProxy parent; + readonly attribute Element? frameElement; + WindowProxy open(optional DOMString url, optional DOMString target, optional DOMString features, optional boolean replace); + getter WindowProxy (unsigned long index); + getter object (DOMString name); + + // the user agent + readonly attribute Navigator navigator; + readonly attribute External external; + readonly attribute ApplicationCache applicationCache; + + // user prompts + void alert(DOMString message); + boolean confirm(DOMString message); + DOMString? prompt(DOMString message, optional DOMString default); + void print(); + any showModalDialog(DOMString url, optional any argument); + + // cross-document messaging + void postMessage(any message, DOMString targetOrigin, optional sequence transfer); + + // event handler IDL attributes + [TreatNonCallableAsNull] attribute Function? onabort; + [TreatNonCallableAsNull] attribute Function? onafterprint; + [TreatNonCallableAsNull] attribute Function? onbeforeprint; + [TreatNonCallableAsNull] attribute Function? onbeforeunload; + [TreatNonCallableAsNull] attribute Function? onblur; + [TreatNonCallableAsNull] attribute Function? oncancel; + [TreatNonCallableAsNull] attribute Function? oncanplay; + [TreatNonCallableAsNull] attribute Function? oncanplaythrough; + [TreatNonCallableAsNull] attribute Function? onchange; + [TreatNonCallableAsNull] attribute Function? onclick; + [TreatNonCallableAsNull] attribute Function? onclose; + [TreatNonCallableAsNull] attribute Function? oncontextmenu; + [TreatNonCallableAsNull] attribute Function? oncuechange; + [TreatNonCallableAsNull] attribute Function? ondblclick; + [TreatNonCallableAsNull] attribute Function? ondrag; + [TreatNonCallableAsNull] attribute Function? ondragend; + [TreatNonCallableAsNull] attribute Function? ondragenter; + [TreatNonCallableAsNull] attribute Function? ondragleave; + [TreatNonCallableAsNull] attribute Function? ondragover; + [TreatNonCallableAsNull] attribute Function? ondragstart; + [TreatNonCallableAsNull] attribute Function? ondrop; + [TreatNonCallableAsNull] attribute Function? ondurationchange; + [TreatNonCallableAsNull] attribute Function? onemptied; + [TreatNonCallableAsNull] attribute Function? onended; + [TreatNonCallableAsNull] attribute Function? onerror; + [TreatNonCallableAsNull] attribute Function? onfocus; + [TreatNonCallableAsNull] attribute Function? onhashchange; + [TreatNonCallableAsNull] attribute Function? oninput; + [TreatNonCallableAsNull] attribute Function? oninvalid; + [TreatNonCallableAsNull] attribute Function? onkeydown; + [TreatNonCallableAsNull] attribute Function? onkeypress; + [TreatNonCallableAsNull] attribute Function? onkeyup; + [TreatNonCallableAsNull] attribute Function? onload; + [TreatNonCallableAsNull] attribute Function? onloadeddata; + [TreatNonCallableAsNull] attribute Function? onloadedmetadata; + [TreatNonCallableAsNull] attribute Function? onloadstart; + [TreatNonCallableAsNull] attribute Function? onmessage; + [TreatNonCallableAsNull] attribute Function? onmousedown; + [TreatNonCallableAsNull] attribute Function? onmousemove; + [TreatNonCallableAsNull] attribute Function? onmouseout; + [TreatNonCallableAsNull] attribute Function? onmouseover; + [TreatNonCallableAsNull] attribute Function? onmouseup; + [TreatNonCallableAsNull] attribute Function? onmousewheel; + [TreatNonCallableAsNull] attribute Function? onoffline; + [TreatNonCallableAsNull] attribute Function? ononline; + [TreatNonCallableAsNull] attribute Function? onpause; + [TreatNonCallableAsNull] attribute Function? onplay; + [TreatNonCallableAsNull] attribute Function? onplaying; + [TreatNonCallableAsNull] attribute Function? onpagehide; + [TreatNonCallableAsNull] attribute Function? onpageshow; + [TreatNonCallableAsNull] attribute Function? onpopstate; + [TreatNonCallableAsNull] attribute Function? onprogress; + [TreatNonCallableAsNull] attribute Function? onratechange; + [TreatNonCallableAsNull] attribute Function? onreset; + [TreatNonCallableAsNull] attribute Function? onresize; + [TreatNonCallableAsNull] attribute Function? onscroll; + [TreatNonCallableAsNull] attribute Function? onseeked; + [TreatNonCallableAsNull] attribute Function? onseeking; + [TreatNonCallableAsNull] attribute Function? onselect; + [TreatNonCallableAsNull] attribute Function? onshow; + [TreatNonCallableAsNull] attribute Function? onstalled; + [TreatNonCallableAsNull] attribute Function? onstorage; + [TreatNonCallableAsNull] attribute Function? onsubmit; + [TreatNonCallableAsNull] attribute Function? onsuspend; + [TreatNonCallableAsNull] attribute Function? ontimeupdate; + [TreatNonCallableAsNull] attribute Function? onunload; + [TreatNonCallableAsNull] attribute Function? onvolumechange; + [TreatNonCallableAsNull] attribute Function? onwaiting; +}; + +*/ + + +static JSBool jsnative_alert(JSContext *cx, uintN argc, jsval *vp) { JSString* u16_txt; char *txt; @@ -48,12 +174,42 @@ static JSBool jsalert(JSContext *cx, uintN argc, jsval *vp) return JS_TRUE; } + static JSFunctionSpec jsfunctions_window[] = { - JS_FN("alert", jsalert, 1, 0), + JS_FN("alert", jsnative_alert, 1, 0), JS_FS_END }; + +static JSBool jsproperty_get_window(JSContext *ctx, JSObject *obj, jsid id, jsval *vp) +{ + JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + return JS_TRUE; +} + +static JSBool jsproperty_set_window(JSContext *ctx, JSObject *obj, jsid id, JSBool strict, jsval *vp) +{ + return JS_FALSE; +} + + +static JSPropertySpec jsproperties_window[] = +{ + { "window", + 0, + JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_SHARED, + jsproperty_get_window, + jsproperty_set_window + }, + { "self", + 0, + JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_SHARED, + jsproperty_get_window, + jsproperty_set_window + }, +}; + /* The class of the global object. */ static JSClass jsclass_window = { "window", @@ -91,12 +247,17 @@ JSObject * jsapi_new_window(JSContext *cx, JSObject *parent, void *win_priv) assert(false); } + /* private pointer to browsing context */ + if (!JS_SetPrivate(cx, window, win_priv)) + return NULL; + + /* functions */ if (!JS_DefineFunctions(cx, window, jsfunctions_window)) { return NULL; } - /* private pointer to browsing context */ - if (!JS_SetPrivate(cx, window, win_priv)) + /* properties */ + if (!JS_DefineProperties(cx, window, jsproperties_window)) return NULL; LOG(("Created new window object %p", window)); -- cgit v1.2.3