[epiphany/gnome-3-20] window: add blacklist of events to not deliver to web view



commit ac8179e7adde8c58be0e3d8b05ccb65a20b1cd13
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Wed Nov 16 15:11:42 2016 -0600

    window: add blacklist of events to not deliver to web view
    
    Certain window and tab management shortcuts are reserved by Epiphany and
    will never be delivered to the webpage, even though webpages should in
    general be allowed to override Epiphany shortcuts (e.g. Ctrl+B in Google
    Docs should embolden text and not open the old bookmarks dialog, Ctrl+I
    should italicize text and not open a new incognito window).
    
    https://bugzilla.gnome.org/show_bug.cgi?id=764653

 src/ephy-window.c |   38 +++++++++++++++++++++++++++++++++-----
 1 files changed, 33 insertions(+), 5 deletions(-)
---
diff --git a/src/ephy-window.c b/src/ephy-window.c
index 0fb186d..069b22c 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -791,6 +791,30 @@ ephy_window_bound_accels (GtkWidget   *widget,
 }
 
 static gboolean
+should_web_view_receive_key_press_event (GdkEventKey *event)
+{
+  if (event->state == GDK_CONTROL_MASK)
+    return event->keyval != GDK_KEY_n &&
+           event->keyval != GDK_KEY_q &&
+           event->keyval != GDK_KEY_t &&
+           event->keyval != GDK_KEY_w &&
+           event->keyval != GDK_KEY_Page_Up &&
+           event->keyval != GDK_KEY_KP_9 &&
+           event->keyval != GDK_KEY_Page_Down &&
+           event->keyval != GDK_KEY_KP_3;
+
+  if (event->state == (GDK_SHIFT_MASK | GDK_CONTROL_MASK))
+    return event->keyval != GDK_KEY_N &&
+           event->keyval != GDK_KEY_T &&
+           event->keyval != GDK_KEY_Page_Up &&
+           event->keyval != GDK_KEY_KP_9 &&
+           event->keyval != GDK_KEY_Page_Down &&
+           event->keyval != GDK_KEY_KP_3;
+
+  return TRUE;
+}
+
+static gboolean
 ephy_window_key_press_event (GtkWidget   *widget,
                              GdkEventKey *event)
 {
@@ -808,13 +832,17 @@ ephy_window_key_press_event (GtkWidget   *widget,
    * because we want to give webpages the chance to override most
    * Epiphany shortcuts. For example, Ctrl+I in Google Docs should
    * italicize your text and not open a new incognito window. So:
-   * first propagate the event to the web view. Next, try
-   * accelerators only if the web view did not handle the event.
+   * first, propagate the event to the web view. Next, try
+   * accelerators only if the web view did not handle the event. But
+   * short-circuit the event propagation if it's a special keybinding
+   * that is reserved for Epiphany not allowed to be seen by webpages.
    */
-  if (!gtk_window_propagate_key_event (GTK_WINDOW (widget), event)) {
-    if (!gtk_window_activate_key (GTK_WINDOW (widget), event))
-      ephy_window_bound_accels (widget, event);
+  if (!should_web_view_receive_key_press_event (event) ||
+      !gtk_window_propagate_key_event (GTK_WINDOW (widget), event)) {
+    if (!ephy_window_bound_accels (widget, event))
+      gtk_window_activate_key (GTK_WINDOW (widget), event);
   }
+
   return GDK_EVENT_STOP;
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]