summaryrefslogtreecommitdiff
path: root/src/scripts.c
diff options
context:
space:
mode:
authorportix <none@none>2012-09-19 01:40:28 +0200
committerportix <none@none>2012-09-19 01:40:28 +0200
commitaa6745301d8dcd1a8bdeaa4dc649f1be9f9a8437 (patch)
tree79c37913b9ea35944b490021f516238f409f2f11 /src/scripts.c
parent3e6ba3478f1200df7d7cd5ccd57728e3f5122be9 (diff)
downloaddwb-aa6745301d8dcd1a8bdeaa4dc649f1be9f9a8437.zip
implementing scratchpad_show/scratchpad_hide
Diffstat (limited to 'src/scripts.c')
-rw-r--r--src/scripts.c67
1 files changed, 55 insertions, 12 deletions
diff --git a/src/scripts.c b/src/scripts.c
index e3ede6bd..4a401d1f 100644
--- a/src/scripts.c
+++ b/src/scripts.c
@@ -31,6 +31,7 @@
#include "application.h"
#include "completion.h"
#include "entry.h"
+#include "scratchpad.h"
//#define kJSDefaultFunction (kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete )
#define kJSDefaultProperty (kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly )
#define kJSDefaultAttributes (kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly )
@@ -121,6 +122,8 @@ static JSStaticValue message_values[] = {
{ "firstParty", message_get_first_party, NULL, kJSDefaultAttributes },
{ 0, 0, 0, 0 },
};
+static JSValueRef sp_show(JSContextRef ctx, JSObjectRef function, JSObjectRef this, size_t argc, const JSValueRef argv[], JSValueRef* exc);
+static JSValueRef sp_hide(JSContextRef ctx, JSObjectRef function, JSObjectRef this, size_t argc, const JSValueRef argv[], JSValueRef* exc);
static JSValueRef frame_inject(JSContextRef ctx, JSObjectRef function, JSObjectRef this, size_t argc, const JSValueRef argv[], JSValueRef* exc);
static JSStaticFunction frame_functions[] = {
@@ -469,6 +472,18 @@ wv_set_title(JSContextRef ctx, JSObjectRef function, JSObjectRef this, size_t ar
/*}}}*/
+static JSValueRef
+sp_show(JSContextRef ctx, JSObjectRef function, JSObjectRef this, size_t argc, const JSValueRef argv[], JSValueRef* exc) {
+ scratchpad_show();
+ return JSValueMakeUndefined(ctx);
+}
+static JSValueRef
+sp_hide(JSContextRef ctx, JSObjectRef function, JSObjectRef this, size_t argc, const JSValueRef argv[], JSValueRef* exc) {
+ scratchpad_hide();
+ return JSValueMakeUndefined(ctx);
+}
+
+
/* SOUP_MESSAGE {{{*/
/* soup_uri_to_js_object {{{*/
JSObjectRef
@@ -1459,14 +1474,24 @@ object_destroy_cb(JSObjectRef o) {
}
static JSObjectRef
+make_object_for_class(JSContextRef ctx, JSClassRef class, GObject *o) {
+ JSObjectRef retobj = g_object_get_qdata(o, ref_quark);
+ if (retobj != NULL)
+ return retobj;
+
+ retobj = JSObjectMake(ctx, class, o);
+ g_object_set_qdata_full(o, ref_quark, retobj, (GDestroyNotify)object_destroy_cb);
+ JSValueProtect(m_global_context, retobj);
+ return retobj;
+}
+
+
+static JSObjectRef
make_object(JSContextRef ctx, GObject *o) {
if (o == NULL) {
JSValueRef v = JSValueMakeNull(ctx);
return JSValueToObject(ctx, v, NULL);
}
- JSObjectRef retobj = g_object_get_qdata(o, ref_quark);
- if (retobj != NULL)
- return retobj;
JSClassRef class;
if (WEBKIT_IS_WEB_VIEW(o))
class = m_webview_class;
@@ -1478,11 +1503,8 @@ make_object(JSContextRef ctx, GObject *o) {
class = m_message_class;
else
class = m_default_class;
+ return make_object_for_class(ctx, class, o);
- retobj = JSObjectMake(ctx, class, o);
- g_object_set_qdata_full(o, ref_quark, retobj, (GDestroyNotify)object_destroy_cb);
- JSValueProtect(m_global_context, retobj);
- return retobj;
}/*}}}*/
static gboolean
@@ -1547,9 +1569,7 @@ create_class(const char *name, JSStaticFunction staticFunctions[], JSStaticValue
static JSObjectRef
create_object(JSContextRef ctx, JSClassRef class, JSObjectRef obj, JSClassAttributes attr, const char *name, void *private) {
JSObjectRef ret = JSObjectMake(ctx, class, private);
- JSStringRef js_name = JSStringCreateWithUTF8CString(name);
- JSObjectSetProperty(ctx, obj, js_name, ret, attr, NULL);
- JSStringRelease(js_name);
+ js_set_property(ctx, obj, name, ret, attr, NULL);
return ret;
}/*}}}*/
@@ -1584,7 +1604,19 @@ set_property(JSContextRef ctx, JSObjectRef object, JSStringRef js_name, JSValueR
gtype == G_TYPE_UINT64 || gtype == G_TYPE_FLAGS)) {
double value = JSValueToNumber(ctx, jsvalue, exception);
if (value != NAN) {
- g_object_set(o, buf, value, NULL);
+ switch (gtype) {
+ case G_TYPE_ENUM :
+ case G_TYPE_FLAGS :
+ case G_TYPE_INT : g_object_set(o, buf, (gint)value, NULL); break;
+ case G_TYPE_UINT : g_object_set(o, buf, (guint)value, NULL); break;
+ case G_TYPE_LONG : g_object_set(o, buf, (long)value, NULL); break;
+ case G_TYPE_ULONG : g_object_set(o, buf, (gulong)value, NULL); break;
+ case G_TYPE_FLOAT : g_object_set(o, buf, (gfloat)value, NULL); break;
+ case G_TYPE_DOUBLE : g_object_set(o, buf, (gdouble)value, NULL); break;
+ case G_TYPE_INT64 : g_object_set(o, buf, (gint64)value, NULL); break;
+ case G_TYPE_UINT64 : g_object_set(o, buf, (guint64)value, NULL); break;
+
+ }
return true;
}
return false;
@@ -1805,7 +1837,18 @@ create_global_object() {
cd.parentClass = m_default_class;
m_download_class = JSClassCreate(&cd);
-
+ JSStaticFunction scratchpad_functions[] = {
+ { "show", sp_show, kJSDefaultAttributes },
+ { "hide", sp_hide, kJSDefaultAttributes },
+ { 0, 0, 0 },
+ };
+ cd.className = "Scratchpad";
+ cd.staticFunctions = scratchpad_functions;
+ cd.staticValues = NULL;
+ cd.parentClass = m_default_class;
+ class = JSClassCreate(&cd);
+ JSObjectRef o = make_object_for_class(m_global_context, class, G_OBJECT(scratchpad_get()));
+ js_set_property(m_global_context, global_object, "scratchpad", o, kJSDefaultAttributes, NULL);
JSObjectRef constructor = JSObjectMakeConstructor(m_global_context, m_download_class, download_constructor_cb);
JSStringRef name = JSStringCreateWithUTF8CString("Download");