2 * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include "bootstrap.h"
19 #include "DumpObjectTreeCommand.h"
22 #include "UiSelector.h"
24 #include "ISearchable.h"
26 DumpObjectTreeCommand::DumpObjectTreeCommand(const ::aurum::ReqDumpObjectTree *request,
27 ::aurum::RspDumpObjectTree *response)
28 : mRequest{request}, mResponse{response}
30 mObjMap = ObjectMapper::getInstance();
33 void DumpObjectTreeCommand::traverse(::aurum::Element *root, std::shared_ptr<Node> node, int depth)
35 if (!node->mNode) return;
36 std::shared_ptr<UiObject> obj = node->mNode;
39 if (mObjMap->getElement(obj->getId()) == nullptr)
40 mObjMap->addElement(obj);
42 root->set_elementid(obj->getId());
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());
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());
58 root->set_widget_type(obj->getElementType());
59 root->set_widget_style(obj->getElementStyle());
61 root->set_text(obj->getText());
62 root->set_automationid(obj->getAutomationId());
63 root->set_package(obj->getApplicationPackage());
64 root->set_role(obj->getRole());
66 root->set_ischecked(obj->isChecked());
67 root->set_ischeckable(obj->isCheckable());
68 root->set_isclickable(obj->isClickable());
69 root->set_isenabled(obj->isEnabled());
70 root->set_isfocused(obj->isFocused());
71 root->set_isfocusable(obj->isFocusable());
72 root->set_isscrollable(obj->isScrollable());
73 root->set_isselected(obj->isSelected());
74 root->set_isshowing(obj->isShowing());
75 root->set_isactive(obj->isActive());
76 root->set_isvisible(obj->isVisible());
77 root->set_isselectable(obj->isSelectable());
79 for( auto && childNode : node->mChildren) {
80 ::aurum::Element *child = root->add_child();
81 traverse(child, childNode, depth+1);
85 ::grpc::Status DumpObjectTreeCommand::execute()
87 LOGI("DumpObjectTree --------------- ");
88 LOGI("elementid : %s", mRequest->elementid().c_str());
89 if (mRequest->elementid().length()) {
90 auto obj = mObjMap->getElement(mRequest->elementid());
91 if (!obj) return grpc::Status::OK;;
93 auto node = obj->getDescendant();
94 ::aurum::Element *root = mResponse->add_roots();
95 traverse(root, node, 0);
97 return grpc::Status::OK;