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 c7a170a225441dbb6c5112289f3e049027e206cb
Author: Cedric BAIL <[email protected]>
AuthorDate: Wed Nov 18 22:53:41 2026 -0600

    elementary: a deleted view leaves its factory's cached items alive
    
    A collection view makes each item a member of its pan and a sub-object
    of itself, and gives it back to its factory when it scrolls away. A
    caching factory keeps such items for the next view it serves, but they
    were still the old view's members and sub-objects: deleting the view
    deleted them with its pan, and the next view got dead items ("No widget
    data"). The item's container also kept pointing at the view.
    
    The container is cleared on release. The pan and sub-object links are
    cut once, when the view is invalidated, for every item a factory then
    holds: doing it on each release made every reuse a reparent, with a
    full theme apply under a custom theme or scale (five times slower
    scrolling) and accessibility events for each row.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 src/lib/elementary/efl_ui_collection_view.c        |  41 ++++++
 src/tests/elementary/efl_ui_test_collection_view.c | 151 +++++++++++++++++++++
 2 files changed, 192 insertions(+)

diff --git a/src/lib/elementary/efl_ui_collection_view.c b/src/lib/elementary/efl_ui_collection_view.c
index 5eccb5b5ac..485d4d94a5 100644
--- a/src/lib/elementary/efl_ui_collection_view.c
+++ b/src/lib/elementary/efl_ui_collection_view.c
@@ -291,6 +291,8 @@ _entity_cleanup(Efl_Ui_Collection_View *obj, Efl_Ui_Factory *factory,
    efl_event_callback_array_del(entities[0], active_item_cbs(), obj);
    efl_replace(&item->entity, NULL);
    efl_event_callback_call(obj, EFL_UI_COLLECTION_VIEW_EVENT_ITEM_UNREALIZED, entities[0]);
+   /* A raw pointer, and the view may be gone by the time it is reused. */
+   efl_ui_item_container_set(entities[0], NULL);
    if (!scheduled_release)
      {
         efl_ui_factory_release(factory, EINA_C_ARRAY_ITERATOR_NEW(entities));
@@ -764,6 +766,7 @@ _entity_fetched_cb(Eo *obj, void *data, const Eina_Value v)
         if (!lookup)
           {
              Efl_Gfx_Entity *entities[1] = { child };
+             efl_ui_item_container_set(child, NULL);
              efl_ui_factory_release(pd->factory, EINA_C_ARRAY_ITERATOR_NEW(entities));
              continue;
           }
@@ -2695,6 +2698,43 @@ _efl_ui_collection_view_efl_object_constructor(Eo *obj, Efl_Ui_Collection_View_D
    return obj;
 }
 
+/* The entities the factory is holding, taken out of this view.
+ *
+ * The factory keeps what it is given back, to hand to whoever asks next, and
+ * it outlives the view. What the view made of an entity when it took it --
+ * a member of its pan, a sub-object of the widget -- is left in place while
+ * it is held, because undoing and redoing it on every reuse is a theme
+ * applied again each time the chain has a scale or a theme of its own. But
+ * both take their members down with them, and the pan is deleted right after
+ * this: a view deleted with entities held left the factory with entities
+ * that were gone, and the next view it served was handed those. After
+ * _all_cleanup() every entity this view made is held. */
+static void
+_factory_held_detach(Efl_Ui_Collection_View *obj, Efl_Ui_Collection_View_Data *pd)
+{
+   Eina_Iterator *it;
+   Eina_Array held;
+   Efl_Gfx_Entity *entity;
+   unsigned int i;
+
+   if (!pd->pan) return;
+
+   eina_array_step_set(&held, sizeof (Eina_Array), 16);
+   it = efl_canvas_group_members_iterate(pd->pan);
+   EINA_ITERATOR_FOREACH(it, entity)
+     if (efl_key_data_get(entity, COLLECTION_VIEW_MANAGED) == COLLECTION_VIEW_MANAGED_YES)
+       eina_array_push(&held, entity);
+   eina_iterator_free(it);
+
+   for (i = 0; i < eina_array_count(&held); i++)
+     {
+        entity = eina_array_data_get(&held, i);
+        efl_canvas_group_member_remove(pd->pan, entity);
+        efl_ui_widget_sub_object_del(obj, entity);
+     }
+   eina_array_flush(&held);
+}
+
 EOLIAN static void
 _efl_ui_collection_view_efl_object_invalidate(Eo *obj,
                                               Efl_Ui_Collection_View_Data *pd)
@@ -2740,6 +2780,7 @@ _efl_ui_collection_view_efl_object_invalidate(Eo *obj,
      }
 
    _all_cleanup(obj, pd);
+   _factory_held_detach(obj, pd);
 
    /* Every entity went back to the factory above: the view has no further
     * use for it, and the reference it took in factory_set is the one thing
diff --git a/src/tests/elementary/efl_ui_test_collection_view.c b/src/tests/elementary/efl_ui_test_collection_view.c
index fd264ccbdd..e626af3c6c 100644
--- a/src/tests/elementary/efl_ui_test_collection_view.c
+++ b/src/tests/elementary/efl_ui_test_collection_view.c
@@ -3,6 +3,7 @@
 #endif
 
 #include <Efl_Ui.h>
+#include <Elementary.h>
 #include "efl_ui_suite.h"
 #include "efl_ui_homogeneous_model.eo.h"
 #include "efl_ui_exact_model.eo.h"
@@ -2707,8 +2708,158 @@ EFL_START_TEST(efl_ui_collection_view_keeps_a_given_select_model)
 }
 EFL_END_TEST
 
+static void
+_realized_alive_cb(void *data, const Efl_Event *ev)
+{
+   int *counts = data;
+
+   counts[0]++;
+   if (efl_invalidated_get(ev->info)) counts[1]++;
+}
+
+/* A factory outlives the view it served, and keeps what the view gave back
+ * to reuse for the next one. What it keeps must still be there: the items
+ * were members of the dead view's pan, which took them down with it. */
+static void
+_factory_outlives_view(const Efl_Class *klass)
+{
+   Efl_Ui_Win *win;
+   Efl_Model *model;
+   Efl_Ui_Collection_View *first, *second;
+   Efl_Ui_Factory *fl;
+   int counts[2] = { 0, 0 };
+
+   win = win_add(NULL, "win", EFL_UI_WIN_TYPE_BASIC);
+   efl_gfx_entity_size_set(win, EINA_SIZE2D(200, 200));
+
+   model = _make_model(win);
+   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));
+   first = efl_add(klass, win,
+                   efl_ui_collection_view_factory_set(efl_added, fl),
+                   efl_ui_view_model_set(efl_added, model));
+   efl_content_set(win, first);
+   efl_gfx_entity_visible_set(win, EINA_TRUE);
+   get_me_to_those_events(first);
+
+   efl_del(first);
+   get_me_to_those_events(win);
+
+   second = efl_add(klass, win,
+                    efl_ui_collection_view_factory_set(efl_added, fl),
+                    efl_ui_view_model_set(efl_added, model),
+                    efl_event_callback_add(efl_added, EFL_UI_COLLECTION_VIEW_EVENT_ITEM_REALIZED,
+                                           _realized_alive_cb, counts));
+   efl_content_set(win, second);
+   get_me_to_those_events(second);
+
+   ck_assert_int_gt(counts[0], 0);
+   ck_assert_int_eq(counts[1], 0);
+}
+
+EFL_START_TEST(efl_ui_collection_view_factory_outlives_a_deleted_view)
+{
+   _factory_outlives_view(EFL_UI_COLLECTION_VIEW_CLASS);
+}
+EFL_END_TEST
+
+EFL_START_TEST(efl_ui_list_view_factory_outlives_a_deleted_view)
+{
+   _factory_outlives_view(EFL_UI_LIST_VIEW_CLASS);
+}
+EFL_END_TEST
+
+static void
+_theme_applied_cb(void *data, const Efl_Event *ev EINA_UNUSED)
+{
+   int *count = data;
+
+   (*count)++;
+}
+
+static void
+_count_themes_cb(void *data, const Efl_Event *ev)
+{
+   int *counts = data;
+
+   /* One counter per item made, in the order they are made. */
+   efl_event_callback_add(ev->info, EFL_UI_LAYOUT_EVENT_THEME_CHANGED,
+                          _theme_applied_cb, &counts[1 + counts[0]++]);
+}
+
+/* A row's item goes back to the factory and comes out again as the view
+ * scrolls. What it is as the view's sub-object is not taken apart and put
+ * together each time: with a scale or a theme of its own in the chain, that
+ * is the whole theme applied again for every row that comes into view. */
+static void
+_scroll_does_not_apply_themes_again(double scale, Eina_Bool own_theme)
+{
+   Efl_Ui_Win *win;
+   Efl_Model *model;
+   Efl_Ui_Collection_View *lv;
+   Efl_Ui_Factory *fl;
+   int counts[64] = { 0 };
+   int i, before, after, made;
+   Elm_Theme *th = NULL;
+
+   win = win_add(NULL, "win", EFL_UI_WIN_TYPE_BASIC);
+   efl_gfx_entity_size_set(win, EINA_SIZE2D(200, 200));
+   model = _make_model(win);
+   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),
+                efl_event_callback_add(efl_added, EFL_UI_FACTORY_EVENT_ITEM_CONSTRUCTING,
+                                       _count_themes_cb, counts));
+   lv = efl_add(EFL_UI_LIST_VIEW_CLASS, win,
+                efl_gfx_entity_scale_set(efl_added, scale),
+                efl_ui_collection_view_factory_set(efl_added, fl),
+                efl_ui_view_model_set(efl_added, model));
+   if (own_theme)
+     {
+        th = elm_theme_new();
+        elm_theme_set(th, "default");
+        elm_object_theme_set(lv, th);
+     }
+   efl_content_set(win, lv);
+   efl_gfx_entity_visible_set(win, EINA_TRUE);
+   get_me_to_those_events(lv);
+
+   made = counts[0];
+   ck_assert_int_gt(made, 0);
+   for (i = 0, before = 0; i < made; i++) before += counts[1 + i];
+
+   for (i = 0; i < 6; i++)
+     {
+        efl_ui_scrollable_content_pos_set(lv, EINA_POSITION2D(0, (i % 2) ? 0 : 400 + (i * 20)));
+        get_me_to_those_events(lv);
+     }
+
+   /* Only the items made on the way count for anything: the ones that were
+      there are reused and left as they are. */
+   for (i = 0, after = 0; i < made; i++) after += counts[1 + i];
+   ck_assert_int_eq(after, before);
+   if (th) elm_theme_free(th);
+}
+
+EFL_START_TEST(efl_ui_list_view_scroll_keeps_the_themes_of_reused_items)
+{
+   _scroll_does_not_apply_themes_again(2.0, EINA_FALSE);
+}
+EFL_END_TEST
+
+EFL_START_TEST(efl_ui_list_view_scroll_keeps_the_themes_with_a_theme_of_its_own)
+{
+   _scroll_does_not_apply_themes_again(1.0, EINA_TRUE);
+}
+EFL_END_TEST
+
 void efl_ui_test_collection_view(TCase *tc)
 {
+   tcase_add_test(tc, efl_ui_list_view_scroll_keeps_the_themes_of_reused_items);
+   tcase_add_test(tc, efl_ui_list_view_scroll_keeps_the_themes_with_a_theme_of_its_own);
+   tcase_add_test(tc, efl_ui_collection_view_factory_outlives_a_deleted_view);
+   tcase_add_test(tc, efl_ui_list_view_factory_outlives_a_deleted_view);
    tcase_add_test(tc, test_efl_ui_collection_view_basic);
    tcase_add_test(tc, efl_ui_collection_view_manager_twice);
    tcase_add_test(tc, efl_ui_collection_view_bare);

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to