add dom event handler to document object

This commit is contained in:
Vincent Sanders 2012-12-17 14:55:16 +00:00
parent 90f0cfb551
commit 347fdf0743
4 changed files with 265 additions and 5 deletions

View File

@ -28,6 +28,7 @@ preamble %{
#include "content/urldb.h"
#include "javascript/js.h"
#include "javascript/jsapi.h"
#include "javascript/jsapi/binding.h"
@ -46,6 +47,9 @@ binding document {
/** location instantiated on first use */
property unshared location;
/* events through a single interface */
property unshared type EventHandler;
}
api finalise %{
@ -272,3 +276,254 @@ operation createElement %{
JSLOG("returning jsobject %p",jsret);
%}
getter EventHandler %{
JSLOG("propname[%d].name=\"%s\"",
tinyid,
jsclass_properties[tinyid].name);
%}
setter EventHandler %{
dom_string *event_type_dom;
JSLOG("propname[%d].name=\"%s\"",
tinyid,
jsclass_properties[tinyid].name);
switch (tinyid) {
case JSAPI_PROP_TINYID_onabort:
event_type_dom = corestring_dom_abort;
break;
case JSAPI_PROP_TINYID_onblur:
event_type_dom = corestring_dom_blur;
break;
case JSAPI_PROP_TINYID_oncancel:
event_type_dom = corestring_dom_cancel;
break;
case JSAPI_PROP_TINYID_oncanplay:
event_type_dom = corestring_dom_canplay;
break;
case JSAPI_PROP_TINYID_oncanplaythrough:
event_type_dom = corestring_dom_canplaythrough;
break;
case JSAPI_PROP_TINYID_onchange:
event_type_dom = corestring_dom_change;
break;
case JSAPI_PROP_TINYID_onclick:
event_type_dom = corestring_dom_click;
break;
case JSAPI_PROP_TINYID_onclose:
event_type_dom = corestring_dom_close;
break;
case JSAPI_PROP_TINYID_oncontextmenu:
event_type_dom = corestring_dom_contextmenu;
break;
case JSAPI_PROP_TINYID_oncuechange:
event_type_dom = corestring_dom_cuechange;
break;
case JSAPI_PROP_TINYID_ondblclick:
event_type_dom = corestring_dom_dblclick;
break;
case JSAPI_PROP_TINYID_ondrag:
event_type_dom = corestring_dom_drag;
break;
case JSAPI_PROP_TINYID_ondragend:
event_type_dom = corestring_dom_dragend;
break;
case JSAPI_PROP_TINYID_ondragenter:
event_type_dom = corestring_dom_dragenter;
break;
case JSAPI_PROP_TINYID_ondragleave:
event_type_dom = corestring_dom_dragleave;
break;
case JSAPI_PROP_TINYID_ondragover:
event_type_dom = corestring_dom_dragover;
break;
case JSAPI_PROP_TINYID_ondragstart:
event_type_dom = corestring_dom_dragstart;
break;
case JSAPI_PROP_TINYID_ondrop:
event_type_dom = corestring_dom_drop;
break;
case JSAPI_PROP_TINYID_ondurationchange:
event_type_dom = corestring_dom_durationchange;
break;
case JSAPI_PROP_TINYID_onemptied:
event_type_dom = corestring_dom_emptied;
break;
case JSAPI_PROP_TINYID_onended:
event_type_dom = corestring_dom_ended;
break;
case JSAPI_PROP_TINYID_onerror:
event_type_dom = corestring_dom_error;
break;
case JSAPI_PROP_TINYID_onfocus:
event_type_dom = corestring_dom_focus;
break;
case JSAPI_PROP_TINYID_oninput:
event_type_dom = corestring_dom_input;
break;
case JSAPI_PROP_TINYID_oninvalid:
event_type_dom = corestring_dom_invalid;
break;
case JSAPI_PROP_TINYID_onkeydown:
event_type_dom = corestring_dom_keydown;
break;
case JSAPI_PROP_TINYID_onkeypress:
event_type_dom = corestring_dom_keypress;
break;
case JSAPI_PROP_TINYID_onkeyup:
event_type_dom = corestring_dom_keyup;
break;
case JSAPI_PROP_TINYID_onload:
event_type_dom = corestring_dom_load;
break;
case JSAPI_PROP_TINYID_onloadeddata:
event_type_dom = corestring_dom_loadeddata;
break;
case JSAPI_PROP_TINYID_onloadedmetadata:
event_type_dom = corestring_dom_loadedmetadata;
break;
case JSAPI_PROP_TINYID_onloadstart:
event_type_dom = corestring_dom_loadstart;
break;
case JSAPI_PROP_TINYID_onmousedown:
event_type_dom = corestring_dom_mousedown;
break;
case JSAPI_PROP_TINYID_onmousemove:
event_type_dom = corestring_dom_mousemove;
break;
case JSAPI_PROP_TINYID_onmouseout:
event_type_dom = corestring_dom_mouseout;
break;
case JSAPI_PROP_TINYID_onmouseover:
event_type_dom = corestring_dom_mouseover;
break;
case JSAPI_PROP_TINYID_onmouseup:
event_type_dom = corestring_dom_mouseup;
break;
case JSAPI_PROP_TINYID_onmousewheel:
event_type_dom = corestring_dom_mousewheel;
break;
case JSAPI_PROP_TINYID_onpause:
event_type_dom = corestring_dom_pause;
break;
case JSAPI_PROP_TINYID_onplay:
event_type_dom = corestring_dom_play;
break;
case JSAPI_PROP_TINYID_onplaying:
event_type_dom = corestring_dom_playing;
break;
case JSAPI_PROP_TINYID_onprogress:
event_type_dom = corestring_dom_progress;
break;
case JSAPI_PROP_TINYID_onratechange:
event_type_dom = corestring_dom_ratechange;
break;
case JSAPI_PROP_TINYID_onreset:
event_type_dom = corestring_dom_reset;
break;
case JSAPI_PROP_TINYID_onscroll:
event_type_dom = corestring_dom_scroll;
break;
case JSAPI_PROP_TINYID_onseeked:
event_type_dom = corestring_dom_seeked;
break;
case JSAPI_PROP_TINYID_onseeking:
event_type_dom = corestring_dom_seeking;
break;
case JSAPI_PROP_TINYID_onselect:
event_type_dom = corestring_dom_select;
break;
case JSAPI_PROP_TINYID_onshow:
event_type_dom = corestring_dom_show;
break;
case JSAPI_PROP_TINYID_onstalled:
event_type_dom = corestring_dom_stalled;
break;
case JSAPI_PROP_TINYID_onsubmit:
event_type_dom = corestring_dom_submit;
break;
case JSAPI_PROP_TINYID_onsuspend:
event_type_dom = corestring_dom_suspend;
break;
case JSAPI_PROP_TINYID_ontimeupdate:
event_type_dom = corestring_dom_timeupdate;
break;
case JSAPI_PROP_TINYID_onvolumechange:
event_type_dom = corestring_dom_volumechange;
break;
case JSAPI_PROP_TINYID_onwaiting:
event_type_dom = corestring_dom_waiting;
break;
case JSAPI_PROP_TINYID_onreadystatechange:
event_type_dom = corestring_dom_readystatechange;
break;
default:
JSLOG("called with unknown tinyid");
return JS_TRUE;
}
js_dom_event_add_listener((struct jscontext *)cx,
private->node,
(dom_node *)private->node,
event_type_dom,
vp);
%}

View File

@ -32,14 +32,15 @@ preamble %{
%}
binding htmlelement {
type js_libdom; /* the binding type */
type js_libdom; /* the binding type */
interface HTMLElement; /* Web IDL interface to generate */
interface HTMLElement; /* Web IDL interface to generate */
private "dom_element *" node;
private "struct html_content *" htmlc;
private "dom_element *" node;
private "struct html_content *" htmlc;
property unshared type EventHandler;
/* events through a single interface */
property unshared type EventHandler;
}
api finalise %{

View File

@ -193,6 +193,7 @@ dom_string *corestring_dom_playing;
dom_string *corestring_dom_popstate;
dom_string *corestring_dom_progress;
dom_string *corestring_dom_ratechange;
dom_string *corestring_dom_readystatechange;
dom_string *corestring_dom_rect;
dom_string *corestring_dom_rel;
dom_string *corestring_dom_reset;
@ -414,6 +415,7 @@ void corestrings_fini(void)
CSS_DOM_STRING_UNREF(popstate);
CSS_DOM_STRING_UNREF(progress);
CSS_DOM_STRING_UNREF(ratechange);
CSS_DOM_STRING_UNREF(readystatechange);
CSS_DOM_STRING_UNREF(rect);
CSS_DOM_STRING_UNREF(rel);
CSS_DOM_STRING_UNREF(reset);
@ -666,6 +668,7 @@ nserror corestrings_init(void)
CSS_DOM_STRING_INTERN(popstate);
CSS_DOM_STRING_INTERN(progress);
CSS_DOM_STRING_INTERN(ratechange);
CSS_DOM_STRING_INTERN(readystatechange);
CSS_DOM_STRING_INTERN(rect);
CSS_DOM_STRING_INTERN(rel);
CSS_DOM_STRING_INTERN(reset);

View File

@ -199,6 +199,7 @@ extern struct dom_string *corestring_dom_playing;
extern struct dom_string *corestring_dom_popstate;
extern struct dom_string *corestring_dom_progress;
extern struct dom_string *corestring_dom_ratechange;
extern struct dom_string *corestring_dom_readystatechange;
extern struct dom_string *corestring_dom_rect;
extern struct dom_string *corestring_dom_rel;
extern struct dom_string *corestring_dom_reset;