libaurum: Introduce setFocus command 69/270869/2
authorWoochanlee <wc0917.lee@samsung.com>
Thu, 10 Feb 2022 08:38:25 +0000 (17:38 +0900)
committerWoochanlee <wc0917.lee@samsung.com>
Fri, 11 Feb 2022 03:40:53 +0000 (12:40 +0900)
This command can sets focus to specific ui object.

sample usage : ret = stub.setFocus(ReqSetFocus(elementId="ID"))

Change-Id: I3d4fbe61620dabc2b5e309f65d6963a97a58e473

16 files changed:
libaurum/inc/Accessibility/AccessibleNode.h
libaurum/inc/Impl/Accessibility/AtspiAccessibleNode.h
libaurum/inc/Impl/Accessibility/AtspiWrapper.h
libaurum/inc/Impl/Accessibility/MockAccessibleNode.h
libaurum/inc/UiObject.h
libaurum/src/Impl/Accessibility/AtspiAccessibleNode.cc
libaurum/src/Impl/Accessibility/AtspiWrapper.cc
libaurum/src/Impl/Accessibility/MockAccessibleNode.cc
libaurum/src/UiObject.cc
org.tizen.aurum-bootstrap/inc/AurumServiceImpl.h
org.tizen.aurum-bootstrap/inc/Commands/Commands.h
org.tizen.aurum-bootstrap/inc/Commands/SetFocusCommand.h [new file with mode: 0644]
org.tizen.aurum-bootstrap/meson.build
org.tizen.aurum-bootstrap/src/AurumServiceImpl.cc
org.tizen.aurum-bootstrap/src/Commands/SetFocusCommand.cc [new file with mode: 0644]
protocol/aurum.proto

index 20373adf9579db354cd8ef5ad8194fbf09df6680..d37377ecb5d22524d025800a68c6adeee01d4497 100644 (file)
@@ -323,6 +323,11 @@ public:
      */
     virtual void updateExtents() = 0;
 
+    /**
+     * @copydoc UiObject::setFocus()
+     */
+    virtual bool setFocus() = 0;
+
     /**
      * @brief Updates Node information from atspi server.
      *
index dfda9ff6367d08b7430deb7edafe533dba4f9f7e..7fb03ff4a91f7f96352ea47d369418e2dc2d9d25 100644 (file)
@@ -116,6 +116,11 @@ public:
      */
     void updateExtents() override;
 
+    /**
+     * @copydoc UiObject::setFocus()
+     */
+    bool setFocus() override;
+
     /**
      * @copydoc AccessibleNode::refresh()
      */
index b3928fbd04bc6a741e017437998f76f72091d07c..51822304bfa656f1352edc2b41863835c41b50fb 100644 (file)
@@ -58,6 +58,7 @@ public:
     static gboolean Atspi_editable_text_insert_text(AtspiEditableText *, int pos, const gchar *text, int len, GError **error);
     static AtspiAccessible *Atspi_accessible_get_application (AtspiAccessible *node, GError **error);
     static void Atspi_accessible_clear_cache (AtspiAccessible *node);
+    static gboolean Atspi_component_grab_focus(AtspiComponent *obj, GError **error);
 
 private:
     static std::recursive_mutex mMutex;
index 7286e0398018f48b981c8dbc606c660262a08186..d2d8e5e9f8e3035a8c9e7d32a355cfb983512468 100644 (file)
@@ -117,6 +117,12 @@ public:
      */
     void updateExtents() override;
 
+    /**
+     * @brief TBD
+     * @since_tizen 7.0
+     */
+    bool setFocus() override;
+
        /**
      * @brief TBD
      * @since_tizen 6.5
index 14ab71740ee29346a3881406d99ee79c0011de62..8c81b730307d07a92b1974a9da92e15297d02ac5 100644 (file)
@@ -480,6 +480,13 @@ public:
      */
     void updateExtents() const;
 
+    /**
+     * @brief Sets focus to object.
+     *
+     * @since_tizen 7.0
+     */
+    bool setFocus() const;
+
     /**
      * @brief Updates object's information from atspi server.
      *
index 3fa127ce48a4e2b4a0ab7abe9538a256fedecfc6..95c4506b544872081cf91650dddd818e187c4eed 100644 (file)
@@ -226,6 +226,18 @@ void AtspiAccessibleNode::updateExtents()
     }
 }
 
+bool AtspiAccessibleNode::setFocus()
+{
+    AtspiComponent *component = AtspiWrapper::Atspi_accessible_get_component_iface(mNode);
+    if (component) {
+        bool ret = AtspiWrapper::Atspi_component_grab_focus(component, NULL);
+        g_object_unref(component);
+        return ret;
+    }
+    else
+        return false;
+}
+
 void AtspiAccessibleNode::refresh()
 {
     AtspiWrapper::Atspi_accessible_clear_cache(mNode);
index 6164ffcb080386d6b7f2b7ae24ddc347e1d3b158..fcf94c043ba5ff813022ca5462fc791a7a9733c1 100644 (file)
@@ -158,3 +158,9 @@ void AtspiWrapper::Atspi_accessible_clear_cache (AtspiAccessible *node)
     std::unique_lock<std::recursive_mutex> lock(mMutex);
     return atspi_accessible_clear_cache(node);
 }
+
+gboolean AtspiWrapper::Atspi_component_grab_focus(AtspiComponent *obj, GError **error)
+{
+    std::unique_lock<std::recursive_mutex> lock(mMutex);
+    return atspi_component_grab_focus(obj, error);
+}
index 2fcce9a1c1a522f3c186d3011d7ff36bd52b5f2b..75a46e1517b00e417bbb0c00e384400ca2fdd23a 100644 (file)
@@ -109,6 +109,11 @@ void MockAccessibleNode::updateExtents()
 {
 }
 
+bool MockAccessibleNode::setFocus()
+{
+    return false;
+}
+
 void MockAccessibleNode::refresh()
 {
 }
index f4bce91066f93c7cb57a77bd38f63e895e55878b..042171a7f0febef0fcfbd588bcad3f42a37e585c 100644 (file)
@@ -304,6 +304,11 @@ void UiObject::updateExtents() const
     mNode->updateExtents();
 }
 
+bool UiObject::setFocus() const
+{
+    return mNode->setFocus();
+}
+
 bool UiObject::isValid() const
 {
     return mNode->isValid();
index 7a6c9718eaa92d6950dfdd7a2d9c1179f011a7a6..a471ec421a406bff9a756ad3265ebd6b3a58f9e8 100644 (file)
@@ -113,6 +113,9 @@ public:
     ::grpc::Status actionAndWaitEvent(::grpc::ServerContext *context,
                                       const ::aurum::ReqActionAndWaitEvent *request,
                                       ::aurum::RspActionAndWaitEvent *response) override;
+    ::grpc::Status setFocus(::grpc::ServerContext *context,
+                            const ::aurum::ReqSetFocus *request,
+                            ::aurum::RspSetFocus *response) override;
 };
 
 #endif
index 754b8eb93048c7dfd6bd2770fdb849d7a5375033..c7728d5e65a9d1834433638a6b85eb5dafb7834f 100644 (file)
@@ -47,3 +47,4 @@
 #include "Commands/DumpObjectTreeCommand.h"
 #include "Commands/GetScreenSizeCommand.h"
 #include "Commands/ActionAndWaitEventCommand.h"
+#include "Commands/SetFocusCommand.h"
diff --git a/org.tizen.aurum-bootstrap/inc/Commands/SetFocusCommand.h b/org.tizen.aurum-bootstrap/inc/Commands/SetFocusCommand.h
new file mode 100644 (file)
index 0000000..6df2850
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *               http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+#include <gio/gio.h>
+#include <grpcpp/grpcpp.h>
+#include "Commands/Command.h"
+#include "ObjectMapper.h"
+#include <aurum.grpc.pb.h>
+#include "config.h"
+
+class SetFocusCommand : public Command {
+private:
+    const ::aurum::ReqSetFocus *mRequest;
+    ::aurum::RspSetFocus *mResponse;
+
+public:
+    SetFocusCommand(const ::aurum::ReqSetFocus *request,
+                   ::aurum::RspSetFocus *response);
+    ::grpc::Status execute() override;
+};
index 3933f64a812d09c4ea1b5b554c77c9f14829e0fa..62ebd350a1ff1d4898337e3c193f81f6797004d9 100644 (file)
@@ -43,6 +43,7 @@ bootstrap_svr_src += [
    files('src/Commands/DumpObjectTreeCommand.cc'),
    files('src/Commands/GetScreenSizeCommand.cc'),
    files('src/Commands/ActionAndWaitEventCommand.cc'),
+   files('src/Commands/SetFocusCommand.cc'),
 ]
 
 bootstrap_svr_dep = [
index 32cdec4bb020a1eec6f7b00c5e402612750c34d0..ea50a2b73f66566b53e44360ef79499481d7b4be 100644 (file)
@@ -248,3 +248,11 @@ aurumServiceImpl::~aurumServiceImpl()
     std::unique_ptr<ActionAndWaitEventCommand> cmd = std::make_unique<ActionAndWaitEventCommand>(request, response);
     return execute(cmd.get(), true);
 }
+
+::grpc::Status aurumServiceImpl::setFocus(::grpc::ServerContext *context,
+                                         const ::aurum::ReqSetFocus *request,
+                                         ::aurum::RspSetFocus *response)
+{
+    std::unique_ptr<SetFocusCommand> cmd = std::make_unique<SetFocusCommand>(request, response);
+    return execute(cmd.get(), true);
+}
diff --git a/org.tizen.aurum-bootstrap/src/Commands/SetFocusCommand.cc b/org.tizen.aurum-bootstrap/src/Commands/SetFocusCommand.cc
new file mode 100644 (file)
index 0000000..061d581
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *               http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+#include "bootstrap.h"
+#include "SetFocusCommand.h"
+#include "UiObject.h"
+
+SetFocusCommand::SetFocusCommand(const ::aurum::ReqSetFocus *request,
+                               ::aurum::RspSetFocus *response)
+    : mRequest{request}, mResponse{response}
+{
+}
+
+::grpc::Status SetFocusCommand::execute()
+{
+    LOGI("SetFocus --------------- ");
+
+    ObjectMapper *mObjMap = ObjectMapper::getInstance();
+    std::shared_ptr<UiObject> obj = mObjMap->getElement(mRequest->elementid());
+    if (obj && obj->setFocus()) {
+        return grpc::Status::OK;
+    }
+
+    return grpc::Status::CANCELLED;
+}
index 1cab347f8f1fb14383e9a1df18c3d50f61b0168e..6b66794035384cd2a00d9f972cd68a359590f029 100644 (file)
@@ -31,6 +31,7 @@ service Bootstrap {
    rpc dumpObjectTree(ReqDumpObjectTree) returns (RspDumpObjectTree) {}
    rpc getScreenSize(ReqGetScreenSize) returns (RspGetScreenSize) {}
    rpc actionAndWaitEvent(ReqActionAndWaitEvent) returns (RspActionAndWaitEvent) {}
+   rpc setFocus(ReqSetFocus) returns (RspSetFocus) {}
 }
 
 // ------------------------------------ //
@@ -452,4 +453,12 @@ message ReqActionAndWaitEvent {
 
 message RspActionAndWaitEvent {
    RspStatus status = 1;
+}
+
+message ReqSetFocus {
+   string elementId = 1;
+}
+
+message RspSetFocus {
+   RspStatus status = 1;
 }
\ No newline at end of file