PointScanner slight refactor 94/163494/2
authorRadoslaw Cybulski <r.cybulski@partner.samsung.com>
Mon, 11 Dec 2017 14:06:34 +0000 (15:06 +0100)
committerRadoslaw Cybulski <r.cybulski@partner.samsung.com>
Wed, 13 Dec 2017 17:51:42 +0000 (18:51 +0100)
Minor refactor of point scanner to publish get at point functionality
as stand-alone static function.

Change-Id: I9db6befc71ccaf5d672c1db398470dde20fa8525

src/PointScanner.cpp
src/PointScanner.hpp

index f7b91d5..c334e5d 100644 (file)
@@ -64,6 +64,24 @@ digraph StateMachine {
  *  @see ScreenScannerManager
  *  @see ScanningProperties
  */
+
+void PointScanner::getAtPoint(const std::shared_ptr<NavigationElement> &root, Point pt, std::function<void(Optional<std::shared_ptr<UIElement>>)> callback)
+{
+       auto elem = root->getAtPoint(pt);
+       if (elem) {
+               auto atspi = Singleton<UniversalSwitch>::instance().getAtspi();
+               auto application = elem->getApplicationCategory();
+               atspi->getAtPoint(pt, Atspi::CoordType::Screen, elem->getVisibleRoot(),
+               [ = ](DBus::ValueOrError<std::shared_ptr<AtspiAccessible>> elem) {
+                       auto uiElem = std::make_shared<UIElement>(elem ? std::move(std::get<0>(elem)) : nullptr, pt, application);
+                       callback(std::move(uiElem));
+               });
+       } else {
+               auto uiElem = std::make_shared<UIElement>(nullptr, pt, UIElement::ApplicationCategory::OTHER);
+               callback(std::move(uiElem));
+       }
+}
+
 class PointScannerImpl : public ScreenScanner
 {
 public:
@@ -206,21 +224,7 @@ void PointScannerImpl::acceptAutoscanningPhase(std::function<void(Optional<std::
                state = State::END;
 
                DEBUG("Scanning complete");
-               {
-                       auto elem = rootNavigationElement->getAtPoint(intersectionPoint);
-                       if (elem) {
-                               auto atspi = Singleton<UniversalSwitch>::instance().getAtspi();
-                               auto application = elem->getApplicationCategory();
-                               atspi->getAtPoint(intersectionPoint, Atspi::CoordType::Screen, elem->getVisibleRoot(),
-                               [ = ](DBus::ValueOrError<std::shared_ptr<AtspiAccessible>> elem) {
-                                       auto uiElem = std::make_shared<UIElement>(elem ? std::move(std::get<0>(elem)) : nullptr, intersectionPoint, application);
-                                       callback(std::move(uiElem));
-                               });
-                       } else {
-                               auto uiElem = std::make_shared<UIElement>(nullptr, intersectionPoint, UIElement::ApplicationCategory::OTHER);
-                               callback(std::move(uiElem));
-                       }
-               }
+               PointScanner::getAtPoint(rootNavigationElement, intersectionPoint, std::move(callback));
                return;
 
        case State::END:
index 5e8c939..db326e1 100644 (file)
@@ -43,6 +43,8 @@ public:
         */
        static std::unique_ptr<ScreenScanner> create(const ScanningProperties &properties,
                        std::shared_ptr<NavigationElement> rootNavigationElement);
+
+       static void getAtPoint(const std::shared_ptr<NavigationElement> &root, Point pt, std::function<void(Optional<std::shared_ptr<UIElement>>)> callback);
 };
 
 #endif