mirror of
https://github.com/rkd77/elinks.git
synced 2024-11-04 08:17:17 -05:00
[libdom] history.cpp
This commit is contained in:
parent
7337ebb888
commit
5c9bafa522
@ -2,6 +2,6 @@ top_builddir=../../..
|
||||
include $(top_builddir)/Makefile.config
|
||||
INCLUDES += $(SPIDERMONKEY_CFLAGS)
|
||||
|
||||
OBJS = keyboard.obj localstorage.obj location.obj message.obj navigator.obj screen.obj unibar.obj window.obj xhr.obj
|
||||
OBJS = history.obj keyboard.obj localstorage.obj location.obj message.obj navigator.obj screen.obj unibar.obj window.obj xhr.obj
|
||||
|
||||
include $(top_srcdir)/Makefile.lib
|
||||
|
177
src/ecmascript/libdom/spidermonkey/history.cpp
Normal file
177
src/ecmascript/libdom/spidermonkey/history.cpp
Normal file
@ -0,0 +1,177 @@
|
||||
/* The SpiderMonkey history object implementation. */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "elinks.h"
|
||||
|
||||
#include "ecmascript/spidermonkey/util.h"
|
||||
#include <jsfriendapi.h>
|
||||
|
||||
#include "bfu/dialog.h"
|
||||
#include "cache/cache.h"
|
||||
#include "cookies/cookies.h"
|
||||
#include "dialogs/menu.h"
|
||||
#include "dialogs/status.h"
|
||||
#include "document/html/frames.h"
|
||||
#include "document/document.h"
|
||||
#include "document/forms.h"
|
||||
#include "document/view.h"
|
||||
#include "ecmascript/ecmascript.h"
|
||||
#include "ecmascript/spidermonkey/history.h"
|
||||
#include "intl/libintl.h"
|
||||
#include "main/select.h"
|
||||
#include "osdep/newwin.h"
|
||||
#include "osdep/sysname.h"
|
||||
#include "protocol/http/http.h"
|
||||
#include "protocol/uri.h"
|
||||
#include "session/history.h"
|
||||
#include "session/location.h"
|
||||
#include "session/session.h"
|
||||
#include "session/task.h"
|
||||
#include "terminal/tab.h"
|
||||
#include "terminal/terminal.h"
|
||||
#include "util/conv.h"
|
||||
#include "util/memory.h"
|
||||
#include "util/string.h"
|
||||
#include "viewer/text/draw.h"
|
||||
#include "viewer/text/form.h"
|
||||
#include "viewer/text/link.h"
|
||||
#include "viewer/text/vs.h"
|
||||
|
||||
|
||||
static bool history_back(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
||||
static bool history_forward(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
||||
static bool history_go(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
||||
|
||||
JSClassOps history_ops = {
|
||||
nullptr, // addProperty
|
||||
nullptr, // deleteProperty
|
||||
nullptr, // enumerate
|
||||
nullptr, // newEnumerate
|
||||
nullptr, // resolve
|
||||
nullptr, // mayResolve
|
||||
nullptr, // finalize
|
||||
nullptr, // call
|
||||
nullptr, // construct
|
||||
JS_GlobalObjectTraceHook
|
||||
};
|
||||
|
||||
JSClass history_class = {
|
||||
"history",
|
||||
JSCLASS_HAS_RESERVED_SLOTS(1),
|
||||
&history_ops
|
||||
};
|
||||
|
||||
const spidermonkeyFunctionSpec history_funcs[] = {
|
||||
{ "back", history_back, 0 },
|
||||
{ "forward", history_forward, 0 },
|
||||
{ "go", history_go, 1 },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
/* @history_funcs{"back"} */
|
||||
static bool
|
||||
history_back(JSContext *ctx, unsigned int argc, JS::Value *rval)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
JS::Realm *comp = js::GetContextRealm(ctx);
|
||||
|
||||
if (!comp) {
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS::GetRealmPrivate(comp);
|
||||
struct document_view *doc_view = interpreter->vs->doc_view;
|
||||
struct session *ses = doc_view->session;
|
||||
JS::CallArgs args = JS::CallArgsFromVp(argc, rval);
|
||||
|
||||
go_back(ses);
|
||||
|
||||
/* history_back() must return 0 for onClick to cause displaying previous page
|
||||
* and return non zero for <a href="javascript:history.back()"> to prevent
|
||||
* "calculating" new link. Returned value 2 is changed to 0 in function
|
||||
* spidermonkey_eval_boolback */
|
||||
args.rval().setNull();
|
||||
return 2;
|
||||
}
|
||||
|
||||
/* @history_funcs{"forward"} */
|
||||
static bool
|
||||
history_forward(JSContext *ctx, unsigned int argc, JS::Value *rval)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
JS::Realm *comp = js::GetContextRealm(ctx);
|
||||
|
||||
if (!comp) {
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS::GetRealmPrivate(comp);
|
||||
struct document_view *doc_view = interpreter->vs->doc_view;
|
||||
struct session *ses = doc_view->session;
|
||||
JS::CallArgs args = JS::CallArgsFromVp(argc, rval);
|
||||
|
||||
go_unback(ses);
|
||||
|
||||
args.rval().setNull();
|
||||
return 2;
|
||||
}
|
||||
|
||||
/* @history_funcs{"go"} */
|
||||
static bool
|
||||
history_go(JSContext *ctx, unsigned int argc, JS::Value *rval)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
JS::Realm *comp = js::GetContextRealm(ctx);
|
||||
|
||||
if (!comp) {
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS::GetRealmPrivate(comp);
|
||||
struct document_view *doc_view = interpreter->vs->doc_view;
|
||||
struct session *ses = doc_view->session;
|
||||
JS::CallArgs args = JS::CallArgsFromVp(argc, rval);
|
||||
|
||||
struct location *loc;
|
||||
|
||||
if (argc != 1)
|
||||
return true;
|
||||
|
||||
int index = args[0].toInt32();
|
||||
|
||||
for (loc = cur_loc(ses);
|
||||
loc != (struct location *) &ses->history.history;
|
||||
loc = index > 0 ? loc->next : loc->prev) {
|
||||
if (!index) {
|
||||
go_history(ses, loc);
|
||||
break;
|
||||
}
|
||||
|
||||
index += index > 0 ? -1 : 1;
|
||||
}
|
||||
|
||||
args.rval().setNull();
|
||||
return 2;
|
||||
}
|
@ -1 +1 @@
|
||||
srcs += files('keyboard.cpp', 'localstorage.cpp', 'location.cpp', 'message.cpp', 'navigator.cpp', 'screen.cpp', 'unibar.cpp', 'window.cpp', 'xhr.cpp')
|
||||
srcs += files('history.cpp', 'keyboard.cpp', 'localstorage.cpp', 'location.cpp', 'message.cpp', 'navigator.cpp', 'screen.cpp', 'unibar.cpp', 'window.cpp', 'xhr.cpp')
|
||||
|
@ -44,6 +44,7 @@
|
||||
#include "viewer/text/link.h"
|
||||
#include "viewer/text/vs.h"
|
||||
|
||||
#ifndef CONFIG_LIBDOM
|
||||
|
||||
static bool history_back(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
||||
static bool history_forward(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
||||
@ -175,3 +176,4 @@ history_go(JSContext *ctx, unsigned int argc, JS::Value *rval)
|
||||
args.rval().setNull();
|
||||
return 2;
|
||||
}
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user