mirror of
https://github.com/rkd77/elinks.git
synced 2024-11-04 08:17:17 -05:00
[spidermonkey] element.clientWidth
This commit is contained in:
parent
bc37d44d52
commit
8238393479
@ -73,6 +73,7 @@ static bool element_set_property_className(JSContext *ctx, unsigned int argc, JS
|
|||||||
static bool element_get_property_clientHeight(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
static bool element_get_property_clientHeight(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||||
static bool element_get_property_clientLeft(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
static bool element_get_property_clientLeft(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||||
static bool element_get_property_clientTop(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
static bool element_get_property_clientTop(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||||
|
static bool element_get_property_clientWidth(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||||
static bool element_get_property_dir(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
static bool element_get_property_dir(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||||
static bool element_set_property_dir(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
static bool element_set_property_dir(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||||
static bool element_get_property_firstChild(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
static bool element_get_property_firstChild(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||||
@ -154,6 +155,7 @@ JSPropertySpec element_props[] = {
|
|||||||
JS_PSG("clientHeight", element_get_property_clientHeight, JSPROP_ENUMERATE),
|
JS_PSG("clientHeight", element_get_property_clientHeight, JSPROP_ENUMERATE),
|
||||||
JS_PSG("clientLeft", element_get_property_clientLeft, JSPROP_ENUMERATE),
|
JS_PSG("clientLeft", element_get_property_clientLeft, JSPROP_ENUMERATE),
|
||||||
JS_PSG("clientTop", element_get_property_clientTop, JSPROP_ENUMERATE),
|
JS_PSG("clientTop", element_get_property_clientTop, JSPROP_ENUMERATE),
|
||||||
|
JS_PSG("clientWidth", element_get_property_clientWidth, JSPROP_ENUMERATE),
|
||||||
JS_PSGS("dir", element_get_property_dir, element_set_property_dir, JSPROP_ENUMERATE),
|
JS_PSGS("dir", element_get_property_dir, element_set_property_dir, JSPROP_ENUMERATE),
|
||||||
JS_PSG("firstChild", element_get_property_firstChild, JSPROP_ENUMERATE),
|
JS_PSG("firstChild", element_get_property_firstChild, JSPROP_ENUMERATE),
|
||||||
JS_PSG("firstElementChild", element_get_property_firstElementChild, JSPROP_ENUMERATE),
|
JS_PSG("firstElementChild", element_get_property_firstElementChild, JSPROP_ENUMERATE),
|
||||||
@ -679,6 +681,80 @@ element_get_property_clientTop(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
element_get_property_clientWidth(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
struct view_state *vs;
|
||||||
|
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);
|
||||||
|
|
||||||
|
/* 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, &element_class, NULL)) {
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
|
||||||
|
#endif
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
vs = interpreter->vs;
|
||||||
|
|
||||||
|
if (!vs) {
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
|
||||||
|
#endif
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
dom_node *el = (dom_node *)JS::GetMaybePtrFromReservedSlot<dom_node>(hobj, 0);
|
||||||
|
|
||||||
|
if (!el) {
|
||||||
|
args.rval().setNull();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
struct document_view *doc_view = vs->doc_view;
|
||||||
|
struct document *document = doc_view->document;
|
||||||
|
struct session *ses;
|
||||||
|
|
||||||
|
if (!document) {
|
||||||
|
args.rval().setInt32(0);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
int offset = find_offset(document->element_map_rev, el);
|
||||||
|
|
||||||
|
if (offset <= 0) {
|
||||||
|
args.rval().setInt32(0);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
struct node_rect *rect = get_element_rect(document, offset);
|
||||||
|
|
||||||
|
if (!rect) {
|
||||||
|
args.rval().setInt32(0);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
ses = doc_view->session;
|
||||||
|
|
||||||
|
if (!ses) {
|
||||||
|
args.rval().setInt32(0);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
int dx = int_max(0, (rect->x1 + 1 - rect->x0) * ses->tab->term->cell_width);
|
||||||
|
args.rval().setInt32(dx);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
element_get_property_dir(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
element_get_property_dir(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user