AurumXML: apply method of creating node partially. 55/287955/4 accepted/tizen/unified/20230215.100725
authorHosang Kim <hosang12.kim@samsung.com>
Wed, 8 Feb 2023 06:11:34 +0000 (15:11 +0900)
committerkim hosang <hosang12.kim@samsung.com>
Mon, 13 Feb 2023 03:34:03 +0000 (03:34 +0000)
Change-Id: I5c1d7658cb03b3d427546616268324c79ad3994e

libaurum/inc/AurumXML.h
libaurum/src/AurumXML.cc
libaurum/src/Impl/Accessibility/AtspiAccessibleNode.cc

index f8a86b1d8b0057e30795e8a59998d4cfb552e705..6574b497b38be66a01b78672fe562a3f4c6450e6 100644 (file)
@@ -66,13 +66,13 @@ public:
     /**
      * @brief Gets a XPath from specific id.
      *
-     * @param id
+     * @param node AccessibleNode
      *
      * @return XPath
      *
      * @since_tizen 7.0
      */
-    std::string getXPath(std::string id);
+    std::string getXPath(std::shared_ptr<AccessibleNode> node);
 
     /**
      * @brief Finds that objects that satisfied with the xpath in the object tree.
@@ -119,13 +119,26 @@ private:
      *
      * @brief Check xml_node exists or not
      *
-     * @param string id
+     * @param node AccessibleNode
      *
      * @return xml_node
      *
      * @since_tizen 7.0
      */
-    xml_node checkNode(std::string id);
+    xml_node checkNode(std::shared_ptr<AccessibleNode> node);
+
+    /**
+     * @internal
+     *
+     * @brief Check parent's xml_node exists or not
+     *
+     * @param node AccessibleNode
+     *
+     * @return AccessibleNode
+     *
+     * @since_tizen 7.5
+     */
+    std::shared_ptr<AccessibleNode> checkParentNode(std::shared_ptr<AccessibleNode> node);
 
 private:
     xml_document                                *mDoc;
index 9a8c8a8fa037602fcc02593562cc5a373430db3e..7ca1303bac6130aa6fe85cfb9b519c3e1e3e136b 100644 (file)
@@ -174,29 +174,58 @@ std::string makeQuery(std::string id)
     return query;
 }
 
-xml_node AurumXML::checkNode(std::string id)
+std::shared_ptr<AccessibleNode> AurumXML::checkParentNode(std::shared_ptr<AccessibleNode> node)
 {
-    xml_node node;
+    auto parent = node->getParent();
+    if (!parent) return nullptr;
+
+    std::string query = makeQuery(node->getId());
+    xml_node xmlNode = mDoc->select_node(query.c_str()).node();
+
+    if (xmlNode) {
+        int childCnt = parent->getChildCount();
+        for (int i = 0; i < childCnt; i++) {
+            std::shared_ptr<AccessibleNode> childNode = parent->getChildAt(i);
+            if (childNode->getRawHandler() == nullptr) continue;
+
+            xml_node childElement = xmlNode.append_child("");
+            traverse(childElement, childNode);
+        }
+        return parent;
+    }
+
+    return checkParentNode(parent);
+}
+
+xml_node AurumXML::checkNode(std::shared_ptr<AccessibleNode> node)
+{
+    xml_node xmlNode;
+
     try {
-        std::string query = makeQuery(id);
-        node = mDoc->select_node(query.c_str()).node();
+        std::string query = makeQuery(node->getId());
+        xmlNode = mDoc->select_node(query.c_str()).node();
+
+        if (!xmlNode) {
+            // 1. find parent and check node again
+            auto parent = checkParentNode(node);
+
+            // 2. clear tree and create tree again
+            if (!parent) createXMLtree();
 
-        if (!node) {
-            createXMLtree();
-            node = mDoc->select_node(query.c_str()).node();
+            xmlNode = mDoc->select_node(query.c_str()).node();
         }
     } catch (const xpath_exception &e) {
         LOGI("getXPath Error: %s", e.what());
     }
-    return node;
+    return xmlNode;
 }
 
-std::string AurumXML::getXPath(std::string id)
+std::string AurumXML::getXPath(std::shared_ptr<AccessibleNode> node)
 {
-    xml_node node = checkNode(id);
+    xml_node xmlNode = checkNode(node);
 
-    if (node) {
-        std::string xpath = getOptimalXPath(mDoc, node);
+    if (xmlNode) {
+        std::string xpath = getOptimalXPath(mDoc, xmlNode);
         return xpath;
     }
 
index 2fc415fd83214680f4bee4cf79c59ef50b67fe0b..ead13997b0d81008cd5511725de212c50ffa5f84 100644 (file)
@@ -250,7 +250,7 @@ void AtspiAccessibleNode::updateXPath()
 
     auto XMLDoc = XMLDocMap[mPkg];
 
-    mXPath = XMLDoc->getXPath(mId);
+    mXPath = XMLDoc->getXPath(shared_from_this());
 }
 
 void AtspiAccessibleNode::updateValue()