[devhelp] Window: delegate ::button-press-event handling to DhWebView
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [devhelp] Window: delegate ::button-press-event handling to DhWebView
- Date: Tue, 15 May 2018 12:07:00 +0000 (UTC)
commit 927843979e586a7a675576a3880e55f03c49ad1b
Author: Sébastien Wilmet <swilmet gnome org>
Date: Tue May 15 14:02:17 2018 +0200
Window: delegate ::button-press-event handling to DhWebView
I've tried to fix the FIXME by handling ::button-press-event on the
whole GtkWindow, but it didn't work well, it was completely buggy, for
example it was necessary to do a double button click when the
GtkSearchEntry had the focus, a single button click didn't work. And
when the DhWebView had the focus the buttons didn't work at all.
Strange.
src/dh-web-view.c | 28 ++++++++++++++++++++++++++++
src/dh-window.c | 32 --------------------------------
2 files changed, 28 insertions(+), 32 deletions(-)
---
diff --git a/src/dh-web-view.c b/src/dh-web-view.c
index 4902da4..b6319a3 100644
--- a/src/dh-web-view.c
+++ b/src/dh-web-view.c
@@ -137,6 +137,33 @@ chain_up:
return GTK_WIDGET_CLASS (dh_web_view_parent_class)->scroll_event (widget, scroll_event);
}
+static gboolean
+dh_web_view_button_press_event (GtkWidget *widget,
+ GdkEventButton *event)
+{
+ WebKitWebView *view = WEBKIT_WEB_VIEW (widget);
+
+ switch (event->button) {
+ /* Some mice emit button presses when the scroll wheel is tilted
+ * to the side. Web browsers use them to navigate in history.
+ */
+ case 8:
+ webkit_web_view_go_back (view);
+ return GDK_EVENT_STOP;
+ case 9:
+ webkit_web_view_go_forward (view);
+ return GDK_EVENT_STOP;
+
+ default:
+ break;
+ }
+
+ if (GTK_WIDGET_CLASS (dh_web_view_parent_class)->button_press_event == NULL)
+ return GDK_EVENT_PROPAGATE;
+
+ return GTK_WIDGET_CLASS (dh_web_view_parent_class)->button_press_event (widget, event);
+}
+
static void
set_fonts (WebKitWebView *view,
const gchar *font_name_fixed,
@@ -245,6 +272,7 @@ dh_web_view_class_init (DhWebViewClass *klass)
object_class->finalize = dh_web_view_finalize;
widget_class->scroll_event = dh_web_view_scroll_event;
+ widget_class->button_press_event = dh_web_view_button_press_event;
}
static void
diff --git a/src/dh-window.c b/src/dh-window.c
index 47124d4..4dcd8bc 100644
--- a/src/dh-window.c
+++ b/src/dh-window.c
@@ -897,33 +897,6 @@ web_view_zoom_level_notify_cb (DhWebView *web_view,
update_zoom_actions_sensitivity (window);
}
-/* FIXME: connect to this signal on the whole DhWindow widget instead? And call
- * webkit_web_view_go_back/forward() on the active web view. Because when the
- * WebKitWebView doesn't have the focus, currently this callback is not called.
- */
-static gboolean
-web_view_button_press_event_cb (WebKitWebView *web_view,
- GdkEventButton *event,
- DhWindow *window)
-{
- switch (event->button) {
- /* Some mice emit button presses when the scroll wheel is tilted
- * to the side. Web browsers use them to navigate in history.
- */
- case 8:
- webkit_web_view_go_back (web_view);
- return GDK_EVENT_STOP;
- case 9:
- webkit_web_view_go_forward (web_view);
- return GDK_EVENT_STOP;
-
- default:
- break;
- }
-
- return GDK_EVENT_PROPAGATE;
-}
-
static gchar *
find_equivalent_local_uri (const gchar *uri)
{
@@ -1088,11 +1061,6 @@ open_new_tab (DhWindow *window,
window);
g_signal_connect (web_view,
- "button-press-event",
- G_CALLBACK (web_view_button_press_event_cb),
- window);
-
- g_signal_connect (web_view,
"decide-policy",
G_CALLBACK (web_view_decide_policy_cb),
window);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]