Fix defects from static analysis
[platform/core/uifw/voice-control-elm.git] / src / vc_elm_efl_dump.c
1 /*
2  * Copyright (c) 2015-2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 /**
18  * @file     vc_elm_efl_dump.c
19  * @brief    The private module for efl object dump.
20  * @author   Jaeyong Hwang <j_yong.hwang@samsung.com>
21  */
22
23 #include "vc_elm_tools.h"
24 #include "vc_elm_efl_dump.h"
25
26 #include <voice_control_elm_private.h>
27
28 #define EVAS_OBJECT_DUMP_DEBUG
29 #ifdef EVAS_OBJECT_DUMP_DEBUG
30 #define VC_ELM_LOG_DUMP(fmt, ...) SLOGD("\033[0;32m" fmt "\033[m", ## __VA_ARGS__)
31 #else
32 #define VC_ELM_LOG_DUMP(fmt, ...)
33 #endif
34
35 typedef struct _Ea_Util_Mgr {
36         Evas *evas;
37         FILE *fp;
38
39         Eina_List *edje_part_name_list;
40         int x, y, w, h;
41 } Ea_Util_Mgr;
42
43 typedef struct _Edje_Info {
44         const Evas_Object *obj;
45
46         char *part_name;
47         const char *image_name;
48         const char *color_class;
49 } Edje_Info;
50
51 #define SPANS_COMMON(x1, w1, x2, w2) \
52         (!(((int)((x2) + (int)(w2)) < (int)(x1)) || (int)((x2) > (int)((x1) + (int)(w1)))))
53
54 #define RECTS_INTERSECT(x, y, w, h, xx, yy, ww, hh) \
55         ((SPANS_COMMON((x), (w), (xx), (ww))) && (SPANS_COMMON((y), (h), (yy), (hh))))
56
57 Eina_List *ret_list = NULL;
58 Eina_List *ret_text_list = NULL;
59 Eina_List *ctxpop_text_list = NULL;
60
61 static Eina_Bool g_set_geometry = EINA_FALSE;
62 static int g_geo_x = 0, g_geo_y = 0, g_geo_w = 0, g_geo_h = 0;
63 static int find_popup = 0;
64 static int skip_text = 0;
65
66 int vc_elm_efl_dump_is_vt_auto_enabled()
67 {
68         int is_vt_automode = 0;
69         int ret = vc_elm_is_supported_vt_auto(&is_vt_automode);
70         if (0 != ret) {
71                 VC_ELM_LOG_DUMP("Fail to check vt auto mode");
72         }
73
74         return is_vt_automode;
75 }
76
77 static Eina_Bool
78 evas_object_is_visible_get(Evas_Object *obj)
79 {
80         int r = 0, g = 0, b = 0, a = 0;
81         Evas_Coord x = 0, y = 0, w = 0, h = 0;
82         Evas_Object *clip = NULL;
83         int vis = 0;
84
85         evas_object_color_get(obj, &r, &g, &b, &a);
86         evas_object_geometry_get(obj, &x, &y, &w, &h);
87
88         if (evas_object_visible_get(obj)) vis = 1;
89         clip = evas_object_clip_get(obj);
90         if (clip) evas_object_color_get(obj, &r, &g, &b, &a);
91         if (clip && !evas_object_visible_get(clip)) vis = 0;
92
93         if (clip && a == 0) vis = 0;
94
95         if (0 == vis)
96                 return EINA_FALSE;
97         else
98                 return EINA_TRUE;
99 }
100
101 static Eina_Bool
102 evas_object_type_match(const Evas_Object *obj, const char *type)
103 {
104         int ret = strcmp(EVAS_OBJECT_TYPE_GET(obj), type);
105
106         if (!ret) return EINA_TRUE;
107         return EINA_FALSE;
108 }
109
110 static Eina_Bool
111 evas_object_is_swallow_rect(const Evas_Object *obj)
112 {
113         int r = 0, g = 0, b = 0, a = 0;
114
115         evas_object_color_get(obj, &r, &g, &b, &a);
116         if (!r && !g && !b && !a
117                         && evas_object_pointer_mode_get(obj) == EVAS_OBJECT_POINTER_MODE_NOGRAB
118                         && evas_object_pass_events_get(obj))
119                 return EINA_TRUE;
120
121         return EINA_FALSE;
122 }
123
124 static void
125 _extract_edje_file_name(Object_Info *object_info, const char *full_path)
126 {
127         char name[255] = {0, };
128         unsigned int i, cnt = 0;
129
130         if (!full_path) return;
131
132         for (i = 0; i < strlen(full_path); i++) {
133                 if (full_path[i] == '/') {
134                         cnt = 0;
135                         continue;
136                 }
137                 name[cnt++] = full_path[i];
138         }
139         name[cnt] = '\0';
140         object_info->edje_file = calloc(1, strlen(name) + 1);
141         strncpy(object_info->edje_file, name, strlen(name) + 1);
142 }
143
144 static void
145 _edje_file_info_save(Ea_Util_Mgr *util_mgr, const Evas_Object *obj)
146 {
147         Evas_Object *ed = NULL;
148         const Evas_Object *pobj = NULL;
149         Eina_List *parts = NULL, *l = NULL;
150         Edje_Info *edje_info = NULL;
151         const char *file = NULL, *group = NULL, *pname = NULL, *ret = NULL;
152         double val = 0.0;
153
154         if (!evas_object_type_match(obj, "edje")) return;
155
156         edje_object_file_get(obj, &file, &group);
157
158         ed = edje_edit_object_add(util_mgr->evas); // evas new ??
159         if (edje_object_file_set(ed, file, group)) {
160                 parts = edje_edit_parts_list_get(ed);
161                 EINA_LIST_FOREACH(parts, l, pname) {
162                         if ((pobj = edje_object_part_object_get(obj, pname))) {
163                                 edje_info = malloc(sizeof(Edje_Info));
164                                 if (!edje_info) {
165                                         VC_ELM_LOG_ERR("[ERROR] Fail to allocate memory");
166                                         return;
167                                 }
168                                 edje_info->obj = pobj;
169                                 edje_info->part_name = strdup(pname);
170                                 ret = edje_object_part_state_get(obj, edje_info->part_name, &val);
171
172                                 if (ret) {
173                                         edje_info->color_class = edje_edit_state_color_class_get(ed, edje_info->part_name , ret, val);
174                                         edje_info->image_name = edje_edit_state_image_get(ed, edje_info->part_name , ret, val);
175                                 }
176
177                                 util_mgr->edje_part_name_list = eina_list_append(util_mgr->edje_part_name_list, edje_info);
178
179                         }
180                 }
181                 edje_edit_string_list_free(parts);
182         }
183         evas_object_del(ed);
184 }
185
186 static void
187 _obj_tree_items(Ea_Util_Mgr *util_mgr, Evas_Object *obj, Object_Info *parent)
188 {
189         Eina_List *children = NULL, *l = NULL;
190         Evas_Object *child, *smart_parent_obj = NULL;
191         Evas_Coord x = 0, y = 0, w = 0, h = 0;
192         Eina_Bool is_clip = EINA_FALSE;
193         int r = 0, g = 0, b = 0, a = 0;
194         const char *ret = NULL;
195         double val = 0.0;
196         const char *file = NULL, *key = NULL, *group = NULL, *text = NULL;
197         Edje_Info *edje_info = NULL;
198         Object_Info *object_info = NULL;
199         char* temp = NULL;
200
201         // visible check
202         if (!evas_object_is_visible_get(obj)) return;
203
204         // viewport check
205         evas_object_geometry_get(obj, &x, &y, &w, &h);
206
207         if (!RECTS_INTERSECT(x, y, w, h, util_mgr->x, util_mgr->y, util_mgr->w, util_mgr->h)) return;
208
209         // clipper check
210         if (evas_object_clipees_get(obj)) is_clip = EINA_TRUE;
211         if (is_clip) goto next;
212
213         object_info = calloc(1, sizeof(Object_Info));
214         if (!object_info) {
215                 VC_ELM_LOG_ERR("[ERROR] Fail to allocate memory");
216                 return;
217         }
218
219         object_info->parent = parent;
220
221         object_info->address = (int)obj;
222         object_info->geometry_info.x = x;
223         object_info->geometry_info.y = y;
224         object_info->geometry_info.w = w;
225         object_info->geometry_info.h = h;
226
227         if (elm_widget_is(obj)) {
228                 if (elm_object_focus_get(obj))
229                         object_info->focus = EINA_TRUE;
230                 else
231                         object_info->focus = EINA_FALSE;
232
233                 if (elm_widget_can_focus_get(obj) &&
234                                 (!elm_object_disabled_get(obj)))
235                         object_info->focusable = EINA_TRUE;
236                 else
237                         object_info->focusable = EINA_FALSE;
238         }
239
240         // evas object type check
241         if (evas_object_is_swallow_rect(obj)) {
242                 object_info->type = calloc(1, strlen("swallow") + 1);
243                 strncpy(object_info->type, "swallow", strlen("swallow") + 1);
244         } else if (evas_object_type_match(obj, "rectangle")) {
245                 object_info->type = calloc(1, strlen("rect") + 1);
246                 strncpy(object_info->type, "rect", strlen("rect") + 1);
247                 evas_object_color_get(obj, &r, &g, &b, &a);
248                 object_info->rgb_info.r = r;
249                 object_info->rgb_info.g = g;
250                 object_info->rgb_info.b = b;
251                 object_info->rgb_info.a = a;
252         } else {
253                 object_info->type = calloc(1, strlen(EVAS_OBJECT_TYPE_GET(obj)) + 1);
254                 strncpy(object_info->type, EVAS_OBJECT_TYPE_GET(obj), strlen(EVAS_OBJECT_TYPE_GET(obj)) + 1);
255         }
256
257         smart_parent_obj = evas_object_smart_parent_get(obj);
258
259         // image info save
260         if (!strcmp(EVAS_OBJECT_TYPE_GET(obj), "elm_icon") ||
261                         !strcmp(EVAS_OBJECT_TYPE_GET(obj), "elm_image")) {
262                 elm_image_file_get(obj, &file, &key);
263                 evas_object_data_set(obj, "image_name", file);
264         }
265
266         // image name check
267         if (smart_parent_obj && evas_object_type_match(obj, "image")
268                         && (evas_object_type_match(smart_parent_obj, "elm_icon")
269                                 || evas_object_type_match(smart_parent_obj, "elm_image"))) {
270                 if ((ret = evas_object_data_get(smart_parent_obj, "image_name"))) {
271                         _extract_edje_file_name(object_info, ret);
272                         evas_object_data_del(smart_parent_obj, "edje_image_name");
273                 }
274         }
275
276         // edje info save
277         if (evas_object_type_match(obj, "edje")) {
278                 edje_object_file_get(obj, &file, &group);
279                 if (group) {
280                         object_info->group = calloc(1, strlen(group) + 1);
281                         strncpy(object_info->group, group, strlen(group) + 1);
282                 }
283
284                 _extract_edje_file_name(object_info, file);
285                 _edje_file_info_save(util_mgr, obj);
286         }
287
288         // edje info check
289         if (!is_clip && smart_parent_obj
290                         && !elm_widget_is(obj) && evas_object_type_match(smart_parent_obj, "edje")) {
291                 EINA_LIST_FOREACH(util_mgr->edje_part_name_list, l, edje_info) {
292                         if (edje_info->obj == obj) {
293                                 if (edje_info->color_class) {
294                                         object_info->color_class = calloc(1, strlen(edje_info->color_class) + 1);
295                                         strncpy(object_info->color_class, edje_info->color_class, strlen(edje_info->color_class) + 1);
296                                 }
297
298                                 ret = edje_object_part_state_get(evas_object_smart_parent_get(obj), edje_info->part_name, &val);
299                                 object_info->part_name = calloc(1, strlen(edje_info->part_name) + 1);
300                                 object_info->part_state = calloc(1, strlen(ret) + 1);
301                                 strncpy(object_info->part_name, edje_info->part_name, strlen(edje_info->part_name) + 1);
302                                 strncpy(object_info->part_state, ret, strlen(ret) + 1);
303
304                                 if (edje_info->image_name) {
305                                         object_info->image_name = calloc(1, strlen(edje_info->image_name) + 1);
306                                         strncpy(object_info->image_name, edje_info->image_name, strlen(edje_info->image_name) + 1);
307                                 }
308                                 break;
309                         }
310                 }
311         }
312
313         text = NULL;
314         if (!strcmp(EVAS_OBJECT_TYPE_GET(obj), "text"))
315                 text = eina_stringshare_add(evas_object_text_text_get(obj));
316         else if (!strcmp(EVAS_OBJECT_TYPE_GET(obj), "textblock")) {
317                 ret = evas_object_textblock_text_markup_get(obj);
318                 temp = evas_textblock_text_markup_to_utf8(obj, ret);
319                 text = eina_stringshare_add(temp);
320
321                 if (NULL != temp) {
322                         free(temp);
323                         temp = NULL;
324                 }
325         }
326         if (text && strlen(text) > 0) {
327                 object_info->text = calloc(1, strlen(text) + 1);
328                 strncpy(object_info->text, text, strlen(text) + 1);
329         }
330
331         ret_list = eina_list_append(ret_list, object_info);
332 next:
333         if (!evas_object_type_match(obj, "rectangle") && !evas_object_type_match(obj, "text") && !evas_object_type_match(obj, "image")) {
334                 children = evas_object_smart_members_get(obj);
335                 EINA_LIST_FREE(children, child)
336                         _obj_tree_items(util_mgr, child, object_info);
337         }
338 }
339
340 static Eina_Bool _is_clickable_object(Evas_Object *obj)
341 {
342         if (!strcmp(EVAS_OBJECT_TYPE_GET(obj), "elm_win") || !strcmp(EVAS_OBJECT_TYPE_GET(obj), "elm_naviframe") || !strcmp(EVAS_OBJECT_TYPE_GET(obj), "elm_label")
343                 || !strcmp(EVAS_OBJECT_TYPE_GET(obj), "elm_ctxpopup") || !strcmp(EVAS_OBJECT_TYPE_GET(obj), "elm_popup")) {
344                 VC_ELM_LOG_DUMP("Not clickable object(%s)", EVAS_OBJECT_TYPE_GET(obj));
345                 return EINA_FALSE;
346         }
347
348         return EINA_TRUE;
349 }
350
351 static Eina_Bool _is_descendant_of_list(Object_Info *object_info)
352 {
353         Object_Info* parent_info = ea_object_dump_parent_widget_data_get(object_info);
354         while (NULL != parent_info) {
355                 const char* widget_type = elm_widget_type_get((const Evas_Object*)(parent_info->address));
356                 if (NULL != widget_type) {
357                         VC_ELM_LOG_DUMP("[DEBUG] object_type(%s), widget_type(%s)", EVAS_OBJECT_TYPE_GET((Evas_Object*)(parent_info->address)), widget_type);
358                         if (!strcmp(widget_type, "Elm_Genlist") || !strcmp(widget_type, "Elm_Gengrid") || !strcmp(widget_type, "Elm_List") || !strcmp(widget_type, "Elm_Ctxpopup") || !strcmp(widget_type, "Elm_Index"))
359                                 return EINA_TRUE;
360                 }
361                 parent_info = ea_object_dump_parent_widget_data_get(parent_info);
362         }
363         return EINA_FALSE;
364 }
365
366 static Eina_Bool _is_descendant_of_ctxpopup(Object_Info *object_info)
367 {
368         Object_Info* parent_info = ea_object_dump_parent_widget_data_get(object_info);
369         while (NULL != parent_info) {
370                 const char* widget_type = elm_widget_type_get((const Evas_Object*)(parent_info->address));
371                 if (NULL != widget_type) {
372                         VC_ELM_LOG_DUMP("[DEBUG] object_type(%s), widget_type(%s)", EVAS_OBJECT_TYPE_GET((Evas_Object*)(parent_info->address)), widget_type);
373                         if (!strcmp(widget_type, "Elm_Ctxpopup"))
374                                 return EINA_TRUE;
375                 }
376                 parent_info = ea_object_dump_parent_widget_data_get(parent_info);
377         }
378         return EINA_FALSE;
379 }
380
381 static Eina_Bool _is_descendant_of_toolbar(Object_Info *object_info)
382 {
383         Object_Info* parent_info = ea_object_dump_parent_widget_data_get(object_info);
384         while (NULL != parent_info) {
385                 const char* widget_type = elm_widget_type_get((const Evas_Object*)(parent_info->address));
386                 if (NULL != widget_type) {
387                         VC_ELM_LOG_DUMP("[DEBUG] object_type(%s), widget_type(%s)", EVAS_OBJECT_TYPE_GET((Evas_Object*)(parent_info->address)), widget_type);
388                         if (!strcmp(widget_type, "Elm_Toolbar"))
389                                 return EINA_TRUE;
390                 }
391                 parent_info = ea_object_dump_parent_widget_data_get(parent_info);
392         }
393         return EINA_FALSE;
394 }
395
396 static Eina_Bool _has_accessible_name(Object_Info *object_info)
397 {
398         Object_Info* parent_info = ea_object_dump_parent_widget_data_get(object_info);
399         while (NULL != parent_info) {
400                 const char* text = NULL;
401                 Evas_Object *obj = (Evas_Object *)(parent_info->address);
402                 const char* widget_type = elm_widget_type_get(obj);
403
404                 if (NULL != widget_type) {
405                         if (elm_atspi_accessible_name_get(obj) && EINA_TRUE == parent_info->focusable && EINA_TRUE == _is_clickable_object(obj)) {
406                                 text = elm_atspi_accessible_name_get(obj);
407                                 VC_ELM_LOG_DUMP("####### [DEBUG] atspi_text(%s)", text);
408                         } else if (elm_atspi_accessible_name_get(obj) && !strcmp(widget_type, "Elm_Toolbar")) {
409                                 text = elm_atspi_accessible_name_get(obj);
410                                 VC_ELM_LOG_DUMP("####### [DEBUG] toolbar(%s)", text);
411                         }
412                 }
413                 if (NULL != text) {
414                         VC_ELM_LOG_DUMP("####### [DEBUG] widget_type(%s), text(%s)", widget_type, text);
415                         return EINA_TRUE;
416                 }
417                 parent_info = ea_object_dump_parent_widget_data_get(parent_info);
418         }
419         return EINA_FALSE;
420 }
421
422 static void
423 _obj_tree_items_exclude_unfocusable_text(Ea_Util_Mgr *util_mgr, Evas_Object *obj, Object_Info *parent, Eina_Bool parent_widget_focusable, Eina_Bool list_type, int cnt)
424 {
425         Eina_List *children = NULL, *l = NULL;
426         Evas_Object *child, *smart_parent_obj = NULL;
427         Evas_Coord x = 0, y = 0, w = 0, h = 0;
428         Eina_Bool is_clip = EINA_FALSE;
429         int r = 0, g = 0, b = 0, a = 0;
430         const char *ret = NULL;
431         double val = 0.0;
432         const char *file = NULL, *key = NULL, *group = NULL, *text = NULL;
433         Edje_Info *edje_info = NULL;
434         Object_Info *object_info = NULL;
435         char* temp = NULL;
436
437         VC_ELM_LOG_DUMP("[%d] Object(%p)(%s), text(%s)(%s)", cnt, obj, EVAS_OBJECT_TYPE_GET(obj), (!evas_object_text_text_get(obj)) ? " " : evas_object_text_text_get(obj), !elm_atspi_accessible_name_get(obj) ? " " : elm_atspi_accessible_name_get(obj));
438
439         // visible check
440         if (!evas_object_is_visible_get(obj)) {
441                 VC_ELM_LOG_DUMP("   [%d] Object(%s) : Invisible)", cnt, EVAS_OBJECT_TYPE_GET(obj));
442                 return;
443         }
444
445         if (evas_object_type_match(obj, "elm_popup") || evas_object_type_match(obj, "elm_ctxpopup")) {
446                 if (elm_object_part_text_get(obj, "title,text")) skip_text = 1;
447                 eina_list_free(ret_list);
448                 ret_list = NULL;
449                 find_popup = 0;
450         }
451
452         if (find_popup) {
453                 VC_ELM_LOG_DUMP("   [%d] Object(%s) : Find_popup", cnt, EVAS_OBJECT_TYPE_GET(obj));
454                 return;
455         }
456
457         // viewport check
458         evas_object_geometry_get(obj, &x, &y, &w, &h);
459
460         if (!RECTS_INTERSECT(x, y, w, h, util_mgr->x, util_mgr->y, util_mgr->w, util_mgr->h)) {
461                 VC_ELM_LOG_DUMP("## x(%d), y(%d), w(%d), h(%d), util_mgr->x(%d), util_mgr->y(%d), util_mgr->w(%d), util_mgr->h(%d)", x, y, w, h, util_mgr->x, util_mgr->y, util_mgr->w, util_mgr->h);
462                 VC_ELM_LOG_DUMP("## RECTS_INTERSECT(%d), SPANS_COMMON_X(%d), SPANS_COMMON_Y(%d)", RECTS_INTERSECT(x, y, w, h, util_mgr->x, util_mgr->y, util_mgr->w, util_mgr->h),
463                         SPANS_COMMON(x, w, util_mgr->x, util_mgr->w), SPANS_COMMON(y, h, util_mgr->y, util_mgr->h));
464                 return;
465         }
466
467         // clipper check
468         if (evas_object_clipees_get(obj)) is_clip = EINA_TRUE;
469         if (is_clip) {
470                 VC_ELM_LOG_DUMP("is_clip(%d)", is_clip);
471                 goto next;
472         }
473
474         if (!strcmp(EVAS_OBJECT_TYPE_GET(obj), "text") || !strcmp(EVAS_OBJECT_TYPE_GET(obj), "textblock")) {
475                 if (!parent_widget_focusable && !list_type) {
476                         VC_ELM_LOG_DUMP("## parent_widget_focusable(%d), list_type(%d)", parent_widget_focusable, list_type);
477                         goto next;
478                 }
479                 if (skip_text) {
480                         skip_text = 0;
481                         VC_ELM_LOG_DUMP("   [%d] Object(%s) : Skip_text", cnt, EVAS_OBJECT_TYPE_GET(obj));
482                         return;
483                 }
484         }
485
486         object_info = calloc(1, sizeof(Object_Info));
487         if (!object_info) {
488                 VC_ELM_LOG_ERR("[ERROR] Fail to allocate memory");
489                 return;
490         }
491
492         object_info->parent = parent;
493
494         object_info->address = (int)obj;
495         object_info->geometry_info.x = x;
496         object_info->geometry_info.y = y;
497         object_info->geometry_info.w = w;
498         object_info->geometry_info.h = h;
499
500         if (elm_widget_is(obj)) {
501                 if (elm_object_focus_get(obj))
502                         object_info->focus = EINA_TRUE;
503                 else
504                         object_info->focus = EINA_FALSE;
505
506                 if (elm_widget_can_focus_get(obj) &&
507                                 (!elm_object_disabled_get(obj))) {
508                         object_info->focusable = EINA_TRUE;
509                         parent_widget_focusable = EINA_TRUE;
510                 } else {
511                         object_info->focusable = EINA_FALSE;
512                         parent_widget_focusable = EINA_FALSE;
513                 }
514         }
515         if (!list_type) {
516             if (evas_object_type_match(obj, "elm_genlist") || evas_object_type_match(obj, "elm_gengrid") || evas_object_type_match(obj, "elm_list") || evas_object_type_match(obj, "elm_ctxpopup") || evas_object_type_match(obj, "elm_index"))
517               list_type = EINA_TRUE;
518          }
519
520         // evas object type check
521         if (evas_object_is_swallow_rect(obj)) {
522                 object_info->type = calloc(1, strlen("swallow") + 1);
523                 strncpy(object_info->type, "swallow", strlen("swallow") + 1);
524         } else if (evas_object_type_match(obj, "rectangle")) {
525                 object_info->type = calloc(1, strlen("rect") + 1);
526                 strncpy(object_info->type, "rect", strlen("rect") + 1);
527                 evas_object_color_get(obj, &r, &g, &b, &a);
528                 object_info->rgb_info.r = r;
529                 object_info->rgb_info.g = g;
530                 object_info->rgb_info.b = b;
531                 object_info->rgb_info.a = a;
532         } else {
533                 object_info->type = calloc(1, strlen(EVAS_OBJECT_TYPE_GET(obj)) + 1);
534                 strncpy(object_info->type, EVAS_OBJECT_TYPE_GET(obj), strlen(EVAS_OBJECT_TYPE_GET(obj)) + 1);
535         }
536
537         smart_parent_obj = evas_object_smart_parent_get(obj);
538
539         // image info save
540         if (!strcmp(EVAS_OBJECT_TYPE_GET(obj), "elm_icon") ||
541                         !strcmp(EVAS_OBJECT_TYPE_GET(obj), "elm_image")) {
542                 elm_image_file_get(obj, &file, &key);
543                 evas_object_data_set(obj, "image_name", file);
544         }
545
546         // image name check
547         if (smart_parent_obj && evas_object_type_match(obj, "image")
548                         && (evas_object_type_match(smart_parent_obj, "elm_icon")
549                                 || evas_object_type_match(smart_parent_obj, "elm_image"))) {
550                 if ((ret = evas_object_data_get(smart_parent_obj, "image_name"))) {
551                         _extract_edje_file_name(object_info, ret);
552                         evas_object_data_del(smart_parent_obj, "edje_image_name");
553                 }
554         }
555
556         // edje info save
557         if (evas_object_type_match(obj, "edje")) {
558                 edje_object_file_get(obj, &file, &group);
559                 if (group) {
560                         object_info->group = calloc(1, strlen(group) + 1);
561                         strncpy(object_info->group, group, strlen(group) + 1);
562                 }
563
564                 _extract_edje_file_name(object_info, file);
565                 _edje_file_info_save(util_mgr, obj);
566         }
567
568         // edje info check
569         if (!is_clip && smart_parent_obj
570                         && !elm_widget_is(obj) && evas_object_type_match(smart_parent_obj, "edje")) {
571                 EINA_LIST_FOREACH(util_mgr->edje_part_name_list, l, edje_info) {
572                         if (edje_info->obj == obj) {
573                                 if (edje_info->color_class) {
574                                         object_info->color_class = calloc(1, strlen(edje_info->color_class) + 1);
575                                         strncpy(object_info->color_class, edje_info->color_class, strlen(edje_info->color_class) + 1);
576                                 }
577
578                                 ret = edje_object_part_state_get(evas_object_smart_parent_get(obj), edje_info->part_name, &val);
579                                 object_info->part_name = calloc(1, strlen(edje_info->part_name) + 1);
580                                 object_info->part_state = calloc(1, strlen(ret) + 1);
581                                 strncpy(object_info->part_name, edje_info->part_name, strlen(edje_info->part_name) + 1);
582                                 strncpy(object_info->part_state, ret, strlen(ret) + 1);
583
584                                 if (edje_info->image_name) {
585                                         object_info->image_name = calloc(1, strlen(edje_info->image_name) + 1);
586                                         strncpy(object_info->image_name, edje_info->image_name, strlen(edje_info->image_name) + 1);
587                                 }
588                                 break;
589                         }
590                 }
591         }
592
593         text = NULL;
594         if (0 == vc_elm_efl_dump_is_vt_auto_enabled()) {
595                 if (!strcmp(EVAS_OBJECT_TYPE_GET(obj), "text"))
596                         text = eina_stringshare_add(evas_object_text_text_get(obj));
597                 else if (!strcmp(EVAS_OBJECT_TYPE_GET(obj), "textblock")) {
598                         ret = evas_object_textblock_text_markup_get(obj);
599                         temp = evas_textblock_text_markup_to_utf8(obj, ret);
600                         text = eina_stringshare_add(temp);
601
602                         if (NULL != temp) {
603                                 free(temp);
604                                 temp = NULL;
605                         }
606                 }
607         } else {
608                 if (!strcmp(EVAS_OBJECT_TYPE_GET(obj), "text") && EINA_TRUE == _is_descendant_of_list(object_info)) {
609                         text = eina_stringshare_add(evas_object_text_text_get(obj));
610                         VC_ELM_LOG_DUMP("####### [DEBUG] text(%s), atspi_text(%s)", text, elm_atspi_accessible_name_get(obj));
611                 } else if (!strcmp(EVAS_OBJECT_TYPE_GET(obj), "textblock") && EINA_TRUE == _is_descendant_of_list(object_info)) {
612                         ret = evas_object_textblock_text_markup_get(obj);
613                         temp = evas_textblock_text_markup_to_utf8(obj, ret);
614                         text = eina_stringshare_add(temp);
615
616                         if (NULL != temp) {
617                                 free(temp);
618                                 temp = NULL;
619                         }
620                         VC_ELM_LOG_DUMP("####### [DEBUG] textblock(%s), atspi_text(%s)", text, elm_atspi_accessible_name_get(obj));
621                 } else if (elm_atspi_accessible_name_get(obj) && EINA_TRUE == object_info->focusable && EINA_TRUE == _is_clickable_object(obj)) {
622                         text = elm_atspi_accessible_name_get(obj);
623                         VC_ELM_LOG_DUMP("####### [DEBUG] atspi_text(%s)", text);
624                 } else if (elm_atspi_accessible_name_get(obj) && !strcmp(EVAS_OBJECT_TYPE_GET(obj), "elm_layout") && EINA_TRUE == _is_descendant_of_toolbar(object_info)) {
625                         text = elm_atspi_accessible_name_get(obj);
626                         VC_ELM_LOG_DUMP("####### [DEBUG] toolbar(%s)", text);
627                 } else {
628                         if (EINA_FALSE == _has_accessible_name(object_info)) {
629                                 if (!strcmp(EVAS_OBJECT_TYPE_GET(obj), "text")) {
630                                         text = eina_stringshare_add(evas_object_text_text_get(obj));
631                                         VC_ELM_LOG_DUMP("####### [DEBUG] text(%s), part_name(%s)", text, object_info->part_name);
632                                 } else if (!strcmp(EVAS_OBJECT_TYPE_GET(obj), "textblock")) {
633                                         ret = evas_object_textblock_text_markup_get(obj);
634                                         temp = evas_textblock_text_markup_to_utf8(obj, ret);
635                                         text = eina_stringshare_add(temp);
636                                         VC_ELM_LOG_DUMP("####### [DEBUG] textblock(%s), part_name(%s)", text, object_info->part_name);
637
638                                         if (NULL != temp) {
639                                                 free(temp);
640                                                 temp = NULL;
641                                         }
642                                 }
643                         }
644                 }
645
646                 if (NULL != text && EINA_TRUE == _is_descendant_of_list(object_info) && EINA_TRUE == _is_descendant_of_ctxpopup(object_info)) {
647                         char* temp_text = strdup(text);
648                         ctxpop_text_list = eina_list_append(ctxpop_text_list, temp_text);
649                         VC_ELM_LOG_DUMP("####### [DEBUG] list in ctxpopup, text(%s)", temp_text);
650                 }
651         }
652         if (text && strlen(text) > 0) {
653                 object_info->text = calloc(1, strlen(text) + 1);
654                 strncpy(object_info->text, text, strlen(text) + 1);
655         }
656
657         ret_list = eina_list_append(ret_list, object_info);
658 next:
659         if (!evas_object_type_match(obj, "rectangle") && !evas_object_type_match(obj, "text") && !evas_object_type_match(obj, "image")) {
660                 children = evas_object_smart_members_get(obj);
661                 EINA_LIST_FREE(children, child)
662                         _obj_tree_items_exclude_unfocusable_text(util_mgr, child, object_info, parent_widget_focusable, list_type, cnt + 1);
663                 if (evas_object_type_match(obj, "elm_popup") || evas_object_type_match(obj, "elm_ctxpopup")) find_popup = 1;
664         }
665         VC_ELM_LOG_DUMP("   [%d] %s : return", cnt, EVAS_OBJECT_TYPE_GET(obj));
666 }
667
668 static void
669 _obj_tree_text_items(Ea_Util_Mgr *util_mgr, Evas_Object *obj)
670 {
671         Eina_List *children = NULL, *l = NULL;
672         Evas_Object *child;
673         Evas_Coord x = 0, y = 0, w = 0, h = 0;
674         Eina_Bool is_clip = EINA_FALSE;
675         const char *ret = NULL;
676         const char *text = NULL;
677         char* temp = NULL;
678         char* data = NULL;
679         Eina_Bool check;
680
681         // visible check
682         if (!evas_object_is_visible_get(obj)) return;
683
684         // viewport check
685         evas_object_geometry_get(obj, &x, &y, &w, &h);
686
687         if (!RECTS_INTERSECT(x, y, w, h, util_mgr->x, util_mgr->y, util_mgr->w, util_mgr->h)) return;
688
689         // clipper check
690         if (evas_object_clipees_get(obj)) is_clip = EINA_TRUE;
691         if (is_clip) goto next;
692
693         text = NULL;
694         if (!strcmp(EVAS_OBJECT_TYPE_GET(obj), "text"))
695                 text = eina_stringshare_add(evas_object_text_text_get(obj));
696         else if (!strcmp(EVAS_OBJECT_TYPE_GET(obj), "textblock")) {
697                 ret = evas_object_textblock_text_markup_get(obj);
698                 temp = evas_textblock_text_markup_to_utf8(obj, ret);
699                 text = eina_stringshare_add(temp);
700
701                 if (NULL != temp) {
702                         free(temp);
703                         temp = NULL;
704                 }
705         }
706         if (text && strlen(text) > 0) {
707                 check = EINA_TRUE;
708                 EINA_LIST_FOREACH(ret_text_list, l, data) {
709                         if (!strcmp(data, text)) {
710                                 check = EINA_FALSE;
711                                 break;
712                         }
713                 }
714                 if (check) ret_text_list = eina_list_append(ret_text_list, text);
715         }
716
717 next:
718         if (!evas_object_type_match(obj, "rectangle") && !evas_object_type_match(obj, "text") && !evas_object_type_match(obj, "image")) {
719                 children = evas_object_smart_members_get(obj);
720                 EINA_LIST_FREE(children, child)
721                         _obj_tree_text_items(util_mgr, child);
722         }
723 }
724
725 static void
726 _obj_tree_text_items_exclude_unfocusable_text(Ea_Util_Mgr *util_mgr, Evas_Object *obj, Eina_Bool parent_widget_focusable)
727 {
728         Eina_List *children = NULL, *l = NULL;
729         Evas_Object *child;
730         Evas_Coord x = 0, y = 0, w = 0, h = 0;
731         Eina_Bool is_clip = EINA_FALSE;
732         const char *ret = NULL;
733         const char *text = NULL;
734         char* data = NULL;
735         char* temp = NULL;
736         Eina_Bool check;
737
738         // visible check
739         if (!evas_object_is_visible_get(obj)) return;
740
741         // viewport check
742         evas_object_geometry_get(obj, &x, &y, &w, &h);
743
744         if (!RECTS_INTERSECT(x, y, w, h, util_mgr->x, util_mgr->y, util_mgr->w, util_mgr->h)) /*return;*/ goto next;
745
746         // clipper check
747         if (evas_object_clipees_get(obj)) is_clip = EINA_TRUE;
748         if (is_clip) goto next;
749
750         if (elm_widget_is(obj)) {
751                 if (elm_widget_can_focus_get(obj)) parent_widget_focusable = EINA_TRUE;
752                 else parent_widget_focusable = EINA_FALSE;
753         }
754
755         text = NULL;
756         if (!strcmp(EVAS_OBJECT_TYPE_GET(obj), "text")) {
757                 if (!parent_widget_focusable) goto next;
758                 text = eina_stringshare_add(evas_object_text_text_get(obj));
759         } else if (!strcmp(EVAS_OBJECT_TYPE_GET(obj), "textblock")) {
760                 if (!parent_widget_focusable) goto next;
761                 ret = evas_object_textblock_text_markup_get(obj);
762                 temp = evas_textblock_text_markup_to_utf8(obj, ret);
763                 text = eina_stringshare_add(temp);
764
765                 if (NULL != temp) {
766                         free(temp);
767                         temp = NULL;
768                 }
769         }
770         if (text && strlen(text) > 0) {
771                 check = EINA_TRUE;
772                 EINA_LIST_FOREACH(ret_text_list, l, data) {
773                         if (!strcmp(data, text)) {
774                                 check = EINA_FALSE;
775                                 break;
776                         }
777                 }
778                 if (check) ret_text_list = eina_list_append(ret_text_list, text);
779         }
780
781 next:
782         if (!evas_object_type_match(obj, "rectangle") && !evas_object_type_match(obj, "text") && !evas_object_type_match(obj, "image")) {
783                 children = evas_object_smart_members_get(obj);
784                 EINA_LIST_FREE(children, child)
785                         _obj_tree_text_items_exclude_unfocusable_text(util_mgr, child, parent_widget_focusable);
786         }
787 }
788
789 static void
790 _object_tree(Ea_Util_Mgr *util_mgr, int val, Eina_Bool exclude_unfocusable_text)
791 {
792         Eina_List *objs = NULL;
793         Evas_Object *obj = NULL;
794
795         objs = evas_objects_in_rectangle_get(util_mgr->evas, SHRT_MIN, SHRT_MIN, USHRT_MAX, USHRT_MAX, EINA_TRUE, EINA_TRUE);
796
797         if (val == 1) {
798                 if (exclude_unfocusable_text) {
799                         EINA_LIST_FREE(objs, obj) {
800                                 VC_ELM_LOG_DUMP("###################### start ########################");
801                                 _obj_tree_items_exclude_unfocusable_text(util_mgr, obj, NULL, EINA_FALSE, EINA_FALSE, 0);
802                         }
803                 } else {
804                         EINA_LIST_FREE(objs, obj)
805                                 _obj_tree_items(util_mgr, obj, NULL);
806                 }
807         } else if (val == 2) {
808                 if (exclude_unfocusable_text) {
809                         EINA_LIST_FREE(objs, obj)
810                                 _obj_tree_text_items_exclude_unfocusable_text(util_mgr, obj, EINA_FALSE);
811                 } else {
812                         EINA_LIST_FREE(objs, obj)
813                                 _obj_tree_text_items(util_mgr, obj);
814                 }
815         }
816 }
817
818 void
819 ea_object_dump_list_clear(void)
820 {
821         Object_Info *obj_info = NULL;
822         EINA_LIST_FREE(ret_list, obj_info) {
823                 if (!obj_info->type) free(obj_info->type);
824                 if (!obj_info->edje_file) free(obj_info->edje_file);
825                 if (!obj_info->group) free(obj_info->group);
826                 if (!obj_info->image_name) free(obj_info->image_name);
827                 if (!obj_info->color_class) free(obj_info->color_class);
828                 if (!obj_info->part_name) free(obj_info->part_name);
829                 if (!obj_info->part_state) free(obj_info->part_state);
830                 if (!obj_info->text) free(obj_info->text);
831                 free(obj_info);
832         }
833         ret_list = NULL;
834 }
835
836
837 Eina_List*
838 ea_object_dump_full_list_get(Eina_Bool exclude_unfocusable_text)
839 {
840         Eina_List *ecore_evas_list = NULL;
841         Ecore_Evas *ee = NULL;
842         Evas *evas = NULL;
843
844         if (ret_list)
845                 ea_object_dump_list_clear();
846         if (ctxpop_text_list) {
847                 text_dump_genlist_in_ctxpopup_clear();
848                 VC_ELM_LOG_DUMP("Clear ctxpop_text_list");
849         }
850         Ea_Util_Mgr *util_mgr = calloc(1, sizeof(Ea_Util_Mgr));
851         if (!util_mgr) {
852                 printf("Fail : utility manager memory alloc\n");
853                 goto exit;
854         }
855
856         ecore_evas_list = ecore_evas_ecore_evas_list_get();
857
858         EINA_LIST_FREE(ecore_evas_list, ee) {
859                 evas = ecore_evas_get(ee);
860                 util_mgr->evas = evas;
861                 find_popup = 0;
862                 skip_text = 0;
863
864                 ecore_wl2_sync();
865
866                 Ecore_Wl2_Display* wl2_display = ecore_wl2_connected_display_get(NULL);
867
868                 if (EINA_TRUE == g_set_geometry) {
869                         util_mgr->x = g_geo_x;
870                         util_mgr->y = g_geo_y;
871                         util_mgr->w = g_geo_w;
872                         util_mgr->h = g_geo_h;
873                 } else {
874                         util_mgr->x = 0;
875                         util_mgr->y = 0;
876                         ecore_wl2_display_screen_size_get(wl2_display, &util_mgr->w, &util_mgr->h);
877                 }
878
879                 _object_tree(util_mgr, 1, exclude_unfocusable_text);
880         }
881
882 exit:
883         if (!util_mgr) return NULL;
884         if (util_mgr->edje_part_name_list)
885                 eina_list_free(util_mgr->edje_part_name_list);  // need to check
886         free(util_mgr);
887         return ret_list;
888 }
889
890 Eina_List*
891 ea_object_dump_text_list_get(Eina_Bool exclude_unfocusable_text)
892 {
893         Eina_List *ecore_evas_list = NULL;
894         Ecore_Evas *ee = NULL;
895         Evas *evas = NULL;
896
897         Ea_Util_Mgr *util_mgr = calloc(1, sizeof(Ea_Util_Mgr));
898         if (!util_mgr) {
899                 printf("Fail : utility manager memory alloc\n");
900                 goto exit;
901         }
902
903         ecore_evas_list = ecore_evas_ecore_evas_list_get();
904
905         EINA_LIST_FREE(ecore_evas_list, ee) {
906                 evas = ecore_evas_get(ee);
907                 util_mgr->evas = evas;
908
909                 ecore_wl2_sync();
910                 util_mgr->x = 0;
911                 util_mgr->y = 0;
912
913                 Ecore_Wl2_Display* wl2_display = ecore_wl2_connected_display_get(NULL);
914                 ecore_wl2_display_screen_size_get(wl2_display, &util_mgr->w, &util_mgr->h);
915
916                 _object_tree(util_mgr, 2, exclude_unfocusable_text);
917         }
918
919 exit:
920         if (!util_mgr) return NULL;
921         free(util_mgr);
922         return ret_text_list;
923 }
924
925 Eina_List*
926 ea_object_dump_find_data(Eina_List *list, const char *str1, const char *str2)
927 {
928         Eina_List *l = NULL;
929         Object_Info *data = NULL;
930         Eina_List *ret_data_list = NULL;
931
932         if (!list) return NULL;
933         if (!str1 || !str2) return NULL;
934
935         if (!strcmp(str1, "type")) {
936                 EINA_LIST_FOREACH(list, l, data) {
937                         if (data->type)
938                                 if (!strcmp(data->type, str2)) ret_data_list = eina_list_append(ret_data_list, data);
939                 }
940         } else if (!strcmp(str1, "edje_file")) {
941                 EINA_LIST_FOREACH(list, l, data) {
942                         if (data->edje_file)
943                                 if (!strcmp(data->edje_file, str2)) ret_data_list = eina_list_append(ret_data_list, data);
944                 }
945         } else if (!strcmp(str1, "group")) {
946                 EINA_LIST_FOREACH(list, l, data) {
947                         if (data->group)
948                                 if (!strcmp(data->group, str2)) ret_data_list = eina_list_append(ret_data_list, data);
949                 }
950         } else if (!strcmp(str1, "image_name")) {
951                 EINA_LIST_FOREACH(list, l, data) {
952                         if (data->image_name)
953                                 if (!strcmp(data->image_name, str2)) ret_data_list = eina_list_append(ret_data_list, data);
954                 }
955         } else if (!strcmp(str1, "color_class")) {
956                 EINA_LIST_FOREACH(list, l, data) {
957                         if (data->color_class)
958                                 if (!strcmp(data->color_class, str2)) ret_data_list = eina_list_append(ret_data_list, data);
959                 }
960         } else if (!strcmp(str1, "part_name")) {
961                 EINA_LIST_FOREACH(list, l, data) {
962                         if (data->part_name)
963                                 if (!strcmp(data->part_name, str2)) ret_data_list = eina_list_append(ret_data_list, data);
964                 }
965         } else if (!strcmp(str1, "part_state")) {
966                 EINA_LIST_FOREACH(list, l, data) {
967                         if (data->part_state)
968                                 if (!strcmp(data->part_state, str2)) ret_data_list = eina_list_append(ret_data_list, data);
969                 }
970         } else if (!strcmp(str1, "text")) {
971                 EINA_LIST_FOREACH(list, l, data) {
972                         if (data->text)
973                                 if (!strcmp(data->text, str2)) ret_data_list = eina_list_append(ret_data_list, data);
974                 }
975         }
976
977         return ret_data_list;
978 }
979
980 Object_Info*
981 ea_object_dump_parent_widget_data_get(const Object_Info *obj_info)
982 {
983         if (NULL == obj_info) {
984                 VC_ELM_LOG_DUMP("obj_info is NULL");
985                 return NULL;
986         }
987
988         Object_Info *parent_info = NULL;
989
990         parent_info = obj_info->parent;
991         while (parent_info) {
992                 if (strstr(parent_info->type, "elm"))
993                         return parent_info;
994                 parent_info = parent_info->parent;
995         }
996         return NULL;
997 }
998
999 void ea_object_dump_set_geometry_info(int x, int y, int w, int h)
1000 {
1001         g_set_geometry = EINA_TRUE;
1002         g_geo_x = x;
1003         g_geo_y = y;
1004         g_geo_w = w;
1005         g_geo_h = h;
1006 }
1007
1008 void ea_object_dump_unset_geometry_info()
1009 {
1010         g_set_geometry = EINA_FALSE;
1011         g_geo_x = 0;
1012         g_geo_y = 0;
1013         g_geo_w = 0;
1014         g_geo_h = 0;
1015 }
1016
1017 Eina_List*
1018 text_dump_genlist_in_ctxpopup_get()
1019 {
1020         return ctxpop_text_list;
1021 }
1022
1023 void
1024 text_dump_genlist_in_ctxpopup_clear(void)
1025 {
1026         char *text = NULL;
1027         EINA_LIST_FREE(ctxpop_text_list, text) {
1028                 if (!text) free(text);
1029         }
1030         ctxpop_text_list = NULL;
1031 }