mirror of
https://github.com/rkd77/elinks.git
synced 2024-09-30 03:26:23 -04:00
[js] screen.availHeight (here it is 16 * box.height)
This commit is contained in:
parent
8b2ef1ef45
commit
10d731f10c
@ -32,6 +32,7 @@
|
|||||||
#include "ecmascript/spidermonkey/location.h"
|
#include "ecmascript/spidermonkey/location.h"
|
||||||
#include "ecmascript/spidermonkey/localstorage.h"
|
#include "ecmascript/spidermonkey/localstorage.h"
|
||||||
#include "ecmascript/spidermonkey/navigator.h"
|
#include "ecmascript/spidermonkey/navigator.h"
|
||||||
|
#include "ecmascript/spidermonkey/screen.h"
|
||||||
#include "ecmascript/spidermonkey/unibar.h"
|
#include "ecmascript/spidermonkey/unibar.h"
|
||||||
#include "ecmascript/spidermonkey/window.h"
|
#include "ecmascript/spidermonkey/window.h"
|
||||||
#include "intl/gettext/libintl.h"
|
#include "intl/gettext/libintl.h"
|
||||||
@ -215,7 +216,7 @@ spidermonkey_get_interpreter(struct ecmascript_interpreter *interpreter)
|
|||||||
{
|
{
|
||||||
JSContext *ctx;
|
JSContext *ctx;
|
||||||
JSObject *console_obj, *document_obj, /* *forms_obj,*/ *history_obj, *location_obj,
|
JSObject *console_obj, *document_obj, /* *forms_obj,*/ *history_obj, *location_obj,
|
||||||
*statusbar_obj, *menubar_obj, *navigator_obj, *localstorage_obj;
|
*statusbar_obj, *menubar_obj, *navigator_obj, *localstorage_obj, *screen_obj;
|
||||||
|
|
||||||
static int initialized = 0;
|
static int initialized = 0;
|
||||||
|
|
||||||
@ -303,6 +304,16 @@ spidermonkey_get_interpreter(struct ecmascript_interpreter *interpreter)
|
|||||||
goto release_and_fail;
|
goto release_and_fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
screen_obj = spidermonkey_InitClass(ctx, window_obj, NULL,
|
||||||
|
&screen_class, NULL, 0,
|
||||||
|
screen_props,
|
||||||
|
NULL,
|
||||||
|
NULL, NULL);
|
||||||
|
|
||||||
|
if (!screen_obj) {
|
||||||
|
goto release_and_fail;
|
||||||
|
}
|
||||||
|
|
||||||
menubar_obj = JS_InitClass(ctx, window_obj, nullptr,
|
menubar_obj = JS_InitClass(ctx, window_obj, nullptr,
|
||||||
&menubar_class, NULL, 0,
|
&menubar_class, NULL, 0,
|
||||||
unibar_props, NULL,
|
unibar_props, NULL,
|
||||||
|
@ -2,6 +2,6 @@ top_builddir=../../..
|
|||||||
include $(top_builddir)/Makefile.config
|
include $(top_builddir)/Makefile.config
|
||||||
INCLUDES += $(SPIDERMONKEY_CFLAGS)
|
INCLUDES += $(SPIDERMONKEY_CFLAGS)
|
||||||
|
|
||||||
OBJS = console.o document.o element.c form.o heartbeat.o location.o localstorage.o localstorage-db.o navigator.o unibar.o window.o
|
OBJS = console.o document.o element.o form.o heartbeat.o location.o localstorage.o localstorage-db.o navigator.o screen.o unibar.o window.o
|
||||||
|
|
||||||
include $(top_srcdir)/Makefile.lib
|
include $(top_srcdir)/Makefile.lib
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
#INCLUDES += $(SPIDERMONKEY_CFLAGS)
|
#INCLUDES += $(SPIDERMONKEY_CFLAGS)
|
||||||
|
|
||||||
srcs += files('console.c', 'document.c', 'element.c', 'form.c', 'heartbeat.c', 'location.c', 'localstorage.c', 'localstorage-db.c', 'navigator.c', 'unibar.c', 'window.c')
|
srcs += files('console.c', 'document.c', 'element.c', 'form.c', 'heartbeat.c', 'location.c', 'localstorage.c', 'localstorage-db.c', 'navigator.c', 'screen.c', 'unibar.c', 'window.c')
|
||||||
|
102
src/ecmascript/spidermonkey/screen.c
Normal file
102
src/ecmascript/spidermonkey/screen.c
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
/* The SpiderMonkey location and history objects 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/screen.h"
|
||||||
|
#include "ecmascript/spidermonkey/window.h"
|
||||||
|
#include "intl/gettext/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"
|
||||||
|
|
||||||
|
JSClassOps screen_ops = {
|
||||||
|
JS_PropertyStub, nullptr,
|
||||||
|
JS_PropertyStub, JS_StrictPropertyStub,
|
||||||
|
nullptr, nullptr, nullptr, nullptr
|
||||||
|
};
|
||||||
|
|
||||||
|
JSClass screen_class = {
|
||||||
|
"screen",
|
||||||
|
JSCLASS_HAS_PRIVATE,
|
||||||
|
&screen_ops
|
||||||
|
};
|
||||||
|
|
||||||
|
static bool screen_get_property_availHeight(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||||
|
|
||||||
|
JSPropertySpec screen_props[] = {
|
||||||
|
JS_PSG("availHeight", screen_get_property_availHeight, JSPROP_ENUMERATE),
|
||||||
|
JS_PS_END
|
||||||
|
};
|
||||||
|
|
||||||
|
static bool
|
||||||
|
screen_get_property_availHeight(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||||
|
{
|
||||||
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
|
||||||
|
struct view_state *vs;
|
||||||
|
JSCompartment *comp = js::GetContextCompartment(ctx);
|
||||||
|
|
||||||
|
if (!comp) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ecmascript_interpreter *interpreter = JS_GetCompartmentPrivate(comp);
|
||||||
|
|
||||||
|
/* This can be called if @obj if not itself an instance of the
|
||||||
|
* appropriate class but has one in its prototype chain. Fail
|
||||||
|
* such calls. */
|
||||||
|
if (!JS_InstanceOf(ctx, hobj, &screen_class, NULL))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
vs = interpreter->vs;
|
||||||
|
if (!vs) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct document_view *doc_view = vs->doc_view;
|
||||||
|
|
||||||
|
if (!doc_view) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
args.rval().setInt32(doc_view->box.height * 16);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
10
src/ecmascript/spidermonkey/screen.h
Normal file
10
src/ecmascript/spidermonkey/screen.h
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
|
||||||
|
#ifndef EL__ECMASCRIPT_SPIDERMONKEY_SCREEN_H
|
||||||
|
#define EL__ECMASCRIPT_SPIDERMONKEY_SCREEN_H
|
||||||
|
|
||||||
|
#include "ecmascript/spidermonkey/util.h"
|
||||||
|
|
||||||
|
extern JSClass screen_class;
|
||||||
|
extern JSPropertySpec screen_props[];
|
||||||
|
|
||||||
|
#endif
|
19
test/ecmascript/availHeight.html
Normal file
19
test/ecmascript/availHeight.html
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<p>Click the button to display the avail height of your screen, in pixels.</p>
|
||||||
|
|
||||||
|
<button onclick="myFunction()">Try it</button>
|
||||||
|
|
||||||
|
<p id="demo"></p>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
function myFunction() {
|
||||||
|
var x = "Avail Height: " + screen.availHeight + "px";
|
||||||
|
alert(x);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in New Issue
Block a user