} Key;
typedef struct {
- unsigned int click;
+ unsigned int target;
unsigned int mask;
guint button;
- void (*func)(Client *c, const Arg *arg);
+ void (*func)(Client *c, const Arg *a, WebKitHitTestResult *h);
const Arg arg;
+ unsigned int stopevent;
} Button;
typedef struct {
WebKitNetworkResponse *resp, Client *c);
static char *buildfile(const char *path);
static char *buildpath(const char *path);
-static gboolean buttonrelease(WebKitWebView *web, GdkEventButton *e, Client *c);
+static gboolean buttonreleased(GtkWidget *w, GdkEventKey *e, Client *c);
static void cleanup(void);
static void clipboard(Client *c, const Arg *arg);
static void handleplumb(Client *c, WebKitWebView *w, const gchar *uri);
-static gboolean initdownload(WebKitWebView *v, WebKitDownload *o, Client *c);
+static void downloadstarted(WebKitWebContext *wc, WebKitDownload *d,
+ Client *c);
+static void responsereceived(WebKitDownload *d, GParamSpec *ps, Client *c);
+static void download(Client *c, WebKitURIResponse *r);
static void inspector(Client *c, const Arg *arg);
static WebKitWebView *inspector_new(WebKitWebInspector *i, WebKitWebView *v,
static void showview(WebKitWebView *v, Client *c);
static void newwindow(Client *c, const Arg *arg, gboolean noembed);
static void pasteuri(GtkClipboard *clipboard, const char *text, gpointer d);
-static gboolean contextmenu(WebKitWebView *view, GtkWidget *menu,
- WebKitHitTestResult *target, gboolean keyboard,
- Client *c);
-static void menuactivate(GtkMenuItem *item, Client *c);
static void print(Client *c, const Arg *arg);
static GdkFilterReturn processx(GdkXEvent *xevent, GdkEvent *event,
gpointer d);
}
gboolean
-buttonrelease(WebKitWebView *web, GdkEventButton *e, Client *c)
+buttonreleased(GtkWidget *w, GdkEventKey *e, Client *c)
{
- WebKitHitTestResultContext context;
- WebKitHitTestResult *result;
- Arg arg;
- unsigned int i;
-
- result = webkit_web_view_get_hit_test_result(web, e);
- g_object_get(result, "context", &context, NULL);
- g_object_get(result, "link-uri", &arg.v, NULL);
- for (i = 0; i < LENGTH(buttons); i++) {
- if (context & buttons[i].click
- && e->button == buttons[i].button
- && CLEANMASK(e->state) == CLEANMASK(buttons[i].mask)
- && buttons[i].func) {
- buttons[i].func(c, buttons[i].click == ClkLink
- && buttons[i].arg.i == 0 ? &arg : &buttons[i].arg);
- return true;
+ WebKitHitTestResultContext element;
+ GdkEventButton *eb = (GdkEventButton*)e;
+ int i;
+
+ element = webkit_hit_test_result_get_context(c->mousepos);
+
+ for (i = 0; i < LENGTH(buttons); ++i) {
+ if (element & buttons[i].target &&
+ eb->button == buttons[i].button &&
+ CLEANMASK(eb->state) == CLEANMASK(buttons[i].mask) &&
+ buttons[i].func) {
+ buttons[i].func(c, &buttons[i].arg, c->mousepos);
+ return buttons[i].stopevent;
}
}
- return false;
+
+ return FALSE;
}
void
spawn(c, &arg);
}
-gboolean
-initdownload(WebKitWebView *view, WebKitDownload *o, Client *c)
+void
+downloadstarted(WebKitWebContext *wc, WebKitDownload *d, Client *c)
{
- Arg arg;
+ g_signal_connect(G_OBJECT(d), "notify::response",
+ G_CALLBACK(responsereceived), c);
+}
- updatewinid(c);
- arg = (Arg)DOWNLOAD((char *)webkit_download_get_uri(o), geturi(c));
- spawn(c, &arg);
- return FALSE;
+void
+responsereceived(WebKitDownload *d, GParamSpec *ps, Client *c)
+{
+ download(c, webkit_download_get_response(d));
+ webkit_download_cancel(d);
+}
+
+void
+download(Client *c, WebKitURIResponse *r)
+{
+ Arg a;
+
+ a = (Arg)DOWNLOAD(webkit_uri_response_get_uri(r), geturi(c));
+ spawn(c, &a);
}
void
webkit_web_context_get_cookie_manager(context),
cookiepolicy_get());
+ g_signal_connect(G_OBJECT(context), "download-started",
+ G_CALLBACK(downloadstarted), c);
+
v = g_object_new(WEBKIT_TYPE_WEB_VIEW,
"settings", settings,
"user-content-manager", contentmanager,
g_signal_connect(G_OBJECT(v),
"notify::estimated-load-progress",
G_CALLBACK(progresschanged), c);
- g_signal_connect(G_OBJECT(v),
- "download-requested",
- G_CALLBACK(initdownload), c);
g_signal_connect(G_OBJECT(v),
"button-release-event",
- G_CALLBACK(buttonrelease), c);
- g_signal_connect(G_OBJECT(v),
- "context-menu",
- G_CALLBACK(contextmenu), c);
+ G_CALLBACK(buttonreleased), c);
g_signal_connect(G_OBJECT(v),
"resource-request-starting",
G_CALLBACK(beforerequest), c);
spawn(NULL, &a);
}
-gboolean
-contextmenu(WebKitWebView *view, GtkWidget *menu, WebKitHitTestResult *target,
- gboolean keyboard, Client *c)
-{
- GList *items = gtk_container_get_children(GTK_CONTAINER(GTK_MENU(menu)));
-
- for (GList *l = items; l; l = l->next)
- g_signal_connect(l->data, "activate", G_CALLBACK(menuactivate), c);
-
- g_list_free(items);
- return FALSE;
-}
-
-void
-menuactivate(GtkMenuItem *item, Client *c)
-{
- /*
- * context-menu-action-2000 open link
- * context-menu-action-1 open link in window
- * context-menu-action-2 download linked file
- * context-menu-action-3 copy link location
- * context-menu-action-7 copy image address
- * context-menu-action-13 reload
- * context-menu-action-10 back
- * context-menu-action-11 forward
- * context-menu-action-12 stop
- */
-
- const gchar *name, *uri;
- GtkClipboard *prisel, *clpbrd;
-
- name = gtk_actionable_get_action_name(GTK_ACTIONABLE(item));
- if (name == NULL)
- return;
-
- if (!g_strcmp0(name, "context-menu-action-3")) {
- prisel = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
- gtk_clipboard_set_text(prisel, c->linkhover, -1);
- } else if (!g_strcmp0(name, "context-menu-action-7")) {
- prisel = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
- clpbrd = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
- uri = gtk_clipboard_wait_for_text(clpbrd);
- if (uri)
- gtk_clipboard_set_text(prisel, uri, -1);
- }
-}
-
void
pasteuri(GtkClipboard *clipboard, const char *text, gpointer d)
{