diff --git a/src/ecmascript/spidermonkey.c b/src/ecmascript/spidermonkey.c index 539e99b1..03cb872b 100644 --- a/src/ecmascript/spidermonkey.c +++ b/src/ecmascript/spidermonkey.c @@ -32,6 +32,7 @@ #include "ecmascript/spidermonkey/location.h" #include "ecmascript/spidermonkey/localstorage.h" #include "ecmascript/spidermonkey/navigator.h" +#include "ecmascript/spidermonkey/screen.h" #include "ecmascript/spidermonkey/unibar.h" #include "ecmascript/spidermonkey/window.h" #include "intl/gettext/libintl.h" @@ -215,7 +216,7 @@ spidermonkey_get_interpreter(struct ecmascript_interpreter *interpreter) { JSContext *ctx; 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; @@ -303,6 +304,16 @@ spidermonkey_get_interpreter(struct ecmascript_interpreter *interpreter) 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_class, NULL, 0, unibar_props, NULL, diff --git a/src/ecmascript/spidermonkey/Makefile b/src/ecmascript/spidermonkey/Makefile index 0c9996f4..6ed866ad 100644 --- a/src/ecmascript/spidermonkey/Makefile +++ b/src/ecmascript/spidermonkey/Makefile @@ -2,6 +2,6 @@ top_builddir=../../.. include $(top_builddir)/Makefile.config 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 diff --git a/src/ecmascript/spidermonkey/meson.build b/src/ecmascript/spidermonkey/meson.build index 2a218759..14435122 100644 --- a/src/ecmascript/spidermonkey/meson.build +++ b/src/ecmascript/spidermonkey/meson.build @@ -1,3 +1,3 @@ #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') diff --git a/src/ecmascript/spidermonkey/screen.c b/src/ecmascript/spidermonkey/screen.c new file mode 100644 index 00000000..aae6dfca --- /dev/null +++ b/src/ecmascript/spidermonkey/screen.c @@ -0,0 +1,102 @@ +/* The SpiderMonkey location and history objects implementation. */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include + +#include "elinks.h" + +#include "ecmascript/spidermonkey/util.h" +#include + +#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; +} diff --git a/src/ecmascript/spidermonkey/screen.h b/src/ecmascript/spidermonkey/screen.h new file mode 100644 index 00000000..39ae6230 --- /dev/null +++ b/src/ecmascript/spidermonkey/screen.h @@ -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 diff --git a/test/ecmascript/availHeight.html b/test/ecmascript/availHeight.html new file mode 100644 index 00000000..bc32760a --- /dev/null +++ b/test/ecmascript/availHeight.html @@ -0,0 +1,19 @@ + + + + +

Click the button to display the avail height of your screen, in pixels.

+ + + +

+ + + + +