mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
[viewer] link.cpp -> link.c
Moved some code to ecmascript-c.cpp
This commit is contained in:
parent
88d836355d
commit
c14989ab91
@ -8,6 +8,7 @@
|
||||
|
||||
#include "dialogs/status.h"
|
||||
#include "document/document.h"
|
||||
#include "document/libdom/mapa.h"
|
||||
#include "document/view.h"
|
||||
#include "ecmascript/ecmascript.h"
|
||||
#include "ecmascript/ecmascript-c.h"
|
||||
@ -31,6 +32,7 @@
|
||||
#include "util/conv.h"
|
||||
#include "util/memory.h"
|
||||
#include "util/string.h"
|
||||
#include "viewer/text/form.h"
|
||||
#include "viewer/text/view.h"
|
||||
|
||||
extern int interpreter_count;
|
||||
@ -348,3 +350,93 @@ check_events_for_element(struct ecmascript_interpreter *ecmascript, dom_node *el
|
||||
event_name = script_event_hook_name[SEVHOOK_ONKEYPRESS];
|
||||
check_element_event(ecmascript, element, event_name, ev);
|
||||
}
|
||||
|
||||
void
|
||||
ecmascript_reset_state(struct view_state *vs)
|
||||
{
|
||||
struct form_view *fv;
|
||||
int i;
|
||||
|
||||
/* Normally, if vs->ecmascript == NULL, the associated
|
||||
* ecmascript_obj pointers are also NULL. However, they might
|
||||
* be non-NULL if the ECMAScript objects have been lazily
|
||||
* created because of scripts running in sibling HTML frames. */
|
||||
foreach (fv, vs->forms)
|
||||
ecmascript_detach_form_view(fv);
|
||||
for (i = 0; i < vs->form_info_len; i++)
|
||||
ecmascript_detach_form_state(&vs->form_info[i]);
|
||||
|
||||
vs->ecmascript_fragile = 0;
|
||||
if (vs->ecmascript)
|
||||
ecmascript_put_interpreter(vs->ecmascript);
|
||||
|
||||
vs->ecmascript = ecmascript_get_interpreter(vs);
|
||||
if (!vs->ecmascript)
|
||||
vs->ecmascript_fragile = 1;
|
||||
}
|
||||
|
||||
int
|
||||
ecmascript_eval_boolback(struct ecmascript_interpreter *interpreter,
|
||||
struct string *code)
|
||||
{
|
||||
int result;
|
||||
|
||||
if (!get_ecmascript_enable(interpreter))
|
||||
return -1;
|
||||
assert(interpreter);
|
||||
interpreter->backend_nesting++;
|
||||
#ifdef CONFIG_MUJS
|
||||
result = mujs_eval_boolback(interpreter, code);
|
||||
#elif defined(CONFIG_QUICKJS)
|
||||
result = quickjs_eval_boolback(interpreter, code);
|
||||
#else
|
||||
result = spidermonkey_eval_boolback(interpreter, code);
|
||||
#endif
|
||||
interpreter->backend_nesting--;
|
||||
|
||||
check_for_rerender(interpreter, "boolback");
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int
|
||||
ecmascript_current_link_evhook(struct document_view *doc_view, enum script_event_hook_type type)
|
||||
{
|
||||
struct link *link;
|
||||
struct script_event_hook *evhook;
|
||||
|
||||
assert(doc_view && doc_view->vs);
|
||||
link = get_current_link(doc_view);
|
||||
if (!link) return -1;
|
||||
if (!doc_view->vs->ecmascript) return -1;
|
||||
|
||||
void *mapa = (void *)doc_view->document->element_map;
|
||||
|
||||
if (mapa) {
|
||||
dom_node *elem = (dom_node *)find_in_map(mapa, link->element_offset);
|
||||
|
||||
if (elem) {
|
||||
const char *event_name = script_event_hook_name[(int)type];
|
||||
check_element_event(doc_view->vs->ecmascript, elem, event_name, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
if (!link->event_hooks) return -1;
|
||||
|
||||
foreach (evhook, *link->event_hooks) {
|
||||
char *ret;
|
||||
|
||||
if (evhook->type != type) continue;
|
||||
ret = evhook->src;
|
||||
while ((ret = strstr(ret, "return ")))
|
||||
while (*ret != ' ') *ret++ = ' ';
|
||||
{
|
||||
struct string src = INIT_STRING(evhook->src, (int)strlen(evhook->src));
|
||||
/* TODO: Some even handlers return a bool. */
|
||||
if (!ecmascript_eval_boolback(doc_view->vs->ecmascript, &src))
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
#ifndef EL__ECMASCRIPT_ECMASCRIPT_C_H
|
||||
#define EL__ECMASCRIPT_ECMASCRIPT_C_H
|
||||
|
||||
#include "document/document.h"
|
||||
#include "ecmascript/libdom/dom.h"
|
||||
#include "main/module.h"
|
||||
|
||||
@ -8,10 +9,12 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct document_options;
|
||||
struct document;
|
||||
struct document_options;
|
||||
struct document_view;
|
||||
struct ecmascript_interpreter;
|
||||
struct session;
|
||||
struct string;
|
||||
struct term_event;
|
||||
struct uri;
|
||||
struct view_state;
|
||||
@ -27,6 +30,9 @@ void check_for_snippets(struct view_state *vs, struct document_options *options,
|
||||
void kill_ecmascript_timeouts(struct document *document);
|
||||
|
||||
void check_events_for_element(struct ecmascript_interpreter *interpreter, dom_node *element, struct term_event *ev);
|
||||
void ecmascript_reset_state(struct view_state *vs);
|
||||
int ecmascript_current_link_evhook(struct document_view *doc_view, enum script_event_hook_type type);
|
||||
int ecmascript_eval_boolback(struct ecmascript_interpreter *interpreter, struct string *code);
|
||||
|
||||
extern struct module ecmascript_module;
|
||||
|
||||
|
@ -395,30 +395,6 @@ ecmascript_eval_stringback(struct ecmascript_interpreter *interpreter,
|
||||
return result;
|
||||
}
|
||||
|
||||
int
|
||||
ecmascript_eval_boolback(struct ecmascript_interpreter *interpreter,
|
||||
struct string *code)
|
||||
{
|
||||
int result;
|
||||
|
||||
if (!get_ecmascript_enable(interpreter))
|
||||
return -1;
|
||||
assert(interpreter);
|
||||
interpreter->backend_nesting++;
|
||||
#ifdef CONFIG_MUJS
|
||||
result = mujs_eval_boolback(interpreter, code);
|
||||
#elif defined(CONFIG_QUICKJS)
|
||||
result = quickjs_eval_boolback(interpreter, code);
|
||||
#else
|
||||
result = spidermonkey_eval_boolback(interpreter, code);
|
||||
#endif
|
||||
interpreter->backend_nesting--;
|
||||
|
||||
check_for_rerender(interpreter, "boolback");
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void
|
||||
ecmascript_detach_form_view(struct form_view *fv)
|
||||
{
|
||||
@ -450,30 +426,6 @@ void ecmascript_moved_form_state(struct form_state *fs)
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
ecmascript_reset_state(struct view_state *vs)
|
||||
{
|
||||
struct form_view *fv;
|
||||
int i;
|
||||
|
||||
/* Normally, if vs->ecmascript == NULL, the associated
|
||||
* ecmascript_obj pointers are also NULL. However, they might
|
||||
* be non-NULL if the ECMAScript objects have been lazily
|
||||
* created because of scripts running in sibling HTML frames. */
|
||||
foreach (fv, vs->forms)
|
||||
ecmascript_detach_form_view(fv);
|
||||
for (i = 0; i < vs->form_info_len; i++)
|
||||
ecmascript_detach_form_state(&vs->form_info[i]);
|
||||
|
||||
vs->ecmascript_fragile = 0;
|
||||
if (vs->ecmascript)
|
||||
ecmascript_put_interpreter(vs->ecmascript);
|
||||
|
||||
vs->ecmascript = ecmascript_get_interpreter(vs);
|
||||
if (!vs->ecmascript)
|
||||
vs->ecmascript_fragile = 1;
|
||||
}
|
||||
|
||||
void
|
||||
ecmascript_timeout_dialog(struct terminal *term, int max_exec_time)
|
||||
{
|
||||
|
@ -164,8 +164,6 @@ void ecmascript_reset_state(struct view_state *vs);
|
||||
|
||||
void ecmascript_eval(struct ecmascript_interpreter *interpreter, struct string *code, struct string *ret, int element_offset);
|
||||
char *ecmascript_eval_stringback(struct ecmascript_interpreter *interpreter, struct string *code);
|
||||
/* Returns -1 if undefined. */
|
||||
int ecmascript_eval_boolback(struct ecmascript_interpreter *interpreter, struct string *code);
|
||||
|
||||
void ecmascript_timeout_dialog(struct terminal *term, int max_exec_time);
|
||||
|
||||
|
@ -5,6 +5,6 @@ INCLUDES += $(TRE_CFLAGS)
|
||||
|
||||
OBJS-$(CONFIG_MARKS) += marks.o
|
||||
|
||||
OBJS = draw.o form.obj link.obj search.o textarea.o view.o vs.o
|
||||
OBJS = draw.o form.obj link.o search.o textarea.o view.o vs.o
|
||||
|
||||
include $(top_srcdir)/Makefile.lib
|
||||
|
@ -27,18 +27,9 @@
|
||||
#include "document/libdom/mapa.h"
|
||||
#include "document/options.h"
|
||||
#include "document/view.h"
|
||||
#include "ecmascript/ecmascript.h"
|
||||
|
||||
#ifdef CONFIG_ECMASCRIPT_SMJS
|
||||
#include "ecmascript/spidermonkey/element.h"
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_QUICKJS
|
||||
#include "ecmascript/quickjs/element.h"
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_MUJS
|
||||
#include "ecmascript/mujs/element.h"
|
||||
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS) || defined(CONFIG_MUJS)
|
||||
#include "ecmascript/ecmascript-c.h"
|
||||
#endif
|
||||
|
||||
#include "intl/libintl.h"
|
||||
@ -74,43 +65,7 @@ int
|
||||
current_link_evhook(struct document_view *doc_view, enum script_event_hook_type type)
|
||||
{
|
||||
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS) || defined(CONFIG_MUJS)
|
||||
struct link *link;
|
||||
struct script_event_hook *evhook;
|
||||
|
||||
assert(doc_view && doc_view->vs);
|
||||
link = get_current_link(doc_view);
|
||||
if (!link) return -1;
|
||||
if (!doc_view->vs->ecmascript) return -1;
|
||||
|
||||
void *mapa = (void *)doc_view->document->element_map;
|
||||
|
||||
if (mapa) {
|
||||
dom_node *elem = (dom_node *)find_in_map(mapa, link->element_offset);
|
||||
|
||||
if (elem) {
|
||||
const char *event_name = script_event_hook_name[(int)type];
|
||||
check_element_event(doc_view->vs->ecmascript, elem, event_name, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
if (!link->event_hooks) return -1;
|
||||
|
||||
foreach (evhook, *link->event_hooks) {
|
||||
char *ret;
|
||||
|
||||
if (evhook->type != type) continue;
|
||||
ret = evhook->src;
|
||||
while ((ret = strstr(ret, "return ")))
|
||||
while (*ret != ' ') *ret++ = ' ';
|
||||
{
|
||||
struct string src = INIT_STRING(evhook->src, (int)strlen(evhook->src));
|
||||
/* TODO: Some even handlers return a bool. */
|
||||
if (!ecmascript_eval_boolback(doc_view->vs->ecmascript, &src))
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
return ecmascript_current_link_evhook(doc_view, type);
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
@ -4,4 +4,4 @@ if conf_data.get('CONFIG_MARKS')
|
||||
srcs += files('marks.c')
|
||||
endif
|
||||
|
||||
srcs += files('draw.c', 'form.cpp', 'link.cpp', 'search.c', 'textarea.c', 'view.c', 'vs.c')
|
||||
srcs += files('draw.c', 'form.cpp', 'link.c', 'search.c', 'textarea.c', 'view.c', 'vs.c')
|
||||
|
Loading…
Reference in New Issue
Block a user