aurum: implement an atspi action for uiobject
authorWonki Kim <wonki_.kim@samsung.com>
Tue, 23 Jun 2020 06:50:16 +0000 (15:50 +0900)
committerJongmin Lee <jm105.lee@samsung.com>
Sun, 28 Jun 2020 23:59:14 +0000 (08:59 +0900)
atspi accessible object has an "action" interface.
and it is used for invoking event such as "click" for an object through atspi.
this patch implement an atspi action for uiobject

Change-Id: I9289ccfb6bfd0fe994f08fd8dff57fd94603a890

libaurum/inc/AccessibleNode.h
libaurum/inc/UiObject.h
libaurum/src/AccessibleNode.cc
libaurum/src/UiObject.cc
org.tizen.aurum-bootstrap/src/Commands/ClickCommand.cc

index 2b1b3eb..11dfcc8 100644 (file)
@@ -349,6 +349,12 @@ public:
      */
     bool isActive() const;
 
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    std::vector<std::string> getActions() const;
+
 public:
     /**
      * @brief TBD
@@ -374,6 +380,12 @@ public:
      */
     void setValue(std::string text) const;
 
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    bool doAction(std::string action) const;
+
 private:
     /**
      * @brief TBD
index e83b384..b56470e 100644 (file)
@@ -246,6 +246,12 @@ public:
      * @brief TBD
      * @since_tizen 5.5
      */
+    bool DoAtspiActivate() const;
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
     void refresh() const;
 
 private:
index 3ec0d33..dd07b01 100644 (file)
@@ -1,6 +1,7 @@
 #include "AccessibleNode.h"
 #include <string.h>
 #include <iostream>
+#include <vector>
 
 #include <loguru.hpp>
 #include "config.h"
@@ -405,3 +406,52 @@ void AccessibleNode::setValue(std::string text) const
                                         NULL);
     }
 }
+
+std::vector<std::string> AccessibleNode::getActions() const
+{
+    std::vector<std::string> result{};
+    const char *name;
+    AtspiAction *action;
+
+    action = atspi_accessible_get_action_iface(mNode.get());
+    if (action) {
+        int a;
+        int n_actions = atspi_action_get_n_actions(action, NULL);
+
+        for (a = 0; a < n_actions; a++) {
+            char *action_name = atspi_action_get_action_name(action, a, NULL);
+            if (!action_name) continue;
+            result.push_back(std::string{action_name});
+            g_free(action_name);
+        }
+        g_object_unref(action);
+    }
+    return result;
+}
+
+bool AccessibleNode::doAction(std::string actionName) const
+{
+    const char *name;
+    AtspiAction *action;
+
+    action = atspi_accessible_get_action_iface(mNode.get());
+    if (action) {
+        int a;
+        int n_actions = atspi_action_get_n_actions(action, NULL);
+
+        for (a = 0; a < n_actions; a++) {
+            char *action_name = atspi_action_get_action_name(action, a, NULL);
+            if (!action_name) return false;
+
+            if (!strcmp(actionName.c_str(), action_name)) {
+                atspi_action_do_action(action, a, NULL);
+                g_free(action_name);
+                g_object_unref(action);
+                return true;
+            }
+            g_free(action_name);
+        }
+        g_object_unref(action);
+    }
+    return false;
+}
\ No newline at end of file
index 67691c4..12502cb 100644 (file)
@@ -244,6 +244,12 @@ void UiObject::longClick(const unsigned int intv) const
     const_cast<UiDevice *>(mDevice)->click(midPoint.x, midPoint.y, intv);
 }
 
+bool UiObject::DoAtspiActivate() const
+{
+    return mNode->doAction("activate");
+}
+
+
 const AccessibleNode *UiObject::getAccessibleNode() const
 {
     if (mNode == nullptr) throw;
index ab67763..2b152e1 100644 (file)
@@ -34,6 +34,7 @@ std::unique_ptr<ClickCommand> ClickCommand::createCommand(const ::aurum::ReqClic
 {
     ObjectMapper* mObjMap = ObjectMapper::getInstance();
     UiObject* obj = mObjMap->getElement(mRequest->elementid());
+    LOG_SCOPE_F(INFO, "ClickElementCommand execute %p", obj);
 
     if (obj) {
         obj->click();
@@ -48,6 +49,7 @@ std::unique_ptr<ClickCommand> ClickCommand::createCommand(const ::aurum::ReqClic
 {
     UiDevice* obj = UiDevice::getInstance(DeviceType::DEFAULT);
     const ::aurum::Point& point = mRequest->coordination();
+    LOG_SCOPE_F(INFO, "ClickCoordCommand execute %p @ (%d, %d)", obj, point.x(), point.y());
     obj->click(point.x(), point.y());
     mResponse->set_status(::aurum::RspStatus::OK);
     return grpc::Status::OK;
@@ -55,5 +57,17 @@ std::unique_ptr<ClickCommand> ClickCommand::createCommand(const ::aurum::ReqClic
 
 ::grpc::Status ClickAtspiCommand::execute()
 {
-    return grpc::Status::CANCELLED;
+    ObjectMapper* mObjMap = ObjectMapper::getInstance();
+    UiObject* obj = mObjMap->getElement(mRequest->elementid());
+
+    LOG_SCOPE_F(INFO, "ClickAtspiCommand execute %p", obj);
+
+    if (obj) {
+        if (obj->DoAtspiActivate()) mResponse->set_status(::aurum::RspStatus::OK);
+        else mResponse->set_status(::aurum::RspStatus::ERROR);
+    } else {
+        mResponse->set_status(::aurum::RspStatus::ERROR);
+    }
+
+    return grpc::Status::OK;
 }