summaryrefslogtreecommitdiff
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
parent3e6ba3478f1200df7d7cd5ccd57728e3f5122be9 (diff)
downloaddwb-aa6745301d8dcd1a8bdeaa4dc649f1be9f9a8437.zip
implementing scratchpad_show/scratchpad_hide
-rw-r--r--src/dwb.c3
-rw-r--r--src/js.c6
-rw-r--r--src/js.h1
-rw-r--r--src/scripts.c67
4 files changed, 64 insertions, 13 deletions
diff --git a/src/dwb.c b/src/dwb.c
index d1689157..4862bbe6 100644
--- a/src/dwb.c
+++ b/src/dwb.c
@@ -47,6 +47,7 @@
#include "domain.h"
#include "application.h"
#include "scripts.h"
+#include "scratchpad.h"
/* DECLARATIONS {{{*/
static DwbStatus dwb_webkit_setting(GList *, WebSettings *);
@@ -3699,11 +3700,11 @@ dwb_init_gui() {
gtk_box_pack_start(GTK_BOX(dwb.gui.status_hbox), dwb.gui.urilabel, true, true, 0);
gtk_box_pack_start(GTK_BOX(dwb.gui.status_hbox), dwb.gui.rstatus, false, false, 0);
gtk_container_add(GTK_CONTAINER(dwb.gui.statusbox), alignment);
+ gtk_box_pack_end(GTK_BOX(dwb.gui.vbox), scratchpad_get(), false, false, 0);
gtk_container_add(GTK_CONTAINER(dwb.gui.window), dwb.gui.vbox);
gtk_widget_show(dwb.gui.mainbox);
-
gtk_widget_show(dwb.gui.vbox);
gtk_widget_show(dwb.gui.window);
diff --git a/src/js.c b/src/js.c
index ce566175..d5b9e02b 100644
--- a/src/js.c
+++ b/src/js.c
@@ -33,6 +33,12 @@ js_make_exception(JSContextRef ctx, JSValueRef *exception, const gchar *format,
}
void
+js_set_property(JSContextRef ctx, JSObjectRef arg, const char *name, JSValueRef prop, JSClassAttributes attributes, JSValueRef *exc) {
+ JSStringRef js_key = JSStringCreateWithUTF8CString(name);
+ JSObjectSetProperty(ctx, arg, js_key, prop, attributes, exc);
+ JSStringRelease(js_key);
+}
+void
js_set_object_property(JSContextRef ctx, JSObjectRef arg, const char *name, const char *value, JSValueRef *exc) {
JSStringRef js_key = JSStringCreateWithUTF8CString(name);
JSValueRef js_value = js_char_to_value(ctx, value);
diff --git a/src/js.h b/src/js.h
index a51cb911..2edf79a3 100644
--- a/src/js.h
+++ b/src/js.h
@@ -23,6 +23,7 @@ void js_make_exception(JSContextRef ctx, JSValueRef *exception, const gchar *for
char * js_string_to_char(JSContextRef ctx, JSStringRef jsstring, size_t );
char * js_value_to_char(JSContextRef ctx, JSValueRef value, size_t limit, JSValueRef *);
JSObjectRef js_get_object_property(JSContextRef ctx, JSObjectRef arg, const char *name);
+void js_set_property(JSContextRef ctx, JSObjectRef arg, const char *name, JSValueRef value, JSClassAttributes attr, JSValueRef *);
void js_set_object_property(JSContextRef ctx, JSObjectRef arg, const char *name, const char *value, JSValueRef *);
void js_set_object_number_property(JSContextRef ctx, JSObjectRef arg, const char *name, gdouble value, JSValueRef *exc);
char * js_get_string_property(JSContextRef ctx, JSObjectRef arg, const char *name);
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");