[gtk/wip/matthiasc/can-focus: 17/17] Reinstate expected focus behavior



commit 7b5db526d37bc7b304e40d3a353718d354f0900c
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Apr 8 07:43:28 2020 -0400

    Reinstate expected focus behavior
    
    After the :can-focus change in the previous commit, widgets
    need to set suitable focus and grab_focus implementations
    to implement the desired focus behavior.
    
    This commit does that for all widgets.

 gtk/gtkaccellabel.c         |  3 +++
 gtk/gtkappchooserbutton.c   |  3 +++
 gtk/gtkappchooserwidget.c   |  4 +++-
 gtk/gtkbuiltinicon.c        |  2 ++
 gtk/gtkbutton.c             |  3 +++
 gtk/gtkcalendar.c           |  3 +++
 gtk/gtkcenterbox.c          |  3 +++
 gtk/gtkcolorbutton.c        |  4 ++++
 gtk/gtkcolorchooserwidget.c |  4 ++++
 gtk/gtkcolorswatch.c        |  2 ++
 gtk/gtkcombobox.c           |  1 +
 gtk/gtkcontainer.c          |  2 ++
 gtk/gtkdragicon.c           |  2 ++
 gtk/gtkdrawingarea.c        |  2 ++
 gtk/gtkentry.c              |  1 +
 gtk/gtkexpander.c           | 11 ++++++-----
 gtk/gtkfilechooserbutton.c  |  3 +++
 gtk/gtkfilechooserwidget.c  |  2 ++
 gtk/gtkfontbutton.c         |  4 ++++
 gtk/gtkfontchooserwidget.c  |  4 +++-
 gtk/gtkglarea.c             |  3 +++
 gtk/gtkiconview.c           |  2 ++
 gtk/gtkimage.c              |  2 ++
 gtk/gtklevelbar.c           |  2 ++
 gtk/gtklistbox.c            |  4 ++--
 gtk/gtkmediacontrols.c      |  3 +++
 gtk/gtkmenubutton.c         | 11 ++++++++++-
 gtk/gtknotebook.c           | 13 +++++++++++++
 gtk/gtkpasswordentry.c      | 14 ++++----------
 gtk/gtkpicture.c            |  2 ++
 gtk/gtkprogressbar.c        |  2 ++
 gtk/gtkscale.c              |  3 +++
 gtk/gtkscrollbar.c          |  4 ++++
 gtk/gtkscrolledwindow.c     |  1 +
 gtk/gtkseparator.c          |  4 ++++
 gtk/gtkshortcutlabel.c      |  4 ++++
 gtk/gtkshortcutsshortcut.c  |  3 +++
 gtk/gtkspinbutton.c         |  1 +
 gtk/gtkspinner.c            |  2 ++
 gtk/gtkstacksidebar.c       |  4 ++++
 gtk/gtkstackswitcher.c      |  3 +++
 gtk/gtkstatusbar.c          |  3 +++
 gtk/gtkswitch.c             |  3 +++
 gtk/gtktextview.c           | 38 ++------------------------------------
 gtk/gtktreeview.c           |  5 +----
 gtk/gtkvideo.c              |  3 +++
 46 files changed, 142 insertions(+), 60 deletions(-)
---
diff --git a/gtk/gtkaccellabel.c b/gtk/gtkaccellabel.c
index 7b83dbad5b..78b40ef887 100644
--- a/gtk/gtkaccellabel.c
+++ b/gtk/gtkaccellabel.c
@@ -128,6 +128,9 @@ gtk_accel_label_class_init (GtkAccelLabelClass *class)
   gobject_class->set_property = gtk_accel_label_set_property;
   gobject_class->get_property = gtk_accel_label_get_property;
 
+  widget_class->focus = gtk_widget_focus_none;
+  widget_class->grab_focus = gtk_widget_grab_focus_none;
+
   gtk_widget_class_set_accessible_role (widget_class, ATK_ROLE_ACCEL_LABEL);
 
   props[PROP_LABEL] =
diff --git a/gtk/gtkappchooserbutton.c b/gtk/gtkappchooserbutton.c
index 4c8dc45ee4..0580b5a333 100644
--- a/gtk/gtkappchooserbutton.c
+++ b/gtk/gtkappchooserbutton.c
@@ -57,6 +57,7 @@
 #include "gtkcellrendererpixbuf.h"
 #include "gtkcellrenderertext.h"
 #include "gtkcombobox.h"
+#include "gtkwidgetprivate.h"
 #include "gtkdialog.h"
 #include "gtkintl.h"
 #include "gtkmarshalers.h"
@@ -667,6 +668,8 @@ gtk_app_chooser_button_class_init (GtkAppChooserButtonClass *klass)
 
   widget_class->measure = gtk_app_chooser_button_measure;
   widget_class->size_allocate = gtk_app_chooser_button_size_allocate;
+  widget_class->grab_focus = gtk_widget_grab_focus_child;
+  widget_class->focus = gtk_widget_focus_child;
 
   g_object_class_override_property (oclass, PROP_CONTENT_TYPE, "content-type");
 
diff --git a/gtk/gtkappchooserwidget.c b/gtk/gtkappchooserwidget.c
index bc1c0ffe17..91e22c7c49 100644
--- a/gtk/gtkappchooserwidget.c
+++ b/gtk/gtkappchooserwidget.c
@@ -38,6 +38,7 @@
 #include "gtkscrolledwindow.h"
 #include "gtklabel.h"
 #include "gtkgestureclick.h"
+#include "gtkwidgetprivate.h"
 
 #include <string.h>
 #include <glib/gi18n-lib.h>
@@ -913,7 +914,8 @@ gtk_app_chooser_widget_class_init (GtkAppChooserWidgetClass *klass)
   widget_class->measure = gtk_app_chooser_widget_measure;
   widget_class->size_allocate = gtk_app_chooser_widget_size_allocate;
   widget_class->snapshot = gtk_app_chooser_widget_snapshot;
-
+  widget_class->grab_focus = gtk_widget_grab_focus_child;
+  widget_class->focus = gtk_widget_focus_child;
 
   g_object_class_override_property (gobject_class, PROP_CONTENT_TYPE, "content-type");
 
diff --git a/gtk/gtkbuiltinicon.c b/gtk/gtkbuiltinicon.c
index b91864db44..53b0318239 100644
--- a/gtk/gtkbuiltinicon.c
+++ b/gtk/gtkbuiltinicon.c
@@ -95,6 +95,8 @@ gtk_builtin_icon_class_init (GtkBuiltinIconClass *klass)
   wclass->snapshot = gtk_builtin_icon_snapshot;
   wclass->measure = gtk_builtin_icon_measure;
   wclass->css_changed = gtk_builtin_icon_css_changed;
+  wclass->grab_focus = gtk_widget_grab_focus_none;
+  wclass->focus = gtk_widget_focus_none;
 }
 
 static void
diff --git a/gtk/gtkbutton.c b/gtk/gtkbutton.c
index 52165f8317..7276d2c24d 100644
--- a/gtk/gtkbutton.c
+++ b/gtk/gtkbutton.c
@@ -68,6 +68,7 @@
 #include "gtkprivate.h"
 #include "gtkstylecontext.h"
 #include "gtktypebuiltins.h"
+#include "gtkwidgetprivate.h"
 
 #include "a11y/gtkbuttonaccessible.h"
 
@@ -204,6 +205,8 @@ gtk_button_class_init (GtkButtonClass *klass)
   widget_class->state_flags_changed = gtk_button_state_flags_changed;
   widget_class->grab_notify = gtk_button_grab_notify;
   widget_class->unmap = gtk_button_unmap;
+  widget_class->grab_focus = gtk_widget_grab_focus_self;
+  widget_class->focus = gtk_widget_focus_self;
 
   container_class->add    = gtk_button_add;
   container_class->remove = gtk_button_remove;
diff --git a/gtk/gtkcalendar.c b/gtk/gtkcalendar.c
index f38d8ac91e..1f29f68c00 100644
--- a/gtk/gtkcalendar.c
+++ b/gtk/gtkcalendar.c
@@ -365,6 +365,9 @@ gtk_calendar_class_init (GtkCalendarClass *class)
   gobject_class->set_property = gtk_calendar_set_property;
   gobject_class->get_property = gtk_calendar_get_property;
 
+  widget_class->focus = gtk_widget_focus_all;
+  widget_class->grab_focus = gtk_widget_grab_focus_self;
+
   /**
    * GtkCalendar:year:
    *
diff --git a/gtk/gtkcenterbox.c b/gtk/gtkcenterbox.c
index 8bd0a7fda0..01885bb3c7 100644
--- a/gtk/gtkcenterbox.c
+++ b/gtk/gtkcenterbox.c
@@ -199,6 +199,9 @@ gtk_center_box_class_init (GtkCenterBoxClass *klass)
   object_class->get_property = gtk_center_box_get_property;
   object_class->dispose = gtk_center_box_dispose;
 
+  widget_class->grab_focus = gtk_widget_grab_focus_child;
+  widget_class->focus = gtk_widget_focus_child;
+
   g_object_class_override_property (object_class, PROP_ORIENTATION, "orientation");
 
   g_object_class_install_property (object_class, PROP_BASELINE_POSITION,
diff --git a/gtk/gtkcolorbutton.c b/gtk/gtkcolorbutton.c
index 76048eb185..9e06f87e76 100644
--- a/gtk/gtkcolorbutton.c
+++ b/gtk/gtkcolorbutton.c
@@ -44,6 +44,7 @@
 #include "gtkprivate.h"
 #include "gtksnapshot.h"
 #include "gtkstylecontext.h"
+#include "gtkwidgetprivate.h"
 
 
 /**
@@ -143,6 +144,9 @@ gtk_color_button_class_init (GtkColorButtonClass *klass)
   gobject_class->set_property = gtk_color_button_set_property;
   gobject_class->finalize = gtk_color_button_finalize;
 
+  widget_class->grab_focus = gtk_widget_grab_focus_child;
+  widget_class->focus = gtk_widget_focus_child;
+
   klass->color_set = NULL;
 
   /**
diff --git a/gtk/gtkcolorchooserwidget.c b/gtk/gtkcolorchooserwidget.c
index 0455d07457..a6b3c5cc53 100644
--- a/gtk/gtkcolorchooserwidget.c
+++ b/gtk/gtkcolorchooserwidget.c
@@ -30,6 +30,7 @@
 #include "gtksizegroup.h"
 #include "gtkstylecontext.h"
 #include "gtkboxlayout.h"
+#include "gtkwidgetprivate.h"
 
 #include "a11y/gtkcompositeaccessible.h"
 
@@ -709,6 +710,9 @@ gtk_color_chooser_widget_class_init (GtkColorChooserWidgetClass *class)
   object_class->set_property = gtk_color_chooser_widget_set_property;
   object_class->finalize = gtk_color_chooser_widget_finalize;
 
+  widget_class->grab_focus = gtk_widget_grab_focus_child;
+  widget_class->focus = gtk_widget_focus_child;
+
   g_object_class_override_property (object_class, PROP_RGBA, "rgba");
   g_object_class_override_property (object_class, PROP_USE_ALPHA, "use-alpha");
 
diff --git a/gtk/gtkcolorswatch.c b/gtk/gtkcolorswatch.c
index f68003cc69..72d66192cc 100644
--- a/gtk/gtkcolorswatch.c
+++ b/gtk/gtkcolorswatch.c
@@ -481,6 +481,8 @@ gtk_color_swatch_class_init (GtkColorSwatchClass *class)
   widget_class->snapshot = swatch_snapshot;
   widget_class->size_allocate = swatch_size_allocate;
   widget_class->state_flags_changed = swatch_state_flags_changed;
+  widget_class->grab_focus = gtk_widget_grab_focus_self;
+  widget_class->focus = gtk_widget_focus_self;
 
   g_object_class_install_property (object_class, PROP_RGBA,
       g_param_spec_boxed ("rgba", P_("RGBA Color"), P_("Color as RGBA"),
diff --git a/gtk/gtkcombobox.c b/gtk/gtkcombobox.c
index 47e3f0cd5b..755d017178 100644
--- a/gtk/gtkcombobox.c
+++ b/gtk/gtkcombobox.c
@@ -420,6 +420,7 @@ gtk_combo_box_class_init (GtkComboBoxClass *klass)
   widget_class->size_allocate = gtk_combo_box_size_allocate;
   widget_class->mnemonic_activate = gtk_combo_box_mnemonic_activate;
   widget_class->grab_focus = gtk_combo_box_grab_focus;
+  widget_class->focus = gtk_widget_focus_child;
   widget_class->measure = gtk_combo_box_measure;
   widget_class->unmap = gtk_combo_box_unmap;
   widget_class->destroy = gtk_combo_box_destroy;
diff --git a/gtk/gtkcontainer.c b/gtk/gtkcontainer.c
index 7d74e4f069..1b8953cbbc 100644
--- a/gtk/gtkcontainer.c
+++ b/gtk/gtkcontainer.c
@@ -140,6 +140,8 @@ gtk_container_class_init (GtkContainerClass *class)
   widget_class->destroy = gtk_container_destroy;
   widget_class->compute_expand = gtk_container_compute_expand;
   widget_class->get_request_mode = gtk_container_get_request_mode;
+  widget_class->grab_focus = gtk_widget_grab_focus_child;
+  widget_class->focus = gtk_widget_focus_child;
 
   class->add = gtk_container_add_unimplemented;
   class->remove = gtk_container_remove_unimplemented;
diff --git a/gtk/gtkdragicon.c b/gtk/gtkdragicon.c
index bc13f75a93..a431716e5b 100644
--- a/gtk/gtkdragicon.c
+++ b/gtk/gtkdragicon.c
@@ -361,6 +361,8 @@ gtk_drag_icon_class_init (GtkDragIconClass *klass)
   widget_class->size_allocate = gtk_drag_icon_size_allocate;
   widget_class->show = gtk_drag_icon_show;
   widget_class->hide = gtk_drag_icon_hide;
+  widget_class->focus = gtk_widget_focus_none;
+  widget_class->grab_focus = gtk_widget_grab_focus_none;
 
   /**
    * GtkDragIcon:child:
diff --git a/gtk/gtkdrawingarea.c b/gtk/gtkdrawingarea.c
index f611bf39f4..2dbbe6a7af 100644
--- a/gtk/gtkdrawingarea.c
+++ b/gtk/gtkdrawingarea.c
@@ -262,6 +262,8 @@ gtk_drawing_area_class_init (GtkDrawingAreaClass *class)
 
   widget_class->measure = gtk_drawing_area_measure;
   widget_class->snapshot = gtk_drawing_area_snapshot;
+  widget_class->focus = gtk_widget_focus_none;
+  widget_class->grab_focus = gtk_widget_grab_focus_none;
 
   /**
    * GtkDrawingArea:content-width
diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c
index 5e95bd6fc3..ac523bf408 100644
--- a/gtk/gtkentry.c
+++ b/gtk/gtkentry.c
@@ -437,6 +437,7 @@ gtk_entry_class_init (GtkEntryClass *class)
   widget_class->query_tooltip = gtk_entry_query_tooltip;
   widget_class->direction_changed = gtk_entry_direction_changed;
   widget_class->grab_focus = gtk_entry_grab_focus;
+  widget_class->focus = gtk_widget_focus_child;
   widget_class->mnemonic_activate = gtk_entry_mnemonic_activate;
   
   quark_entry_completion = g_quark_from_static_string ("gtk-entry-completion-key");
diff --git a/gtk/gtkexpander.c b/gtk/gtkexpander.c
index 91f73aa654..74b393a3f9 100644
--- a/gtk/gtkexpander.c
+++ b/gtk/gtkexpander.c
@@ -300,12 +300,13 @@ gtk_expander_class_init (GtkExpanderClass *klass)
   gobject_class->set_property = gtk_expander_set_property;
   gobject_class->get_property = gtk_expander_get_property;
 
-  widget_class->destroy              = gtk_expander_destroy;
-  widget_class->size_allocate        = gtk_expander_size_allocate;
-  widget_class->focus                = gtk_expander_focus;
-  widget_class->measure              = gtk_expander_measure;
+  widget_class->destroy = gtk_expander_destroy;
+  widget_class->size_allocate = gtk_expander_size_allocate;
+  widget_class->focus = gtk_expander_focus;
+  widget_class->grab_focus = gtk_widget_grab_focus_self;
+  widget_class->measure = gtk_expander_measure;
 
-  container_class->add    = gtk_expander_add;
+  container_class->add = gtk_expander_add;
   container_class->remove = gtk_expander_remove;
   container_class->forall = gtk_expander_forall;
 
diff --git a/gtk/gtkfilechooserbutton.c b/gtk/gtkfilechooserbutton.c
index ce15326723..e0064fc9f3 100644
--- a/gtk/gtkfilechooserbutton.c
+++ b/gtk/gtkfilechooserbutton.c
@@ -61,6 +61,7 @@
 #include "gtkstylecontextprivate.h"
 #include "gtkbitmaskprivate.h"
 #include "gtkeventcontroller.h"
+#include "gtkwidgetprivate.h"
 
 /**
  * SECTION:gtkfilechooserbutton
@@ -476,6 +477,8 @@ gtk_file_chooser_button_class_init (GtkFileChooserButtonClass * class)
   widget_class->root = gtk_file_chooser_button_root;
   widget_class->mnemonic_activate = gtk_file_chooser_button_mnemonic_activate;
   widget_class->state_flags_changed = gtk_file_chooser_button_state_flags_changed;
+  widget_class->grab_focus = gtk_widget_grab_focus_child;
+  widget_class->focus = gtk_widget_focus_child;
 
   /**
    * GtkFileChooserButton::file-set:
diff --git a/gtk/gtkfilechooserwidget.c b/gtk/gtkfilechooserwidget.c
index 689c8e9eb1..53e7409c4e 100644
--- a/gtk/gtkfilechooserwidget.c
+++ b/gtk/gtkfilechooserwidget.c
@@ -7222,6 +7222,8 @@ gtk_file_chooser_widget_class_init (GtkFileChooserWidgetClass *class)
   widget_class->unroot = gtk_file_chooser_widget_unroot;
   widget_class->css_changed = gtk_file_chooser_widget_css_changed;
   widget_class->size_allocate = gtk_file_chooser_widget_size_allocate;
+  widget_class->grab_focus = gtk_widget_grab_focus_child;
+  widget_class->focus = gtk_widget_focus_child;
 
   /*
    * Signals
diff --git a/gtk/gtkfontbutton.c b/gtk/gtkfontbutton.c
index 1e5cf9889e..1cad2f6c59 100644
--- a/gtk/gtkfontbutton.c
+++ b/gtk/gtkfontbutton.c
@@ -41,6 +41,7 @@
 #include "gtkprivate.h"
 #include "gtkseparator.h"
 #include "gtkstylecontext.h"
+#include "gtkwidgetprivate.h"
 
 #include <string.h>
 #include <stdio.h>
@@ -483,6 +484,9 @@ gtk_font_button_class_init (GtkFontButtonClass *klass)
   gobject_class->set_property = gtk_font_button_set_property;
   gobject_class->get_property = gtk_font_button_get_property;
 
+  widget_class->grab_focus = gtk_widget_grab_focus_child;
+  widget_class->focus = gtk_widget_focus_child;
+
   klass->font_set = NULL;
 
   _gtk_font_chooser_install_properties (gobject_class);
diff --git a/gtk/gtkfontchooserwidget.c b/gtk/gtkfontchooserwidget.c
index be77f9bf5d..a492410331 100644
--- a/gtk/gtkfontchooserwidget.c
+++ b/gtk/gtkfontchooserwidget.c
@@ -49,7 +49,7 @@
 #include "gtktextview.h"
 #include "gtktreeselection.h"
 #include "gtktreeview.h"
-#include "gtkwidget.h"
+#include "gtkwidgetprivate.h"
 #include "gtksettings.h"
 #include "gtkdialog.h"
 #include "gtkradiobutton.h"
@@ -737,6 +737,8 @@ gtk_font_chooser_widget_class_init (GtkFontChooserWidgetClass *klass)
   widget_class->unroot = gtk_font_chooser_widget_unroot;
   widget_class->map = gtk_font_chooser_widget_map;
   widget_class->unmap = gtk_font_chooser_widget_unmap;
+  widget_class->focus = gtk_widget_focus_child;
+  widget_class->grab_focus = gtk_widget_grab_focus_child;
 
   gobject_class->finalize = gtk_font_chooser_widget_finalize;
   gobject_class->dispose = gtk_font_chooser_widget_dispose;
diff --git a/gtk/gtkglarea.c b/gtk/gtkglarea.c
index 5ee6eb4d0b..6d8ac8f342 100644
--- a/gtk/gtkglarea.c
+++ b/gtk/gtkglarea.c
@@ -30,6 +30,7 @@
 #include "gtkrender.h"
 #include "gtksnapshot.h"
 #include "gtknative.h"
+#include "gtkwidgetprivate.h"
 
 #include <epoxy/gl.h>
 
@@ -782,6 +783,8 @@ gtk_gl_area_class_init (GtkGLAreaClass *klass)
   widget_class->unrealize = gtk_gl_area_unrealize;
   widget_class->size_allocate = gtk_gl_area_size_allocate;
   widget_class->snapshot = gtk_gl_area_snapshot;
+  widget_class->focus = gtk_widget_focus_none;
+  widget_class->grab_focus = gtk_widget_grab_focus_none;
 
   gtk_widget_class_set_accessible_role (widget_class, ATK_ROLE_DRAWING_AREA);
 
diff --git a/gtk/gtkiconview.c b/gtk/gtkiconview.c
index 508a016c19..163b97b8bf 100644
--- a/gtk/gtkiconview.c
+++ b/gtk/gtkiconview.c
@@ -350,6 +350,8 @@ gtk_icon_view_class_init (GtkIconViewClass *klass)
   widget_class->measure = gtk_icon_view_measure;
   widget_class->size_allocate = gtk_icon_view_size_allocate;
   widget_class->snapshot = gtk_icon_view_snapshot;
+  widget_class->focus = gtk_widget_focus_self;
+  widget_class->grab_focus = gtk_widget_grab_focus_self;
 
   container_class->remove = gtk_icon_view_remove;
   container_class->forall = gtk_icon_view_forall;
diff --git a/gtk/gtkimage.c b/gtk/gtkimage.c
index da98ccc698..c4ee1642cb 100644
--- a/gtk/gtkimage.c
+++ b/gtk/gtkimage.c
@@ -157,6 +157,8 @@ gtk_image_class_init (GtkImageClass *class)
   widget_class->measure = gtk_image_measure;
   widget_class->unrealize = gtk_image_unrealize;
   widget_class->css_changed = gtk_image_css_changed;
+  widget_class->grab_focus = gtk_widget_grab_focus_none;
+  widget_class->focus = gtk_widget_focus_none;
 
   image_props[PROP_PAINTABLE] =
       g_param_spec_object ("paintable",
diff --git a/gtk/gtklevelbar.c b/gtk/gtklevelbar.c
index d00a03f1f3..cd9d6531dd 100644
--- a/gtk/gtklevelbar.c
+++ b/gtk/gtklevelbar.c
@@ -901,6 +901,8 @@ gtk_level_bar_class_init (GtkLevelBarClass *klass)
   oclass->finalize = gtk_level_bar_finalize;
 
   wclass->direction_changed = gtk_level_bar_direction_changed;
+  wclass->grab_focus = gtk_widget_grab_focus_none;
+  wclass->focus = gtk_widget_focus_none;
 
   g_object_class_override_property (oclass, PROP_ORIENTATION, "orientation");
 
diff --git a/gtk/gtklistbox.c b/gtk/gtklistbox.c
index f2cf390cde..090ee4f2d4 100644
--- a/gtk/gtklistbox.c
+++ b/gtk/gtklistbox.c
@@ -436,6 +436,7 @@ gtk_list_box_class_init (GtkListBoxClass *klass)
   object_class->finalize = gtk_list_box_finalize;
   widget_class->show = gtk_list_box_show;
   widget_class->focus = gtk_list_box_focus;
+  widget_class->grab_focus = gtk_widget_grab_focus_self;
   widget_class->compute_expand = gtk_list_box_compute_expand;
   widget_class->get_request_mode = gtk_list_box_get_request_mode;
   widget_class->measure = gtk_list_box_measure;
@@ -3346,8 +3347,7 @@ gtk_list_box_row_grab_focus (GtkWidget *widget)
 
   g_return_val_if_fail (box != NULL, FALSE);
 
-  if (!GTK_WIDGET_CLASS (gtk_list_box_row_parent_class)->grab_focus (widget))
-    return FALSE;
+  gtk_widget_grab_focus_self (widget);
 
   if (box->cursor_row != row)
     gtk_list_box_update_cursor (box, row, FALSE);
diff --git a/gtk/gtkmediacontrols.c b/gtk/gtkmediacontrols.c
index a350e6c366..d0bfb41212 100644
--- a/gtk/gtkmediacontrols.c
+++ b/gtk/gtkmediacontrols.c
@@ -25,6 +25,7 @@
 #include "gtkbutton.h"
 #include "gtkintl.h"
 #include "gtklabel.h"
+#include "gtkwidgetprivate.h"
 
 /**
  * SECTION:gtkmediacontrols
@@ -259,6 +260,8 @@ gtk_media_controls_class_init (GtkMediaControlsClass *klass)
 
   widget_class->measure = gtk_media_controls_measure;
   widget_class->size_allocate = gtk_media_controls_size_allocate;
+  widget_class->grab_focus = gtk_widget_grab_focus_child;
+  widget_class->focus = gtk_widget_focus_child;
 
   gobject_class->dispose = gtk_media_controls_dispose;
   gobject_class->get_property = gtk_media_controls_get_property;
diff --git a/gtk/gtkmenubutton.c b/gtk/gtkmenubutton.c
index 0b405fbb12..c210d096d0 100644
--- a/gtk/gtkmenubutton.c
+++ b/gtk/gtkmenubutton.c
@@ -330,7 +330,15 @@ gtk_menu_button_focus (GtkWidget        *widget,
   if (self->popover && gtk_widget_get_visible (self->popover))
     return gtk_widget_child_focus (self->popover, direction);
   else
-    return GTK_WIDGET_CLASS (gtk_menu_button_parent_class)->focus (widget, direction);
+    return gtk_widget_child_focus (self->button, direction);
+}
+
+static gboolean
+gtk_menu_button_grab_focus (GtkWidget *widget)
+{
+  GtkMenuButton *self = GTK_MENU_BUTTON (widget);
+
+  return gtk_widget_grab_focus (self->button);
 }
 
 static void
@@ -347,6 +355,7 @@ gtk_menu_button_class_init (GtkMenuButtonClass *klass)
   widget_class->size_allocate = gtk_menu_button_size_allocate;
   widget_class->state_flags_changed = gtk_menu_button_state_flags_changed;
   widget_class->focus = gtk_menu_button_focus;
+  widget_class->grab_focus = gtk_menu_button_grab_focus;
 
   /**
    * GtkMenuButton:menu-model:
diff --git a/gtk/gtknotebook.c b/gtk/gtknotebook.c
index 96b1f598e9..36a651d23c 100644
--- a/gtk/gtknotebook.c
+++ b/gtk/gtknotebook.c
@@ -780,6 +780,7 @@ static void gtk_notebook_direction_changed   (GtkWidget        *widget,
                                               GtkTextDirection  previous_direction);
 static gboolean gtk_notebook_focus           (GtkWidget        *widget,
                                               GtkDirectionType  direction);
+static gboolean gtk_notebook_grab_focus      (GtkWidget        *widget);
 
 /*** Drag and drop Methods ***/
 static void gtk_notebook_dnd_finished_cb     (GdkDrag          *drag,
@@ -1043,6 +1044,7 @@ gtk_notebook_class_init (GtkNotebookClass *class)
   widget_class->state_flags_changed = gtk_notebook_state_flags_changed;
   widget_class->direction_changed = gtk_notebook_direction_changed;
   widget_class->focus = gtk_notebook_focus;
+  widget_class->grab_focus = gtk_notebook_grab_focus;
   widget_class->compute_expand = gtk_notebook_compute_expand;
 
   container_class->add = gtk_notebook_add;
@@ -3707,6 +3709,17 @@ gtk_notebook_focus (GtkWidget        *widget,
   return FALSE;
 }
 
+static gboolean
+gtk_notebook_grab_focus (GtkWidget *widget)
+{
+  GtkNotebook *notebook = GTK_NOTEBOOK (widget);
+
+  if (notebook->show_tabs)
+    return gtk_widget_grab_focus_self (widget);
+  else
+    return gtk_widget_grab_focus_child (widget);
+}
+
 static void
 gtk_notebook_set_focus_child (GtkContainer *container,
                               GtkWidget    *child)
diff --git a/gtk/gtkpasswordentry.c b/gtk/gtkpasswordentry.c
index b6f202f247..8474b52152 100644
--- a/gtk/gtkpasswordentry.c
+++ b/gtk/gtkpasswordentry.c
@@ -30,6 +30,7 @@
 #include "gtkimage.h"
 #include "gtkintl.h"
 #include "gtkprivate.h"
+#include "gtkwidgetprivate.h"
 #include "gtkmarshalers.h"
 #include "gtkstylecontext.h"
 #include "gtkeventcontrollerkey.h"
@@ -348,15 +349,6 @@ gtk_password_entry_get_accessible (GtkWidget *widget)
   return atk_obj;
 }
 
-static gboolean
-gtk_password_entry_grab_focus (GtkWidget *widget)
-{
-  GtkPasswordEntry *entry = GTK_PASSWORD_ENTRY (widget);
-  GtkPasswordEntryPrivate *priv = gtk_password_entry_get_instance_private (entry);
-
-  return gtk_widget_grab_focus (priv->entry);
-}
-
 static gboolean
 gtk_password_entry_mnemonic_activate (GtkWidget *widget,
                                       gboolean   group_cycling)
@@ -383,8 +375,10 @@ gtk_password_entry_class_init (GtkPasswordEntryClass *klass)
   widget_class->measure = gtk_password_entry_measure;
   widget_class->size_allocate = gtk_password_entry_size_allocate;
   widget_class->get_accessible = gtk_password_entry_get_accessible;
-  widget_class->grab_focus = gtk_password_entry_grab_focus;
+  widget_class->grab_focus = gtk_widget_grab_focus_child;
+  widget_class->focus = gtk_widget_focus_child;
   widget_class->mnemonic_activate = gtk_password_entry_mnemonic_activate;
+
   props[PROP_PLACEHOLDER_TEXT] =
       g_param_spec_string ("placeholder-text",
                            P_("Placeholder text"),
diff --git a/gtk/gtkpicture.c b/gtk/gtkpicture.c
index 401e0a8a07..71d322dd9f 100644
--- a/gtk/gtkpicture.c
+++ b/gtk/gtkpicture.c
@@ -301,6 +301,8 @@ gtk_picture_class_init (GtkPictureClass *class)
   widget_class->snapshot = gtk_picture_snapshot;
   widget_class->get_request_mode = gtk_picture_get_request_mode;
   widget_class->measure = gtk_picture_measure;
+  widget_class->grab_focus = gtk_widget_grab_focus_none;
+  widget_class->focus = gtk_widget_focus_none;
 
   /**
    * GtkPicture:paintable:
diff --git a/gtk/gtkprogressbar.c b/gtk/gtkprogressbar.c
index c293046838..dab0b3da3b 100644
--- a/gtk/gtkprogressbar.c
+++ b/gtk/gtkprogressbar.c
@@ -181,6 +181,8 @@ gtk_progress_bar_class_init (GtkProgressBarClass *class)
   gobject_class->finalize = gtk_progress_bar_finalize;
 
   widget_class->direction_changed = gtk_progress_bar_direction_changed;
+  widget_class->grab_focus = gtk_widget_grab_focus_none;
+  widget_class->focus = gtk_widget_focus_none;
 
   g_object_class_override_property (gobject_class, PROP_ORIENTATION, "orientation");
 
diff --git a/gtk/gtkscale.c b/gtk/gtkscale.c
index c961919524..3f043c6305 100644
--- a/gtk/gtkscale.c
+++ b/gtk/gtkscale.c
@@ -41,6 +41,7 @@
 #include "gtkstylecontextprivate.h"
 #include "gtkstylepropertyprivate.h"
 #include "gtktypebuiltins.h"
+#include "gtkwidgetprivate.h"
 
 #include "a11y/gtkscaleaccessible.h"
 
@@ -663,6 +664,8 @@ gtk_scale_class_init (GtkScaleClass *class)
   widget_class->snapshot = gtk_scale_snapshot;
   widget_class->size_allocate = gtk_scale_size_allocate;
   widget_class->measure = gtk_scale_measure;
+  widget_class->grab_focus = gtk_widget_grab_focus_self;
+  widget_class->focus = gtk_widget_focus_self;
 
   range_class->get_range_border = gtk_scale_get_range_border;
   range_class->value_changed = gtk_scale_value_changed;
diff --git a/gtk/gtkscrollbar.c b/gtk/gtkscrollbar.c
index 84b18c02dc..66cede913b 100644
--- a/gtk/gtkscrollbar.c
+++ b/gtk/gtkscrollbar.c
@@ -33,6 +33,7 @@
 #include "gtkorientable.h"
 #include "gtkorientableprivate.h"
 #include "gtkprivate.h"
+#include "gtkwidgetprivate.h"
 #include "gtkboxlayout.h"
 
 #include "a11y/gtkscrollbaraccessible.h"
@@ -195,6 +196,9 @@ gtk_scrollbar_class_init (GtkScrollbarClass *class)
   object_class->set_property = gtk_scrollbar_set_property;
   object_class->dispose = gtk_scrollbar_dispose;
 
+  widget_class->focus = gtk_widget_focus_none;
+  widget_class->grab_focus = gtk_widget_grab_focus_none;
+
   props[PROP_ADJUSTMENT] =
       g_param_spec_object ("adjustment",
                            P_("Adjustment"),
diff --git a/gtk/gtkscrolledwindow.c b/gtk/gtkscrolledwindow.c
index 3bb8d023b8..db66c3ff9d 100644
--- a/gtk/gtkscrolledwindow.c
+++ b/gtk/gtkscrolledwindow.c
@@ -526,6 +526,7 @@ gtk_scrolled_window_class_init (GtkScrolledWindowClass *class)
   widget_class->snapshot = gtk_scrolled_window_snapshot;
   widget_class->size_allocate = gtk_scrolled_window_size_allocate;
   widget_class->focus = gtk_scrolled_window_focus;
+  widget_class->grab_focus = gtk_widget_grab_focus_self;
   widget_class->measure = gtk_scrolled_window_measure;
   widget_class->map = gtk_scrolled_window_map;
   widget_class->unmap = gtk_scrolled_window_unmap;
diff --git a/gtk/gtkseparator.c b/gtk/gtkseparator.c
index 97050fa653..b83d274228 100644
--- a/gtk/gtkseparator.c
+++ b/gtk/gtkseparator.c
@@ -29,6 +29,7 @@
 #include "gtkorientableprivate.h"
 #include "gtkintl.h"
 #include "gtkprivate.h"
+#include "gtkwidgetprivate.h"
 
 /**
  * SECTION:gtkseparator
@@ -141,6 +142,9 @@ gtk_separator_class_init (GtkSeparatorClass *class)
   object_class->set_property = gtk_separator_set_property;
   object_class->get_property = gtk_separator_get_property;
 
+  widget_class->grab_focus = gtk_widget_grab_focus_none;
+  widget_class->focus = gtk_widget_focus_none;
+
   g_object_class_override_property (object_class, PROP_ORIENTATION, "orientation");
 
   gtk_widget_class_set_accessible_role (widget_class, ATK_ROLE_SEPARATOR);
diff --git a/gtk/gtkshortcutlabel.c b/gtk/gtkshortcutlabel.c
index 5b453edd9d..c424c51994 100644
--- a/gtk/gtkshortcutlabel.c
+++ b/gtk/gtkshortcutlabel.c
@@ -22,6 +22,7 @@
 #include "gtkboxlayout.h"
 #include "gtklabel.h"
 #include "gtkframe.h"
+#include "gtkwidgetprivate.h"
 #include "gtkintl.h"
 
 /**
@@ -474,6 +475,9 @@ gtk_shortcut_label_class_init (GtkShortcutLabelClass *klass)
   object_class->get_property = gtk_shortcut_label_get_property;
   object_class->set_property = gtk_shortcut_label_set_property;
 
+  widget_class->grab_focus = gtk_widget_grab_focus_none;
+  widget_class->focus = gtk_widget_focus_none;
+
   /**
    * GtkShortcutLabel:accelerator:
    *
diff --git a/gtk/gtkshortcutsshortcut.c b/gtk/gtkshortcutsshortcut.c
index 0aea8286d0..95407986b1 100644
--- a/gtk/gtkshortcutsshortcut.c
+++ b/gtk/gtkshortcutsshortcut.c
@@ -25,6 +25,7 @@
 #include "gtkintl.h"
 #include "gtklabel.h"
 #include "gtkprivate.h"
+#include "gtkwidgetprivate.h"
 #include "gtkshortcutlabel.h"
 #include "gtkshortcutswindowprivate.h"
 #include "gtksizegroup.h"
@@ -547,6 +548,8 @@ gtk_shortcuts_shortcut_class_init (GtkShortcutsShortcutClass *klass)
   widget_class->measure = gtk_shortcuts_shortcut_measure;
   widget_class->snapshot = gtk_shortcuts_shortcut_snapshot;
   widget_class->size_allocate = gtk_shortcuts_shortcut_size_allocate;
+  widget_class->grab_focus = gtk_widget_grab_focus_none;
+  widget_class->focus = gtk_widget_focus_none;
 
   /**
    * GtkShortcutsShortcut:accelerator:
diff --git a/gtk/gtkspinbutton.c b/gtk/gtkspinbutton.c
index 6d610e7ef3..c59ef30ab8 100644
--- a/gtk/gtkspinbutton.c
+++ b/gtk/gtkspinbutton.c
@@ -349,6 +349,7 @@ gtk_spin_button_class_init (GtkSpinButtonClass *class)
   widget_class->grab_notify = gtk_spin_button_grab_notify;
   widget_class->state_flags_changed = gtk_spin_button_state_flags_changed;
   widget_class->grab_focus = gtk_spin_button_grab_focus;
+  widget_class->focus = gtk_widget_focus_child;
   widget_class->mnemonic_activate = gtk_spin_button_mnemonic_activate;
 
   class->input = NULL;
diff --git a/gtk/gtkspinner.c b/gtk/gtkspinner.c
index cb83e568f0..55ae28a33d 100644
--- a/gtk/gtkspinner.c
+++ b/gtk/gtkspinner.c
@@ -229,6 +229,8 @@ gtk_spinner_class_init (GtkSpinnerClass *klass)
   widget_class->snapshot = gtk_spinner_snapshot;
   widget_class->measure = gtk_spinner_measure;
   widget_class->css_changed = gtk_spinner_css_changed;
+  widget_class->grab_focus = gtk_widget_grab_focus_none;
+  widget_class->focus = gtk_widget_focus_none;
 
   /* GtkSpinner:spinning:
    *
diff --git a/gtk/gtkstacksidebar.c b/gtk/gtkstacksidebar.c
index 03b909017d..97d0f48e4f 100644
--- a/gtk/gtkstacksidebar.c
+++ b/gtk/gtkstacksidebar.c
@@ -32,6 +32,7 @@
 #include "gtkselectionmodel.h"
 #include "gtkstack.h"
 #include "gtkprivate.h"
+#include "gtkwidgetprivate.h"
 #include "gtkintl.h"
 
 /**
@@ -389,6 +390,9 @@ gtk_stack_sidebar_class_init (GtkStackSidebarClass *klass)
   object_class->set_property = gtk_stack_sidebar_set_property;
   object_class->get_property = gtk_stack_sidebar_get_property;
 
+  widget_class->focus = gtk_widget_focus_child;
+  widget_class->grab_focus = gtk_widget_grab_focus_child;
+
   obj_properties[PROP_STACK] =
       g_param_spec_object (I_("stack"), P_("Stack"),
                            P_("Associated stack for this GtkStackSidebar"),
diff --git a/gtk/gtkstackswitcher.c b/gtk/gtkstackswitcher.c
index 48173692eb..2b43fa3211 100644
--- a/gtk/gtkstackswitcher.c
+++ b/gtk/gtkstackswitcher.c
@@ -518,6 +518,9 @@ gtk_stack_switcher_class_init (GtkStackSwitcherClass *class)
   object_class->dispose = gtk_stack_switcher_dispose;
   object_class->finalize = gtk_stack_switcher_finalize;
 
+  widget_class->grab_focus = gtk_widget_grab_focus_child;
+  widget_class->focus = gtk_widget_focus_child;
+
   g_object_class_install_property (object_class,
                                    PROP_STACK,
                                    g_param_spec_object ("stack",
diff --git a/gtk/gtkstatusbar.c b/gtk/gtkstatusbar.c
index 0bf52f35f8..0669fc650a 100644
--- a/gtk/gtkstatusbar.c
+++ b/gtk/gtkstatusbar.c
@@ -36,6 +36,7 @@
 #include "gtkintl.h"
 #include "gtkorientable.h"
 #include "gtktypebuiltins.h"
+#include "gtkwidgetprivate.h"
 #include "a11y/gtkstatusbaraccessible.h"
 
 /**
@@ -151,6 +152,8 @@ gtk_statusbar_class_init (GtkStatusbarClass *class)
   object_class->dispose = gtk_statusbar_dispose;
 
   widget_class->destroy = gtk_statusbar_destroy;
+  widget_class->grab_focus = gtk_widget_grab_focus_child;
+  widget_class->focus = gtk_widget_focus_child;
 
   class->text_pushed = gtk_statusbar_update;
   class->text_popped = gtk_statusbar_update;
diff --git a/gtk/gtkswitch.c b/gtk/gtkswitch.c
index a62a83b1e2..ffc7371c73 100644
--- a/gtk/gtkswitch.c
+++ b/gtk/gtkswitch.c
@@ -548,6 +548,9 @@ gtk_switch_class_init (GtkSwitchClass *klass)
 
   g_object_class_install_properties (gobject_class, LAST_PROP, switch_props);
 
+  widget_class->grab_focus = gtk_widget_grab_focus_self;
+  widget_class->focus = gtk_widget_focus_self;
+
   klass->activate = gtk_switch_activate;
   klass->state_set = state_set;
 
diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c
index dd0bbe71dd..a7d8c5504c 100644
--- a/gtk/gtktextview.c
+++ b/gtk/gtktextview.c
@@ -421,8 +421,6 @@ static void gtk_text_view_motion               (GtkEventController *controller,
                                                 gpointer            user_data);
 static void gtk_text_view_snapshot             (GtkWidget        *widget,
                                                 GtkSnapshot      *snapshot);
-static gboolean gtk_text_view_focus            (GtkWidget        *widget,
-                                                GtkDirectionType  direction);
 static void gtk_text_view_select_all           (GtkWidget        *widget,
                                                 gboolean          select);
 static gboolean get_middle_click_paste         (GtkTextView      *text_view);
@@ -823,7 +821,8 @@ gtk_text_view_class_init (GtkTextViewClass *klass)
   widget_class->measure = gtk_text_view_measure;
   widget_class->size_allocate = gtk_text_view_size_allocate;
   widget_class->snapshot = gtk_text_view_snapshot;
-  widget_class->focus = gtk_text_view_focus;
+  widget_class->grab_focus = gtk_widget_grab_focus_self;
+  widget_class->focus = gtk_widget_focus_all;
 
   container_class->add = gtk_text_view_add;
   container_class->remove = gtk_text_view_remove;
@@ -5679,39 +5678,6 @@ gtk_text_view_snapshot (GtkWidget   *widget,
     }
 }
 
-static gboolean
-gtk_text_view_focus (GtkWidget        *widget,
-                     GtkDirectionType  direction)
-{
-  gboolean result;
-
-  if (!gtk_widget_is_focus (widget) &&
-      gtk_widget_get_focus_child (widget) == NULL)
-    {
-      if (gtk_widget_get_can_focus (widget))
-        {
-          gtk_widget_grab_focus (widget);
-          return TRUE;
-        }
-
-      return FALSE;
-    }
-  else
-    {
-      gboolean can_focus;
-      /*
-       * Unset CAN_FOCUS flag so that gtk_container_focus() allows
-       * children to get the focus
-       */
-      can_focus = gtk_widget_get_can_focus (widget);
-      gtk_widget_set_can_focus (widget, FALSE);
-      result = GTK_WIDGET_CLASS (gtk_text_view_parent_class)->focus (widget, direction);
-      gtk_widget_set_can_focus (widget, can_focus);
-
-      return result;
-    }
-}
-
 /*
  * Container
  */
diff --git a/gtk/gtktreeview.c b/gtk/gtktreeview.c
index 6d68907a5a..83daf4f487 100644
--- a/gtk/gtktreeview.c
+++ b/gtk/gtktreeview.c
@@ -7852,9 +7852,6 @@ gtk_tree_view_focus (GtkWidget        *widget,
   GtkTreeView *tree_view = GTK_TREE_VIEW (widget);
   GtkWidget *focus_child;
 
-  if (!gtk_widget_is_sensitive (widget) || !gtk_widget_get_can_focus (widget))
-    return FALSE;
-
   focus_child = gtk_widget_get_focus_child (widget);
 
   gtk_tree_view_stop_editing (GTK_TREE_VIEW (widget), FALSE);
@@ -7898,7 +7895,7 @@ gtk_tree_view_focus (GtkWidget        *widget,
 static gboolean
 gtk_tree_view_grab_focus (GtkWidget *widget)
 {
-  if (!GTK_WIDGET_CLASS (gtk_tree_view_parent_class)->grab_focus (widget))
+  if (!gtk_widget_grab_focus_self (widget))
     return FALSE;
 
   gtk_tree_view_focus_to_cursor (GTK_TREE_VIEW (widget));
diff --git a/gtk/gtkvideo.c b/gtk/gtkvideo.c
index 1ae48bcddc..843253d5ff 100644
--- a/gtk/gtkvideo.c
+++ b/gtk/gtkvideo.c
@@ -30,6 +30,7 @@
 #include "gtknative.h"
 #include "gtkpicture.h"
 #include "gtkrevealer.h"
+#include "gtkwidgetprivate.h"
 
 /**
  * SECTION:gtkvideo
@@ -252,6 +253,8 @@ gtk_video_class_init (GtkVideoClass *klass)
   widget_class->unrealize = gtk_video_unrealize;
   widget_class->map = gtk_video_map;
   widget_class->unmap = gtk_video_unmap;
+  widget_class->grab_focus = gtk_widget_grab_focus_child;
+  widget_class->focus = gtk_widget_focus_child;
 
   gobject_class->dispose = gtk_video_dispose;
   gobject_class->get_property = gtk_video_get_property;


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