elm: efl_access: Add attribute_append, attributes_clear APIs
authorShilpa Singh <shilpa.singh@samsung.com>
Tue, 28 Nov 2017 13:39:58 +0000 (19:09 +0530)
committerJiyoun Park <jy0703.park@samsung.com>
Thu, 21 Dec 2017 10:17:22 +0000 (19:17 +0900)
elm: efl_access: Add reading_info_type set/get APIs

contributed to efl opensource
https://phab.enlightenment.org/D5510
https://phab.enlightenment.org/D5524

Change-Id: I6156d084be95429664898c3d9e58c974c6e5f718

src/lib/elementary/efl_access.c
src/lib/elementary/efl_access.eo

index 4923860..7043b08 100644 (file)
@@ -123,11 +123,13 @@ struct _Efl_Access_Event_Handler
 
 struct _Efl_Access_Data
 {
-   Efl_Access_Role role;
+   Efl_Access_Relation_Set relations;
+   Eina_List     *attr_list;
    const char    *name;
    const char    *description;
    const char    *translation_domain;
-   Efl_Access_Relation_Set relations;
+   Efl_Access_Role role;
+   Efl_Access_Reading_Info_Type reading_info;
    Efl_Access_Type type: 2;
 };
 
@@ -193,9 +195,99 @@ _efl_access_parent_set(Eo *obj, Efl_Access_Data *pd EINA_UNUSED, Efl_Access *new
 EOLIAN Eina_List*
 _efl_access_attributes_get(Eo *obj EINA_UNUSED, Efl_Access_Data *pd EINA_UNUSED)
 {
-   WRN("The %s object does not implement the \"accessible_attributes_set\" function.",
-       efl_class_name_get(efl_class_get(obj)));
-   return NULL;
+   Eina_List *attr_list = NULL;
+   if (pd->attr_list)
+     {
+        Eina_List *l = NULL;
+        Efl_Access_Attribute *t_attr = NULL;
+        EINA_LIST_FOREACH(pd->attr_list, l, t_attr)
+          {
+             Efl_Access_Attribute *attr = calloc(1, sizeof(Efl_Access_Attribute));
+             if (!attr)
+                  return attr_list;
+
+             attr->key = eina_stringshare_add(t_attr->key);
+             attr->value = eina_stringshare_add(t_attr->value);
+             attr_list = eina_list_append(attr_list, attr);
+          }
+     }
+   return attr_list;
+}
+
+EOLIAN static void
+_efl_access_attribute_append(Eo *obj EINA_UNUSED, Efl_Access_Data *pd EINA_UNUSED, const char *key, const char *value)
+{
+   Eina_List *l;
+   Efl_Access_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(Efl_Access_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);
+}
+
+EOLIAN static void _efl_access_attributes_clear(Eo *obj EINA_UNUSED, Efl_Access_Data *pd)
+{
+   if (!pd->attr_list) return;
+   Efl_Access_Attribute *attr;
+   EINA_LIST_FREE(pd->attr_list, attr)
+     {
+        eina_stringshare_del(attr->key);
+        eina_stringshare_del(attr->value);
+        free(attr);
+     }
+   pd->attr_list = NULL;
+}
+
+EOLIAN static void
+_efl_access_reading_info_type_set(Eo *obj, Efl_Access_Data *pd, Efl_Access_Reading_Info_Type reading_info)
+{
+   Eina_Strbuf *buf = NULL;
+   pd->reading_info = reading_info;
+   buf = eina_strbuf_new();
+   eina_strbuf_reset(buf);
+   if (reading_info & (EFL_ACCESS_READING_INFO_TYPE_NAME))
+     {
+        eina_strbuf_append(buf, "name");
+        eina_strbuf_append_char(buf, '|');
+     }
+   if (reading_info & (EFL_ACCESS_READING_INFO_TYPE_ROLE))
+     {
+        eina_strbuf_append(buf, "role");
+        eina_strbuf_append_char(buf, '|');
+     }
+   if (reading_info & (EFL_ACCESS_READING_INFO_TYPE_DESCRIPTION))
+     {
+        eina_strbuf_append(buf, "description");
+        eina_strbuf_append_char(buf, '|');
+     }
+   if (reading_info & (EFL_ACCESS_READING_INFO_TYPE_STATE))
+     {
+        eina_strbuf_append(buf, "state");
+     }
+   efl_access_attribute_append(obj, "reading_info_type", eina_strbuf_string_get(buf));
+   eina_strbuf_free(buf);
+}
+
+EOLIAN Efl_Access_Reading_Info_Type
+_efl_access_reading_info_type_get(Eo *obj EINA_UNUSED, Efl_Access_Data *pd)
+{
+   return pd->reading_info;
 }
 
 EOLIAN static Efl_Access_Role
index 6552d90..ac31370 100644 (file)
@@ -314,7 +314,32 @@ mixin Efl.Access (Efl.Interface, Efl.Object)
          get {
          }
          values {
-            attributes: free(list<ptr(Efl.Access.Attribute) @owned>, efl_access_attributes_list_free) @owned; [[List of object attributes]]
+            attributes: list<ptr(Efl.Access.Attribute) @owned> @owned; [[List of object attributes, Must be freed by the user]]
+         }
+      }
+      attribute_append {
+         [[Add key-value pair identifying object extra attributes
+         ]]
+         params {
+            @in key: string; [[The string key to give extra information]]
+            @in value: string; [[The string value to give extra information]]
+         }
+      }
+      attributes_clear {
+         [[Removes all attributes in accessible object.
+
+           \@internal
+         ]]
+      }
+      @property reading_info_type @protected {
+         get {
+            [[Gets reading information types of an accessible object.]]
+         }
+         set {
+            [[Sets reading information of an accessible object.]]
+         }
+         values {
+            reading_info: Efl.Access.Reading.Info.Type; [[Reading information types]]
          }
       }
       attribute_append {