forked from AuroraMiddleware/gtk
Merge branch 'emoji-keynav' into 'master'
Emoji keynav See merge request GNOME/gtk!1687
This commit is contained in:
commit
fb2502fa5f
@ -24,7 +24,7 @@
|
||||
#include "gtkbutton.h"
|
||||
#include "gtkcssprovider.h"
|
||||
#include "gtkentry.h"
|
||||
#include "gtkflowbox.h"
|
||||
#include "gtkflowboxprivate.h"
|
||||
#include "gtkstack.h"
|
||||
#include "gtklabel.h"
|
||||
#include "gtkgesturelongpress.h"
|
||||
@ -36,6 +36,7 @@
|
||||
#include "gtkstylecontext.h"
|
||||
#include "gtktext.h"
|
||||
#include "gtknative.h"
|
||||
#include "gtkwidgetprivate.h"
|
||||
#include "gdk/gdkprofilerprivate.h"
|
||||
|
||||
/**
|
||||
@ -119,6 +120,16 @@ gtk_emoji_chooser_child_focus (GtkWidget *widget,
|
||||
return GTK_WIDGET_CLASS (gtk_emoji_chooser_child_parent_class)->focus (widget, direction);
|
||||
}
|
||||
|
||||
static void scroll_to_child (GtkWidget *child);
|
||||
|
||||
static gboolean
|
||||
gtk_emoji_chooser_child_grab_focus (GtkWidget *widget)
|
||||
{
|
||||
gtk_widget_grab_focus_self (widget);
|
||||
scroll_to_child (widget);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void show_variations (GtkEmojiChooser *chooser,
|
||||
GtkWidget *child);
|
||||
|
||||
@ -140,6 +151,7 @@ gtk_emoji_chooser_child_class_init (GtkEmojiChooserChildClass *class)
|
||||
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
|
||||
widget_class->size_allocate = gtk_emoji_chooser_child_size_allocate;
|
||||
widget_class->focus = gtk_emoji_chooser_child_focus;
|
||||
widget_class->grab_focus = gtk_emoji_chooser_child_grab_focus;
|
||||
|
||||
gtk_widget_class_install_action (widget_class, "menu.popup", NULL, gtk_emoji_chooser_child_popup_menu);
|
||||
|
||||
@ -221,15 +233,13 @@ gtk_emoji_chooser_finalize (GObject *object)
|
||||
}
|
||||
|
||||
static void
|
||||
scroll_to_section (GtkButton *button,
|
||||
gpointer data)
|
||||
scroll_to_section (EmojiSection *section)
|
||||
{
|
||||
EmojiSection *section = data;
|
||||
GtkEmojiChooser *chooser;
|
||||
GtkAdjustment *adj;
|
||||
GtkAllocation alloc = { 0, 0, 0, 0 };
|
||||
|
||||
chooser = GTK_EMOJI_CHOOSER (gtk_widget_get_ancestor (GTK_WIDGET (button), GTK_TYPE_EMOJI_CHOOSER));
|
||||
chooser = GTK_EMOJI_CHOOSER (gtk_widget_get_ancestor (section->box, GTK_TYPE_EMOJI_CHOOSER));
|
||||
|
||||
adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (chooser->scrolled_window));
|
||||
if (section->heading)
|
||||
@ -237,6 +247,33 @@ scroll_to_section (GtkButton *button,
|
||||
gtk_adjustment_animate_to_value (adj, alloc.y - BOX_SPACE);
|
||||
}
|
||||
|
||||
static void
|
||||
scroll_to_child (GtkWidget *child)
|
||||
{
|
||||
GtkEmojiChooser *chooser;
|
||||
GtkAdjustment *adj;
|
||||
GtkAllocation alloc;
|
||||
int pos;
|
||||
double value;
|
||||
double page_size;
|
||||
|
||||
chooser = GTK_EMOJI_CHOOSER (gtk_widget_get_ancestor (child, GTK_TYPE_EMOJI_CHOOSER));
|
||||
|
||||
adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (chooser->scrolled_window));
|
||||
|
||||
gtk_widget_get_allocation (child, &alloc);
|
||||
|
||||
value = gtk_adjustment_get_value (adj);
|
||||
page_size = gtk_adjustment_get_page_size (adj);
|
||||
|
||||
gtk_widget_translate_coordinates (child, gtk_widget_get_parent (chooser->recent.box), 0, 0, NULL, &pos);
|
||||
|
||||
if (pos < value)
|
||||
gtk_adjustment_animate_to_value (adj, pos);
|
||||
else if (pos + alloc.height >= value + page_size)
|
||||
gtk_adjustment_animate_to_value (adj, value + ((pos + alloc.height) - (value + page_size)));
|
||||
}
|
||||
|
||||
static void
|
||||
add_emoji (GtkWidget *box,
|
||||
gboolean prepend,
|
||||
@ -744,8 +781,9 @@ setup_section (GtkEmojiChooser *chooser,
|
||||
adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (chooser->scrolled_window));
|
||||
|
||||
gtk_container_set_focus_vadjustment (GTK_CONTAINER (section->box), adj);
|
||||
gtk_flow_box_disable_move_cursor (GTK_FLOW_BOX (section->box));
|
||||
gtk_flow_box_set_filter_func (GTK_FLOW_BOX (section->box), filter_func, section, NULL);
|
||||
g_signal_connect (section->button, "clicked", G_CALLBACK (scroll_to_section), section);
|
||||
g_signal_connect_swapped (section->button, "clicked", G_CALLBACK (scroll_to_section), section);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -817,6 +855,137 @@ gtk_emoji_chooser_show (GtkWidget *widget)
|
||||
gtk_editable_set_text (GTK_EDITABLE (chooser->search_entry), "");
|
||||
}
|
||||
|
||||
static EmojiSection *
|
||||
find_next_section (GtkEmojiChooser *chooser,
|
||||
GtkWidget *box,
|
||||
gboolean down)
|
||||
{
|
||||
EmojiSection *next;
|
||||
|
||||
if (box == chooser->recent.box)
|
||||
next = down ? &chooser->people : NULL;
|
||||
else if (box == chooser->people.box)
|
||||
next = down ? &chooser->body : &chooser->recent;
|
||||
else if (box == chooser->body.box)
|
||||
next = down ? &chooser->nature : &chooser->people;
|
||||
else if (box == chooser->nature.box)
|
||||
next = down ? &chooser->food : &chooser->body;
|
||||
else if (box == chooser->food.box)
|
||||
next = down ? &chooser->travel : &chooser->nature;
|
||||
else if (box == chooser->travel.box)
|
||||
next = down ? &chooser->activities : &chooser->food;
|
||||
else if (box == chooser->activities.box)
|
||||
next = down ? &chooser->objects : &chooser->travel;
|
||||
else if (box == chooser->objects.box)
|
||||
next = down ? &chooser->symbols : &chooser->activities;
|
||||
else if (box == chooser->symbols.box)
|
||||
next = down ? &chooser->flags : &chooser->objects;
|
||||
else if (box == chooser->flags.box)
|
||||
next = down ? NULL : &chooser->symbols;
|
||||
else
|
||||
next = NULL;
|
||||
|
||||
return next;
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_emoji_chooser_scroll_section (GtkWidget *widget,
|
||||
const char *action_name,
|
||||
GVariant *parameter)
|
||||
{
|
||||
GtkEmojiChooser *chooser = GTK_EMOJI_CHOOSER (widget);
|
||||
int direction = g_variant_get_int32 (parameter);
|
||||
GtkWidget *focus;
|
||||
GtkWidget *box;
|
||||
EmojiSection *next;
|
||||
|
||||
focus = gtk_root_get_focus (gtk_widget_get_root (widget));
|
||||
if (focus == NULL)
|
||||
return;
|
||||
|
||||
if (gtk_widget_is_ancestor (focus, chooser->search_entry))
|
||||
box = chooser->recent.box;
|
||||
else
|
||||
box = gtk_widget_get_ancestor (focus, GTK_TYPE_FLOW_BOX);
|
||||
|
||||
next = find_next_section (chooser, box, direction > 0);
|
||||
|
||||
if (next)
|
||||
{
|
||||
gtk_widget_child_focus (next->box, GTK_DIR_TAB_FORWARD);
|
||||
scroll_to_section (next);
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
keynav_failed (GtkWidget *box,
|
||||
GtkDirectionType direction,
|
||||
GtkEmojiChooser *chooser)
|
||||
{
|
||||
EmojiSection *next;
|
||||
GtkWidget *focus;
|
||||
GtkWidget *child;
|
||||
GtkWidget *sibling;
|
||||
int i;
|
||||
int column;
|
||||
|
||||
focus = gtk_root_get_focus (gtk_widget_get_root (box));
|
||||
if (focus == NULL)
|
||||
return FALSE;
|
||||
|
||||
child = gtk_widget_get_ancestor (focus, GTK_TYPE_EMOJI_CHOOSER_CHILD);
|
||||
|
||||
i = 0;
|
||||
for (sibling = gtk_widget_get_first_child (box);
|
||||
sibling != child;
|
||||
sibling = gtk_widget_get_next_sibling (sibling))
|
||||
i++;
|
||||
|
||||
column = i % 7;
|
||||
|
||||
if (direction == GTK_DIR_DOWN)
|
||||
{
|
||||
next = find_next_section (chooser, box, TRUE);
|
||||
if (next == NULL)
|
||||
return FALSE;
|
||||
|
||||
i = 0;
|
||||
for (sibling = gtk_widget_get_first_child (next->box);
|
||||
sibling;
|
||||
sibling = gtk_widget_get_next_sibling (sibling), i++)
|
||||
{
|
||||
if (i == column)
|
||||
{
|
||||
gtk_widget_grab_focus (sibling);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (direction == GTK_DIR_UP)
|
||||
{
|
||||
next = find_next_section (chooser, box, FALSE);
|
||||
if (next == NULL)
|
||||
return FALSE;
|
||||
|
||||
i = 0;
|
||||
child = NULL;
|
||||
for (sibling = gtk_widget_get_first_child (next->box);
|
||||
sibling;
|
||||
sibling = gtk_widget_get_next_sibling (sibling), i++)
|
||||
{
|
||||
if ((i % 7) == column)
|
||||
child = sibling;
|
||||
}
|
||||
if (child)
|
||||
{
|
||||
gtk_widget_grab_focus (child);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_emoji_chooser_class_init (GtkEmojiChooserClass *klass)
|
||||
{
|
||||
@ -892,6 +1061,15 @@ gtk_emoji_chooser_class_init (GtkEmojiChooserClass *klass)
|
||||
gtk_widget_class_bind_template_callback (widget_class, stop_search);
|
||||
gtk_widget_class_bind_template_callback (widget_class, pressed_cb);
|
||||
gtk_widget_class_bind_template_callback (widget_class, long_pressed_cb);
|
||||
gtk_widget_class_bind_template_callback (widget_class, keynav_failed);
|
||||
|
||||
gtk_widget_class_install_action (widget_class, "scroll.section", "i",
|
||||
gtk_emoji_chooser_scroll_section);
|
||||
|
||||
gtk_widget_class_add_binding_action (widget_class, GDK_KEY_n, GDK_CONTROL_MASK,
|
||||
"scroll.section", "i", 1);
|
||||
gtk_widget_class_add_binding_action (widget_class, GDK_KEY_p, GDK_CONTROL_MASK,
|
||||
"scroll.section", "i", -1);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -76,6 +76,7 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "gtkflowbox.h"
|
||||
#include "gtkflowboxprivate.h"
|
||||
|
||||
#include "gtkadjustment.h"
|
||||
#include "gtkcontainerprivate.h"
|
||||
@ -426,7 +427,6 @@ gtk_flow_box_child_class_init (GtkFlowBoxChildClass *class)
|
||||
static void
|
||||
gtk_flow_box_child_init (GtkFlowBoxChild *child)
|
||||
{
|
||||
gtk_widget_set_can_focus (GTK_WIDGET (child), TRUE);
|
||||
}
|
||||
|
||||
/* Public API {{{2 */
|
||||
@ -641,6 +641,8 @@ struct _GtkFlowBoxPrivate {
|
||||
GtkFlowBoxCreateWidgetFunc create_widget_func;
|
||||
gpointer create_widget_func_data;
|
||||
GDestroyNotify create_widget_func_data_destroy;
|
||||
|
||||
gboolean disable_move_cursor;
|
||||
};
|
||||
|
||||
#define BOX_PRIV(box) ((GtkFlowBoxPrivate*)gtk_flow_box_get_instance_private ((GtkFlowBox*)(box)))
|
||||
@ -2903,12 +2905,6 @@ gtk_flow_box_focus (GtkWidget *widget,
|
||||
GSequenceIter *iter;
|
||||
GtkFlowBoxChild *next_focus_child;
|
||||
|
||||
/* Without "can-focus" flag fall back to the default behavior immediately */
|
||||
if (!gtk_widget_get_can_focus (widget))
|
||||
{
|
||||
return GTK_WIDGET_CLASS (gtk_flow_box_parent_class)->focus (widget, direction);
|
||||
}
|
||||
|
||||
focus_child = gtk_widget_get_focus_child (widget);
|
||||
next_focus_child = NULL;
|
||||
|
||||
@ -3012,6 +3008,14 @@ gtk_flow_box_toggle_cursor_child (GtkFlowBox *box)
|
||||
gtk_flow_box_select_and_activate (box, priv->cursor_child);
|
||||
}
|
||||
|
||||
void
|
||||
gtk_flow_box_disable_move_cursor (GtkFlowBox *box)
|
||||
{
|
||||
GtkFlowBoxPrivate *priv = BOX_PRIV (box);
|
||||
|
||||
priv->disable_move_cursor = TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gtk_flow_box_move_cursor (GtkFlowBox *box,
|
||||
GtkMovementStep step,
|
||||
@ -3030,8 +3034,7 @@ gtk_flow_box_move_cursor (GtkFlowBox *box,
|
||||
GtkAdjustment *adjustment;
|
||||
gboolean vertical;
|
||||
|
||||
/* Without "can-focus" flag fall back to the default behavior immediately */
|
||||
if (!gtk_widget_get_can_focus (GTK_WIDGET (box)))
|
||||
if (priv->disable_move_cursor)
|
||||
return FALSE;
|
||||
|
||||
vertical = priv->orientation == GTK_ORIENTATION_VERTICAL;
|
||||
|
26
gtk/gtkflowboxprivate.h
Normal file
26
gtk/gtkflowboxprivate.h
Normal file
@ -0,0 +1,26 @@
|
||||
/* GTK - The GIMP Toolkit
|
||||
*
|
||||
* Copyright (C) 2020 Red Hat, Inc
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __GTK_FLOW_BOX_PRIVATE_H__
|
||||
#define __GTK_FLOW_BOX_PRIVATE_H__
|
||||
|
||||
#include "gtkflowbox.h"
|
||||
|
||||
void gtk_flow_box_disable_move_cursor (GtkFlowBox *box);
|
||||
|
||||
#endif
|
@ -42,6 +42,7 @@
|
||||
<property name="homogeneous">1</property>
|
||||
<property name="selection-mode">none</property>
|
||||
<signal name="child-activated" handler="emoji_activated"/>
|
||||
<signal name="keynav-failed" handler="keynav_failed"/>
|
||||
<child>
|
||||
<object class="GtkGestureLongPress">
|
||||
<signal name="pressed" handler="long_pressed_cb"/>
|
||||
@ -66,6 +67,7 @@
|
||||
<property name="homogeneous">1</property>
|
||||
<property name="selection-mode">none</property>
|
||||
<signal name="child-activated" handler="emoji_activated"/>
|
||||
<signal name="keynav-failed" handler="keynav_failed"/>
|
||||
<child>
|
||||
<object class="GtkGestureLongPress">
|
||||
<signal name="pressed" handler="long_pressed_cb"/>
|
||||
@ -90,6 +92,7 @@
|
||||
<property name="homogeneous">1</property>
|
||||
<property name="selection-mode">none</property>
|
||||
<signal name="child-activated" handler="emoji_activated"/>
|
||||
<signal name="keynav-failed" handler="keynav_failed"/>
|
||||
<child>
|
||||
<object class="GtkGestureLongPress">
|
||||
<signal name="pressed" handler="long_pressed_cb"/>
|
||||
@ -114,6 +117,7 @@
|
||||
<property name="homogeneous">1</property>
|
||||
<property name="selection-mode">none</property>
|
||||
<signal name="child-activated" handler="emoji_activated"/>
|
||||
<signal name="keynav-failed" handler="keynav_failed"/>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
@ -127,6 +131,7 @@
|
||||
<property name="homogeneous">1</property>
|
||||
<property name="selection-mode">none</property>
|
||||
<signal name="child-activated" handler="emoji_activated"/>
|
||||
<signal name="keynav-failed" handler="keynav_failed"/>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
@ -140,6 +145,7 @@
|
||||
<property name="homogeneous">1</property>
|
||||
<property name="selection-mode">none</property>
|
||||
<signal name="child-activated" handler="emoji_activated"/>
|
||||
<signal name="keynav-failed" handler="keynav_failed"/>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
@ -153,6 +159,7 @@
|
||||
<property name="homogeneous">1</property>
|
||||
<property name="selection-mode">none</property>
|
||||
<signal name="child-activated" handler="emoji_activated"/>
|
||||
<signal name="keynav-failed" handler="keynav_failed"/>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
@ -166,6 +173,7 @@
|
||||
<property name="homogeneous">1</property>
|
||||
<property name="selection-mode">none</property>
|
||||
<signal name="child-activated" handler="emoji_activated"/>
|
||||
<signal name="keynav-failed" handler="keynav_failed"/>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
@ -179,6 +187,7 @@
|
||||
<property name="homogeneous">1</property>
|
||||
<property name="selection-mode">none</property>
|
||||
<signal name="child-activated" handler="emoji_activated"/>
|
||||
<signal name="keynav-failed" handler="keynav_failed"/>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
@ -192,6 +201,7 @@
|
||||
<property name="homogeneous">1</property>
|
||||
<property name="selection-mode">none</property>
|
||||
<signal name="child-activated" handler="emoji_activated"/>
|
||||
<signal name="keynav-failed" handler="keynav_failed"/>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
|
Loading…
Reference in New Issue
Block a user