Minor refactor of NavigationInterface 51/164551/31
authorRadoslaw Cybulski <r.cybulski@partner.samsung.com>
Tue, 19 Dec 2017 14:58:37 +0000 (15:58 +0100)
committerRadoslaw Cybulski <r.cybulski@partner.samsung.com>
Wed, 17 Jan 2018 14:50:37 +0000 (15:50 +0100)
Adds methods to receive current context element and current visible
root atspi object.
Removes dependency on Window object to retrieve screen size -
constructing Window object in batch mode was causing constant
navigation context changes.

Change-Id: I37851c7aaa8a6267060f63937b59222131b67394

src/NavigationInterface.cpp
src/NavigationInterface.hpp
src/UniversalSwitch.cpp
src/UniversalSwitch.hpp

index 160955b..7558b22 100644 (file)
@@ -110,8 +110,19 @@ public:
 
        ~NavigationImpl() = default;
 
+       std::shared_ptr<UIElement> getCurrentVisibleRoot() const override
+       {
+               return currentVisibleRootUIElement;
+       }
+
+       std::shared_ptr<NavigationElement> getCurrentNavigationContext() const override
+       {
+               return currentRootElement;
+       }
+
 private:
-       std::shared_ptr<NavigationElement> contentRootElement;
+       std::shared_ptr<NavigationElement> currentRootElement;
+       std::shared_ptr<UIElement> currentVisibleRootUIElement;
        std::unique_ptr<Atspi::WatchHandler> watchHandle;
        ecore::Timer rebuildContextTimer;
        std::shared_ptr<AtspiAccessible> rootObject, keyboardRootObject;
@@ -312,12 +323,21 @@ private:
 
        static void filterRows(std::vector<AcceptedObjectInfo> &objects)
        {
-               auto mainWindow = Singleton<UniversalSwitch>::instance().getMainWindow();
-               auto mainWindowDims = mainWindow->getDimensions();
+               auto screenDims = Rectangle{ { 0, 0}, { std::numeric_limits<int>::max(), std::numeric_limits<int>::max() } };
+
+               // Note: you can't use getMainWindow()->getDimensions() in batch execution mode, as it
+               // creates new window every time (thus causing context switch, which causes new call
+               // to filterRows, which causes new window and context change and so on).
+               // Luckily we don't care for real screen size in batch execution mode, as
+               // we don't use navigation context in this mode, so largest possible screen
+               // (thus allowing all objects) is fine.
+               if (!Singleton<UniversalSwitch>::instance().isInBatchMode()) {
+                       screenDims = Singleton<UniversalSwitch>::instance().getMainWindow()->getDimensions();
+               }
 
                size_t src = 0, dst = 0;
                for (; src < objects.size(); ++src) {
-                       auto d = Rectangle::intersect(mainWindowDims, objects[src].pos);
+                       auto d = Rectangle::intersect(screenDims, objects[src].pos);
                        if (!d.hasPositiveSize()) continue;
                        if (src + 1 < objects.size() && objects[src].pos == objects[src + 1].pos) continue;
                        objects[dst++] = std::move(objects[src]);
@@ -1048,10 +1068,10 @@ private:
                        ptr->obj = (*elem).obj;
                        return ptr;
                };
-               contentRootElement = buildRows({}, 0, realContext);
+               currentRootElement = buildRows({}, 0, realContext);
                DEBUG("new context content is");
                std::ostringstream os;
-               contentRootElement->dump(os);
+               currentRootElement->dump(os);
                size_t i = 0;
                auto s = os.str();
                while (i < s.size()) {
@@ -1068,11 +1088,11 @@ private:
 
                auto root = realContext.getRootVisibleObject();
                auto pos = (*realContext.getRowSize(0)).getCenterPoint();
-               auto ui = std::make_shared<UIElement>(root, pos, realContext.getApplicationCategory());
+               currentVisibleRootUIElement = std::make_shared<UIElement>(root, pos, realContext.getApplicationCategory());
                rootObject = realContext.getRootObject();
                keyboardRootObject = keyboardContext ? (*keyboardContext).getRootObject() : nullptr;
-               ASSERT(contentRootElement);
-               emitCallback<NavigationCallbackType::ContextChanged>(ui, contentRootElement);
+               ASSERT(currentRootElement);
+               emitCallback<NavigationCallbackType::ContextChanged>(currentVisibleRootUIElement, currentRootElement);
        }
 
        void initializeRebuildingContext(bool force, float delay = 0.2f)
index 499aa07..b4d7060 100644 (file)
@@ -105,6 +105,8 @@ public:
        using CallbackHandle = std::unique_ptr<CallbackHandleBase>;
 
        virtual ~NavigationInterface();
+       virtual std::shared_ptr<UIElement> getCurrentVisibleRoot() const = 0;
+       virtual std::shared_ptr<NavigationElement> getCurrentNavigationContext() const = 0;
 
        template <NavigationCallbackType type>
        CallbackHandle registerCb(std::function<typename NavigationCallbackTraits<type>::CallbackFunctionType> callback)
index 2bf85fa..fbe1083 100644 (file)
@@ -74,8 +74,14 @@ void UniversalSwitch::initialize(const std::array<Optional<std::string>, (size_t
        });
 }
 
+bool UniversalSwitch::isInBatchMode() const
+{
+       return mode == Mode::testExecution;
+}
+
 void UniversalSwitch::changeMode(Mode mode)
 {
+       this->mode = mode;
        switch (mode) {
        case Mode::active:
                DEBUG("Universal-switch active mode");
index c55394a..ea41a93 100644 (file)
@@ -42,6 +42,12 @@ class SoundFeedback;
 class UniversalSwitch
 {
 public:
+       enum class Mode {
+               passive,
+               active,
+               testExecution
+       };
+
        std::shared_ptr<SwitchManager> getSwitchManager() const;
        std::shared_ptr<CompositeSwitchProvider> getCompositeSwitchProvider() const;
        std::shared_ptr<Configuration> getConfiguration() const;
@@ -57,14 +63,9 @@ public:
        void setScrollActivitiesData(std::shared_ptr<ScrollActivitiesData>);
 
        void initialize(const std::array<Optional<std::string>, (size_t)utils::Argument::_count> &arguments);
+       bool isInBatchMode() const;
        void terminate();
 private:
-       enum class Mode {
-               passive,
-               active,
-               testExecution
-       };
-
        void changeMode(Mode mode);
        void updateMode();
        void setSwitchManager(const std::shared_ptr<SwitchManager> &sm);
@@ -91,6 +92,7 @@ private:
        bool isDisplayOn = false;
        std::string batchFilePath;
        std::string batchOutputPath;
+       Mode mode;
 };
 
 #endif