find_by_name looks in keyboard now in batch mode 56/206956/3
authorRadoslaw Cybulski <r.cybulski@partner.samsung.com>
Wed, 29 May 2019 09:56:13 +0000 (11:56 +0200)
committerRadoslaw Cybulski <r.cybulski@partner.samsung.com>
Wed, 29 May 2019 12:00:01 +0000 (14:00 +0200)
Change-Id: Iebfac5a856179b32f7bd292c90a5fc95f9bb06b1

src/NavigationInterface.cpp
src/NavigationInterface.hpp
src/ScreenScannerManager.cpp
src/batch/BatchRunner.cpp
src/batch/BatchRunner.hpp
src/batch/EvaluationContext.hpp
tests/no-ui-scenarios/BatchExecTests.cpp

index c2fcf12..e959d3e 100644 (file)
@@ -99,8 +99,8 @@ class NavigationImpl : public NavigationInterface
 public:
        NavigationImpl()
        {
-               isfPanelStateChangeHandle = Singleton<VConfInterface>::instance().registerKeyChangedCb<int>(
-               VCONFKEY_ISF_INPUT_PANEL_STATE, [this](auto val) {
+               isfPanelStateChangeHandle = Singleton<VConfInterface>::instance().registerAndGet<int>(
+               VCONFKEY_ISF_INPUT_PANEL_STATE, VCONFKEY_ISF_INPUT_PANEL_STATE_HIDE, [this](auto val) {
                        isfPanelStateValue = val;
                        this->initializeRebuildingContext(true, 0.5f);
                });
@@ -122,6 +122,11 @@ public:
                return currentVisibleRootUIElement;
        }
 
+       std::shared_ptr<UIElement> getCurrentKeyboardVisibleRoot() const override
+       {
+               return currentKeyboardVisibleRootUIElement;
+       }
+
        std::shared_ptr<NavigationElement> getCurrentNavigationContext() const override
        {
                return currentRootElement;
@@ -132,7 +137,7 @@ private:
        int isfPanelStateValue = VCONFKEY_ISF_INPUT_PANEL_STATE_HIDE;
 
        std::shared_ptr<NavigationElement> currentRootElement;
-       std::shared_ptr<UIElement> currentVisibleRootUIElement;
+       std::shared_ptr<UIElement> currentVisibleRootUIElement, currentKeyboardVisibleRootUIElement;
        std::unique_ptr<Atspi::WatchHandler> watchHandle;
        ecore::Timer rebuildContextTimer;
        std::shared_ptr<AtspiAccessible> rootObject, keyboardRootObject;
@@ -718,7 +723,9 @@ private:
                                                                        col,
                                                                        ATSPI_Collection_SORT_ORDER_CANONICAL, 9999,
                                                                        Atspi::Matcher().states({ATSPI_STATE_SHOWING, ATSPI_STATE_VISIBLE}, ATSPI_Collection_MATCH_ALL).
-                                                                       roles({ ATSPI_ROLE_DIALOG, ATSPI_ROLE_FRAME, ATSPI_ROLE_WINDOW, ATSPI_ROLE_PAGE_TAB }, ATSPI_Collection_MATCH_ANY),
+                                                                       roles({ ATSPI_ROLE_DIALOG, ATSPI_ROLE_FRAME, ATSPI_ROLE_PAGE_TAB,
+                                                                                       application == UIElement::ApplicationCategory::KEYBOARD ? ATSPI_ROLE_INPUT_METHOD_WINDOW : ATSPI_ROLE_WINDOW
+                                                                                 }, ATSPI_Collection_MATCH_ANY),
                                                                        false,
                                                                [ = ](DBus::ValueOrError<std::vector<AtspiAccessiblePtr>> elems) {
                                                                        if (continueProcessing(elems)) {
@@ -1061,8 +1068,16 @@ private:
                currentVisibleRootUIElement = std::make_shared<UIElement>(root, pos, realContext.getApplicationCategory());
                rootObject = realContext.getRootObject();
                keyboardRootObject = keyboardContext ? (*keyboardContext).getRootObject() : nullptr;
+               if (keyboardContext) {
+                       auto kRoot = keyboardContext->getRootVisibleObject();
+                       auto pos = (*keyboardContext->getRowSize(0)).getCenterPoint();
+                       currentKeyboardVisibleRootUIElement = std::make_shared<UIElement>(kRoot, pos, keyboardContext->getApplicationCategory());
+               } else {
+                       currentKeyboardVisibleRootUIElement = {};
+               }
+
                ASSERT(currentRootElement);
-               emitCallback<NavigationCallbackType::ContextChanged>(currentVisibleRootUIElement, currentRootElement);
+               emitCallback<NavigationCallbackType::ContextChanged>(currentVisibleRootUIElement, currentKeyboardVisibleRootUIElement, currentRootElement);
        }
 
        void initializeRebuildingContext(bool force, float delay = 0.2f)
index ea40507..39ca675 100644 (file)
@@ -106,6 +106,7 @@ public:
 
        virtual ~NavigationInterface();
        virtual std::shared_ptr<UIElement> getCurrentVisibleRoot() const = 0;
+       virtual std::shared_ptr<UIElement> getCurrentKeyboardVisibleRoot() const = 0;
        virtual std::shared_ptr<NavigationElement> getCurrentNavigationContext() const = 0;
        virtual void terminate() = 0;
 
@@ -160,7 +161,7 @@ protected:
                using CallbackFunctionType = FunctionType; \
        };
 
-SPECIALIZE_CALLBACK_TRAITS(ContextChanged, void(std::shared_ptr<UIElement>, std::shared_ptr<NavigationElement>));
+SPECIALIZE_CALLBACK_TRAITS(ContextChanged, void(std::shared_ptr<UIElement>, std::shared_ptr<UIElement>, std::shared_ptr<NavigationElement>));
 #undef SPECIALIZE_CALLBACK_TRAITS
 
 std::shared_ptr<NavigationInterface> createNavigationImpl();
index 635a3c2..34bd3b5 100644 (file)
@@ -31,7 +31,7 @@ ScreenScannerManager::ScreenScannerManager()
 
        //TODO: register for screen orientation change (probably better to do it in class Window)
        contextChangedHandle = Singleton<UniversalSwitch>::instance().getNavigationInterface()->registerCb<NavigationCallbackType::ContextChanged>(
-       [](std::shared_ptr<UIElement> root, std::shared_ptr<NavigationElement> navigationContext) {
+       [](std::shared_ptr<UIElement> root, std::shared_ptr<UIElement> keyboardRoot, std::shared_ptr<NavigationElement> navigationContext) {
                ASSERT(navigationContext);
                auto self = Singleton<UniversalSwitch>::instance().getScreenScannerManager();
                if (self) {
index 0d4bff4..dfaf7a0 100644 (file)
@@ -212,20 +212,22 @@ void BatchExecutor::registerContextChangeCallback()
                DEBUG("no navigation interface found, context changed callback not registered");
                return;
        }
-       auto updateContextInfo = [this](std::shared_ptr<UIElement> root, std::shared_ptr<NavigationElement> navigationContext) {
+       auto updateContextInfo = [this](std::shared_ptr<UIElement> root, std::shared_ptr<UIElement> keyboardRoot, std::shared_ptr<NavigationElement> navigationContext) {
                std::string name;
                if (root && root->getObject()) {
                        auto r = Singleton<UniversalSwitch>::instance().getAtspi()->getName(root->getObject());
                        if (r)
                                name = std::move(*r);
                }
-               DEBUG("context changed to root %s (%s)", root ? Atspi::getUniqueId(root->getObject()).c_str() : "", name.c_str());
+               DEBUG("context changed to root %s (%s) [%s]", root ? Atspi::getUniqueId(root->getObject()).c_str() : "", name.c_str(),
+                         keyboardRoot ? Atspi::getUniqueId(keyboardRoot->getObject()).c_str() : "");
                auto h = contextInfo.lock();
                h->navigation = std::move(navigationContext);
                h->root = std::move(root);
+               h->keyboardRoot = std::move(keyboardRoot);
                h->rootName = std::move(name);
        };
-       updateContextInfo(nav->getCurrentVisibleRoot(), nav->getCurrentNavigationContext());
+       updateContextInfo(nav->getCurrentVisibleRoot(), nav->getCurrentKeyboardVisibleRoot(), nav->getCurrentNavigationContext());
        contextChangedHandle = nav->registerCb<NavigationCallbackType::ContextChanged>(std::move(updateContextInfo));
 }
 
@@ -243,6 +245,12 @@ std::shared_ptr<UIElement> BatchExecutor::getVisibleRoot()
        return h->root;
 }
 
+std::shared_ptr<UIElement> BatchExecutor::getKeyboardRoot()
+{
+       auto h = contextInfo.lock();
+       return h->keyboardRoot;
+}
+
 std::ostream &BatchExecutor::outputStream()
 {
        return output;
@@ -436,34 +444,34 @@ void BatchExecutor::makeUIElements(std::vector<AtspiAccessiblePtr> sources,
 
 std::shared_ptr<UIElement> BatchExecutor::convertToUIElement(const std::string &requestedName)
 {
-       Monitor<BatchValueOrError<std::shared_ptr<UIElement>>> monitor;
-
-       return executeOnMainThread([&]() {
-               auto uiRoot = getVisibleRoot();
-               if (!uiRoot) throw EvaluationFailure{} << "no visible root (context change didn't happen)";
-               auto root = uiRoot->getObject();
-               ASSERT(root);
-               getAllObjects(root, wrap(monitor, [ = ](DBus::ValueOrError<std::vector<AtspiAccessiblePtr>> elems) mutable {
-                       findByName(std::get<0>(elems), requestedName,
-                                          wrap(monitor, [ = ](DBus::ValueOrError<std::vector<AtspiAccessiblePtr>> elements)
-                       {
-                               auto &e = std::get<0>(elements);
-                               if (e.empty()) {
-                                       throw EvaluationFailure{} << "no at-spi object found with name '" << requestedName << "'";
-                               }
-                               if (e.size() > 1) {
+       for (auto root : {
+                               getVisibleRoot(), getKeyboardRoot()
+                       }) {
+               if (root && root->getObject()) {
+                       Monitor<BatchValueOrError<std::vector<std::shared_ptr<UIElement>>>> monitor;
+                       auto r = executeOnMainThread([&]() {
+                               getAllObjects(root->getObject(), wrap(monitor, [ = ](DBus::ValueOrError<std::vector<AtspiAccessiblePtr>> allElements) {
+                                       findByName(std::get<0>(allElements), requestedName, wrap(monitor, [ = ](DBus::ValueOrError<std::vector<AtspiAccessiblePtr>> elements) {
+                                               auto &elems = std::get<0>(elements);
+                                               makeUIElements(std::move(elems), wrap(monitor, [ = ](DBus::ValueOrError<std::vector<std::shared_ptr<UIElement>>> uiElems) {
+                                                       auto h = monitor.lock();
+                                                       h->setValue(std::move(std::get<0>(uiElems)));
+                                               }));
+                                       }));
+                               }));
+                       }, monitor);
+                       if (!r.empty()) {
+                               if (r.size() > 1) {
                                        std::ostringstream names;
-                                       for (auto &elem : e) names << " " << Atspi::getUniqueId(elem);
+                                       for (auto &elem : r) names << " " << Atspi::getUniqueId(elem->getObject());
                                        throw EvaluationFailure{} << "found more, than one at-spi object with name '" <<
                                                                                          requestedName << "' (see" << names.str() << ")";
                                }
-                               makeUIElement(e[0], wrap(monitor, [ = ](DBus::ValueOrError<std::shared_ptr<UIElement>> elem) {
-                                       auto h = monitor.lock();
-                                       h->setValue(std::move(std::get<0>(elem)));
-                               }));
-                       }));
-               }));
-       }, monitor);
+                               return std::move(r[0]);
+                       }
+               }
+       }
+       throw EvaluationFailure{} << "found no at-spi object with name '" << requestedName;
 }
 
 std::string BatchExecutor::getFileContent(const std::string &filename)
@@ -925,23 +933,25 @@ void BatchExecutor::insertMethods()
                } };
 
        variables["find_by_name"] = EvaluationValueFunction{ [&](std::string name) -> EvaluationValue {
-                       auto root = getVisibleRoot();
-                       if (!root) throw EvaluationFailure{} << "no visible root (context changed didn't happen)";
-                       ASSERT(root->getObject());
-                       Monitor<BatchValueOrError<std::vector<std::shared_ptr<UIElement>>>> monitor;
-
-                       return executeOnMainThread([&]()
+                       for (auto root : { getVisibleRoot(), getKeyboardRoot() })
                        {
-                               getAllObjects(root->getObject(), wrap(monitor, [ = ](DBus::ValueOrError<std::vector<AtspiAccessiblePtr>> allElements) {
-                                       findByName(std::get<0>(allElements), name, wrap(monitor, [ = ](DBus::ValueOrError<std::vector<AtspiAccessiblePtr>> elements) {
-                                               auto &elems = std::get<0>(elements);
-                                               makeUIElements(std::move(elems), wrap(monitor, [ = ](DBus::ValueOrError<std::vector<std::shared_ptr<UIElement>>> uiElems) {
-                                                       auto h = monitor.lock();
-                                                       h->setValue(std::move(std::get<0>(uiElems)));
+                               if (root && root->getObject()) {
+                                       Monitor<BatchValueOrError<std::vector<std::shared_ptr<UIElement>>>> monitor;
+                                       auto r = executeOnMainThread([&]() {
+                                               getAllObjects(root->getObject(), wrap(monitor, [ = ](DBus::ValueOrError<std::vector<AtspiAccessiblePtr>> allElements) {
+                                                       findByName(std::get<0>(allElements), name, wrap(monitor, [ = ](DBus::ValueOrError<std::vector<AtspiAccessiblePtr>> elements) {
+                                                               auto &elems = std::get<0>(elements);
+                                                               makeUIElements(std::move(elems), wrap(monitor, [ = ](DBus::ValueOrError<std::vector<std::shared_ptr<UIElement>>> uiElems) {
+                                                                       auto h = monitor.lock();
+                                                                       h->setValue(std::move(std::get<0>(uiElems)));
+                                                               }));
+                                                       }));
                                                }));
-                                       }));
-                               }));
-                       }, monitor);
+                                       }, monitor);
+                                       if (!r.empty()) return std::move(r);
+                               }
+                       }
+                       return std::vector<std::shared_ptr<UIElement>>{};
                }, { { "name" } } };
 
        auto generateTapFunction = [&](size_t tapCount) {
index bd1c968..8c58b46 100644 (file)
@@ -65,6 +65,7 @@ class BatchExecutor : public ExecutorInterface
 public:
        struct ContextInfo {
                std::shared_ptr<UIElement> root;
+               std::shared_ptr<UIElement> keyboardRoot;
                std::shared_ptr<NavigationElement> navigation;
                std::string rootName;
        };
@@ -95,6 +96,7 @@ public:
        std::string getFileContent(const std::string &filename) override;
 
        std::shared_ptr<UIElement> getVisibleRoot() override;
+       std::shared_ptr<UIElement> getKeyboardRoot() 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;
index b49f9be..7b6bb0a 100644 (file)
@@ -95,6 +95,11 @@ struct ExecutorInterface {
        virtual std::shared_ptr<UIElement> getVisibleRoot() = 0;
 
        /**
+        * @brief Returns at-spi object, which is root of keyboard, if one is visible
+        */
+       virtual std::shared_ptr<UIElement> getKeyboardRoot() = 0;
+
+       /**
         * @brief Returns stream, which should be used for writing any kind of output
         *
         * Note, that this stream should be only used from batch's thread.
index 4dac1be..dc32ec1 100644 (file)
@@ -44,6 +44,11 @@ struct TestExecutor : ExecutorInterface {
                ASSERT(0);
                return {};
        }
+       std::shared_ptr<UIElement> getKeyboardRoot() override
+       {
+               ASSERT(0);
+               return {};
+       }
        std::ostream &outputStream() override
        {
                return std::cout;