widget: Fix can-focus

Setting can-focus to FALSE on a widget is supposed
to prevent focus from entering the entire subtree.
So when we grab focus directly to a widget, we need
to check the can-focus flag not just of the widget
itself, but all its ancestors.

Fixes: #3610
This commit is contained in:
Matthias Clasen 2021-01-26 23:43:11 -05:00
parent ec9159f983
commit 8ef1d6a49c

View File

@ -4390,13 +4390,27 @@ gtk_widget_can_activate (GtkWidget *self)
return FALSE;
}
static gboolean
get_effective_can_focus (GtkWidget *widget)
{
GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
if (!priv->can_focus)
return FALSE;
if (priv->parent)
return get_effective_can_focus (priv->parent);
return TRUE;
}
static gboolean
gtk_widget_real_mnemonic_activate (GtkWidget *widget,
gboolean group_cycling)
{
if (!group_cycling && gtk_widget_can_activate (widget))
gtk_widget_activate (widget);
else if (gtk_widget_get_can_focus (widget))
else if (get_effective_can_focus (widget))
return gtk_widget_grab_focus (widget);
else
{
@ -4782,7 +4796,7 @@ gtk_widget_grab_focus (GtkWidget *widget)
g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
if (!gtk_widget_is_sensitive (widget) ||
!gtk_widget_get_can_focus (widget) ||
!get_effective_can_focus (widget) ||
widget->priv->root == NULL)
return FALSE;