[epiphany/gnome-3-36] Revert "Revert "Fix mouse back/forward gesture""



commit ad44d0f95309d77d8e38128d1f466fbc3ddf2243
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Thu Jul 2 13:44:24 2020 -0500

    Revert "Revert "Fix mouse back/forward gesture""
    
    This reverts commit 23e8b56411fafb3a298d00cc933085f7bbb237b8.

 src/ephy-action-bar-start.c           | 64 +++++++++++++++++++++++------------
 src/ephy-link.c                       |  2 +-
 src/resources/gtk/action-bar-start.ui |  2 --
 src/window-commands.c                 |  6 ----
 4 files changed, 43 insertions(+), 31 deletions(-)
---
diff --git a/src/ephy-action-bar-start.c b/src/ephy-action-bar-start.c
index eb0821e09..71642ea30 100644
--- a/src/ephy-action-bar-start.c
+++ b/src/ephy-action-bar-start.c
@@ -27,6 +27,7 @@
 #include "ephy-embed-prefs.h"
 #include "ephy-embed-utils.h"
 #include "ephy-favicon-helpers.h"
+#include "ephy-gui.h"
 #include "ephy-settings.h"
 #include "ephy-shell.h"
 #include "ephy-window.h"
@@ -307,13 +308,13 @@ navigation_button_press_event_cb (GtkButton *button,
 {
   EphyActionBarStart *action_bar_start = EPHY_ACTION_BAR_START (user_data);
   EphyNavigationHistoryDirection direction;
-  const gchar *action_name;
   PopupData *data;
+  gboolean is_back = FALSE;
 
-  action_name = gtk_actionable_get_action_name (GTK_ACTIONABLE (button));
+  is_back = (GTK_WIDGET (button) == action_bar_start->navigation_back);
 
-  direction = strstr (action_name, "back") ? EPHY_NAVIGATION_HISTORY_DIRECTION_BACK
-                                           : EPHY_NAVIGATION_HISTORY_DIRECTION_FORWARD;
+  direction = is_back ? EPHY_NAVIGATION_HISTORY_DIRECTION_BACK
+                      : EPHY_NAVIGATION_HISTORY_DIRECTION_FORWARD;
 
   switch (((GdkEventButton *)event)->button) {
     case GDK_BUTTON_SECONDARY:
@@ -354,30 +355,49 @@ navigation_button_release_event_cb (GtkButton *button,
   GActionGroup *action_group;
   GAction *action;
   EphyNavigationHistoryDirection direction;
-  const gchar *action_name;
+  gboolean is_back = FALSE;
+  gboolean open_in_new_tab = FALSE;
+  gboolean open_in_current_tab = FALSE;
+  GdkEventType type = GDK_NOTHING;
+  guint state = 0, button_val = (guint) - 1, keyval = (guint) - 1;
+
+  ephy_gui_get_current_event (&type, &state, &button_val, &keyval);
+  is_back = (GTK_WIDGET (button) == action_bar_start->navigation_back);
 
   g_clear_handle_id (&action_bar_start->navigation_buttons_menu_timeout, g_source_remove);
 
-  action_name = gtk_actionable_get_action_name (GTK_ACTIONABLE (button));
   action_group = gtk_widget_get_action_group (gtk_widget_get_ancestor (GTK_WIDGET (action_bar_start), 
EPHY_TYPE_WINDOW), "toolbar");
 
-  direction = strcmp (action_name, "toolbar.navigation-back") == 0 ? EPHY_NAVIGATION_HISTORY_DIRECTION_BACK
-                                                                   : 
EPHY_NAVIGATION_HISTORY_DIRECTION_FORWARD;
+  direction = is_back ? EPHY_NAVIGATION_HISTORY_DIRECTION_BACK
+                      : EPHY_NAVIGATION_HISTORY_DIRECTION_FORWARD;
 
-  switch (((GdkEventButton *)event)->button) {
-    case GDK_BUTTON_MIDDLE:
-      if (direction == EPHY_NAVIGATION_HISTORY_DIRECTION_BACK) {
-        action = g_action_map_lookup_action (G_ACTION_MAP (action_group),
-                                             "navigation-back-new-tab");
-        g_action_activate (action, NULL);
-      } else if (direction == EPHY_NAVIGATION_HISTORY_DIRECTION_FORWARD) {
-        action = g_action_map_lookup_action (G_ACTION_MAP (action_group),
-                                             "navigation-forward-new-tab");
-        g_action_activate (action, NULL);
-      }
-      return GDK_EVENT_STOP;
-    default:
-      break;
+  open_in_new_tab = (((GdkEventButton *)event)->button == GDK_BUTTON_MIDDLE) || (state == GDK_CONTROL_MASK);
+  open_in_current_tab = ((GdkEventButton *)event)->button == GDK_BUTTON_PRIMARY;
+
+  if (open_in_new_tab) {
+    if (direction == EPHY_NAVIGATION_HISTORY_DIRECTION_BACK) {
+      action = g_action_map_lookup_action (G_ACTION_MAP (action_group),
+                                           "navigation-back-new-tab");
+      g_action_activate (action, NULL);
+    } else if (direction == EPHY_NAVIGATION_HISTORY_DIRECTION_FORWARD) {
+      action = g_action_map_lookup_action (G_ACTION_MAP (action_group),
+                                           "navigation-forward-new-tab");
+      g_action_activate (action, NULL);
+    }
+    return GDK_EVENT_STOP;
+  }
+
+  if (open_in_current_tab) {
+    if (direction == EPHY_NAVIGATION_HISTORY_DIRECTION_BACK) {
+      action = g_action_map_lookup_action (G_ACTION_MAP (action_group),
+                                           "navigation-back");
+      g_action_activate (action, NULL);
+    } else if (direction == EPHY_NAVIGATION_HISTORY_DIRECTION_FORWARD) {
+      action = g_action_map_lookup_action (G_ACTION_MAP (action_group),
+                                           "navigation-forward");
+      g_action_activate (action, NULL);
+    }
+    return GDK_EVENT_STOP;
   }
 
   return GDK_EVENT_PROPAGATE;
diff --git a/src/ephy-link.c b/src/ephy-link.c
index 9f7191f5f..cc7f69386 100644
--- a/src/ephy-link.c
+++ b/src/ephy-link.c
@@ -103,7 +103,7 @@ ephy_link_flags_from_current_event (void)
 
   ephy_gui_get_current_event (&type, &state, &button, &keyval);
 
-  if (button == 2 && (type == GDK_BUTTON_PRESS || type == GDK_BUTTON_RELEASE)) {
+  if (button == GDK_BUTTON_MIDDLE && (type == GDK_BUTTON_PRESS || type == GDK_BUTTON_RELEASE)) {
     if (state == GDK_SHIFT_MASK) {
       flags = EPHY_LINK_NEW_WINDOW;
     } else if (state == 0 || state == GDK_CONTROL_MASK) {
diff --git a/src/resources/gtk/action-bar-start.ui b/src/resources/gtk/action-bar-start.ui
index 2c56ffa58..b42daa334 100644
--- a/src/resources/gtk/action-bar-start.ui
+++ b/src/resources/gtk/action-bar-start.ui
@@ -14,7 +14,6 @@
         <child>
           <object class="GtkButton" id="navigation_back">
             <property name="visible">True</property>
-            <property name="action-name">toolbar.navigation-back</property>
             <property name="valign">center</property>
             <!-- Translators: tooltip for the back button -->
             <property name="tooltip_text" translatable="yes">Go back to the previous page</property>
@@ -33,7 +32,6 @@
         <child>
           <object class="GtkButton" id="navigation_forward">
             <property name="visible">True</property>
-            <property name="action-name">toolbar.navigation-forward</property>
             <property name="valign">center</property>
             <!-- Translators: tooltip for the forward button -->
             <property name="tooltip_text" translatable="yes">Go forward to the next page</property>
diff --git a/src/window-commands.c b/src/window-commands.c
index 15abec58e..b89062744 100644
--- a/src/window-commands.c
+++ b/src/window-commands.c
@@ -723,12 +723,6 @@ window_cmd_navigation (GSimpleAction *action,
   EphyWindow *window = EPHY_WINDOW (user_data);
   EphyEmbed *embed;
   WebKitWebView *web_view;
-  EphyLinkFlags flags = ephy_link_flags_from_current_event ();
-
-  if (flags & EPHY_LINK_NEW_TAB) {
-    window_cmd_navigation_new_tab (action, parameter, user_data);
-    return;
-  }
 
   embed = ephy_embed_container_get_active_child (EPHY_EMBED_CONTAINER (window));
   g_assert (embed != NULL);


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