mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
[ecmascript] Changes related to events (ontest.html)
This commit is contained in:
parent
f9993e3918
commit
8ad10015f2
@ -90,6 +90,7 @@ struct ecmascript_interpreter {
|
||||
* to redraw. */
|
||||
unsigned int onload_snippets_cache_id;
|
||||
#ifdef CONFIG_ECMASCRIPT_SMJS
|
||||
JSAutoRealm *ar;
|
||||
JS::Heap<JSObject*> *ac;
|
||||
#endif
|
||||
#ifdef CONFIG_QUICKJS
|
||||
|
@ -2304,16 +2304,16 @@ mjs_element_init(js_State *J)
|
||||
}
|
||||
|
||||
void
|
||||
check_element_event(void *elem, const char *event_name, struct term_event *ev)
|
||||
check_element_event(void *interp, void *elem, const char *event_name, struct term_event *ev)
|
||||
{
|
||||
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)interp;
|
||||
js_State *J = (js_State *)interpreter->backend_data;
|
||||
void *second = attr_find_in_map(map_privates, elem);
|
||||
|
||||
if (!second) {
|
||||
return;
|
||||
}
|
||||
struct mjs_element_private *el_private = (struct mjs_element_private *)second;
|
||||
struct ecmascript_interpreter *interpreter = el_private->interpreter;
|
||||
js_State *J = (js_State *)interpreter->backend_data;
|
||||
|
||||
struct listener *l;
|
||||
|
||||
@ -2321,6 +2321,7 @@ check_element_event(void *elem, const char *event_name, struct term_event *ev)
|
||||
if (strcmp(l->typ, event_name)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ev && ev->ev == EVENT_KBD && (!strcmp(event_name, "keydown") || !strcmp(event_name, "keyup"))) {
|
||||
js_getregistry(J, l->fun); /* retrieve the js function from the registry */
|
||||
js_getregistry(J, el_private->thisval);
|
||||
|
@ -2599,15 +2599,15 @@ getElement(JSContext *ctx, void *node)
|
||||
}
|
||||
|
||||
void
|
||||
check_element_event(void *elem, const char *event_name, struct term_event *ev)
|
||||
check_element_event(void *interp, void *elem, const char *event_name, struct term_event *ev)
|
||||
{
|
||||
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)interp;
|
||||
JSContext *ctx = (JSContext *)interpreter->backend_data;
|
||||
struct js_element_private *el_private = attr_find_in_map_void(map_privates, elem);
|
||||
|
||||
if (!el_private) {
|
||||
return;
|
||||
}
|
||||
struct ecmascript_interpreter *interpreter = el_private->interpreter;
|
||||
JSContext *ctx = (JSContext *)interpreter->backend_data;
|
||||
interpreter->heartbeat = add_heartbeat(interpreter);
|
||||
|
||||
struct element_listener *l;
|
||||
|
@ -4076,8 +4076,10 @@ getElement(JSContext *ctx, void *node)
|
||||
}
|
||||
|
||||
void
|
||||
check_element_event(void *elem, const char *event_name, struct term_event *ev)
|
||||
check_element_event(void *interp, void *elem, const char *event_name, struct term_event *ev)
|
||||
{
|
||||
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)interp;
|
||||
JSContext *ctx = (JSContext *)interpreter->backend_data;
|
||||
JSObject *obj;
|
||||
auto el = map_privates.find(elem);
|
||||
|
||||
@ -4085,8 +4087,6 @@ check_element_event(void *elem, const char *event_name, struct term_event *ev)
|
||||
return;
|
||||
}
|
||||
struct element_private *el_private = el->second;
|
||||
struct ecmascript_interpreter *interpreter = el_private->interpreter;
|
||||
JSContext *ctx = (JSContext *)interpreter->backend_data;
|
||||
JSAutoRealm ar(ctx, (JSObject *)interpreter->ac->get());
|
||||
JS::RootedValue r_val(ctx);
|
||||
interpreter->heartbeat = add_heartbeat(interpreter);
|
||||
|
@ -12,7 +12,7 @@ struct term_event;
|
||||
int mjs_element_init(js_State *J);
|
||||
void mjs_push_element(js_State *J, void *node);
|
||||
void walk_tree(struct string *buf, void *nod, bool start, bool toSortAttrs);
|
||||
void check_element_event(void *elem, const char *event_name, struct term_event *ev);
|
||||
void check_element_event(void *interp, void *elem, const char *event_name, struct term_event *ev);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ JSValue getElement(JSContext *ctx, void *node);
|
||||
|
||||
int js_element_init(JSContext *ctx);
|
||||
void walk_tree(struct string *buf, void *nod, bool start, bool toSortAttrs);
|
||||
void check_element_event(void *elem, const char *event_name, struct term_event *ev);
|
||||
void check_element_event(void *interp, void *elem, const char *event_name, struct term_event *ev);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -172,7 +172,7 @@ spidermonkey_get_interpreter(struct ecmascript_interpreter *interpreter)
|
||||
JS::Heap<JSObject*> *window_obj = new JS::Heap<JSObject*>(JS_NewGlobalObject(ctx, &window_class, NULL, JS::FireOnNewGlobalHook, options));
|
||||
|
||||
global = window_obj->get();
|
||||
JSAutoRealm ar(ctx, global);
|
||||
interpreter->ar = new JSAutoRealm(ctx, global);
|
||||
|
||||
if (!global) {
|
||||
goto release_and_fail;
|
||||
@ -314,10 +314,12 @@ spidermonkey_put_interpreter(struct ecmascript_interpreter *interpreter)
|
||||
assert(interpreter);
|
||||
if (!js_module_init_ok) return;
|
||||
|
||||
delete interpreter->ar;
|
||||
delete interpreter->ac;
|
||||
|
||||
interpreter->backend_data = NULL;
|
||||
interpreter->ac = nullptr;
|
||||
interpreter->ar = nullptr;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -11,6 +11,6 @@ JSObject *getElement(JSContext *ctx, void *node);
|
||||
|
||||
void walk_tree(struct string *buf, void *nod, bool start = true, bool toSortAttrs = false);
|
||||
|
||||
void check_element_event(void *elem, const char *event_name, struct term_event *ev);
|
||||
void check_element_event(void *interpreter, void *elem, const char *event_name, struct term_event *ev);
|
||||
|
||||
#endif
|
||||
|
@ -9,6 +9,12 @@
|
||||
|
||||
#include "elinks.h"
|
||||
|
||||
#ifdef CONFIG_LIBDOM
|
||||
#include "ecmascript/libdom/dom.h"
|
||||
#include <dom/dom.h>
|
||||
#include <dom/bindings/hubbub/parser.h>
|
||||
#endif
|
||||
|
||||
#include "bfu/listmenu.h"
|
||||
#include "bfu/menu.h"
|
||||
#include "bfu/style.h"
|
||||
@ -17,6 +23,7 @@
|
||||
#include "document/document.h"
|
||||
#include "document/forms.h"
|
||||
#include "document/html/renderer.h"
|
||||
#include "document/libdom/mapa.h"
|
||||
#include "document/options.h"
|
||||
#include "document/view.h"
|
||||
#include "ecmascript/ecmascript.h"
|
||||
@ -34,7 +41,6 @@
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS) || defined(CONFIG_MUJS)
|
||||
#include <libxml++/libxml++.h>
|
||||
#include <map>
|
||||
#endif
|
||||
|
||||
@ -80,14 +86,14 @@ current_link_evhook(struct document_view *doc_view, enum script_event_hook_type
|
||||
if (!doc_view->vs->ecmascript) return -1;
|
||||
|
||||
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS) || defined(CONFIG_MUJS)
|
||||
std::map<int, xmlpp::Element *> *mapa = (std::map<int, xmlpp::Element *> *)doc_view->document->element_map;
|
||||
void *mapa = (void *)doc_view->document->element_map;
|
||||
|
||||
if (mapa) {
|
||||
auto element = (*mapa).find(link->element_offset);
|
||||
dom_node *elem = find_in_map(mapa, link->element_offset);
|
||||
|
||||
if (element != (*mapa).end()) {
|
||||
if (elem) {
|
||||
const char *event_name = script_event_hook_name[(int)type];
|
||||
check_element_event(element->second, event_name, NULL);
|
||||
check_element_event(doc_view->vs->ecmascript, elem, event_name, NULL);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -13,11 +13,18 @@
|
||||
|
||||
#include "elinks.h"
|
||||
|
||||
#ifdef CONFIG_LIBDOM
|
||||
#include "ecmascript/libdom/dom.h"
|
||||
#include <dom/dom.h>
|
||||
#include <dom/bindings/hubbub/parser.h>
|
||||
#endif
|
||||
|
||||
#include "bfu/leds.h"
|
||||
#include "bfu/menu.h"
|
||||
#include "bfu/dialog.h"
|
||||
#include "config/kbdbind.h"
|
||||
#include "config/options.h"
|
||||
#include "document/libdom/mapa.h"
|
||||
#include "dialogs/document.h"
|
||||
#include "dialogs/menu.h"
|
||||
#include "dialogs/options.h"
|
||||
@ -41,7 +48,6 @@
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS) || defined(CONFIG_MUJS)
|
||||
#include <libxml++/libxml++.h>
|
||||
#include <map>
|
||||
#endif
|
||||
|
||||
@ -1304,17 +1310,17 @@ try_form_action(struct session *ses, struct document_view *doc_view,
|
||||
|
||||
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS) || defined(CONFIG_MUJS)
|
||||
if (ses->insert_mode == INSERT_MODE_ON) {
|
||||
std::map<int, xmlpp::Element *> *mapa = (std::map<int, xmlpp::Element *> *)doc_view->document->element_map;
|
||||
void *mapa = doc_view->document->element_map;
|
||||
|
||||
if (mapa) {
|
||||
auto element = (*mapa).find(link->element_offset);
|
||||
dom_node *element = find_in_map(mapa, link->element_offset);
|
||||
|
||||
if (element != (*mapa).end()) {
|
||||
if (element) {
|
||||
const char *event_name = script_event_hook_name[SEVHOOK_ONKEYDOWN];
|
||||
|
||||
check_element_event(element->second, event_name, ev);
|
||||
check_element_event(doc_view->vs->ecmascript, element, event_name, ev);
|
||||
event_name = script_event_hook_name[SEVHOOK_ONKEYUP];
|
||||
check_element_event(element->second, event_name, ev);
|
||||
check_element_event(doc_view->vs->ecmascript, element, event_name, ev);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
<input type="button" onClick='location.href="http://pasky.or.cz/"' value="button onClick"><br>
|
||||
<input type="button" onMouseOver='window.alert("Tadam")' value="button onMouseOver"><br>
|
||||
<img src="haha" onMouseOut='window.alert("JS is annoying anyway")' alt="img onMouseOut"><br>
|
||||
<a href="#" onClick='window.open("http://elinks.or.cz/")'>a href onClick</a><br>
|
||||
<input type="button" onClick="location.href='http://pasky.or.cz/'" value="button onClick"><br>
|
||||
<input type="button" onMouseOver="window.alert('Tadam')" value="button onMouseOver"><br>
|
||||
<img src="haha" onMouseOut="window.alert('JS is annoying anyway')" alt="img onMouseOut"><br>
|
||||
<a href="#" onClick="window.open('http://elinks.or.cz/')">a href onClick</a><br>
|
||||
|
Loading…
Reference in New Issue
Block a user