summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/dwb.c3
-rw-r--r--src/js.c6
-rw-r--r--src/js.h1
-rw-r--r--src/scratchpad.c64
-rw-r--r--src/scratchpad.h28
-rw-r--r--src/scripts.c80
6 files changed, 169 insertions, 13 deletions
diff --git a/src/dwb.c b/src/dwb.c
index b8ef725e..1c63cff5 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 548d1f13..789471a4 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 07a4cf58..a46ade58 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/scratchpad.c b/src/scratchpad.c
new file mode 100644
index 00000000..4ae25848
--- /dev/null
+++ b/src/scratchpad.c
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2010-2012 Stefan Bolte <portix@gmx.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "dwb.h"
+
+GtkWidget *g_scratchpad;
+static gboolean
+navigation_cb(WebKitWebView *wv, WebKitWebFrame *frame, WebKitNetworkRequest *request,
+ WebKitWebNavigationAction *action, WebKitWebPolicyDecision *decision) {
+ const char *uri = webkit_network_request_get_uri(request);
+ if (g_strcmp0("scratchpad", uri) && ! g_str_has_prefix(uri, "file://")) {
+ webkit_web_policy_decision_ignore(decision);
+ return true;
+ }
+ return false;
+}
+
+void
+scratchpad_load(const char *text) {
+ if (g_str_has_prefix(text, "file://"))
+ webkit_web_view_load_uri(WEBKIT_WEB_VIEW(g_scratchpad), text);
+ else
+ webkit_web_view_load_string(WEBKIT_WEB_VIEW(g_scratchpad), text, NULL, NULL, "scratchpad");
+}
+
+void
+scratchpad_show(void) {
+ gtk_widget_show(g_scratchpad);
+ gtk_widget_grab_focus(g_scratchpad);
+}
+void
+scratchpad_hide(void) {
+ gtk_widget_hide(g_scratchpad);
+ dwb_focus_scroll(dwb.state.fview);
+}
+static void
+scratchpad_init(void) {
+ g_scratchpad = webkit_web_view_new();
+ g_signal_connect(g_scratchpad, "navigation-policy-decision-requested", G_CALLBACK(navigation_cb), NULL);
+ gtk_widget_set_size_request(g_scratchpad, -1, 200);
+}
+GtkWidget *
+scratchpad_get(void) {
+ if (g_scratchpad == NULL)
+ scratchpad_init();
+ return g_scratchpad;
+}
+
+
diff --git a/src/scratchpad.h b/src/scratchpad.h
new file mode 100644
index 00000000..8e1da0cb
--- /dev/null
+++ b/src/scratchpad.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2010-2012 Stefan Bolte <portix@gmx.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef SCRATCHPAD_H
+#define SCRATCHPAD_H
+
+GtkWidget * scratchpad_init(void);
+void scratchpad_show(void);
+void scratchpad_hide(void);
+void scratchpad_load(const char *);
+GtkWidget * scratchpad_get(void);
+
+#endif
diff --git a/src/scripts.c b/src/scripts.c
index 8851701b..1d8c6f6f 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,9 @@ 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 sp_load(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[] = {
@@ -475,6 +479,29 @@ 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);
+}
+static JSValueRef
+sp_load(JSContextRef ctx, JSObjectRef function, JSObjectRef this, size_t argc, const JSValueRef argv[], JSValueRef* exc) {
+ char *text;
+ if (argc > 0 && (text = js_value_to_char(ctx, argv[0], -1, exc)) != NULL) {
+ scratchpad_load(text);
+ g_free(text);
+ }
+ return JSValueMakeUndefined(ctx);
+
+}
+
+
+
/* SOUP_MESSAGE {{{*/
/* soup_uri_to_js_object {{{*/
JSObjectRef
@@ -1465,14 +1492,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;
@@ -1484,11 +1521,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
@@ -1553,9 +1587,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;
}/*}}}*/
@@ -1590,7 +1622,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;
@@ -1811,7 +1855,19 @@ create_global_object() {
cd.parentClass = m_default_class;
m_download_class = JSClassCreate(&cd);
-
+ JSStaticFunction scratchpad_functions[] = {
+ { "show", sp_show, kJSDefaultAttributes },
+ { "hide", sp_hide, kJSDefaultAttributes },
+ { "load", sp_load, 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");