1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-06-27 01:25:34 +00:00

[js] screen.height (term->height * 16)

This commit is contained in:
Witold Filipczyk 2021-05-31 14:27:40 +02:00
parent 54a7bd7339
commit fb90f2a832
2 changed files with 64 additions and 1 deletions

View File

@ -59,11 +59,13 @@ JSClass screen_class = {
static bool screen_get_property_availHeight(JSContext *ctx, unsigned int argc, JS::Value *vp);
static bool screen_get_property_availWidth(JSContext *ctx, unsigned int argc, JS::Value *vp);
static bool screen_get_property_height(JSContext *ctx, unsigned int argc, JS::Value *vp);
static bool screen_get_property_width(JSContext *ctx, unsigned int argc, JS::Value *vp);
JSPropertySpec screen_props[] = {
JS_PSG("availHeight", screen_get_property_availHeight, JSPROP_ENUMERATE),
JS_PSG("availWidth", screen_get_property_availWidth, JSPROP_ENUMERATE),
JS_PSG("height", screen_get_property_height, JSPROP_ENUMERATE),
JS_PSG("width", screen_get_property_width, JSPROP_ENUMERATE),
JS_PS_END
};
@ -142,6 +144,49 @@ screen_get_property_availWidth(JSContext *ctx, unsigned int argc, JS::Value *vp)
return true;
}
static bool
screen_get_property_height(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;
}
struct session *ses = doc_view->session;
if (!ses) {
return false;
}
args.rval().setInt32(ses->tab->term->height * 16);
return true;
}
static bool
screen_get_property_width(JSContext *ctx, unsigned int argc, JS::Value *vp)
{
@ -184,4 +229,3 @@ screen_get_property_width(JSContext *ctx, unsigned int argc, JS::Value *vp)
return true;
}

View File

@ -0,0 +1,19 @@
<!DOCTYPE html>
<html>
<body>
<p>Click the button to display the height of your screen, in pixels.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = "Height: " + screen.height + "px";
alert(x);
}
</script>
</body>
</html>