From 2b6bd44ef0aec9c99617e7125bda918545be7316 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Thu, 1 Nov 2012 23:30:28 +0000 Subject: add location binding --- Makefile.sources.javascript | 1 + javascript/jsapi/binding.h | 6 +++ javascript/jsapi/bindings/location.bnd | 53 +++++++++++++++++++++ javascript/jsapi/bindings/window.bnd | 84 +++++++++++++++++++--------------- 4 files changed, 108 insertions(+), 36 deletions(-) create mode 100644 javascript/jsapi/bindings/location.bnd diff --git a/Makefile.sources.javascript b/Makefile.sources.javascript index 3fb1fb275..58b8860b0 100644 --- a/Makefile.sources.javascript +++ b/Makefile.sources.javascript @@ -15,6 +15,7 @@ JSAPI_BINDING_htmlelement := javascript/jsapi/bindings/htmlelement.bnd JSAPI_BINDING_window := javascript/jsapi/bindings/window.bnd JSAPI_BINDING_navigator := javascript/jsapi/bindings/navigator.bnd JSAPI_BINDING_console := javascript/jsapi/bindings/console.bnd +JSAPI_BINDING_location := javascript/jsapi/bindings/location.bnd # 1: input file # 2: output file diff --git a/javascript/jsapi/binding.h b/javascript/jsapi/binding.h index 8b32e91db..68ab6d1ed 100644 --- a/javascript/jsapi/binding.h +++ b/javascript/jsapi/binding.h @@ -41,6 +41,12 @@ JSObject *jsapi_new_Window(JSContext *cx, struct browser_window *bw, html_content *htmlc); +JSObject *jsapi_InitClass_Location(JSContext *cx, JSObject *parent); +JSObject *jsapi_new_Location(JSContext *cx, + JSObject *window, + JSObject *parent, + struct browser_window *bw); + JSObject *jsapi_InitClass_Document(JSContext *cx, JSObject *parent); diff --git a/javascript/jsapi/bindings/location.bnd b/javascript/jsapi/bindings/location.bnd new file mode 100644 index 000000000..c83fe46e3 --- /dev/null +++ b/javascript/jsapi/bindings/location.bnd @@ -0,0 +1,53 @@ +/* Binding to generate Location interface + * + * Copyright 2012 Vincent Sanders + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * Released under the terms of the MIT License, + * http://www.opensource.org/licenses/mit-license + */ + +#include "dom.bnd" + +webidlfile "html.idl"; + +hdrcomment "Copyright 2012 Vincent Sanders "; +hdrcomment "This file is part of NetSurf, http://www.netsurf-browser.org/"; +hdrcomment "Released under the terms of the MIT License,"; +hdrcomment " http://www.opensource.org/licenses/mit-license"; + +preamble %{ + +#include "desktop/browser.h" + +#include "utils/config.h" +#include "utils/log.h" + +#include "javascript/jsapi.h" +#include "javascript/jsapi/binding.h" + +%} + +binding location { + type js_libdom; /* the binding type */ + + interface Location; /* Web IDL interface to generate */ + + /* private members: + * - stored in private context structure. + * - passed as parameters to constructor and stored automatically. + * - are *not* considered for property getters/setters. + * + * internal members: + * - value stored in private context structure + * - not passed to constructor + * - must be instantiated by constructor + * - are considered for property getters/setters. + */ + private "struct browser_window *" bw; +} + +operation reload %{ + browser_window_reload(private->bw, false); +%} diff --git a/javascript/jsapi/bindings/window.bnd b/javascript/jsapi/bindings/window.bnd index beb2b128e..956932c77 100644 --- a/javascript/jsapi/bindings/window.bnd +++ b/javascript/jsapi/bindings/window.bnd @@ -18,25 +18,26 @@ preamble %{ %} -operation confirm %{ - warn_user(message, NULL); -%} - -operation alert %{ - warn_user(message, NULL); -%} - -operation prompt %{ - warn_user(message, NULL); -%} - -getter window %{ - jsret = obj; -%} +binding window { + type js_libdom; /* the binding type */ + + interface Window; /* Web IDL interface to generate */ + + /* private are parameters to constructor stored in private + * context structure. + * + * internal are value stored in private context structure but not + * passed to constructor but are considered for property + * getters/setters. + */ + private "struct browser_window *" bw; + private "struct html_content *" htmlc; + internal "JSObject *" document; + internal "JSObject *" navigator; + internal "JSObject *" console; + internal "JSObject *" location; +} -getter self %{ - jsret = obj; -%} api init %{ JSObject *user_proto; @@ -85,6 +86,11 @@ api init %{ return NULL; } + user_proto = jsapi_InitClass_Location(cx, prototype); + if (user_proto == NULL) { + return NULL; + } + user_proto = jsapi_InitClass_Console(cx, prototype); if (user_proto == NULL) { return NULL; @@ -121,7 +127,11 @@ api new %{ return NULL; } - /** @todo forms, history, location */ + private->location = jsapi_new_Location(cx, NULL, newobject, bw); + if (private->location == NULL) { + free(private); + return NULL; + } private->console = jsapi_new_Console(cx, NULL, newobject); if (private->console == NULL) { @@ -129,25 +139,27 @@ api new %{ return NULL; } + /** @todo forms, history */ + LOG(("Created new window object %p", newobject)); %} +operation confirm %{ + warn_user(message, NULL); +%} -binding window { - type js_libdom; /* the binding type */ - - interface Window; /* Web IDL interface to generate */ - - /* private are parameters to constructor stored in private - * context structure. - * - * internal are value stored in private context structure but not - * passed to constructor but are considered for property getters/setters. - */ - private "struct browser_window *" bw; - private "struct html_content *" htmlc; - internal "JSObject *" document; - internal "JSObject *" navigator; - internal "JSObject *" console; +operation alert %{ + warn_user(message, NULL); +%} -} +operation prompt %{ + warn_user(message, NULL); +%} + +getter window %{ + jsret = obj; +%} + +getter self %{ + jsret = obj; +%} -- cgit v1.2.3