This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch master
in repository efl.
View the commit online.
commit a2b8d07603195cfa001eb2970b018acf5d345b83
Author: Cedric BAIL <[email protected]>
AuthorDate: Mon Oct 26 15:30:29 2026 -0600
elementary: tab goes through a collection view's rows, in and out of it
Keyboard focus could not get through a list or grid view:
- Shift+Tab from below entered it on the last row's item, but the view
still showed its top, so the next Shift+Tab found no item for the row
before and focus fell out of the view.
- Tab went down the rows the view had items for, then out of the view a
few rows past the bottom of what it showed. The view scrolled to the
focused row with an animation, and focus moved on to rows whose items
were not built yet.
- Tab and Shift+Tab inside the view followed the order the focus manager
had heard of the items in, which is not the rows' order once items are
reused for other rows.
The focus manager of the view now:
- moves Tab and Shift+Tab to the next or previous row by index, as it
already did for rows outside the visible range;
- scrolls whichever row focus lands on into view, however it got there,
without animation, so the rows around it are built for the next key;
- keeps focus where it is when the next row's item is still being built,
instead of leaving the view;
- enters on the row focus was on last, whose item is kept for that, or
else on the first row from above and the last row from below;
- does not remember the row it picks when the window first focuses the
view to put it in a known state, which happens before every entry and
would otherwise make Shift+Tab land on the first row.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
src/lib/elementary/efl_ui_collection_view.c | 124 +++++++++++++++------
.../efl_ui_collection_view_focus_manager.eo | 1 +
src/tests/elementary/efl_ui_test_collection_view.c | 97 ++++++++++++++++
3 files changed, 191 insertions(+), 31 deletions(-)
diff --git a/src/lib/elementary/efl_ui_collection_view.c b/src/lib/elementary/efl_ui_collection_view.c
index fdab2ac274..f0c34eb869 100644
--- a/src/lib/elementary/efl_ui_collection_view.c
+++ b/src/lib/elementary/efl_ui_collection_view.c
@@ -84,7 +84,8 @@ struct _Efl_Ui_Collection_View_Data
struct {
Efl_Gfx_Entity *last; // The last item of the collection, so focus can start by the end if necessary.
- Efl_Gfx_Entity *previously; // The previously selected item in the collection, so focus can come back to it.
+ // The item focus was on last in the collection, so focus can come back to it.
+ Efl_Gfx_Entity *previously;
} focus;
unsigned int start_id;
@@ -1444,12 +1445,15 @@ _row_selected(Efl_Model *model)
/* A selected row keeps its item while it is off screen, so that what
last_selected hands out stays the object the application was given. So
- does the last row, which focus enters the view on from below. */
+ does the last row, which focus enters the view on from below, and the
+ row focus was on, which it comes back to. */
static Eina_Bool
_lookup_kept(Efl_Ui_Collection_View_Data *pd, Efl_Ui_Collection_Item_Lookup *lookup)
{
if (!lookup->item.entity) return EINA_FALSE;
- return (lookup->item.entity == pd->focus.last) || _row_selected(lookup->item.model);
+ return (lookup->item.entity == pd->focus.last) ||
+ (lookup->item.entity == pd->focus.previously) ||
+ _row_selected(lookup->item.model);
}
// An RbTree has the nice property of sorting content. The smaller than the root being in
@@ -2624,18 +2628,6 @@ _efl_ui_collection_view_efl_ui_focus_manager_move(Eo *obj, Efl_Ui_Collection_Vie
}
}
}
- else
- {
- Efl_Model *model;
- Eina_Value *vindex;
- unsigned int index;
-
- model = efl_ui_view_model_get(new_obj);
- vindex = efl_model_property_get(model, "child.index");
- if (eina_value_uint_convert(vindex, &index))
- _item_scroll_internal(obj, pd, index, .0, EINA_TRUE);
- eina_value_free(vindex);
- }
return new_obj;
}
@@ -2710,39 +2702,104 @@ _assert_item_available(Eo *item, int new_id, Efl_Ui_Collection_View_Data *pd)
efl_gfx_entity_visible_set(item, EINA_TRUE);
efl_gfx_entity_geometry_set(item, efl_ui_position_manager_entity_position_single_item(pd->manager, new_id));
}
+
+static Efl_Ui_Item *
+_index_entity(Efl_Ui_Collection_View_Data *pd, unsigned int index)
+{
+ Efl_Ui_Collection_Item_Lookup *lookup;
+
+ lookup = (void*) eina_rbtree_inline_lookup(pd->cache, &index, sizeof (index),
+ _cache_tree_lookup, NULL);
+ return lookup ? lookup->item.entity : NULL;
+}
+
+/* The item focus goes to as it comes into the view: back to the row it was
+ on, or else the first row -- the last one, coming in backwards from
+ below, which the view keeps an item of for that. If that row has no
+ item, the first or last row shown. */
+static Efl_Ui_Item *
+_entry_item(Efl_Ui_Collection_View_Data *pd, Eina_Bool backwards)
+{
+ Efl_Ui_Item *item;
+ unsigned int count;
+
+ if (pd->focus.previously) return pd->focus.previously;
+ if (!pd->model) return NULL;
+ count = efl_model_children_count_get(pd->model);
+ if (!count) return NULL;
+
+ item = _index_entity(pd, backwards ? count - 1 : 0);
+ if (!item) item = _index_entity(pd, backwards ? pd->end_id : pd->start_id);
+ return item;
+}
+
EOLIAN static void
_efl_ui_collection_view_focus_manager_efl_ui_focus_manager_manager_focus_set(Eo *obj, Efl_Ui_Collection_View_Focus_Manager_Data *pd, Efl_Ui_Focus_Object *focus)
{
MY_DATA_GET(pd->collection, cpd);
Efl_Ui_Item *item = NULL;
+ Eina_Bool remember = EINA_TRUE;
unsigned int item_id;
if (focus == efl_ui_focus_manager_root_get(obj))
{
- // Find last item
- item = cpd->focus.previously;
- if (!item) item = cpd->focus.last;
- if (item) item_id = _lookup_entity_index(item, NULL);
- else item_id = efl_model_children_count_get(cpd->model) - 1;
+ /* Focus given to the view itself: the manager would pick whichever
+ item it heard of first, which once items are reused for other
+ rows can be any row. This is also how the manager puts a view
+ it starts to send focus to in a known state, before focus comes
+ in from a direction: what is picked here is not remembered as
+ the row focus was on. */
+ item = _entry_item(cpd, EINA_FALSE);
+ remember = EINA_FALSE;
+ if (!item)
+ {
+ efl_ui_focus_manager_focus_set(efl_super(obj,
+ EFL_UI_COLLECTION_VIEW_FOCUS_MANAGER_CLASS),
+ focus);
+ return;
+ }
+ focus = item;
}
- else
- {
- item = _find_item(obj, cpd, focus);
- if (!item) return ;
- item_id = _lookup_entity_index(item, NULL);
- }
+ item = _find_item(obj, cpd, focus);
+ if (!item) return ;
// If this is NULL then we are before finalize, we cannot serve any sane value here
if (!cpd->manager) return ;
+ item_id = _lookup_entity_index(item, NULL);
if (ITEM_IS_OUTSIDE_VISIBLE(item_id))
{
_assert_item_available(item, item_id, cpd);
}
+ /* However focus got there, the row it is on is shown. Without
+ animation: the rows around it are only built as the view scrolls, and
+ the next key may already want one of them. */
+ _item_scroll_internal(pd->collection, cpd, item_id, .0, EINA_FALSE);
+ if (remember) efl_replace(&cpd->focus.previously, item);
efl_ui_focus_manager_focus_set(efl_super(obj, EFL_UI_COLLECTION_VIEW_FOCUS_MANAGER_CLASS), focus);
}
+EOLIAN static void
+_efl_ui_collection_view_focus_manager_efl_ui_focus_manager_setup_on_first_touch(Eo *obj,
+ Efl_Ui_Collection_View_Focus_Manager_Data *pd,
+ Efl_Ui_Focus_Direction direction,
+ Efl_Ui_Focus_Object *entry)
+{
+ MY_DATA_GET(pd->collection, cpd);
+ Efl_Ui_Item *item = NULL;
+
+ /* The manager would come in backwards on the last item it heard of. */
+ if (direction == EFL_UI_FOCUS_DIRECTION_PREVIOUS)
+ item = _entry_item(cpd, EINA_TRUE);
+ if (item)
+ efl_ui_focus_manager_focus_set(obj, item);
+ else
+ efl_ui_focus_manager_setup_on_first_touch(efl_super(obj,
+ EFL_UI_COLLECTION_VIEW_FOCUS_MANAGER_CLASS),
+ direction, entry);
+}
+
static int
_id_from_item(Efl_Ui_Item *item, unsigned int *index)
{
@@ -2777,7 +2834,11 @@ _efl_ui_collection_view_focus_manager_efl_ui_focus_manager_request_move(Eo *obj,
if (!_id_from_item(item, &item_id))
goto end;
- if (ITEM_IS_OUTSIDE_VISIBLE(item_id))
+ /* Tab goes through the rows in their order, which the order the manager
+ heard of their items in says nothing of once items are reused. */
+ if (ITEM_IS_OUTSIDE_VISIBLE(item_id) ||
+ (direction == EFL_UI_FOCUS_DIRECTION_NEXT) ||
+ (direction == EFL_UI_FOCUS_DIRECTION_PREVIOUS))
{
unsigned int new_id;
@@ -2812,15 +2873,17 @@ _efl_ui_collection_view_focus_manager_efl_ui_focus_manager_request_move(Eo *obj,
lookup = (void*) eina_rbtree_inline_lookup(cpd->cache, &search_index,
sizeof (search_index), _cache_tree_lookup,
NULL);
- if (lookup)
+ if (lookup && lookup->item.entity)
{
_assert_item_available(lookup->item.entity, new_id, cpd);
new_item = lookup->item.entity;
}
else
{
- ERR("This item cannot get focus right now. It should be visible first.");
- new_item = NULL;
+ /* The row is there, but its item is still being built
+ as the view scrolls: focus stays where it is rather
+ than leave the view, and the next key finds it. */
+ new_item = item;
}
#endif
}
@@ -2831,7 +2894,6 @@ _efl_ui_collection_view_focus_manager_efl_ui_focus_manager_request_move(Eo *obj,
}
end:
- efl_replace(&cpd->focus.previously, new_item);
return new_item;
}
diff --git a/src/lib/elementary/efl_ui_collection_view_focus_manager.eo b/src/lib/elementary/efl_ui_collection_view_focus_manager.eo
index bd4e27727b..afd8f2fc0b 100644
--- a/src/lib/elementary/efl_ui_collection_view_focus_manager.eo
+++ b/src/lib/elementary/efl_ui_collection_view_focus_manager.eo
@@ -3,5 +3,6 @@ class @beta Efl.Ui.Collection_View_Focus_Manager extends Efl.Ui.Focus.Manager_Ca
implements {
Efl.Ui.Focus.Manager.manager_focus { set; }
Efl.Ui.Focus.Manager.request_move;
+ Efl.Ui.Focus.Manager.setup_on_first_touch;
}
}
diff --git a/src/tests/elementary/efl_ui_test_collection_view.c b/src/tests/elementary/efl_ui_test_collection_view.c
index 63052ddc38..1a845ee697 100644
--- a/src/tests/elementary/efl_ui_test_collection_view.c
+++ b/src/tests/elementary/efl_ui_test_collection_view.c
@@ -390,6 +390,101 @@ EFL_START_TEST(efl_ui_collection_view_manager_twice)
}
EFL_END_TEST
+/* A list between two buttons, its rows more than it shows. */
+static Eo *
+_list_between(Eo **above, Eo **below)
+{
+ Efl_Ui_Win *win;
+ Efl_Ui_Factory *fl;
+ Eo *box, *lv;
+ int i;
+
+ win = win_add(NULL, "win", EFL_UI_WIN_TYPE_BASIC);
+ efl_gfx_entity_size_set(win, EINA_SIZE2D(200, 300));
+ box = efl_add(EFL_UI_BOX_CLASS, win);
+ efl_content_set(win, box);
+ *above = efl_add(EFL_UI_BUTTON_CLASS, box, efl_pack_end(box, efl_added));
+ fl = efl_add(EFL_UI_LAYOUT_FACTORY_CLASS, win,
+ efl_ui_property_bind(efl_added, "text", "title"),
+ efl_ui_widget_factory_item_class_set(efl_added, EFL_UI_LIST_DEFAULT_ITEM_CLASS));
+ lv = efl_add(EFL_UI_LIST_VIEW_CLASS, box,
+ efl_ui_collection_view_factory_set(efl_added, fl),
+ efl_ui_view_model_set(efl_added, _make_model(win)),
+ efl_pack_end(box, efl_added));
+ *below = efl_add(EFL_UI_BUTTON_CLASS, box, efl_pack_end(box, efl_added));
+ get_me_to_those_events(lv);
+ for (i = 0; i < 50; i++)
+ {
+ ecore_main_loop_iterate();
+ }
+ return lv;
+}
+
+/* Moves focus as a key would, then lets the view catch up, and says which
+ row has focus in the view, or -1 if it is not in the view. */
+static int
+_tab(Eo *lv, Efl_Ui_Focus_Direction direction)
+{
+ Eo *win = efl_provider_find(lv, EFL_UI_WIN_CLASS);
+ Eo *focus;
+ int i;
+
+ efl_ui_focus_manager_move(win, direction);
+ for (i = 0; i < 10; i++)
+ {
+ ecore_main_loop_iterate();
+ }
+ focus = efl_ui_focus_manager_focus_get(win);
+ if (focus != lv) return -1;
+ focus = efl_ui_focus_manager_focus_get(lv);
+ return efl_isa(focus, EFL_UI_ITEM_CLASS) ? _item_row(focus) : -1;
+}
+
+/* Tab enters a list on its first row and goes through its rows in order,
+ past those it shows -- the list scrolls to each -- and out of it after
+ the last one. Shift+Tab on the first row leaves it upwards. */
+EFL_START_TEST(test_efl_ui_collection_view_tab)
+{
+ Eo *win, *lv, *above, *below;
+ int i;
+
+ lv = _list_between(&above, &below);
+ win = efl_provider_find(lv, EFL_UI_WIN_CLASS);
+ efl_ui_focus_util_focus(above);
+ ck_assert_int_eq(_tab(lv, EFL_UI_FOCUS_DIRECTION_NEXT), 0);
+ ck_assert_int_eq(_tab(lv, EFL_UI_FOCUS_DIRECTION_PREVIOUS), -1);
+ ck_assert_ptr_eq(efl_ui_focus_manager_focus_get(win), above);
+
+ for (i = 0; i < NUM_ITEMS; i++)
+ {
+ ck_assert_int_eq(_tab(lv, EFL_UI_FOCUS_DIRECTION_NEXT), i);
+ if (i == 10) ck_assert_int_gt(efl_ui_scrollable_content_pos_get(lv).y, 0);
+ }
+ ck_assert_int_eq(_tab(lv, EFL_UI_FOCUS_DIRECTION_NEXT), -1);
+ ck_assert_ptr_eq(efl_ui_focus_manager_focus_get(win), below);
+}
+EFL_END_TEST
+
+/* Shift+Tab from below enters a list on its last row, though it shows the
+ top, and goes back through the rows; focus coming back to the list
+ comes back to the row it left. */
+EFL_START_TEST(test_efl_ui_collection_view_shift_tab)
+{
+ Eo *lv, *above, *below;
+ int i;
+
+ lv = _list_between(&above, &below);
+ efl_ui_focus_util_focus(below);
+ for (i = NUM_ITEMS - 1; i > NUM_ITEMS - 10; i--)
+ {
+ ck_assert_int_eq(_tab(lv, EFL_UI_FOCUS_DIRECTION_PREVIOUS), i);
+ }
+
+ efl_ui_focus_util_focus(above);
+ ck_assert_int_eq(_tab(lv, EFL_UI_FOCUS_DIRECTION_NEXT), NUM_ITEMS - 9);
+}
+EFL_END_TEST
+
void efl_ui_test_collection_view(TCase *tc)
{
tcase_add_test(tc, test_efl_ui_collection_view_basic);
@@ -397,5 +492,7 @@ void efl_ui_test_collection_view(TCase *tc)
tcase_add_test(tc, test_efl_ui_collection_view_select);
tcase_add_test(tc, test_efl_ui_collection_view_last_selected_is_an_item);
tcase_add_test(tc, test_efl_ui_collection_view_last_row_kept);
+ tcase_add_test(tc, test_efl_ui_collection_view_tab);
+ tcase_add_test(tc, test_efl_ui_collection_view_shift_tab);
tcase_add_test(tc, test_efl_ui_collection_view_sizes_agree);
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.