Introduce new getMatchesInMatches API. 94/303694/5 accepted/tizen/unified/20240205.162750 accepted/tizen/unified/x/20240206.004203
authorHosang Kim <hosang12.kim@samsung.com>
Wed, 3 Jan 2024 10:47:30 +0000 (19:47 +0900)
committerHosang Kim <hosang12.kim@samsung.com>
Wed, 10 Jan 2024 07:14:28 +0000 (16:14 +0900)
The getMatchesInMatches API gets the object that satisfied with both condition in the object tree.
It runs quickly because the search happens in the app.

Change-Id: I377fd73360014d4c99d43d388257d27dc1247c87

libaurum/inc/Accessibility/AccessibleNode.h
libaurum/inc/Impl/Accessibility/AtspiAccessibleNode.h
libaurum/inc/Impl/Accessibility/AtspiWrapper.h
libaurum/inc/Impl/Accessibility/MockAccessibleNode.h
libaurum/inc/UiDevice.h
libaurum/inc/UiObject.h
libaurum/src/Impl/Accessibility/AtspiAccessibleNode.cc
libaurum/src/Impl/Accessibility/AtspiWrapper.cc
libaurum/src/Impl/Accessibility/MockAccessibleNode.cc
libaurum/src/UiDevice.cc
libaurum/src/UiObject.cc

index bcdc1fc..16f7c89 100644 (file)
@@ -138,6 +138,11 @@ public:
     virtual std::vector<std::shared_ptr<AccessibleNode>> getMatches(const std::shared_ptr<UiSelector> selector, const bool ealryReturn) const = 0;
 
     /**
+     * @copydoc UiObject::getMatchesInMatches()
+     */
+    virtual std::vector<std::shared_ptr<AccessibleNode>> getMatchesInMatches(const std::shared_ptr<UiSelector> firstSelector, const std::shared_ptr<UiSelector> secondSelector, const bool ealryReturn) const = 0;
+
+    /**
      * @brief Called by @AccessibleWatcher::notifyAll.
      *        Changes Node property If it's @EventType, @ObjectEventType are matches.
      *
index 29c0aeb..eb78152 100644 (file)
@@ -76,6 +76,11 @@ public:
     std::vector<std::shared_ptr<AccessibleNode>> getMatches(const std::shared_ptr<UiSelector> selector, const bool ealryReturn) const override;
 
     /**
+     * @copydoc UiObject::getMatchesInMatches()
+     */
+    std::vector<std::shared_ptr<AccessibleNode>> getMatchesInMatches(const std::shared_ptr<UiSelector> firstSelector, const std::shared_ptr<UiSelector> secondSelector, const bool ealryReturn) const override;
+
+    /**
      * @copydoc AccessibleNode::isValid()
      */
     bool isValid() const override;
index 63ac89d..e7901c4 100644 (file)
@@ -73,6 +73,7 @@ public:
     static void Atspi_accessible_set_listen_post_render(AtspiAccessible *obj, gboolean enabled, GError **error);
     static AtspiCollection *Atspi_accessible_get_collection_iface(AtspiAccessible *node);
     static GArray *Atspi_collection_get_matches(AtspiCollection *obj, AtspiMatchRule *rule, AtspiCollectionSortOrder sortby, gint count, gboolean traverse, GError **error);
+    static GArray *Atspi_collection_get_matches_in_matches(AtspiCollection *obj, AtspiMatchRule *first_rule, AtspiMatchRule *second_rule, AtspiCollectionSortOrder sortby, gint first_count, gint second_count, gboolean traverse, GError **error);
     static AtspiAccessibleNodeInfo *Atspi_accessible_get_node_info(AtspiAccessible *obj, GError **error);
     static void Atspi_accessible_free_node_info(AtspiAccessibleNodeInfo *node_info);
 
index c2df6a7..4f2d02d 100644 (file)
@@ -74,6 +74,11 @@ public:
      */
     std::vector<std::shared_ptr<AccessibleNode>> getMatches(const std::shared_ptr<UiSelector> selector, const bool ealryReturn) const override;
 
+    /**
+     * @copydoc UiObject::getMatchesInMatches()
+     */
+    std::vector<std::shared_ptr<AccessibleNode>> getMatchesInMatches(const std::shared_ptr<UiSelector> firstSelector, const std::shared_ptr<UiSelector> secondSelector, const bool ealryReturn) const override;
+
 public:
     /**
      * @brief TBD
index 7315f7b..75a9b4c 100644 (file)
@@ -328,6 +328,20 @@ public:
         const std::shared_ptr<UiSelector> selector, const bool earlyReturn) const;
 
     /**
+     * @brief Get the object that satisfied with both condition in the object tree.
+     *
+     * @param[in] firstSelector @UiSelector
+     * @param[in] secondSelector @UiSelector
+     * @param[in] earlyReturn boolean
+     *
+     * @return the list of found UiObject pointer vector
+     *
+     * @since_tizen 8.0
+     */
+    std::vector<std::shared_ptr<UiObject>> getMatchesInMatches(
+        const std::shared_ptr<UiSelector> firstSelector, const std::shared_ptr<UiSelector> secondSelector, const bool earlyReturn) const;
+
+    /**
      * TODO
      */
     bool waitFor(
index 6689962..4b58602 100644 (file)
@@ -153,6 +153,20 @@ public:
         const std::shared_ptr<UiSelector> selector, const bool earlyReturn) const;
 
     /**
+     * @brief Get the object that satisfied with both condition in the object tree.
+     *
+     * @param[in] firstSelector @UiSelector
+     * @param[in] secondSelector @UiSelector
+     * @param[in] earlyReturn boolean
+     *
+     * @return the list of found UiObject pointer vector
+     *
+     * @since_tizen 8.0
+     */
+    std::vector<std::shared_ptr<UiObject>> getMatchesInMatches(
+        const std::shared_ptr<UiSelector> firstSelector, const std::shared_ptr<UiSelector> secondSelector, const bool earlyReturn) const;
+
+    /**
      * TODO
      */
     bool waitFor(
index df3b064..5cc212a 100644 (file)
@@ -725,3 +725,35 @@ std::vector<std::shared_ptr<AccessibleNode>> AtspiAccessibleNode::getMatches(con
 
     return ret;
 }
+
+std::vector<std::shared_ptr<AccessibleNode>> AtspiAccessibleNode::getMatchesInMatches(const std::shared_ptr<UiSelector> firstSelector, const std::shared_ptr<UiSelector> secondSelector, const bool ealryReturn) const
+{
+    std::vector<std::shared_ptr<AccessibleNode>> ret{};
+
+    AtspiCollection *collection = AtspiWrapper::Atspi_accessible_get_collection_iface(mNode);
+    if (collection) {
+        AtspiMatchRule *firstRule = AtspiMatchRuleConvertor(firstSelector);
+        if (!firstRule) return ret;
+
+        AtspiMatchRule *secondRule = AtspiMatchRuleConvertor(secondSelector);
+        if (!secondRule) return ret;
+
+        int count = ealryReturn ? 1 : 0;
+        GArray *matches = AtspiWrapper::Atspi_collection_get_matches_in_matches(collection, firstRule, secondRule, ATSPI_Collection_SORT_ORDER_CANONICAL, 0, count, false, NULL);
+        if (matches) {
+            ret.reserve(matches->len);
+            AtspiAccessible *match = nullptr;
+            for (unsigned int i = 0; i < matches->len; i++) {
+                match = g_array_index(matches, AtspiAccessible *, i);
+               if (match) {
+                   ret.push_back(std::make_shared<AtspiAccessibleNode>(match));
+               }
+            }
+            g_array_free(matches, true);
+        }
+        g_object_unref(secondRule);
+        g_object_unref(firstRule);
+    }
+
+    return ret;
+}
index 10f98ff..33c1832 100644 (file)
@@ -249,6 +249,12 @@ GArray *AtspiWrapper::Atspi_collection_get_matches(AtspiCollection *obj, AtspiMa
     return atspi_collection_get_matches(obj, rule, sortby, count, traverse, error);
 }
 
+GArray *AtspiWrapper::Atspi_collection_get_matches_in_matches(AtspiCollection *obj, AtspiMatchRule *first_rule, AtspiMatchRule *second_rule,  AtspiCollectionSortOrder sortby, gint first_count, gint second_count, gboolean traverse, GError **error)
+{
+    std::unique_lock<std::recursive_mutex> lock(mMutex);
+    return atspi_collection_get_matches_in_matches(obj, first_rule, second_rule, sortby, first_count, second_count, traverse, error);
+}
+
 AtspiAccessibleNodeInfo *AtspiWrapper::Atspi_accessible_get_node_info(AtspiAccessible *obj, GError **error)
 {
     std::unique_lock<std::recursive_mutex> lock(mMutex);
index 8a51e90..ca6fc10 100644 (file)
@@ -68,6 +68,14 @@ std::vector<std::shared_ptr<AccessibleNode>> MockAccessibleNode::getMatches(cons
     return ret;
 }
 
+std::vector<std::shared_ptr<AccessibleNode>> MockAccessibleNode::getMatchesInMatches(const std::shared_ptr<UiSelector> firstSelector, const std::shared_ptr<UiSelector> secondSelector, const bool ealryReturn) const
+{
+    std::vector<std::shared_ptr<AccessibleNode>> ret{};
+
+    return ret;
+}
+
+
 void* MockAccessibleNode::getRawHandler(void) const
 {
     printf("%s:%d / %s\n",__FILE__, __LINE__, __PRETTY_FUNCTION__);
index 9bb7e42..2dacea6 100644 (file)
@@ -128,6 +128,20 @@ std::vector<std::shared_ptr<UiObject>> UiDevice::getMatches(
     return ret;
 }
 
+std::vector<std::shared_ptr<UiObject>> UiDevice::getMatchesInMatches(
+    const std::shared_ptr<UiSelector> firstSelector, const std::shared_ptr<UiSelector> secondSelector, const bool earlyReturn) const
+{
+    std::vector<std::shared_ptr<UiObject>> ret{};
+
+    auto rootNodes = getWindowRoot();
+    for (const auto &window : rootNodes) {
+        auto nodes = window->getMatchesInMatches(firstSelector, secondSelector, earlyReturn);
+        for (auto &node : nodes)
+            ret.push_back(std::make_shared<UiObject>(getInstance(), nullptr, node));
+    }
+    return ret;
+}
+
 bool UiDevice::waitFor(
     const std::function<bool(const ISearchable *)> condition) const
 {
index 82d9563..d8c3cfa 100644 (file)
@@ -117,6 +117,18 @@ std::vector<std::shared_ptr<UiObject>> UiObject::getMatches(
     return result;
 }
 
+std::vector<std::shared_ptr<UiObject>> UiObject::getMatchesInMatches(
+    const std::shared_ptr<UiSelector> firstSelector, const std::shared_ptr<UiSelector> secondSelector, const bool earlyReturn) const
+{
+    std::vector<std::shared_ptr<UiObject>> result{};
+
+    auto nodes = getAccessibleNode()->getMatchesInMatches(firstSelector, secondSelector, earlyReturn);
+    for (auto &node : nodes) {
+        result.push_back(std::make_shared<UiObject>(mDevice, nullptr, std::move(node)));
+    }
+    return result;
+}
+
 bool UiObject::waitFor(
     const std::function<bool(const ISearchable *)> condition) const
 {