Change the default value of GtkWidget:can-focus

Make widgets can-focus by default, and change the semantics
of can-focus to be recursive . If it is set to FALSE, focus
can not enter the widget or its descendents at all anymore.

This commit temporarily breaks focus behavior of widgets
that did not expect to receive focus.
This commit is contained in:
Matthias Clasen 2020-04-08 07:40:48 -04:00
parent 3c39613d9c
commit 22e1827f84
9 changed files with 4 additions and 18 deletions

View File

@ -189,8 +189,6 @@ gtk_font_plane_init (GtkFontPlane *plane)
{
GtkGesture *gesture;
gtk_widget_set_can_focus (GTK_WIDGET (plane), TRUE);
gesture = gtk_gesture_drag_new ();
g_signal_connect (gesture, "drag-begin",
G_CALLBACK (plane_drag_gesture_begin), plane);

View File

@ -408,7 +408,6 @@ gtk_button_init (GtkButton *button)
GtkButtonPrivate *priv = gtk_button_get_instance_private (button);
GtkEventController *key_controller;
gtk_widget_set_can_focus (GTK_WIDGET (button), TRUE);
gtk_widget_set_receives_default (GTK_WIDGET (button), TRUE);
priv->in_button = FALSE;

View File

@ -407,8 +407,6 @@ gtk_color_plane_init (GtkColorPlane *plane)
plane->priv = gtk_color_plane_get_instance_private (plane);
gtk_widget_set_can_focus (GTK_WIDGET (plane), TRUE);
atk_obj = gtk_widget_get_accessible (GTK_WIDGET (plane));
if (GTK_IS_ACCESSIBLE (atk_obj))
{

View File

@ -385,8 +385,6 @@ gtk_expander_init (GtkExpander *expander)
GtkGesture *gesture;
GtkEventController *controller;
gtk_widget_set_can_focus (GTK_WIDGET (expander), TRUE);
priv->label_widget = NULL;
priv->child = NULL;

View File

@ -943,7 +943,6 @@ gtk_icon_view_init (GtkIconView *icon_view)
icon_view->priv->mouse_x = -1;
icon_view->priv->mouse_y = -1;
gtk_widget_set_can_focus (GTK_WIDGET (icon_view), TRUE);
gtk_widget_set_overflow (GTK_WIDGET (icon_view), GTK_OVERFLOW_HIDDEN);
icon_view->priv->item_orientation = GTK_ORIENTATION_VERTICAL;

View File

@ -3430,8 +3430,6 @@ gtk_list_box_row_class_init (GtkListBoxRowClass *klass)
static void
gtk_list_box_row_init (GtkListBoxRow *row)
{
gtk_widget_set_can_focus (GTK_WIDGET (row), TRUE);
ROW_PRIV (row)->activatable = TRUE;
ROW_PRIV (row)->selectable = TRUE;

View File

@ -1387,8 +1387,6 @@ gtk_notebook_init (GtkNotebook *notebook)
GtkLayoutManager *layout;
GtkDropTarget *dest;
gtk_widget_set_can_focus (GTK_WIDGET (notebook), TRUE);
notebook->cur_page = NULL;
notebook->children = NULL;
notebook->first_tab = NULL;
@ -6087,8 +6085,6 @@ gtk_notebook_set_show_tabs (GtkNotebook *notebook,
if (!show_tabs)
{
gtk_widget_set_can_focus (GTK_WIDGET (notebook), FALSE);
while (children)
{
page = children->data;
@ -6106,7 +6102,6 @@ gtk_notebook_set_show_tabs (GtkNotebook *notebook,
}
else
{
gtk_widget_set_can_focus (GTK_WIDGET (notebook), TRUE);
gtk_notebook_update_labels (notebook);
gtk_widget_show (notebook->header_widget);
}

View File

@ -1707,7 +1707,6 @@ gtk_tree_view_init (GtkTreeView *tree_view)
GtkEventController **controllers;
guint n_controllers, i;
gtk_widget_set_can_focus (GTK_WIDGET (tree_view), TRUE);
gtk_widget_set_overflow (GTK_WIDGET (tree_view), GTK_OVERFLOW_HIDDEN);
tree_view->show_expanders = TRUE;

View File

@ -978,7 +978,7 @@ gtk_widget_class_init (GtkWidgetClass *klass)
g_param_spec_boolean ("can-focus",
P_("Can focus"),
P_("Whether the widget can accept the input focus"),
FALSE,
TRUE,
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
widget_props[PROP_HAS_FOCUS] =
@ -2294,6 +2294,7 @@ gtk_widget_init (GTypeInstance *instance, gpointer g_class)
#ifdef G_ENABLE_DEBUG
priv->highlight_resize = FALSE;
#endif
priv->can_focus = TRUE;
priv->can_target = TRUE;
switch (_gtk_widget_get_direction (widget))
@ -6681,7 +6682,8 @@ gtk_widget_child_focus (GtkWidget *widget,
g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
if (!_gtk_widget_get_visible (widget) ||
!gtk_widget_is_sensitive (widget))
!gtk_widget_is_sensitive (widget) ||
!gtk_widget_get_can_focus (widget))
return FALSE;
/* Emit ::focus in any case, even if can-focus is FALSE,