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
This commit is contained in:
Ali Alzyod 2020-08-05 13:09:00 +09:00 committed by WooHyun Jung
parent 45c6212d20
commit ed18471ba9
2 changed files with 49 additions and 37 deletions

View File

@ -578,8 +578,6 @@ static void evas_object_textblock_coords_recalc(Evas_Object *eo_obj,
void *type_private_data);
static void _canvas_text_format_changed(Eo *eo_obj, Efl_Canvas_Textblock_Data *o);
static void _evas_textblock_cursor_paragraph_first(Efl_Text_Cursor_Handle *cur,
Eina_Bool emit_change);
static const Evas_Object_Func object_func =
{
/* methods (compulsory) */
@ -8754,16 +8752,36 @@ _evas_object_textblock_text_markup_set(Eo *eo_obj, Efl_Canvas_Textblock_Data *o,
}
_nodes_clear(eo_obj);
Efl_Text_Cursor_Handle *co = o->cursor;
co->node = _evas_textblock_node_text_new();
if (o->cursor->pos != 0)
{
o->cursor->changed = EINA_TRUE;
o->cursor->pos = 0;
}
o->text_nodes = _NODE_TEXT(eina_inlist_append(
EINA_INLIST_GET(o->text_nodes),
EINA_INLIST_GET(co->node)));
evas_textblock_cursor_paragraph_first(o->cursor);
EINA_INLIST_GET(_evas_textblock_node_text_new())));
o->cursor->node = o->text_nodes;
evas_object_textblock_text_markup_prepend(o->cursor, text);
Eina_List *l;
Efl_Text_Cursor_Handle *cur;
EINA_LIST_FOREACH(o->cursors, l, cur)
{
cur->node = o->text_nodes;
if (cur->pos != 0)
{
cur->pos = 0;
cur->changed = EINA_TRUE;
}
}
_cursor_emit_if_changed(o->cursor);
EINA_LIST_FOREACH(o->cursors, l, cur)
{
_cursor_emit_if_changed(cur);
}
/*If there was no text markup_prepend will not call change function
So we will call it inside markup_set*/
if (!text || !*text)
@ -8772,26 +8790,6 @@ _evas_object_textblock_text_markup_set(Eo *eo_obj, Efl_Canvas_Textblock_Data *o,
_evas_textblock_changed(o, eo_obj);
}
efl_event_freeze(eo_obj);
/* Point all the cursors to the starrt */
{
Eina_List *l;
Efl_Text_Cursor_Handle *cur;
/*update all cursors positions first, without emitting change*/
EINA_LIST_FOREACH(o->cursors, l, cur)
{
_evas_textblock_cursor_paragraph_first(cur, EINA_FALSE);
}
/*emitting change event for all cursors, after all of them are ready*/
EINA_LIST_FOREACH(o->cursors, l, cur)
{
_evas_textblock_cursor_object_changed(cur);
}
}
efl_event_thaw(eo_obj);
o->markup_text = text;
}
@ -10039,8 +10037,8 @@ found:
_evas_textblock_changed(o, eo_obj);
}
static void
_evas_textblock_cursor_paragraph_first(Efl_Text_Cursor_Handle *cur, Eina_Bool emit_change)
EAPI void
evas_textblock_cursor_paragraph_first(Efl_Text_Cursor_Handle *cur)
{
if (!cur) return;
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
Efl_Canvas_Textblock_Data *o = efl_data_scope_get(cur->obj, MY_CLASS);
cur->node = o->text_nodes;
cur->pos = 0;
if (emit_change)
_evas_textblock_cursor_object_changed(cur);
}
EAPI void
evas_textblock_cursor_paragraph_first(Efl_Text_Cursor_Handle *cur)
{
_evas_textblock_cursor_paragraph_first(cur, EINA_TRUE);
_evas_textblock_cursor_object_changed(cur);
}
EAPI void

View File

@ -4847,6 +4847,26 @@ EFL_START_TEST(efl_canvas_textblock_cursor)
}
EFL_END_TEST
EFL_START_TEST(efl_canvas_textblock_cursor_change)
{
START_EFL_CANVAS_TEXTBLOCK_TEST();
(void) cur_obj;
int changed_emit1 = 0;
int changed_emit2 = 0;
Efl_Object *cur1, *cur2;
cur1 = efl_canvas_textblock_cursor_create(txt);
cur2 = efl_canvas_textblock_cursor_create(txt);
efl_text_set(txt, "Hello World");
efl_text_cursor_object_position_set(cur1, 0);
efl_text_cursor_object_position_set(cur2, 1);
efl_event_callback_add(cur1, EFL_TEXT_CURSOR_OBJECT_EVENT_CHANGED, _increment_int_changed, &changed_emit1);
efl_event_callback_add(cur2, EFL_TEXT_CURSOR_OBJECT_EVENT_CHANGED, _increment_int_changed, &changed_emit2);
efl_text_set(txt, "");
ck_assert_int_eq(changed_emit1, 0);
ck_assert_int_eq(changed_emit2, 1);
}
EFL_END_TEST
EFL_START_TEST(efl_canvas_textblock_markup)
{
@ -5143,6 +5163,7 @@ void evas_test_textblock(TCase *tc)
tcase_add_test(tc, efl_canvas_textblock_simple);
tcase_add_test(tc, efl_text);
tcase_add_test(tc, efl_canvas_textblock_cursor);
tcase_add_test(tc, efl_canvas_textblock_cursor_change);
tcase_add_test(tc, efl_canvas_textblock_markup);
tcase_add_test(tc, efl_canvas_textblock_markup_invalid_escape);
tcase_add_test(tc, efl_text_font);