2 * Copyright (c) 2022 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.
26 using namespace Aurum;
28 UiObject::UiObject() : UiObject(nullptr, nullptr, nullptr) {}
32 if (mWaiter) delete mWaiter;
35 UiObject::UiObject(const std::shared_ptr<UiDevice> device, const std::shared_ptr<UiSelector> selector,
36 const AccessibleNode *node)
39 mNode(std::shared_ptr<AccessibleNode>(const_cast<AccessibleNode *>(node))),
40 mWaiter(new Waiter{this, this})
44 UiObject::UiObject(const std::shared_ptr<UiDevice> device, const std::shared_ptr<UiSelector> selector,
45 std::shared_ptr<AccessibleNode> node)
48 mNode(std::move(node)),
49 mWaiter(new Waiter{this, this})
53 UiObject::UiObject(UiObject &&src)
54 : mDevice(src.mDevice),
55 mSelector(std::move(src.mSelector)),
56 mNode(std::move(src.mNode)),
59 src.mDevice = nullptr;
60 src.mSelector = nullptr;
62 src.mWaiter = nullptr;
65 std::shared_ptr<UiSelector> UiObject::getSelector()
67 return this->mSelector;
70 bool UiObject::hasObject(const std::shared_ptr<UiSelector> selector) const
72 std::shared_ptr<AccessibleNode> node =
73 Comparer::findObject(mDevice, selector, getAccessibleNode());
74 if (node != nullptr) {
75 // todo : what is this node.recycle()
81 std::shared_ptr<UiObject> UiObject::findObject(const std::shared_ptr<UiSelector> selector) const
83 std::shared_ptr<AccessibleNode> node =
84 Comparer::findObject(mDevice, selector, getAccessibleNode());
86 return std::make_shared<UiObject>(mDevice, selector, std::move(node));
88 return std::shared_ptr<UiObject>{nullptr};
91 std::vector<std::shared_ptr<UiObject>> UiObject::findObjects(
92 const std::shared_ptr<UiSelector> selector) const
94 std::vector<std::shared_ptr<UiObject>> result{};
96 std::vector<std::shared_ptr<AccessibleNode>> nodes{};
97 Comparer::findObjects(nodes, mDevice, selector, getAccessibleNode());
98 for ( auto& node : nodes) {
100 LOGI("Skipped! (node == nullptr)");
103 result.push_back(std::make_shared<UiObject>(mDevice, selector, std::move(node)));
108 bool UiObject::waitFor(
109 const std::function<bool(const ISearchable *)> condition) const
111 return mWaiter->waitFor(condition);
114 std::shared_ptr<UiObject> UiObject::waitFor(
115 const std::function<std::shared_ptr<UiObject>(const ISearchable *)>
118 return mWaiter->waitFor(condition);
121 bool UiObject::waitFor(
122 const std::function<bool(const UiObject *)> condition) const
124 return mWaiter->waitFor(condition);
127 UiObject *UiObject::getParent() const
129 std::shared_ptr<AccessibleNode> node = getAccessibleNode()->getParent();
130 if (!node) return nullptr;
131 return new UiObject(mDevice, mSelector, std::move(node));
134 int UiObject::getChildCount() const
136 return getAccessibleNode()->getChildCount();
139 std::shared_ptr<UiObject> UiObject::getChildAt(int index) const {
140 auto childNode = getAccessibleNode()->getChildAt(index);
142 return std::make_shared<UiObject>(mDevice, mSelector, childNode);
147 std::vector<std::shared_ptr<UiObject>> UiObject::getChildren() const
149 std::vector<std::shared_ptr<UiObject>> ret{};
151 auto children = getAccessibleNode()->getChildren();
152 for (auto &child : children) {
153 ret.push_back(std::make_shared<UiObject>(mDevice, mSelector, child));
159 std::shared_ptr<Node> UiObject::getDescendant()
161 std::vector<std::shared_ptr<Node>> nodeChildren{};
163 auto children = getChildren();
164 for (auto &&child : children) {
165 nodeChildren.push_back(child->getDescendant());
167 return std::make_shared<Node>(shared_from_this(), nodeChildren);
170 std::string UiObject::getApplicationPackage() const
172 return getAccessibleNode()->getPkg();
175 std::string UiObject::getId() const
177 return getAccessibleNode()->getId();
180 std::string UiObject::getAutomationId() const
182 return getAccessibleNode()->getAutomationId();
185 std::string UiObject::getType() const
187 return getAccessibleNode()->getType();
190 std::string UiObject::getElementStyle() const
192 return getAccessibleNode()->getStyle();
195 std::string UiObject::getText() const
197 return getAccessibleNode()->getText();
200 std::string UiObject::getRole() const
202 return getAccessibleNode()->getRole();
205 std::string UiObject::getXPath() const
207 return getAccessibleNode()->getXPath();
210 const double UiObject::getMinValue() const
212 return getAccessibleNode()->getMinValue();
215 const double UiObject::getMaxValue() const
217 return getAccessibleNode()->getMaxValue();
220 const double UiObject::getValue() const
222 return getAccessibleNode()->getValue();
225 const double UiObject::getIncrement() const
227 return getAccessibleNode()->getIncrement();
230 const Rect<int> UiObject::getTextMinBoundingRect() const
232 return getAccessibleNode()->getTextMinBoundingRect();
235 bool UiObject::setValue(double value)
237 return getAccessibleNode()->setValue(value);
240 bool UiObject::setText(std::string text)
242 return getAccessibleNode()->setValue(text);
245 std::string UiObject::getOcrText() const
247 return getAccessibleNode()->getOcrText();
250 std::string UiObject::getToolkitName() const
252 getAccessibleNode()->updateToolkitName();
253 return getAccessibleNode()->getToolkitName();
256 void UiObject::setOcrText(std::string text)
258 getAccessibleNode()->setOcrText(text);
261 bool UiObject::isCheckable() const
263 return getAccessibleNode()->isCheckable();
266 bool UiObject::isChecked() const
268 return getAccessibleNode()->isChecked();
271 bool UiObject::isClickable() const
273 return getAccessibleNode()->isClickable();
276 bool UiObject::isEnabled() const
278 return getAccessibleNode()->isEnabled();
281 bool UiObject::isFocusable() const
283 return getAccessibleNode()->isFocusable();
286 bool UiObject::isFocused() const
288 return getAccessibleNode()->isFocused();
291 bool UiObject::isLongClickable() const
293 return getAccessibleNode()->isLongClickable();
296 bool UiObject::isScrollable() const
298 return getAccessibleNode()->isScrollable();
301 bool UiObject::isSelectable() const
303 return getAccessibleNode()->isSelectable();
306 bool UiObject::isSelected() const
308 return getAccessibleNode()->isSelected();
311 bool UiObject::isVisible() const
313 return getAccessibleNode()->isVisible();
316 bool UiObject::isShowing() const
318 return getAccessibleNode()->isShowing();
321 bool UiObject::isActive() const
323 return getAccessibleNode()->isActive();
326 bool UiObject::isHighlightable() const
328 return getAccessibleNode()->isHighlightable();
331 void UiObject::refresh() const
336 void UiObject::updateRoleName() const
338 mNode->updateRoleName();
341 void UiObject::updateUniqueId() const
343 mNode->updateUniqueId();
346 void UiObject::updateName() const
351 void UiObject::updateApplication() const
353 mNode->updateApplication();
356 void UiObject::updateAttributes() const
358 mNode->updateAttributes();
361 void UiObject::updateStates() const
363 mNode->updateStates();
366 void UiObject::updateExtents() const
368 mNode->updateExtents();
371 void UiObject::updateXPath() const
373 mNode->updateXPath();
376 void UiObject::updateValue() const
378 mNode->updateValue();
381 void UiObject::updatePid() const
386 void UiObject::updateToolkitName() const
388 mNode->updateToolkitName();
391 void UiObject::updateTextMinBoundingRect() const
393 mNode->updateTextMinBoundingRect();
396 bool UiObject::setFocus() const
398 return mNode->setFocus();
401 bool UiObject::isValid() const
403 return mNode->isValid();
406 const Rect<int> UiObject::getScreenBoundingBox() const
408 return mNode->getScreenBoundingBox();
411 const Rect<int> UiObject::getWindowBoundingBox() const
413 return mNode->getWindowBoundingBox();
416 void UiObject::click() const
418 mNode->updateExtents();
419 const Rect<int> rect = mNode->getScreenBoundingBox();
420 const Point2D<int> midPoint = rect.midPoint();
421 mDevice->click(midPoint.x, midPoint.y);
424 void UiObject::longClick(const unsigned int durationMs) const
426 mNode->updateExtents();
427 const Rect<int> rect = mNode->getScreenBoundingBox();
428 const Point2D<int> midPoint = rect.midPoint();
429 mDevice->click(midPoint.x, midPoint.y, durationMs);
432 bool UiObject::DoAtspiActivate() const
434 return mNode->doAction("activate");
438 std::shared_ptr<AccessibleNode> UiObject::getAccessibleNode() const
440 if (mNode == nullptr) throw;
441 // TODO : wait for animation and refresh current node
442 // mDevice->waitForIdle();