summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAli Alzyod <ali198724@gmail.com>2020-08-05 13:09:00 +0900
committerWooHyun Jung <wh0705.jung@samsung.com>2020-08-05 13:09:00 +0900
commited18471ba955be316abb2117ebdde3f3df418751 (patch)
treeb9310cb76fdd1d6b16607b08d2434d96522be6bd
parent45c6212d2078ce33f2966b3dca698a97ad51b9f9 (diff)
evas_textblock: enhance cursor event submitting during markup_set/text_set
Summary: Enhance text cursor events submitting: 1- Submit events only for changed cursors. 2- Reduce code complexity for cursor change. 3- Add test case for cursor event change Reviewers: woohyun, zmike, bu5hm4n Reviewed By: woohyun Subscribers: cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D11775
-rw-r--r--src/lib/evas/canvas/evas_object_textblock.c65
-rw-r--r--src/tests/evas/evas_test_textblock.c21
2 files changed, 49 insertions, 37 deletions
diff --git a/src/lib/evas/canvas/evas_object_textblock.c b/src/lib/evas/canvas/evas_object_textblock.c
index 6ed1593e15..e9b89dec98 100644
--- a/src/lib/evas/canvas/evas_object_textblock.c
+++ b/src/lib/evas/canvas/evas_object_textblock.c
@@ -578,8 +578,6 @@ static void evas_object_textblock_coords_recalc(Evas_Object *eo_obj,
578 void *type_private_data); 578 void *type_private_data);
579static void _canvas_text_format_changed(Eo *eo_obj, Efl_Canvas_Textblock_Data *o); 579static void _canvas_text_format_changed(Eo *eo_obj, Efl_Canvas_Textblock_Data *o);
580 580
581static void _evas_textblock_cursor_paragraph_first(Efl_Text_Cursor_Handle *cur,
582 Eina_Bool emit_change);
583static const Evas_Object_Func object_func = 581static const Evas_Object_Func object_func =
584{ 582{
585 /* methods (compulsory) */ 583 /* methods (compulsory) */
@@ -8754,16 +8752,36 @@ _evas_object_textblock_text_markup_set(Eo *eo_obj, Efl_Canvas_Textblock_Data *o,
8754 } 8752 }
8755 _nodes_clear(eo_obj); 8753 _nodes_clear(eo_obj);
8756 8754
8757 Efl_Text_Cursor_Handle *co = o->cursor; 8755 if (o->cursor->pos != 0)
8758 co->node = _evas_textblock_node_text_new(); 8756 {
8757 o->cursor->changed = EINA_TRUE;
8758 o->cursor->pos = 0;
8759 }
8760
8759 o->text_nodes = _NODE_TEXT(eina_inlist_append( 8761 o->text_nodes = _NODE_TEXT(eina_inlist_append(
8760 EINA_INLIST_GET(o->text_nodes), 8762 EINA_INLIST_GET(o->text_nodes),
8761 EINA_INLIST_GET(co->node))); 8763 EINA_INLIST_GET(_evas_textblock_node_text_new())));
8762 8764 o->cursor->node = o->text_nodes;
8763 evas_textblock_cursor_paragraph_first(o->cursor);
8764 8765
8765 evas_object_textblock_text_markup_prepend(o->cursor, text); 8766 evas_object_textblock_text_markup_prepend(o->cursor, text);
8766 8767
8768 Eina_List *l;
8769 Efl_Text_Cursor_Handle *cur;
8770 EINA_LIST_FOREACH(o->cursors, l, cur)
8771 {
8772 cur->node = o->text_nodes;
8773 if (cur->pos != 0)
8774 {
8775 cur->pos = 0;
8776 cur->changed = EINA_TRUE;
8777 }
8778 }
8779 _cursor_emit_if_changed(o->cursor);
8780 EINA_LIST_FOREACH(o->cursors, l, cur)
8781 {
8782 _cursor_emit_if_changed(cur);
8783 }
8784
8767 /*If there was no text markup_prepend will not call change function 8785 /*If there was no text markup_prepend will not call change function
8768 So we will call it inside markup_set*/ 8786 So we will call it inside markup_set*/
8769 if (!text || !*text) 8787 if (!text || !*text)
@@ -8772,26 +8790,6 @@ _evas_object_textblock_text_markup_set(Eo *eo_obj, Efl_Canvas_Textblock_Data *o,
8772 _evas_textblock_changed(o, eo_obj); 8790 _evas_textblock_changed(o, eo_obj);
8773 } 8791 }
8774 8792
8775 efl_event_freeze(eo_obj);
8776 /* Point all the cursors to the starrt */
8777 {
8778 Eina_List *l;
8779 Efl_Text_Cursor_Handle *cur;
8780
8781 /*update all cursors positions first, without emitting change*/
8782 EINA_LIST_FOREACH(o->cursors, l, cur)
8783 {
8784 _evas_textblock_cursor_paragraph_first(cur, EINA_FALSE);
8785 }
8786 /*emitting change event for all cursors, after all of them are ready*/
8787 EINA_LIST_FOREACH(o->cursors, l, cur)
8788 {
8789 _evas_textblock_cursor_object_changed(cur);
8790 }
8791
8792 }
8793 efl_event_thaw(eo_obj);
8794
8795 o->markup_text = text; 8793 o->markup_text = text;
8796} 8794}
8797 8795
@@ -10039,8 +10037,8 @@ found:
10039 _evas_textblock_changed(o, eo_obj); 10037 _evas_textblock_changed(o, eo_obj);
10040} 10038}
10041 10039
10042static void 10040EAPI void
10043_evas_textblock_cursor_paragraph_first(Efl_Text_Cursor_Handle *cur, Eina_Bool emit_change) 10041evas_textblock_cursor_paragraph_first(Efl_Text_Cursor_Handle *cur)
10044{ 10042{
10045 if (!cur) return; 10043 if (!cur) return;
10046 Evas_Object_Protected_Data *obj = efl_data_scope_get(cur->obj, EFL_CANVAS_OBJECT_CLASS); 10044 Evas_Object_Protected_Data *obj = efl_data_scope_get(cur->obj, EFL_CANVAS_OBJECT_CLASS);
@@ -10048,14 +10046,7 @@ _evas_textblock_cursor_paragraph_first(Efl_Text_Cursor_Handle *cur, Eina_Bool em
10048 Efl_Canvas_Textblock_Data *o = efl_data_scope_get(cur->obj, MY_CLASS); 10046 Efl_Canvas_Textblock_Data *o = efl_data_scope_get(cur->obj, MY_CLASS);
10049 cur->node = o->text_nodes; 10047 cur->node = o->text_nodes;
10050 cur->pos = 0; 10048 cur->pos = 0;
10051 if (emit_change) 10049 _evas_textblock_cursor_object_changed(cur);
10052 _evas_textblock_cursor_object_changed(cur);
10053}
10054
10055EAPI void
10056evas_textblock_cursor_paragraph_first(Efl_Text_Cursor_Handle *cur)
10057{
10058 _evas_textblock_cursor_paragraph_first(cur, EINA_TRUE);
10059} 10050}
10060 10051
10061EAPI void 10052EAPI void
diff --git a/src/tests/evas/evas_test_textblock.c b/src/tests/evas/evas_test_textblock.c
index 707c72f22c..6bdf25a19d 100644
--- a/src/tests/evas/evas_test_textblock.c
+++ b/src/tests/evas/evas_test_textblock.c
@@ -4847,6 +4847,26 @@ EFL_START_TEST(efl_canvas_textblock_cursor)
4847} 4847}
4848EFL_END_TEST 4848EFL_END_TEST
4849 4849
4850EFL_START_TEST(efl_canvas_textblock_cursor_change)
4851{
4852 START_EFL_CANVAS_TEXTBLOCK_TEST();
4853 (void) cur_obj;
4854 int changed_emit1 = 0;
4855 int changed_emit2 = 0;
4856 Efl_Object *cur1, *cur2;
4857 cur1 = efl_canvas_textblock_cursor_create(txt);
4858 cur2 = efl_canvas_textblock_cursor_create(txt);
4859 efl_text_set(txt, "Hello World");
4860 efl_text_cursor_object_position_set(cur1, 0);
4861 efl_text_cursor_object_position_set(cur2, 1);
4862 efl_event_callback_add(cur1, EFL_TEXT_CURSOR_OBJECT_EVENT_CHANGED, _increment_int_changed, &changed_emit1);
4863 efl_event_callback_add(cur2, EFL_TEXT_CURSOR_OBJECT_EVENT_CHANGED, _increment_int_changed, &changed_emit2);
4864 efl_text_set(txt, "");
4865 ck_assert_int_eq(changed_emit1, 0);
4866 ck_assert_int_eq(changed_emit2, 1);
4867}
4868EFL_END_TEST
4869
4850 4870
4851EFL_START_TEST(efl_canvas_textblock_markup) 4871EFL_START_TEST(efl_canvas_textblock_markup)
4852{ 4872{
@@ -5143,6 +5163,7 @@ void evas_test_textblock(TCase *tc)
5143 tcase_add_test(tc, efl_canvas_textblock_simple); 5163 tcase_add_test(tc, efl_canvas_textblock_simple);
5144 tcase_add_test(tc, efl_text); 5164 tcase_add_test(tc, efl_text);
5145 tcase_add_test(tc, efl_canvas_textblock_cursor); 5165 tcase_add_test(tc, efl_canvas_textblock_cursor);
5166 tcase_add_test(tc, efl_canvas_textblock_cursor_change);
5146 tcase_add_test(tc, efl_canvas_textblock_markup); 5167 tcase_add_test(tc, efl_canvas_textblock_markup);
5147 tcase_add_test(tc, efl_canvas_textblock_markup_invalid_escape); 5168 tcase_add_test(tc, efl_canvas_textblock_markup_invalid_escape);
5148 tcase_add_test(tc, efl_text_font); 5169 tcase_add_test(tc, efl_text_font);