aurum: add getXPath method
[platform/core/uifw/aurum.git] / org.tizen.aurum-bootstrap / src / Commands / DumpObjectTreeCommand.cc
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *  Licensed under the Apache License, Version 2.0 (the "License");
5  *  you may not use this file except in compliance with the License.
6  *  You may obtain a copy of the License at
7  *
8  *               http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License.
15  *
16  */
17
18 #include "bootstrap.h"
19 #include "DumpObjectTreeCommand.h"
20 #include "UiObject.h"
21 #include "UiDevice.h"
22 #include "UiSelector.h"
23 #include "Sel.h"
24 #include "ISearchable.h"
25
26 DumpObjectTreeCommand::DumpObjectTreeCommand(const ::aurum::ReqDumpObjectTree *request,
27                                                    ::aurum::RspDumpObjectTree *response)
28     : mRequest{request}, mResponse{response}
29 {
30     mObjMap = ObjectMapper::getInstance();
31 }
32
33 void DumpObjectTreeCommand::traverse(::aurum::Element *root, std::shared_ptr<Node> node, int depth)
34 {
35     if (!node->mNode) return;
36     std::shared_ptr<UiObject> obj = node->mNode;
37
38     obj->refresh();
39     if (mObjMap->getElement(obj->getId()) == nullptr)
40         mObjMap->addElement(obj);
41
42     root->set_elementid(obj->getId());
43
44     ::aurum::Rect *rect = root->mutable_geometry();
45     const Rect<int> &size = obj->getScreenBoundingBox();
46     rect->set_x(size.mTopLeft.x);
47     rect->set_y(size.mTopLeft.y);
48     rect->set_width(size.width());
49     rect->set_height(size.height());
50
51     ::aurum::Rect *windowRect = root->mutable_window_relative_geometry();
52     const Rect<int> &windowSize = obj->getWindowBoundingBox();
53     windowRect->set_x(windowSize.mTopLeft.x);
54     windowRect->set_y(windowSize.mTopLeft.y);
55     windowRect->set_width(windowSize.width());
56     windowRect->set_height(windowSize.height());
57
58     root->set_widget_type(obj->getElementType());
59     root->set_widget_style(obj->getElementStyle());
60
61     root->set_text(obj->getText());
62     root->set_xpath(obj->getXPath());
63     root->set_automationid(obj->getAutomationId());
64     root->set_package(obj->getApplicationPackage());
65     root->set_role(obj->getRole());
66
67     root->set_ischecked(obj->isChecked());
68     root->set_ischeckable(obj->isCheckable());
69     root->set_isclickable(obj->isClickable());
70     root->set_isenabled(obj->isEnabled());
71     root->set_isfocused(obj->isFocused());
72     root->set_isfocusable(obj->isFocusable());
73     root->set_isscrollable(obj->isScrollable());
74     root->set_isselected(obj->isSelected());
75     root->set_isshowing(obj->isShowing());
76     root->set_isactive(obj->isActive());
77     root->set_isvisible(obj->isVisible());
78     root->set_isselectable(obj->isSelectable());
79
80     for( auto && childNode : node->mChildren) {
81         ::aurum::Element *child = root->add_child();
82         traverse(child, childNode, depth+1);
83     }
84 }
85
86 ::grpc::Status DumpObjectTreeCommand::execute()
87 {
88     LOGI("DumpObjectTree --------------- ");
89     LOGI("elementid : %s", mRequest->elementid().c_str());
90     if (mRequest->elementid().length()) {
91         auto obj = mObjMap->getElement(mRequest->elementid());
92         if (!obj) return grpc::Status::OK;;
93
94         auto node = obj->getDescendant();
95         ::aurum::Element *root = mResponse->add_roots();
96         traverse(root, node, 0);
97     }
98     return grpc::Status::OK;
99 }