mirror of
https://github.com/rkd77/elinks.git
synced 2024-11-04 08:17:17 -05:00
[quickjs] libdom screen.c
This commit is contained in:
parent
c4a747749d
commit
d4658a85fb
@ -1,6 +1,6 @@
|
||||
top_builddir=../../../..
|
||||
include $(top_builddir)/Makefile.config
|
||||
|
||||
OBJS = attr.o attributes.o collection.o console.o heartbeat.o history.o keyboard.o localstorage.o mapa.obj navigator.o
|
||||
OBJS = attr.o attributes.o collection.o console.o heartbeat.o history.o keyboard.o localstorage.o mapa.obj navigator.o screen.o
|
||||
|
||||
include $(top_srcdir)/Makefile.lib
|
||||
|
@ -1 +1 @@
|
||||
srcs += files('attr.c', 'attributes.c', 'collection.c', 'console.c', 'heartbeat.c', 'history.c', 'keyboard.c', 'localstorage.c', 'mapa.cpp', 'navigator.c')
|
||||
srcs += files('attr.c', 'attributes.c', 'collection.c', 'console.c', 'heartbeat.c', 'history.c', 'keyboard.c', 'localstorage.c', 'mapa.cpp', 'navigator.c', 'screen.c')
|
||||
|
164
src/ecmascript/libdom/quickjs/screen.c
Normal file
164
src/ecmascript/libdom/quickjs/screen.c
Normal file
@ -0,0 +1,164 @@
|
||||
/* The QuickJS screen object implementation. */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "elinks.h"
|
||||
|
||||
#include "document/view.h"
|
||||
#include "ecmascript/ecmascript.h"
|
||||
#include "ecmascript/quickjs.h"
|
||||
#include "ecmascript/quickjs/screen.h"
|
||||
#include "session/session.h"
|
||||
|
||||
#define countof(x) (sizeof(x) / sizeof((x)[0]))
|
||||
|
||||
static JSClassID js_screen_class_id;
|
||||
|
||||
static JSValue
|
||||
js_screen_get_property_availHeight(JSContext *ctx, JSValueConst this_val)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
REF_JS(this_val);
|
||||
|
||||
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
|
||||
struct view_state *vs = interpreter->vs;
|
||||
struct document_view *doc_view = vs->doc_view;
|
||||
|
||||
if (!doc_view) {
|
||||
return JS_UNDEFINED;
|
||||
}
|
||||
|
||||
return JS_NewInt32(ctx, doc_view->box.height * 16);
|
||||
}
|
||||
|
||||
static JSValue
|
||||
js_screen_get_property_availWidth(JSContext *ctx, JSValueConst this_val)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
REF_JS(this_val);
|
||||
|
||||
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
|
||||
struct view_state *vs = interpreter->vs;
|
||||
struct document_view *doc_view = vs->doc_view;
|
||||
|
||||
if (!doc_view) {
|
||||
return JS_UNDEFINED;
|
||||
}
|
||||
|
||||
return JS_NewInt32(ctx, doc_view->box.width * 8);
|
||||
}
|
||||
|
||||
static JSValue
|
||||
js_screen_get_property_height(JSContext *ctx, JSValueConst this_val)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
REF_JS(this_val);
|
||||
|
||||
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
|
||||
struct view_state *vs = interpreter->vs;
|
||||
struct document_view *doc_view = vs->doc_view;
|
||||
|
||||
if (!doc_view) {
|
||||
return JS_UNDEFINED;
|
||||
}
|
||||
|
||||
struct session *ses = doc_view->session;
|
||||
|
||||
if (!ses) {
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
|
||||
#endif
|
||||
return JS_UNDEFINED;
|
||||
}
|
||||
|
||||
return JS_NewInt32(ctx, ses->tab->term->height * 16);
|
||||
}
|
||||
|
||||
static JSValue
|
||||
js_screen_get_property_width(JSContext *ctx, JSValueConst this_val)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
REF_JS(this_val);
|
||||
|
||||
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
|
||||
struct view_state *vs = interpreter->vs;
|
||||
struct document_view *doc_view = vs->doc_view;
|
||||
|
||||
if (!doc_view) {
|
||||
return JS_UNDEFINED;
|
||||
}
|
||||
|
||||
struct session *ses = doc_view->session;
|
||||
|
||||
if (!ses) {
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
|
||||
#endif
|
||||
return JS_UNDEFINED;
|
||||
}
|
||||
|
||||
return JS_NewInt32(ctx, ses->tab->term->width * 8);
|
||||
}
|
||||
|
||||
static JSValue
|
||||
js_screen_toString(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
REF_JS(this_val);
|
||||
|
||||
return JS_NewString(ctx, "[screen object]");
|
||||
}
|
||||
|
||||
static const JSCFunctionListEntry js_screen_proto_funcs[] = {
|
||||
JS_CGETSET_DEF("availHeight", js_screen_get_property_availHeight, NULL),
|
||||
JS_CGETSET_DEF("availWidth", js_screen_get_property_availWidth, NULL),
|
||||
JS_CGETSET_DEF("height", js_screen_get_property_height, NULL),
|
||||
JS_CGETSET_DEF("width", js_screen_get_property_width, NULL),
|
||||
JS_CFUNC_DEF("toString", 0, js_screen_toString)
|
||||
};
|
||||
|
||||
static JSClassDef js_screen_class = {
|
||||
"screen",
|
||||
};
|
||||
|
||||
int
|
||||
js_screen_init(JSContext *ctx)
|
||||
{
|
||||
JSValue screen_proto;
|
||||
|
||||
/* create the screen class */
|
||||
JS_NewClassID(&js_screen_class_id);
|
||||
JS_NewClass(JS_GetRuntime(ctx), js_screen_class_id, &js_screen_class);
|
||||
|
||||
JSValue global_obj = JS_GetGlobalObject(ctx);
|
||||
REF_JS(global_obj);
|
||||
|
||||
screen_proto = JS_NewObject(ctx);
|
||||
REF_JS(screen_proto);
|
||||
|
||||
JS_SetPropertyFunctionList(ctx, screen_proto, js_screen_proto_funcs, countof(js_screen_proto_funcs));
|
||||
JS_SetClassProto(ctx, js_screen_class_id, screen_proto);
|
||||
|
||||
JS_SetPropertyStr(ctx, global_obj, "screen", JS_DupValue(ctx, screen_proto));
|
||||
|
||||
JS_FreeValue(ctx, global_obj);
|
||||
REF_JS(global_obj);
|
||||
|
||||
return 0;
|
||||
}
|
@ -43,6 +43,8 @@
|
||||
#include "viewer/text/link.h"
|
||||
#include "viewer/text/vs.h"
|
||||
|
||||
#ifndef CONFIG_LIBDOM
|
||||
|
||||
#define countof(x) (sizeof(x) / sizeof((x)[0]))
|
||||
|
||||
static JSClassID js_screen_class_id;
|
||||
@ -189,3 +191,4 @@ js_screen_init(JSContext *ctx)
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
@ -1,9 +1,16 @@
|
||||
|
||||
#ifndef EL__ECMASCRIPT_QUICKJS_SCREEN_H
|
||||
#define EL__ECMASCRIPT_QUICKJS_SCREEN_H
|
||||
|
||||
#include <quickjs/quickjs.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int js_screen_init(JSContext *ctx);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user