atspi: Check existing attribute and override 77/125477/4
authorShinwoo Kim <cinoo.kim@samsung.com>
Mon, 17 Apr 2017 11:33:44 +0000 (20:33 +0900)
committerGerrit Code Review <gerrit@review.vlan103.tizen.org>
Fri, 21 Apr 2017 06:00:47 +0000 (23:00 -0700)
elm_atspi_accessible_attribute_append should be deprecated because the attribute
is not appended. The attribute should work with setter, getter function.

It seems that atspi_accessible_get_attributes returns unique key and value.
The screen reader could get the last appended key and value though.
The previously added key and value is not necessary.

Change-Id: Id11540cdfddd86aa8214543a5c7a2eadf9f637e0

src/lib/elm_interface_atspi_accessible.c

index 5bd83179a3ec352562b3a0f0eb9692df090250a3..b453aa2d31de0cea0729f2a7fa2afb89bf2f5c25 100644 (file)
@@ -234,11 +234,25 @@ _elm_interface_atspi_accessible_attributes_get(Eo *obj EINA_UNUSED, Elm_Interfac
 EOLIAN static void
 _elm_interface_atspi_accessible_attribute_append(Eo *obj EINA_UNUSED, Elm_Interface_Atspi_Accessible_Data *pd EINA_UNUSED, const char *key, const char *value)
 {
-   if (!key || !value)
-       return;
-   Elm_Atspi_Attribute *attr = calloc(1, sizeof(Elm_Atspi_Attribute));
-   if (!attr)
-       return;
+   Eina_List *l;
+   Elm_Atspi_Attribute *attr = NULL;
+
+   if (!key || !value) return;
+
+   /* Check existing attributes has this key */
+   EINA_LIST_FOREACH(pd->attr_list, l, attr)
+     {
+        if (!strcmp((const char *)attr->key, key))
+          {
+             eina_stringshare_replace(&attr->value, value);
+             return;
+          }
+     }
+
+   /* Add new attribute */
+   attr = calloc(1, sizeof(Elm_Atspi_Attribute));
+   if (!attr) return;
+
    attr->key = eina_stringshare_add(key);
    attr->value = eina_stringshare_add(value);
    pd->attr_list = eina_list_append(pd->attr_list, attr);
@@ -248,16 +262,17 @@ EAPI void
 elm_atspi_attribute_list_free(Eina_List *list)
 {
    Elm_Atspi_Attribute *attr;
-
    EINA_LIST_FREE(list, attr)
+     {
+        eina_stringshare_del(attr->key);
+        eina_stringshare_del(attr->value);
         free(attr);
-
-       eina_list_free(list);
+     }
 }
 
 EOLIAN static void _elm_interface_atspi_accessible_attributes_clear(Eo *obj EINA_UNUSED, Elm_Interface_Atspi_Accessible_Data *pd) {
-       elm_atspi_attribute_list_free(pd->attr_list);
-       pd->attr_list = NULL;
+   elm_atspi_attribute_list_free(pd->attr_list);
+   pd->attr_list = NULL;
 }
 
 EOLIAN static void