flicks now take fingers arg in batch mode 95/206395/4
authorRadoslaw Cybulski <r.cybulski@partner.samsung.com>
Fri, 17 May 2019 08:28:09 +0000 (10:28 +0200)
committerRadoslaw Cybulski <r.cybulski@partner.samsung.com>
Fri, 17 May 2019 11:16:53 +0000 (13:16 +0200)
Change-Id: I450a4bd557673072c2eab8ff86e5bd9519680e9b

src/Atspi.cpp
src/UIElement.cpp
src/UIElement.hpp
src/batch/BatchRunner.cpp
src/batch/BatchRunner.hpp
src/batch/EvaluationContext.cpp
src/batch/EvaluationContext.hpp
src/batch/EvaluationValueUIElement.cpp

index e73b7c8..f8c2de4 100644 (file)
@@ -777,7 +777,7 @@ Optional<Rectangle> Atspi::getScreenPosition(const AtspiComponentPtr &accessible
        if (!res)
                return {};
        Rectangle rectangle{ { res->x, res->y }, { res->width, res->height } };
-       g_object_unref(res);
+       g_free(res);
        return rectangle;
 }
 
index 1fc1760..cd3da7b 100644 (file)
@@ -81,6 +81,11 @@ void UIElement::getAttributeAsync(const std::string &key, std::function<void(std
        find(true);
 }
 
+void UIElement::setScanningCoordinates(Point p)
+{
+       scanningCoordinates = p;
+}
+
 Point UIElement::getScanningCoordinates() const
 {
        return scanningCoordinates;
index 5cf2ca2..f34c82f 100644 (file)
@@ -50,6 +50,7 @@ public:
 
        void printDebug();
 
+       void setScanningCoordinates(Point);
 private:
        void getAttributesAsync(std::function<void(bool)> callback);
 
index 3b71d8f..c3f74f8 100644 (file)
@@ -294,6 +294,20 @@ Atspi::StateSet BatchExecutor::getUIElementStates(const std::shared_ptr<UIElemen
        });
 }
 
+Rectangle BatchExecutor::getUIElementPosition(const std::shared_ptr<UIElement> &uiElem)
+{
+       return executeOnMainThread([&]() {
+               auto atspi = Singleton<UniversalSwitch>::instance().getAtspi();
+               auto component = atspi->getComponentInterface(uiElem->getObject());
+               if (component) {
+                       auto found = atspi->getScreenPosition(component);
+                       if (found)
+                               return std::move(*found);
+               }
+               throw EvaluationFailure{} << "failed to get at-spi object's position (use dlogutil to get at-spi error message)";
+       });
+}
+
 std::string BatchExecutor::getUIElementName(const std::shared_ptr<UIElement> &uiElem)
 {
        return executeOnMainThread([&]() {
@@ -898,6 +912,7 @@ void BatchExecutor::insertMethods()
                                        target = this->convertToUIElement(target.convertToString());
                                }
                                auto dest = target.convertToUIElement();
+                               auto coord = getUIElementPosition(dest).getCenterPoint();
                                auto fingerCount = fingers.convertToInteger();
                                if (fingerCount <= 0 || fingerCount > 3)
                                        throw EvaluationFailure{} << "invalid finger count (must be between 1 and 3)";
@@ -906,7 +921,6 @@ void BatchExecutor::insertMethods()
                                for (auto i = 0u; i < tapCount; ++i)
                                {
                                        executeOnMainThread([&]() {
-                                               auto coord = dest->getScanningCoordinates();
                                                auto res = utils::generateTapGesture(coord.x, coord.y, 0.0f, fingerCount);
                                                if (!res)
                                                        throw EvaluationFailure{} << "failed to execute " << tapCount << " tap gesture, " << res.getError().message;
@@ -922,23 +936,27 @@ void BatchExecutor::insertMethods()
        variables["TRIPLE_TAP"] = generateTapFunction(3);
 
        auto generateFlickFunction = [&](int x0, int y0, int x1, int y1) {
-               return EvaluationValueFunction{ [ &, x0, y0, x1, y1]() -> EvaluationValue {
+               return EvaluationValueFunction{ [ &, x0, y0, x1, y1](EvaluationValue fingers) -> EvaluationValue {
                                auto root = getVisibleRoot();
                                if (!root) throw EvaluationFailure{} << "no visible root (context changed didn't happen)";
                                ASSERT(root->getObject());
 
+                               auto fingerCount = fingers.convertToInteger();
+                               if (fingerCount <= 0 || fingerCount > 3)
+                                       throw EvaluationFailure{} << "invalid finger count (must be between 1 and 3)";
+
                                executeOnMainThread([&]()
                                {
-                                       utils::generateDragGesture(x0, y0, x1, y1, 10, 0.0);
+                                       utils::generateDragGesture(x0, y0, x1, y1, 10, 0.0, fingerCount);
                                });
-                               std::this_thread::sleep_for(std::chrono::milliseconds{ 150 });
+                               std::this_thread::sleep_for(std::chrono::milliseconds{ 1000 });
                                return EvaluationValue{};
-                       }, { } };
+                       }, { { "fingers", 1 } } };
        };
        variables["FLICK_RIGHT"] = generateFlickFunction(200, 200, 400, 200);
        variables["FLICK_LEFT"] = generateFlickFunction(400, 200, 200, 200);
-       variables["FLICK_UP"] = generateFlickFunction(300, 400, 300, 200);
-       variables["FLICK_DOWN"] = generateFlickFunction(300, 200, 300, 400);
+       variables["FLICK_UP"] = generateFlickFunction(300, 600, 300, 200);
+       variables["FLICK_DOWN"] = generateFlickFunction(300, 200, 300, 600);
 }
 
 class PredicateWaitInterface : public EvaluationValueWaitInterface
index 6d18fc4..43108a9 100644 (file)
@@ -93,6 +93,7 @@ public:
        std::shared_ptr<UIElement> getVisibleRoot() override;
        std::shared_ptr<UIElement> convertToUIElement(Point pt) override;
        std::string getUIElementName(const std::shared_ptr<UIElement> &uiElem) override;
+       Rectangle getUIElementPosition(const std::shared_ptr<UIElement> &uiElem) override;
        Atspi::StateSet getUIElementStates(const std::shared_ptr<UIElement> &o) override;
        unsigned int getUIElementRole(const std::shared_ptr<UIElement> &o) override;
        std::unordered_map<std::string, std::string> getUIElementAttributes(const std::shared_ptr<UIElement> &o) override;
index 5e2c75b..735c0c1 100644 (file)
@@ -106,6 +106,11 @@ std::unordered_map<std::string, std::string> ExecutorInterface::getUIElementAttr
        throw EvaluationFailure{} << "getUIElementAttributes not implemeneted";
 }
 
+Rectangle ExecutorInterface::getUIElementPosition(const std::shared_ptr<UIElement> &uiElem)
+{
+       throw EvaluationFailure{} << "getUIElementPosition not implemeneted";
+}
+
 std::string ExecutorInterface::getUIElementName(const std::shared_ptr<UIElement> &elem)
 {
        throw EvaluationFailure{} << "getUIElementName not implemeneted";
index 4d007d8..714abcb 100644 (file)
@@ -77,6 +77,7 @@ struct ExecutorInterface {
         */
        virtual std::string getUIElementName(const std::shared_ptr<UIElement> &);
 
+       virtual Rectangle getUIElementPosition(const std::shared_ptr<UIElement> &uiElem);
        virtual Atspi::StateSet getUIElementStates(const std::shared_ptr<UIElement> &);
        virtual unsigned int getUIElementRole(const std::shared_ptr<UIElement> &);
        virtual std::unordered_map<std::string, std::string> getUIElementAttributes(const std::shared_ptr<UIElement> &);
index e4b69c8..88aa286 100644 (file)
@@ -72,8 +72,10 @@ public:
        {
                if (name == "name")
                        return create(EvaluationContext::getCurrentEvaluationContext().executionInterface().getUIElementName(value));
-               if (name == "center")
-                       return create(value->getScanningCoordinates());
+               if (name == "center") {
+                       auto v = EvaluationContext::getCurrentEvaluationContext().executionInterface().getUIElementPosition(value);
+                       return create(v.getCenterPoint());
+               }
                if (name == "role")
                        return create(EvaluationContext::getCurrentEvaluationContext().executionInterface().getUIElementRole(value));
                if (name == "states") {