Fix for invalid marshalling of AtspiAccessible objects 44/151044/6
authorRadoslaw Cybulski <r.cybulski@partner.samsung.com>
Tue, 19 Sep 2017 11:58:35 +0000 (13:58 +0200)
committerRadoslaw Cybulski <r.cybulski@partner.samsung.com>
Wed, 20 Sep 2017 10:30:28 +0000 (12:30 +0200)
This change temporary requires following patches:
  https://review.tizen.org/gerrit/#/c/143845 (at-spi2-core)
  https://review.tizen.org/gerrit/#/c/143847 (elementary)
  https://review.tizen.org/gerrit/#/c/143623 (e-mod-tizen-screen-reader)
  https://review.tizen.org/gerrit/#/c/142317 (screen-reader)
Screen-reader has to be started before universal-switch.

Requirement for those patches is temporary and will be removed soon.

Change-Id: I3fe8e0fa4224ef5f03ecd2c1054e5ac2b383a040

src/Atspi.cpp
src/Atspi.hpp
src/DBus.hpp
src/NavigationInterface.cpp
src/NavigationInterface.hpp
src/RowScanner.cpp
src/ScreenScannerManager.cpp
src/Window.cpp

index 93305ff..1f13471 100644 (file)
@@ -89,7 +89,7 @@ template <typename T> struct InterfaceNameFromType {
                GError *error = nullptr;                                                                          \
                auto v = atspi_accessible_get_unique_id(ATSPI_ACCESSIBLE(obj.get()), &error);                     \
                PRINT_ERROR_AND_FREE(error);                                                                      \
-               if (!error) return "(failed)";                                                                    \
+               if (error) return "(failed)";                                                                     \
                auto z = std::string { v };                                                                       \
                g_free(v);                                                                                        \
                return std::move(z);                                                                              \
index 7928e36..9e66db7 100644 (file)
 
 namespace detail
 {
-       template <typename T> struct AsyncCallbackHelper {
+       template <typename T>
+       struct AsyncCallbackHelper {
                using type = std::function<void(Optional<T>)>;
        };
-       template <> struct AsyncCallbackHelper<void> {
+
+       template <>
+       struct AsyncCallbackHelper<void> {
                using type = std::function<void(bool)>;
        };
 }
@@ -32,6 +35,8 @@ template <typename T> using AsyncCallback = typename detail::AsyncCallbackHelper
 
 class Atspi
 {
+       template <typename T> using AsyncCallback = typename detail::AsyncCallbackHelper<T>::type;
+
 public:
        using StateSet = std::bitset<ATSPI_STATE_LAST_DEFINED>;
 
index 8a2d6f0..23efabd 100644 (file)
@@ -337,7 +337,7 @@ namespace detail
                                sig = '{';
                        free(t);
                        std::pair<A, B> a;
-                       while (signature<std::pair<A, B>>::get(s, a))
+                       while (signature<std::pair<A, B>>::get(s, a, sig))
                                v.push_back(std::move(a));
                        return true;
                }
@@ -385,7 +385,7 @@ namespace detail
                        v.clear();
                        if (!eldbus_message_iter_get_and_next(iter, 'a', &s)) return false;
                        std::pair<A, B> a;
-                       while (signature<std::pair<A, B>>::get(s, a))
+                       while (signature<std::pair<A, B>>::get(s, a, '{'))
                                v.insert(std::move(a));
                        return true;
                }
@@ -411,7 +411,7 @@ namespace detail
                        v.clear();
                        if (!eldbus_message_iter_get_and_next(iter, 'a', &s)) return false;
                        std::pair<A, B> a;
-                       while (signature<A>::get(s, a))
+                       while (signature<std::pair<A, B>>::get(s, a, '{'))
                                v.insert(std::move(a));
                        return true;
                }
index b882f13..0435b08 100644 (file)
@@ -54,7 +54,7 @@ public:
                        return;
 
 #define LISTEN(n) \
-       do { navProxy.listen<void()>(#n).add([=]() { emitCallback(CallbackType::n); }); } while (0)
+       do { navProxy.listen<void()>(#n).add([=]() { emitCallback<NavigationCallbackType::n>(); }); } while (0)
                LISTEN(FirstRow);
                LISTEN(LastRow);
                LISTEN(FirstElementInRow);
@@ -62,18 +62,18 @@ public:
 #undef LISTEN
 
 #define LISTEN(n, SignalName) \
-       do { navProxy.listen<void()>(SignalName).add([=]() { emitCallback(CallbackType::n); }); } while (0)
+       do { navProxy.listen<void()>(SignalName).add([=]() { emitCallback<NavigationCallbackType::n>(); }); } while (0)
                LISTEN(DashedRow, "SpecialRow");
                LISTEN(DashedElementInRow, "SpecialElementInRow");
 #undef LISTEN
-               navProxy.listen<void(AtspiAccessiblePtr)>("ContextChanged").add(
-               [ = ](AtspiAccessiblePtr obj) {
-                       emitCallback(CallbackType::ContextChanged, std::make_shared<UIElement>(obj));
+               navProxy.listen<void(AtspiAccessiblePtr, int, int, int, int)>("ContextChanged").add(
+               [ = ](AtspiAccessiblePtr obj, int x, int y, int w, int h) {
+                       emitCallback<NavigationCallbackType::ContextChanged>(std::make_shared<UIElement>(obj), x, y, w, h);
                        DEBUG("got element %s", Singleton<Atspi>::instance().getUniqueId(obj).c_str());
                });
                navProxy.listen<void(int, int, int, int, BoxPositionMode)>("BoxMoved").add(
                [ = ](int x, int y, int w, int h, BoxPositionMode mode) {
-                       emitCallback(CallbackType::BoxMoved, x, y, w, h, mode);
+                       emitCallback<NavigationCallbackType::BoxMoved>(x, y, w, h, mode);
                });
                navProxy.listen<void(AtspiAccessiblePtr, std::vector<std::pair<std::string, std::string>>)>("HackAttributesForRootAfterContextChanged").add(
                [ = ](AtspiAccessiblePtr root, std::vector<std::pair<std::string, std::string>> attrs) {
@@ -122,12 +122,13 @@ public:
        }
 
 private:
-       template <typename ... ARGS>
-       void emitCallback(CallbackType type, ARGS ... args)
+       template <NavigationCallbackType type, typename ... ARGS>
+       void emitCallback(ARGS ... args)
        {
                for (auto a : callbacks) {
                        if (a->type == type) {
-                               auto b = static_cast<typename NavigationInterface::CallbackHandleImpl<void(ARGS...)>*>(a);
+                               using CallbackType = typename NavigationCallbackTraits<type>::CallbackFunctionType;
+                               auto b = static_cast<typename NavigationInterface::CallbackHandleImpl<CallbackType>*>(a);
                                b->callback(args...);
                        }
                }
index a1a6550..f210d18 100644 (file)
@@ -9,6 +9,19 @@
 #include <vector>
 #include <memory>
 
+enum class NavigationCallbackType {
+       FirstRow, LastRow, DashedRow,
+       FirstElementInRow, LastElementInRow, DashedElementInRow,
+       ContextChanged,
+       BoxMoved
+};
+
+template <NavigationCallbackType>
+struct NavigationCallbackTraits {
+       using CallbackFunctionType = void();
+};
+
+
 class NavigationInterface
 {
 public:
@@ -22,23 +35,11 @@ public:
                DASHED
        };
 
-       enum class CallbackType {
-               FirstRow, LastRow, DashedRow,
-               FirstElementInRow, LastElementInRow, DashedElementInRow,
-               ContextChanged,
-               BoxMoved
-       };
-
-       template <CallbackType>
-       struct CallbackTraits {
-               using CallbackFunctionType = void();
-       };
-
        struct CallbackHandleBase {
-               CallbackType type;
+               NavigationCallbackType type;
                bool registered = false;
 
-               CallbackHandleBase(CallbackType type)
+               CallbackHandleBase(NavigationCallbackType type)
                        : type(type)
                {}
 
@@ -60,10 +61,10 @@ public:
        virtual std::shared_ptr<UIElement> getCurrentElement() = 0;
        virtual std::shared_ptr<UIElement> getElementAtPoint(int x, int y) = 0;
 
-       template <CallbackType type>
-       CallbackHandle registerCb(std::function<typename CallbackTraits<type>::CallbackFunctionType> callback)
+       template <NavigationCallbackType type>
+       CallbackHandle registerCb(std::function<typename NavigationCallbackTraits<type>::CallbackFunctionType> callback)
        {
-               using T = typename CallbackTraits<type>::CallbackFunctionType;
+               using T = typename NavigationCallbackTraits<type>::CallbackFunctionType;
                std::unique_ptr<CallbackHandleImpl<T>> ptr{new CallbackHandleImpl<T>(type, std::move(callback))};
                callbacks.push_back(ptr.get());
                ptr->registered = true;
@@ -75,7 +76,7 @@ protected:
        struct CallbackHandleImpl : public CallbackHandleBase {
                std::function<T> callback;
 
-               CallbackHandleImpl(CallbackType type, std::function<T> c)
+               CallbackHandleImpl(NavigationCallbackType type, std::function<T> c)
                        : CallbackHandleBase(type), callback(std::move(c))
                {}
        };
@@ -87,13 +88,13 @@ protected:
 
 #define SPECIALIZE_CALLBACK_TRAITS(Item, FunctionType) \
        template <> \
-       struct NavigationInterface::CallbackTraits<NavigationInterface::CallbackType::Item> \
+       struct NavigationCallbackTraits<NavigationCallbackType::Item> \
        { \
                using CallbackFunctionType = FunctionType; \
        };
 
 SPECIALIZE_CALLBACK_TRAITS(ContextChanged, void(std::shared_ptr<UIElement>, int, int, int, int));
-SPECIALIZE_CALLBACK_TRAITS(BoxMoved, void(int, int, int, int, BoxPositionMode));
+SPECIALIZE_CALLBACK_TRAITS(BoxMoved, void(int, int, int, int, NavigationInterface::BoxPositionMode));
 #undef SPECIALIZE_CALLBACK_TRAITS
 
 #endif
index 182c03b..75ffdac 100644 (file)
@@ -102,7 +102,7 @@ RowScannerImpl::RowScannerImpl(const ScanningProperties &properties)
 
        auto &navigation = Singleton<NavigationInterface>::instance();
        navigation.resetPosition();
-       using CT = NavigationInterface::CallbackType;
+       using CT = NavigationCallbackType;
        navigationHandles.push_back(navigation.registerCb<CT::DashedRow>([ this ]() {
                countInactivityAfterCompletedLoop();
        }));
index b954819..87bb38a 100644 (file)
@@ -14,7 +14,7 @@ ScreenScannerManager::ScreenScannerManager()
        scanningMethod = properties.getMethod();
 
        //TODO: register for screen orientation change (probably better to do it in class Window)
-       contextChangedHandle = Singleton<NavigationInterface>::instance().registerCb<NavigationInterface::CallbackType::ContextChanged>(
+       contextChangedHandle = Singleton<NavigationInterface>::instance().registerCb<NavigationCallbackType::ContextChanged>(
        [this](std::shared_ptr<UIElement> obj, int x, int y, int width, int height) {
                auto rect = Rectangle {{x, y}, {width, height}};
                properties.setScanningField(rect);
@@ -95,9 +95,9 @@ void ScreenScannerManager::stopAutoscanning()
 void ScreenScannerManager::acceptAutoscanning()
 {
        Optional<std::shared_ptr<UIElement>> element;
-       if (!properties.isAutoScanEnabled() && properties.getMethod() == ScanningMethod::ROW)
+       if (!properties.isAutoScanEnabled() && properties.getMethod() == ScanningMethod::ROW) {
                element = Singleton<NavigationInterface>::instance().getCurrentElement();
-       else {
+       else {
                if (!screenScanner) {
                        ERROR("scanner type not selected");
                        return;
index bab0a11..fadf3be 100644 (file)
@@ -44,5 +44,5 @@ void Window::inputRegionOff()
 
 Rectangle Window::getDimensions() const
 {
-       return {{0, 0}, {screenWidth, screenHeight}};;
+       return {{0, 0}, {screenWidth, screenHeight}};
 }