summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQuentin Rameau <quinq@fifth.space>2015-11-18 17:59:50 +0100
committerQuentin Rameau <quinq@fifth.space>2015-11-20 00:34:20 +0100
commit42c6c90366b7ce7708b13037a6ba819b08fbb20e (patch)
treefcb362db9ae191a9107b064c519313977d43dd18
parentb9530ad5d1cd29e176c9f16b92f1983993b22049 (diff)
downloadsurf-42c6c90366b7ce7708b13037a6ba819b08fbb20e.tar.gz
surf-42c6c90366b7ce7708b13037a6ba819b08fbb20e.tar.bz2
surf-42c6c90366b7ce7708b13037a6ba819b08fbb20e.zip
Replace linkhover() with mousetargetchanged()
The “linkhover” can now be more than a simple link (image, video, etc.). As we can't anymore perform a hit test when we want, we have to keep the last known hit test to be able to know where the mouse is on the next click event.
-rw-r--r--surf.c35
1 files changed, 23 insertions, 12 deletions
diff --git a/surf.c b/surf.c
index 22a3e8a..af994bb 100644
--- a/surf.c
+++ b/surf.c
@@ -59,7 +59,8 @@ typedef struct Client {
Window xid;
WebKitWebView *view;
WebKitWebInspector *inspector;
- const char *title, *linkhover;
+ WebKitHitTestResult *mousepos;
+ const char *title, *targeturi;
const char *needle;
gint progress;
struct Client *next;
@@ -151,8 +152,8 @@ static void inspector_finished(WebKitWebInspector *i, Client *c);
static gboolean keypress(GtkAccelGroup *group, GObject *obj, guint key,
GdkModifierType mods, Client *c);
-static void linkhover(WebKitWebView *v, const char* t, const char* l,
- Client *c);
+static void mousetargetchanged(WebKitWebView *v, WebKitHitTestResult *h,
+ guint modifiers, Client *c);
static void loadstatuschange(WebKitWebView *view, GParamSpec *pspec,
Client *c);
static void loaduri(Client *c, const Arg *arg);
@@ -691,14 +692,24 @@ keypress(GtkAccelGroup *group, GObject *obj, guint key, GdkModifierType mods,
}
void
-linkhover(WebKitWebView *v, const char* t, const char* l, Client *c)
+mousetargetchanged(WebKitWebView *v, WebKitHitTestResult *h, guint modifiers,
+ Client *c)
{
- if (l) {
- c->linkhover = copystr(&c->linkhover, l);
- } else if (c->linkhover) {
- free(c->linkhover);
- c->linkhover = NULL;
- }
+ WebKitHitTestResultContext hc;
+
+ /* Keep the hit test to know where is the pointer on the next click */
+ c->mousepos = h;
+
+ hc = webkit_hit_test_result_get_context(h);
+
+ if (hc & OnLink)
+ c->targeturi = webkit_hit_test_result_get_link_uri(h);
+ else if (hc & OnImg)
+ c->targeturi = webkit_hit_test_result_get_image_uri(h);
+ else if (hc & OnMedia)
+ c->targeturi = webkit_hit_test_result_get_media_uri(h);
+ else
+ c->targeturi = NULL;
updatetitle(c);
}
@@ -869,8 +880,8 @@ newview(Client *c, WebKitWebView *rv)
"notify::title",
G_CALLBACK(titlechanged), c);
g_signal_connect(G_OBJECT(v),
- "hovering-over-link",
- G_CALLBACK(linkhover), c);
+ "mouse-target-changed",
+ G_CALLBACK(mousetargetchanged), c);
g_signal_connect(G_OBJECT(v),
"geolocation-policy-decision-requested",
G_CALLBACK(geopolicyrequested), c);