Bug 1176929 - Disable Ctrl-K in GtkEntry unless custom key bindings are set on GTK3. r=karlt, a=lizzard
authorAndrew Comminos <acomminos@mozilla.com>
Thu, 24 Sep 2015 12:37:08 -0700
changeset 298103 f25b717ac20ab4635dbfbbebf7cb24501ccd10fd
parent 298102 b60e63d9a14b21dcba21f0b2a93015ad991e7196
child 298104 c54ea35177605946a46883ba8539f1a29bc02510
push id962
push userjlund@mozilla.com
push dateFri, 04 Dec 2015 23:28:54 +0000
treeherdermozilla-release@23a2d286e80f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskarlt, lizzard
bugs1176929
milestone43.0a2
Bug 1176929 - Disable Ctrl-K in GtkEntry unless custom key bindings are set on GTK3. r=karlt, a=lizzard
widget/gtk/NativeKeyBindings.cpp
widget/gtk/mozgtk/mozgtk.c
--- a/widget/gtk/NativeKeyBindings.cpp
+++ b/widget/gtk/NativeKeyBindings.cpp
@@ -60,19 +60,35 @@ static const Command sDeleteCommands[][2
   { CommandDoNothing, CommandDoNothing } // WHITESPACE
 };
 
 static void
 delete_from_cursor_cb(GtkWidget *w, GtkDeleteType del_type,
                       gint count, gpointer user_data)
 {
   g_signal_stop_emission_by_name(w, "delete_from_cursor");
-  gHandled = true;
+  bool forward = count > 0;
+
+#if (MOZ_WIDGET_GTK == 3)
+  // Ignore GTK's Ctrl-K keybinding introduced in GTK 3.14 and removed in
+  // 3.18 if the user has custom bindings set. See bug 1176929.
+  if (del_type == GTK_DELETE_PARAGRAPH_ENDS && forward && GTK_IS_ENTRY(w) &&
+      !gtk_check_version(3, 14, 1) && gtk_check_version(3, 17, 9)) {
+    GtkStyleContext* context = gtk_widget_get_style_context(w);
+    GtkStateFlags flags = gtk_widget_get_state_flags(w);
 
-  bool forward = count > 0;
+    GPtrArray* array;
+    gtk_style_context_get(context, flags, "gtk-key-bindings", &array, nullptr);
+    if (!array)
+      return;
+    g_ptr_array_unref(array);
+  }
+#endif
+
+  gHandled = true;
   if (uint32_t(del_type) >= ArrayLength(sDeleteCommands)) {
     // unsupported deletion type
     return;
   }
 
   if (del_type == GTK_DELETE_WORDS) {
     // This works like word_ends, except we first move the caret to the
     // beginning/end of the current word.
--- a/widget/gtk/mozgtk/mozgtk.c
+++ b/widget/gtk/mozgtk/mozgtk.c
@@ -534,30 +534,32 @@ STUB(gtk_render_frame_gap)
 STUB(gtk_render_handle)
 STUB(gtk_render_line)
 STUB(gtk_render_option)
 STUB(gtk_render_slider)
 STUB(gtk_scale_new)
 STUB(gtk_scrollbar_new)
 STUB(gtk_style_context_add_class)
 STUB(gtk_style_context_add_region)
+STUB(gtk_style_context_get)
 STUB(gtk_style_context_get_background_color)
 STUB(gtk_style_context_get_border)
 STUB(gtk_style_context_get_border_color)
 STUB(gtk_style_context_get_color)
 STUB(gtk_style_context_get_margin)
 STUB(gtk_style_context_get_padding)
 STUB(gtk_style_context_new)
 STUB(gtk_style_context_remove_region)
 STUB(gtk_style_context_restore)
 STUB(gtk_style_context_save)
 STUB(gtk_style_context_set_path)
 STUB(gtk_style_context_set_state)
 STUB(gtk_tree_view_column_get_button)
 STUB(gtk_widget_get_preferred_size)
+STUB(gtk_widget_get_state_flags)
 STUB(gtk_widget_get_style_context)
 STUB(gtk_widget_path_append_type)
 STUB(gtk_widget_path_free)
 STUB(gtk_widget_path_new)
 STUB(gtk_widget_set_visual)
 STUB(gtk_app_chooser_dialog_new_for_content_type)
 STUB(gtk_app_chooser_get_type)
 STUB(gtk_app_chooser_get_app_info)