[gtk+/popovers: 29/33] popover: Implement keyboard focus behavior
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/popovers: 29/33] popover: Implement keyboard focus behavior
- Date: Fri, 10 Jan 2014 15:17:24 +0000 (UTC)
commit fa6b58d4aa6ee92ffd414482092634996bcd14d5
Author: Carlos Garnacho <carlosg gnome org>
Date: Thu Jan 9 12:53:29 2014 +0100
popover: Implement keyboard focus behavior
When a popover is focused, the focus is forwarded so the first
child what would get the focus actually gets it. Also, implement
correct focus chain, so the keyboard focus stays within the popover
when navigating with keyboard.
gtk/gtkpopover.c | 42 ++++++++++++++++++++++++++++++++++++++++++
1 files changed, 42 insertions(+), 0 deletions(-)
---
diff --git a/gtk/gtkpopover.c b/gtk/gtkpopover.c
index e68e983..55a2274 100644
--- a/gtk/gtkpopover.c
+++ b/gtk/gtkpopover.c
@@ -773,6 +773,46 @@ gtk_popover_key_press (GtkWidget *widget,
}
static void
+gtk_popover_grab_focus (GtkWidget *widget)
+{
+ /* Focus the first natural child */
+ gtk_widget_child_focus (gtk_bin_get_child (GTK_BIN (widget)),
+ GTK_DIR_TAB_FORWARD);
+}
+
+static gboolean
+gtk_popover_focus (GtkWidget *widget,
+ GtkDirectionType direction)
+{
+ GtkPopoverPrivate *priv;
+
+ priv = gtk_popover_get_instance_private (GTK_POPOVER (widget));
+
+ if (!GTK_WIDGET_CLASS (gtk_popover_parent_class)->focus (widget, direction))
+ {
+ GtkWidget *focus;
+
+ focus = gtk_window_get_focus (priv->window);
+ focus = gtk_widget_get_parent (focus);
+
+ /* Unset focus child through children, so it is next stepped from
+ * scratch.
+ */
+ while (focus && focus != widget)
+ {
+ gtk_container_set_focus_child (GTK_CONTAINER (focus), NULL);
+ focus = gtk_widget_get_parent (focus);
+ }
+
+ return gtk_widget_child_focus (gtk_bin_get_child (GTK_BIN (widget)),
+ direction);
+ }
+
+ return TRUE;
+}
+
+
+static void
gtk_popover_class_init (GtkPopoverClass *klass)
{
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
@@ -792,6 +832,8 @@ gtk_popover_class_init (GtkPopoverClass *klass)
widget_class->draw = gtk_popover_draw;
widget_class->button_press_event = gtk_popover_button_press;
widget_class->key_press_event = gtk_popover_key_press;
+ widget_class->grab_focus = gtk_popover_grab_focus;
+ widget_class->focus = gtk_popover_focus;
/**
* GtkPopover:relative-to:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]