libaurum: add role option for getMatches and getMatchesInMatches. 55/311455/5
authorHosang Kim <hosang12.kim@samsung.com>
Tue, 21 May 2024 10:22:14 +0000 (19:22 +0900)
committerHosang Kim <hosang12.kim@samsung.com>
Mon, 24 Jun 2024 01:17:37 +0000 (10:17 +0900)
Change-Id: I4dc0f1239e1df67c60d0a606a799cf78b4b380bc

libaurum/src/Impl/Accessibility/AtspiMatchRuleConvertor.cc

index d5c9294afdf685d45feeb7967a50abbc7d17602e..fed973978fdd7cf688f82f936317d2406ae7e87e 100644 (file)
@@ -39,6 +39,7 @@ AtspiMatchRuleConvertor::operator AtspiMatchRule *()
 
     AtspiCollectionMatchType stateMatchType = ATSPI_Collection_MATCH_INVALID;
     AtspiCollectionMatchType attributeMatchType = ATSPI_Collection_MATCH_INVALID;
+    AtspiCollectionMatchType roleMatchType = ATSPI_Collection_MATCH_INVALID;
 
     // Add rule of states
     AtspiStateSet *ss = atspi_state_set_new(nullptr);
@@ -87,14 +88,45 @@ AtspiMatchRuleConvertor::operator AtspiMatchRule *()
         attributeMatchType = ATSPI_Collection_MATCH_ALL;
     }
 
+    GArray *roles = g_array_new(true, true, sizeof(AtspiRole));
+    if (mSelector->mMatchRole)
+    {
+        if (!strncmp(mSelector->mRole.c_str(), "label", 5))
+        {
+            gint role = ATSPI_ROLE_LABEL;
+            roles = g_array_append_val(roles, role);
+        }
+        else if (!strncmp(mSelector->mRole.c_str(), "image", 5))
+        {
+            gint role = ATSPI_ROLE_IMAGE;
+            roles = g_array_append_val(roles, role);
+        }
+        else if (!strncmp(mSelector->mRole.c_str(), "window", 6))
+        {
+            gint role = ATSPI_ROLE_WINDOW;
+            roles = g_array_append_val(roles, role);
+        }
+    }
+
+    if (roles->len == 0)
+    {
+        g_array_free(roles, true);
+        roles = nullptr;
+    }
+    else
+    {
+        roleMatchType = ATSPI_Collection_MATCH_ALL;
+    }
+
     AtspiMatchRule* rule = atspi_match_rule_new(ss, stateMatchType,
                                                 attributes, attributeMatchType,
-                                                nullptr, ATSPI_Collection_MATCH_INVALID,
+                                                roles, roleMatchType,
                                                 nullptr, ATSPI_Collection_MATCH_INVALID,
                                                 false);
 
     if (ss) g_object_unref(ss);
     if (attributes) g_hash_table_unref (attributes);
+    if (roles) g_array_free(roles, true);
 
     return rule;
 }