|
|
@@ -700,6 +700,50 @@ static void doc_createevent(js_State *state)
|
|
|
event_build_object(state, type, 0, 0, 1);
|
|
|
}
|
|
|
|
|
|
+static void custom_event_call(js_State *state)
|
|
|
+{
|
|
|
+ event_call(state);
|
|
|
+ if (js_isobject(state, 2))
|
|
|
+ js_getproperty(state, 2, "detail");
|
|
|
+ else
|
|
|
+ js_pushnull(state);
|
|
|
+ js_setproperty(state, -2, "detail");
|
|
|
+}
|
|
|
+
|
|
|
+static void mouse_event_call(js_State *state)
|
|
|
+{
|
|
|
+ static const struct {
|
|
|
+ const char *name;
|
|
|
+ int is_number;
|
|
|
+ } props[] = {
|
|
|
+ { "clientX", 1 }, { "clientY", 1 }, { "screenX", 1 },
|
|
|
+ { "screenY", 1 }, { "button", 1 }, { "buttons", 1 },
|
|
|
+ { "ctrlKey", 0 }, { "shiftKey", 0 }, { "altKey", 0 },
|
|
|
+ { "metaKey", 0 }
|
|
|
+ };
|
|
|
+ unsigned int i;
|
|
|
+
|
|
|
+ event_call(state);
|
|
|
+ if (!js_isobject(state, 2))
|
|
|
+ return;
|
|
|
+ for (i = 0; i < sizeof(props) / sizeof(props[0]); i++) {
|
|
|
+ js_getproperty(state, 2, props[i].name);
|
|
|
+ if (props[i].is_number) {
|
|
|
+ double v = js_isnumber(state, -1) ?
|
|
|
+ js_tonumber(state, -1) : 0;
|
|
|
+
|
|
|
+ js_pop(state, 1);
|
|
|
+ js_pushnumber(state, v);
|
|
|
+ } else {
|
|
|
+ int v = js_toboolean(state, -1);
|
|
|
+
|
|
|
+ js_pop(state, 1);
|
|
|
+ js_pushboolean(state, v);
|
|
|
+ }
|
|
|
+ js_setproperty(state, -2, props[i].name);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
int js_browser_event(unsigned int node, const char *type, int bubbles,
|
|
|
int cancelable)
|
|
|
{
|
|
|
@@ -2697,6 +2741,10 @@ static void install_globals(js_State *state)
|
|
|
|
|
|
js_newcfunction(state, event_call, "Event", 1);
|
|
|
js_defglobal(state, "Event", JS_DONTENUM);
|
|
|
+ js_newcfunction(state, custom_event_call, "CustomEvent", 1);
|
|
|
+ js_defglobal(state, "CustomEvent", JS_DONTENUM);
|
|
|
+ js_newcfunction(state, mouse_event_call, "MouseEvent", 1);
|
|
|
+ js_defglobal(state, "MouseEvent", JS_DONTENUM);
|
|
|
|
|
|
push_location(state);
|
|
|
js_defglobal(state, "location", JS_DONTENUM);
|