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 cf5ae64bb3109eb9367d769a03426daec9fa5b37
Author: Cedric BAIL <[email protected]>
AuthorDate: Fri Nov 6 00:08:51 2026 -0600
elementary: a cached item is announced as building once when reused
The Caching_Factory raised item,building for items it made and for
themed ones it took back from the cache, but not for plain ones taken
back from the cache. Part bindings the Widget_Factory removes on
releasing were then never bound again, and the item stayed
calculation-locked. Raise it there too.
A factory binds an item again every time it hands one out, a reused one
too, and with item,building raised for those the same binding was added
to the item on each trip through the cache, so a model change updated
it once per trip. Binding a part, or a widget key, to the property it is
already bound to now replaces the binding instead of adding another.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
src/lib/elementary/efl_ui_caching_factory.c | 1 +
src/lib/elementary/efl_ui_layout.c | 33 +++++-
src/lib/elementary/efl_ui_widget.c | 32 ++++++
src/tests/elementary/efl_ui_test_caching_factory.c | 128 ++++++++++++++++++++-
src/tests/elementary/efl_ui_test_property_bind.c | 28 +++++
5 files changed, 220 insertions(+), 2 deletions(-)
diff --git a/src/lib/elementary/efl_ui_caching_factory.c b/src/lib/elementary/efl_ui_caching_factory.c
index 33c61af910..0e35f33cc6 100644
--- a/src/lib/elementary/efl_ui_caching_factory.c
+++ b/src/lib/elementary/efl_ui_caching_factory.c
@@ -261,6 +261,7 @@ _efl_ui_caching_factory_efl_ui_factory_create(Eo *obj,
_efl_ui_caching_factory_remove(pd, pd->cache, w);
efl_ui_view_model_set(w, model);
+ efl_event_callback_call(obj, EFL_UI_FACTORY_EVENT_ITEM_BUILDING, w);
eina_value_array_append(&gr->done, w);
diff --git a/src/lib/elementary/efl_ui_layout.c b/src/lib/elementary/efl_ui_layout.c
index 2ffbcbd4ce..d18ab3a746 100644
--- a/src/lib/elementary/efl_ui_layout.c
+++ b/src/lib/elementary/efl_ui_layout.c
@@ -2691,6 +2691,25 @@ _efl_ui_layout_base_model_watch(Eo *obj, Efl_Ui_Layout_Data *pd)
_efl_ui_layout_base_model_register(obj, pd, model);
}
+static Eina_Bool
+_efl_ui_layout_connected(Eina_Hash *hash, Eina_Stringshare *property, const char *part)
+{
+ Eina_Iterator *it = eina_hash_iterator_tuple_new(hash);
+ Eina_Hash_Tuple *tuple;
+ Eina_Bool found = EINA_FALSE;
+
+ EINA_ITERATOR_FOREACH(it, tuple)
+ {
+ if ((tuple->key == property) && !strcmp(tuple->data, part))
+ {
+ found = EINA_TRUE;
+ break;
+ }
+ }
+ eina_iterator_free(it);
+ return found;
+}
+
EOLIAN static Eina_Error
_efl_ui_layout_base_efl_ui_property_bind_property_bind(Eo *obj, Efl_Ui_Layout_Data *pd, const char *key, const char *property)
{
@@ -2701,6 +2720,7 @@ _efl_ui_layout_base_efl_ui_property_bind_property_bind(Eo *obj, Efl_Ui_Layout_Da
char *data = ""
Efl_Model *model;
Eina_Error r;
+ Eina_Bool duplicate = EINA_FALSE;
// First try binding with property on the Widget
r = efl_ui_property_bind(efl_super(obj, EFL_UI_LAYOUT_BASE_CLASS), key, property);
@@ -2717,7 +2737,6 @@ _efl_ui_layout_base_efl_ui_property_bind_property_bind(Eo *obj, Efl_Ui_Layout_Da
sprop = eina_stringshare_add(property);
- // FIXME: prevent double connect of key to multiple property ?
if (strncmp(SIGNAL_PREFIX, key, sizeof(SIGNAL_PREFIX) - 1) == 0)
{
hash = pd->connect.signals;
@@ -2733,6 +2752,12 @@ _efl_ui_layout_base_efl_ui_property_bind_property_bind(Eo *obj, Efl_Ui_Layout_Da
{
// FIXME: remove the entry from the hash ?
}
+ else if (_efl_ui_layout_connected(hash, sprop, data))
+ {
+ // Binding the same part to the same property again, as a factory
+ // does for an item it reuses, changes nothing
+ duplicate = EINA_TRUE;
+ }
else
{
eina_hash_add(hash, sprop, data);
@@ -2748,6 +2773,12 @@ _efl_ui_layout_base_efl_ui_property_bind_property_bind(Eo *obj, Efl_Ui_Layout_Da
_efl_ui_layout_view_model_property_update(pd, data, sprop);
}
+ if (duplicate)
+ {
+ eina_stringshare_del(sprop);
+ free(data);
+ }
+
sk = eina_stringshare_add(key);
efl_event_callback_call(obj, EFL_UI_PROPERTY_BIND_EVENT_PROPERTY_BOUND, (void*) sk);
eina_stringshare_del(sk);
diff --git a/src/lib/elementary/efl_ui_widget.c b/src/lib/elementary/efl_ui_widget.c
index d879fbd66d..e2b1fb75ca 100644
--- a/src/lib/elementary/efl_ui_widget.c
+++ b/src/lib/elementary/efl_ui_widget.c
@@ -6104,6 +6104,34 @@ _efl_ui_widget_model_unregister(Eo *obj, Efl_Ui_Widget_Data *pd)
_efl_ui_widget_model_provider_invalidate(obj, NULL);
}
+static void
+_efl_ui_property_unbind(Efl_Ui_Widget_Data *pd, const char *part, const char *key)
+{
+ Efl_Ui_Property_Bound *prop, *found = NULL;
+ Eina_Stringshare *ss_part = eina_stringshare_add(part);
+ Eina_Stringshare *ss_key = eina_stringshare_add(key);
+ Eina_Iterator *it;
+
+ it = eina_hash_iterator_data_new(pd->properties.model_lookup);
+ EINA_ITERATOR_FOREACH(it, prop)
+ {
+ if ((prop->part == ss_part) && (prop->key == ss_key))
+ {
+ found = prop;
+ break;
+ }
+ }
+ eina_iterator_free(it);
+
+ if (found)
+ {
+ if (!found->part) eina_hash_del(pd->properties.view_lookup, found->key, found);
+ eina_hash_del(pd->properties.model_lookup, found->property, found);
+ }
+ eina_stringshare_del(ss_part);
+ eina_stringshare_del(ss_key);
+}
+
static Eina_Error
_efl_ui_property_bind(Eo *widget, Eo *target, Efl_Ui_Widget_Data *pd,
const char *part, const char *key, const char *property)
@@ -6136,6 +6164,10 @@ _efl_ui_property_bind(Eo *widget, Eo *target, Efl_Ui_Widget_Data *pd,
_efl_ui_widget_model_register(widget, pd);
}
+ // One binding per part and key: a factory binds again every item it
+ // reuses, and the old binding would otherwise keep updating it as well
+ _efl_ui_property_unbind(pd, part, key);
+
prop = calloc(1, sizeof (Efl_Ui_Property_Bound));
if (!prop) return ENOMEM;
prop->part = eina_stringshare_add(part);
diff --git a/src/tests/elementary/efl_ui_test_caching_factory.c b/src/tests/elementary/efl_ui_test_caching_factory.c
index a5d634b4a4..839494f52c 100644
--- a/src/tests/elementary/efl_ui_test_caching_factory.c
+++ b/src/tests/elementary/efl_ui_test_caching_factory.c
@@ -1,9 +1,11 @@
-#define EFL_NOLEGACY_API_SUPPORT
#ifdef HAVE_CONFIG_H
# include "elementary_config.h"
#endif
#include <Efl_Ui.h>
+#include <Elementary.h>
+#include "elm_widget.h"
+#include "elm_widget_layout.h"
#include "efl_ui_suite.h"
EFL_START_TEST(efl_ui_test_caching_factory_del_before_pause)
@@ -27,7 +29,131 @@ EFL_START_TEST(efl_ui_test_caching_factory_del_before_pause)
}
EFL_END_TEST
+static Eina_Value
+_made_cb(Eo *o EINA_UNUSED, void *data, const Eina_Value v)
+{
+ Eo **made = data;
+
+ eina_value_array_get(&v, 0, made);
+ efl_ref(*made);
+ return v;
+}
+
+/* Asks a factory for one item of a model and turns the loop until it is
+ there. */
+static Eo *
+_factory_item_make(Eo *factory, Efl_Model *model)
+{
+ Eo *made = NULL;
+ Eina_Array arr;
+ int i;
+
+ eina_array_step_set(&arr, sizeof(arr), 1);
+ eina_array_push(&arr, model);
+ efl_future_then(factory,
+ efl_ui_view_factory_create_with_event(factory, eina_array_iterator_new(&arr)),
+ .success = _made_cb,
+ .success_type = EINA_VALUE_TYPE_ARRAY, .data = ""
+ eina_array_flush(&arr);
+ for (i = 0; !made && (i < 100); i++)
+ ecore_main_loop_iterate();
+ ck_assert_ptr_ne(made, NULL);
+ return made;
+}
+
+static void
+_building_count(void *data, const Efl_Event *ev EINA_UNUSED)
+{
+ unsigned int *count = data;
+
+ (*count)++;
+}
+
+/* Every item the factory hands out is announced as building, the ones it had
+ kept as much as the ones it made. */
+EFL_START_TEST(efl_ui_test_caching_factory_building_on_reuse)
+{
+ Eo *win, *factory, *model, *item, *again;
+ Eina_Array arr;
+ unsigned int building = 0;
+
+ win = win_add(NULL, "factory", EFL_UI_WIN_TYPE_BASIC);
+ model = efl_add(EFL_GENERIC_MODEL_CLASS, win);
+ factory = efl_add(EFL_UI_CACHING_FACTORY_CLASS, win,
+ 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_BUILDING,
+ _building_count, &building));
+
+ item = _factory_item_make(factory, efl_model_child_add(model));
+ ck_assert_uint_eq(building, 1);
+
+ eina_array_step_set(&arr, sizeof(arr), 1);
+ eina_array_push(&arr, item);
+ efl_ui_factory_release(factory, eina_array_iterator_new(&arr));
+ eina_array_flush(&arr);
+ efl_unref(item);
+
+ again = _factory_item_make(factory, efl_model_child_add(model));
+ ck_assert_ptr_eq(again, item);
+ ck_assert_uint_eq(building, 2);
+ efl_unref(again);
+}
+EFL_END_TEST
+
+/* A layout factory binds each item again every time it hands one out, a
+ * reused one too. Binding a part to the same property again must leave one
+ * binding, or every trip through the cache would make the item update one
+ * more time for each change of the model. */
+EFL_START_TEST(efl_ui_test_layout_factory_reuse_binds_once)
+{
+ Eo *win, *factory, *model, *child, *item, *again;
+ Efl_Ui_Layout_Data *pd;
+ Eina_Iterator *it;
+ Eina_Hash_Tuple *tuple;
+ Eina_Array arr;
+ unsigned int bound = 0;
+ int i;
+
+ win = win_add(NULL, "factory", EFL_UI_WIN_TYPE_BASIC);
+ model = efl_add(EFL_GENERIC_MODEL_CLASS, win);
+ child = efl_model_child_add(model);
+ efl_model_property_set(child, "title", eina_value_string_new("first"));
+
+ factory = efl_add(EFL_UI_LAYOUT_FACTORY_CLASS, win,
+ efl_ui_property_bind(efl_added, "efl.text", "title"));
+
+ item = _factory_item_make(factory, child);
+ for (i = 0; i < 6; i++)
+ {
+ eina_array_step_set(&arr, sizeof(arr), 1);
+ eina_array_push(&arr, item);
+ efl_ui_factory_release(factory, eina_array_iterator_new(&arr));
+ eina_array_flush(&arr);
+ efl_unref(item);
+
+ again = _factory_item_make(factory, child);
+ ck_assert_ptr_eq(again, item);
+ item = again;
+ }
+
+ // One binding of the part to the property, however many times it came back
+ pd = efl_data_scope_get(item, EFL_UI_LAYOUT_BASE_CLASS);
+ it = eina_hash_iterator_tuple_new(pd->connect.properties);
+ EINA_ITERATOR_FOREACH(it, tuple)
+ {
+ if (!strcmp(tuple->key, "title") && !strcmp(tuple->data, "efl.text")) bound++;
+ }
+ eina_iterator_free(it);
+ ck_assert_uint_eq(bound, 1);
+ ck_assert_int_eq(eina_hash_population(pd->connect.properties), 1);
+
+ efl_unref(item);
+}
+EFL_END_TEST
+
void efl_ui_test_caching_factory(TCase *tc)
{
tcase_add_test(tc, efl_ui_test_caching_factory_del_before_pause);
+ tcase_add_test(tc, efl_ui_test_caching_factory_building_on_reuse);
+ tcase_add_test(tc, efl_ui_test_layout_factory_reuse_binds_once);
}
diff --git a/src/tests/elementary/efl_ui_test_property_bind.c b/src/tests/elementary/efl_ui_test_property_bind.c
index f72aac032c..60059d5bf8 100644
--- a/src/tests/elementary/efl_ui_test_property_bind.c
+++ b/src/tests/elementary/efl_ui_test_property_bind.c
@@ -4,6 +4,7 @@
#include <Efl_Ui.h>
#include <Elementary.h>
+#include "elm_widget.h"
#include "efl_ui_suite.h"
/* A widget bound to a property of its model must write what the user did
@@ -603,11 +604,38 @@ EFL_START_TEST(efl_ui_model_provider_live_edit)
}
EFL_END_TEST
+/* A factory binds every item again each time it hands one out, reused or
+ * not. Binding the same key again replaces the binding: nothing piles up. */
+EFL_START_TEST(rebinding_a_key_replaces_the_binding)
+{
+ Eo *win = _window();
+ Eo *model = _model_new("t", eina_value_string_new("first"));
+ Eo *txt;
+ Efl_Ui_Widget_Data *pd;
+ int i;
+
+ txt = efl_add(EFL_UI_TEXTBOX_CLASS, win,
+ efl_ui_view_model_set(efl_added, model));
+ for (i = 0; i < 6; i++)
+ ck_assert_int_eq(efl_ui_property_bind(txt, "text", "t"), 0);
+
+ pd = efl_data_scope_get(txt, EFL_UI_WIDGET_CLASS);
+ ck_assert_int_eq(eina_hash_population(pd->properties.model_lookup), 1);
+ ck_assert_int_eq(eina_hash_population(pd->properties.view_lookup), 1);
+ ck_assert_str_eq(efl_text_get(txt), "first");
+
+ _model_set(model, "t", eina_value_string_new("second"));
+ ck_assert_str_eq(efl_text_get(txt), "second");
+ efl_unref(model);
+}
+EFL_END_TEST
+
void
efl_ui_test_property_bind(TCase *tc)
{
tcase_add_test(tc, textbox_user_edit_reaches_the_model);
tcase_add_test(tc, efl_ui_model_provider_live_edit);
+ tcase_add_test(tc, rebinding_a_key_replaces_the_binding);
tcase_add_test(tc, textbox_model_change_does_not_loop);
tcase_add_test(tc, textbox_typing_in_the_middle_keeps_the_cursor);
tcase_add_test(tc, textbox_typing_at_the_start_keeps_the_cursor);
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.