summaryrefslogtreecommitdiff
path: root/javascript/jsapi
diff options
context:
space:
mode:
authorVincent Sanders <vince@netsurf-browser.org>2012-11-28 18:07:36 +0000
committerVincent Sanders <vince@netsurf-browser.org>2012-11-28 18:07:36 +0000
commit68f359d1ec2212939f19a25dfb182d08cfa37afd (patch)
tree73849c43d97aa9eaaad69935bc45ee7757be207e /javascript/jsapi
parentfb5d763d757719a552b8849cbdef9c2a1c1c2db0 (diff)
downloadnetsurf-68f359d1ec2212939f19a25dfb182d08cfa37afd.tar.gz
netsurf-68f359d1ec2212939f19a25dfb182d08cfa37afd.tar.bz2
initial event fireing implementation
Diffstat (limited to 'javascript/jsapi')
-rw-r--r--javascript/jsapi/binding.h7
-rw-r--r--javascript/jsapi/event.bnd36
-rw-r--r--javascript/jsapi/window.bnd47
3 files changed, 90 insertions, 0 deletions
diff --git a/javascript/jsapi/binding.h b/javascript/jsapi/binding.h
index 6d069b973..f27493532 100644
--- a/javascript/jsapi/binding.h
+++ b/javascript/jsapi/binding.h
@@ -149,4 +149,11 @@ JSObject *jsapi_new_Node(JSContext *cx,
JSObject *prototype,
JSObject *parent);
+extern JSClass JSClass_Event;
+JSObject *jsapi_InitClass_Event(JSContext *cx, JSObject *parent);
+JSObject *jsapi_new_Event(JSContext *cx,
+ JSObject *prototype,
+ JSObject *parent,
+ dom_event *event);
+
#endif
diff --git a/javascript/jsapi/event.bnd b/javascript/jsapi/event.bnd
new file mode 100644
index 000000000..cc03c920a
--- /dev/null
+++ b/javascript/jsapi/event.bnd
@@ -0,0 +1,36 @@
+/* Binding to generate event 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
+ */
+
+webidlfile "dom.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 <dom/dom.h>
+
+#include "utils/config.h"
+#include "utils/log.h"
+
+#include "javascript/jsapi.h"
+#include "javascript/jsapi/binding.h"
+
+%}
+
+binding node {
+ type js_libdom; /* the binding type */
+
+ interface Event; /* Web IDL interface to generate */
+
+ private "dom_event *" event;
+}
diff --git a/javascript/jsapi/window.bnd b/javascript/jsapi/window.bnd
index 7875ab40f..3f8930441 100644
--- a/javascript/jsapi/window.bnd
+++ b/javascript/jsapi/window.bnd
@@ -23,6 +23,7 @@ preamble %{
#include "utils/config.h"
#include "utils/log.h"
+#include "utils/corestrings.h"
#include "javascript/jsapi.h"
#include "javascript/jsapi/binding.h"
@@ -147,6 +148,11 @@ api init %{
return NULL;
}
+ user_proto = jsapi_InitClass_Event(cx, prototype);
+ if (user_proto == NULL) {
+ return NULL;
+ }
+
%}
api new %{
@@ -211,10 +217,51 @@ getter self %{
jsret = obj;
%}
+/* boolean dispatchEvent(Event event); */
+operation dispatchEvent %{
+ /* this implementation is unique to the window object as it is
+ * not a "real" dom node.
+ */
+
+ /* caution, this must match the struct generated from event.bnd */
+ if (event == JSVAL_VOID) {
+ jsret = JS_FALSE;
+ } else {
+ dom_event *domevent;
+ dom_string *type_dom;
+ dom_exception exc;
+ jsval eventval = JSVAL_VOID;
+ jsval event_argv[1];
+ jsval event_rval;
+
+ domevent = JS_GetInstancePrivate(cx, event, &JSClass_Event, NULL);
+ if (domevent == NULL) {
+ /** @todo type error? */
+ jsret = JS_FALSE;
+ } else {
+ exc = dom_event_get_type(domevent, &type_dom);
+ if (dom_string_isequal(type_dom, corestring_dom_load)) {
+ JS_GetProperty(cx, JSAPI_THIS_OBJECT(cx, vp), "onload", &eventval);
+ }
+
+ if (eventval != JSVAL_VOID) {
+ event_argv[0] = event;
+ jsret = JS_CallFunctionValue(cx, NULL, eventval, 1, event_argv, &event_rval);
+ }
+ }
+ }
+%}
+
getter EventHandler %{
+ /* this implementation is unique to the window object as it is
+ * not a dom node.
+ */
JSLOG("propname[%d] %s %s", tinyid , jsclass_properties[tinyid].name, JS_GetTypeName(cx, JS_TypeOfValue(cx, tinyid_jsval)));
%}
setter EventHandler %{
+ /* this implementation is unique to the window object as it is
+ * not a dom node.
+ */
JSLOG("propname[%d] %s %s", tinyid, jsclass_properties[tinyid].name, JS_GetTypeName(cx, JS_TypeOfValue(cx, tinyid_jsval)));
%}