AurumXML: Sort child objects by coordinates. 49/302649/3
authorHosang Kim <hosang12.kim@samsung.com>
Mon, 11 Dec 2023 10:57:28 +0000 (19:57 +0900)
committerkim hosang <hosang12.kim@samsung.com>
Tue, 2 Jan 2024 08:47:58 +0000 (08:47 +0000)
Sometimes the order of child objects is not consistent.
Therefore, we sort them to always ensure the same order.

Change-Id: Ia49c88bc1fa32d1e73ebeca1c8415789d9d1594e

libaurum/src/AurumXML.cc

index 8f90001..6974d59 100644 (file)
@@ -67,6 +67,19 @@ void AurumXML::traverse(xml_node& element, const std::shared_ptr<AccessibleNode>
     mXNodeMap[node->getId()] = node;
 
     auto children = node->getChildren();
+
+    std::sort(children.begin(), children.end(), [](std::shared_ptr<AccessibleNode> a, std::shared_ptr<AccessibleNode> b){
+        a->updateExtents();
+        b->updateExtents();
+
+        auto aRect = a->getScreenBoundingBox();
+        auto bRect = b->getScreenBoundingBox();
+
+        if (aRect.mTopLeft.x != bRect.mTopLeft.x) return aRect.mTopLeft.x < bRect.mTopLeft.x;
+        if (aRect.mTopLeft.y != bRect.mTopLeft.y) return aRect.mTopLeft.y < bRect.mTopLeft.y;
+        else return aRect.width() * aRect.height() <= bRect.width() * bRect.height();
+    });
+
     for (const auto &child : children)
     {
         if (child->getRawHandler() == nullptr) continue;