Aurum: Improve performance of findElements command
[platform/core/uifw/aurum.git] / libaurum / src / UiObject.cc
index f802b6a..3bbecc0 100644 (file)
@@ -1,3 +1,20 @@
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *               http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
 #include "Aurum.h"
 
 #include <iostream>
@@ -6,6 +23,8 @@
 #include <chrono>
 #include <thread>
 
+using namespace Aurum;
+
 UiObject::UiObject() : UiObject(nullptr, nullptr, nullptr) {}
 
 UiObject::~UiObject()
@@ -31,16 +50,6 @@ UiObject::UiObject(const std::shared_ptr<UiDevice> device, const std::shared_ptr
 {
 }
 
-// UiObject::UiObject(const UiObject &src)
-//     : mDevice(src.mDevice),
-//       mSelector(src.mSelector),
-//       mNode(src.mNode),
-//       mWaiter{src.mWaiter},
-//       mNode_src(std::move(src.mNode_src))
-
-// {
-// }
-
 UiObject::UiObject(UiObject &&src)
     : mDevice(src.mDevice),
       mSelector(std::move(src.mSelector)),
@@ -83,7 +92,9 @@ std::vector<std::shared_ptr<UiObject>> UiObject::findObjects(
     const std::shared_ptr<UiSelector> selector) const
 {
     std::vector<std::shared_ptr<UiObject>> result{};
-    auto nodes = Comparer::findObjects(mDevice, selector, getAccessibleNode());
+
+    std::vector<std::shared_ptr<AccessibleNode>> nodes{};
+    Comparer::findObjects(nodes, mDevice, selector, getAccessibleNode());
     for ( auto& node : nodes) {
         if (!node) {
             LOGI("Skipped! (node == nullptr)");
@@ -135,8 +146,14 @@ std::shared_ptr<UiObject> UiObject::getChildAt(int index) const {
 
 std::vector<std::shared_ptr<UiObject>> UiObject::getChildren() const
 {
-    auto sel = Sel::depth(1);
-    return this->findObjects(sel);
+    std::vector<std::shared_ptr<UiObject>> ret{};
+
+    auto children = getAccessibleNode()->getChildren();
+    for (auto &child : children) {
+        ret.push_back(std::make_shared<UiObject>(mDevice, mSelector, child));
+    }
+
+    return ret;
 }
 
 std::shared_ptr<Node> UiObject::getDescendant()
@@ -165,7 +182,7 @@ std::string UiObject::getAutomationId() const
     return getAccessibleNode()->getAutomationId();
 }
 
-std::string UiObject::getElementType() const
+std::string UiObject::getType() const
 {
     return getAccessibleNode()->getType();
 }
@@ -185,9 +202,60 @@ std::string UiObject::getRole() const
     return getAccessibleNode()->getRole();
 }
 
-void UiObject::setText(std::string text)
+std::string UiObject::getXPath() const
+{
+    return getAccessibleNode()->getXPath();
+}
+
+const double UiObject::getMinValue() const
+{
+    return getAccessibleNode()->getMinValue();
+}
+
+const double UiObject::getMaxValue() const
+{
+    return getAccessibleNode()->getMaxValue();
+}
+
+const double UiObject::getValue() const
+{
+    return getAccessibleNode()->getValue();
+}
+
+const double UiObject::getIncrement() const
+{
+    return getAccessibleNode()->getIncrement();
+}
+
+const Rect<int> UiObject::getTextMinBoundingRect() const
+{
+    return getAccessibleNode()->getTextMinBoundingRect();
+}
+
+bool UiObject::setValue(double value)
+{
+    return getAccessibleNode()->setValue(value);
+}
+
+bool UiObject::setText(std::string text)
+{
+    return getAccessibleNode()->setValue(text);
+}
+
+std::string UiObject::getOcrText() const
+{
+    return getAccessibleNode()->getOcrText();
+}
+
+std::string UiObject::getToolkitName() const
+{
+    getAccessibleNode()->updateToolkitName();
+    return getAccessibleNode()->getToolkitName();
+}
+
+void UiObject::setOcrText(std::string text)
 {
-    getAccessibleNode()->setValue(text);
+    getAccessibleNode()->setOcrText(text);
 }
 
 bool UiObject::isCheckable() const
@@ -255,36 +323,110 @@ bool UiObject::isActive() const
     return getAccessibleNode()->isActive();
 }
 
+bool UiObject::isHighlightable() const
+{
+    return getAccessibleNode()->isHighlightable();
+}
+
 void UiObject::refresh() const
 {
     mNode->refresh();
 }
 
+void UiObject::updateRoleName() const
+{
+    mNode->updateRoleName();
+}
+
+void UiObject::updateUniqueId() const
+{
+    mNode->updateUniqueId();
+}
+
+void UiObject::updateName() const
+{
+    mNode->updateName();
+}
+
+void UiObject::updateApplication() const
+{
+    mNode->updateApplication();
+}
+
+void UiObject::updateAttributes() const
+{
+    mNode->updateAttributes();
+}
+
+void UiObject::updateStates() const
+{
+    mNode->updateStates();
+}
+
+void UiObject::updateExtents() const
+{
+    mNode->updateExtents();
+}
+
+void UiObject::updateXPath() const
+{
+    mNode->updateXPath();
+}
+
+void UiObject::updateValue() const
+{
+    mNode->updateValue();
+}
+
+void UiObject::updatePid() const
+{
+    mNode->updatePid();
+}
+
+void UiObject::updateToolkitName() const
+{
+    mNode->updateToolkitName();
+}
+
+void UiObject::updateTextMinBoundingRect() const
+{
+    mNode->updateTextMinBoundingRect();
+}
+
+bool UiObject::setFocus() const
+{
+    return mNode->setFocus();
+}
+
 bool UiObject::isValid() const
 {
     return mNode->isValid();
 }
 
-const Rect<int> UiObject::getBoundingBox() const
+const Rect<int> UiObject::getScreenBoundingBox() const
 {
-    mNode->refresh();
-    return mNode->getBoundingBox();
+    return mNode->getScreenBoundingBox();
+}
+
+const Rect<int> UiObject::getWindowBoundingBox() const
+{
+    return mNode->getWindowBoundingBox();
 }
 
 void UiObject::click() const
 {
-    mNode->refresh();
-    const Rect<int> rect = mNode->getBoundingBox();
+    mNode->updateExtents();
+    const Rect<int> rect = mNode->getScreenBoundingBox();
     const Point2D<int> midPoint = rect.midPoint();
     mDevice->click(midPoint.x, midPoint.y);
 }
 
-void UiObject::longClick(const unsigned int intv) const
+void UiObject::longClick(const unsigned int durationMs) const
 {
-    mNode->refresh();
-    const Rect<int> rect = mNode->getBoundingBox();
+    mNode->updateExtents();
+    const Rect<int> rect = mNode->getScreenBoundingBox();
     const Point2D<int> midPoint = rect.midPoint();
-    mDevice->click(midPoint.x, midPoint.y, intv);
+    mDevice->click(midPoint.x, midPoint.y, durationMs);
 }
 
 bool UiObject::DoAtspiActivate() const
@@ -298,6 +440,5 @@ std::shared_ptr<AccessibleNode> UiObject::getAccessibleNode() const
     if (mNode == nullptr) throw;
     // TODO : wait for animation and refresh current node
     // mDevice->waitForIdle();
-    mNode->refresh();
     return mNode;
 }