add location binding

This commit is contained in:
Vincent Sanders 2012-11-01 23:30:28 +00:00
parent b34cbc5e83
commit 2b6bd44ef0
4 changed files with 104 additions and 32 deletions

View File

@ -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

View File

@ -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);

View File

@ -0,0 +1,53 @@
/* Binding to generate Location interface
*
* Copyright 2012 Vincent Sanders <vince@netsurf-browser.org>
*
* 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 <vince@netsurf-browser.org>";
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);
%}

View File

@ -18,25 +18,26 @@ preamble %{
%}
operation confirm %{
warn_user(message, NULL);
%}
binding window {
type js_libdom; /* the binding type */
operation alert %{
warn_user(message, NULL);
%}
interface Window; /* Web IDL interface to generate */
operation prompt %{
warn_user(message, NULL);
%}
/* 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 window %{
jsret = obj;
%}
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 */
operation alert %{
warn_user(message, NULL);
%}
interface Window; /* Web IDL interface to generate */
operation prompt %{
warn_user(message, NULL);
%}
/* 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;
getter window %{
jsret = obj;
%}
}
getter self %{
jsret = obj;
%}