Introduce consistent method for composition of extended description 41/280241/2
authorLukasz Oleksak <l.oleksak@samsung.com>
Thu, 25 Aug 2022 13:32:12 +0000 (15:32 +0200)
committerLukasz Oleksak <l.oleksak@samsung.com>
Tue, 30 Aug 2022 14:42:03 +0000 (14:42 +0000)
Change-Id: I8bc5411a90ef3cf2ed6051d806c83738ee9c7ec0

src/reading_composer.c

index 2e0fbf4555f294520e87f8662a61350e66e150b9..f8f00d39412214b1dc51777e6058e8172ebaa945 100644 (file)
@@ -356,43 +356,6 @@ TIZEN_PROD_STATIC char *generate_description_trait(AtspiAccessibleReadingMateria
        return ret;
 }
 
-TIZEN_PROD_STATIC char *generate_description_from_relation_object(AtspiAccessibleReadingMaterial *rm)
-{
-       char *trait = NULL;
-       Eina_Strbuf *buf;
-       char *role_name = generate_role_trait(rm);
-       char *description_from_role = NULL;
-       char *state_from_role = generate_state_trait(rm);
-
-       buf = eina_strbuf_new();
-       if (role_name && strlen(role_name) > 0)
-               ESAL(buf, role_name);
-
-       if (vc_get_read_description())
-               description_from_role = generate_description_trait(rm);
-       if (description_from_role && strlen(description_from_role) > 0) {
-               if (eina_strbuf_length_get(buf))
-                       ESAL(buf, " , ");
-               ESAL(buf, description_from_role);
-       }
-
-       if (state_from_role && strlen(state_from_role) > 0) {
-               if (eina_strbuf_length_get(buf))
-                       ESAL(buf, " , ");
-               ESAL(buf, state_from_role);
-       }
-       SCREEN_READER_SAFE_FREE(role_name, free);
-       SCREEN_READER_SAFE_FREE(description_from_role, free);
-       SCREEN_READER_SAFE_FREE(state_from_role, free);
-
-       if (rm->description && strlen(rm->description) > 0)
-               eina_strbuf_prepend_printf(buf, "%s , ", rm->description);
-
-       trait = eina_strbuf_string_steal(buf);
-       eina_strbuf_free(buf);
-       return trait;
-}
-
 TIZEN_PROD_STATIC
 unsigned short int reading_composer_reading_attribute_get(AtspiAccessibleReadingMaterial *rm)
 {
@@ -611,8 +574,8 @@ char* reading_composer_description_get(ReadingComposerData *data)
        DEBUG("END");
        return base_desc;
 }
-
-char* reading_composer_extended_description_get(ReadingComposerData *data)
+TIZEN_PROD_STATIC
+char* reading_composer_extended_description_get_recursive(ReadingComposerData *data, int nest_level, int max_nest_level)
 {
        DEBUG("START");
        char *description = NULL;
@@ -621,7 +584,7 @@ char* reading_composer_extended_description_get(ReadingComposerData *data)
        char *description_from_role = NULL;
        AtspiAccessibleReadingMaterial *rm;
 
-       if (!data)
+       if (!data || nest_level > max_nest_level)
                return NULL;
 
        rm = data;
@@ -640,29 +603,29 @@ char* reading_composer_extended_description_get(ReadingComposerData *data)
        if (reading_attribute & ACCESSIBLE_READING_INFO_TYPE_DESCRIPTION) {
                /* read_description is determined by vconf value for the 'read usage hints aloud' */
                DEBUG("START : ACCESSIBLE_READING_INFO_TYPE_DESCRIPTION (read usage hints: %d)", vc_get_read_description());
-               description = rm->description;
-               /* If description is set by application side, do not read other default information */
-               if (vc_get_read_description() && description && strlen(description) > 0) {
-                       ESAL(buf2, description);
-               } else if (STATE_SET_CONTAINS(rm->states, ATSPI_STATE_ENABLED)) {
-                       if (vc_get_read_description())
-                               description_from_role = generate_description_trait(rm);
-
-                       if (rm->described_by_accessible) {
-                               AtspiAccessibleReadingMaterial *_rm = atspi_accessible_get_reading_material(rm->described_by_accessible, NULL);
-                               if (_rm) {
-                                       description_from_relation = generate_description_from_relation_object(_rm);
-                                       reading_composer_reading_material_free(_rm);
+               if (vc_get_read_description()) {
+                       description = rm->description;
+                       if (description && strlen(description) > 0) {
+                               /* If description is explicitely set by application side, read it as it is (without any other default information) */
+                               ESAL(buf2, description);
+                       } else if (STATE_SET_CONTAINS(rm->states, ATSPI_STATE_ENABLED)) {
+                               /* If description is not explicitely set by application side, provide default information */
+                               if (rm->described_by_accessible) {
+                                       AtspiAccessibleReadingMaterial *_rm = atspi_accessible_get_reading_material(rm->described_by_accessible, NULL);
+                                       if (_rm) {
+                                               description_from_relation = reading_composer_extended_description_get_recursive(_rm, ++nest_level, max_nest_level);
+                                               reading_composer_reading_material_free(_rm);
+                                       }
                                }
-                       }
 
-                       if (description_from_role && strlen(description_from_role) > 0) {
-                               ESAL(buf2, description_from_role);
-                       }
-                       if (description_from_relation && strlen(description_from_relation)) {
-                               if (eina_strbuf_length_get(buf2))
-                                       ESAL(buf2, " , ");
-                               ESAL(buf2, description_from_relation);
+                               if (description_from_relation && strlen(description_from_relation)) {
+                                       ESAL(buf2, description_from_relation);
+                               } else {
+                                       description_from_role = generate_description_trait(rm);
+                                       if (description_from_role && strlen(description_from_role) > 0) {
+                                               ESAL(buf2, description_from_role);
+                                       }
+                               }
                        }
                }
                SCREEN_READER_SAFE_FREE(description_from_relation, free);
@@ -677,6 +640,10 @@ char* reading_composer_extended_description_get(ReadingComposerData *data)
        return ext_desc;
 }
 
+char* reading_composer_extended_description_get(ReadingComposerData *data) {
+       return reading_composer_extended_description_get_recursive(data, 0, 1);
+}
+
 char* reading_composer_percent_value_description_get(ReadingComposerData *data) {
        Eina_Strbuf *buf = NULL;
        AtspiAccessibleReadingMaterial *rm;