9 UiObject::UiObject() : UiObject(nullptr, nullptr, nullptr) {}
13 if (mWaiter) delete mWaiter;
16 UiObject::UiObject(const std::shared_ptr<UiDevice> device, const std::shared_ptr<UiSelector> selector,
17 const AccessibleNode *node)
20 mNode(std::shared_ptr<AccessibleNode>(const_cast<AccessibleNode *>(node))),
21 mWaiter(new Waiter{this, this})
25 UiObject::UiObject(const std::shared_ptr<UiDevice> device, const std::shared_ptr<UiSelector> selector,
26 std::shared_ptr<AccessibleNode> node)
29 mNode(std::move(node)),
30 mWaiter(new Waiter{this, this})
34 UiObject::UiObject(UiObject &&src)
35 : mDevice(src.mDevice),
36 mSelector(std::move(src.mSelector)),
37 mNode(std::move(src.mNode)),
40 src.mDevice = nullptr;
41 src.mSelector = nullptr;
43 src.mWaiter = nullptr;
46 std::shared_ptr<UiSelector> UiObject::getSelector()
48 return this->mSelector;
51 bool UiObject::hasObject(const std::shared_ptr<UiSelector> selector) const
53 std::shared_ptr<AccessibleNode> node =
54 Comparer::findObject(mDevice, selector, getAccessibleNode());
55 if (node != nullptr) {
56 // todo : what is this node.recycle()
62 std::shared_ptr<UiObject> UiObject::findObject(const std::shared_ptr<UiSelector> selector) const
64 std::shared_ptr<AccessibleNode> node =
65 Comparer::findObject(mDevice, selector, getAccessibleNode());
67 return std::make_shared<UiObject>(mDevice, selector, std::move(node));
69 return std::shared_ptr<UiObject>{nullptr};
72 std::vector<std::shared_ptr<UiObject>> UiObject::findObjects(
73 const std::shared_ptr<UiSelector> selector) const
75 std::vector<std::shared_ptr<UiObject>> result{};
76 auto nodes = Comparer::findObjects(mDevice, selector, getAccessibleNode());
77 for ( auto& node : nodes) {
79 LOGI("Skipped! (node == nullptr)");
82 result.push_back(std::make_shared<UiObject>(mDevice, selector, std::move(node)));
87 bool UiObject::waitFor(
88 const std::function<bool(const ISearchable *)> condition) const
90 return mWaiter->waitFor(condition);
93 std::shared_ptr<UiObject> UiObject::waitFor(
94 const std::function<std::shared_ptr<UiObject>(const ISearchable *)>
97 return mWaiter->waitFor(condition);
100 bool UiObject::waitFor(
101 const std::function<bool(const UiObject *)> condition) const
103 return mWaiter->waitFor(condition);
106 UiObject *UiObject::getParent() const
108 std::shared_ptr<AccessibleNode> node = getAccessibleNode()->getParent();
109 if (!node) return nullptr;
110 return new UiObject(mDevice, mSelector, std::move(node));
113 int UiObject::getChildCount() const
115 return getAccessibleNode()->getChildCount();
118 std::shared_ptr<UiObject> UiObject::getChildAt(int index) const {
119 auto childNode = getAccessibleNode()->getChildAt(index);
121 return std::make_shared<UiObject>(mDevice, mSelector, childNode);
126 std::vector<std::shared_ptr<UiObject>> UiObject::getChildren() const
128 auto sel = Sel::depth(1);
129 return this->findObjects(sel);
132 std::shared_ptr<Node> UiObject::getDescendant()
134 std::vector<std::shared_ptr<Node>> nodeChildren{};
136 auto children = getChildren();
137 for (auto &&child : children) {
138 nodeChildren.push_back(child->getDescendant());
140 return std::make_shared<Node>(shared_from_this(), nodeChildren);
143 std::string UiObject::getApplicationPackage() const
145 return getAccessibleNode()->getPkg();
148 std::string UiObject::getId() const
150 return getAccessibleNode()->getId();
153 std::string UiObject::getAutomationId() const
155 return getAccessibleNode()->getAutomationId();
158 std::string UiObject::getElementType() const
160 return getAccessibleNode()->getType();
163 std::string UiObject::getElementStyle() const
165 return getAccessibleNode()->getStyle();
168 std::string UiObject::getText() const
170 return getAccessibleNode()->getText();
173 std::string UiObject::getRole() const
175 return getAccessibleNode()->getRole();
178 void UiObject::setText(std::string text)
180 getAccessibleNode()->setValue(text);
183 bool UiObject::isCheckable() const
185 return getAccessibleNode()->isCheckable();
188 bool UiObject::isChecked() const
190 return getAccessibleNode()->isChecked();
193 bool UiObject::isClickable() const
195 return getAccessibleNode()->isClickable();
198 bool UiObject::isEnabled() const
200 return getAccessibleNode()->isEnabled();
203 bool UiObject::isFocusable() const
205 return getAccessibleNode()->isFocusable();
208 bool UiObject::isFocused() const
210 return getAccessibleNode()->isFocused();
213 bool UiObject::isLongClickable() const
215 return getAccessibleNode()->isLongClickable();
218 bool UiObject::isScrollable() const
220 return getAccessibleNode()->isScrollable();
223 bool UiObject::isSelectable() const
225 return getAccessibleNode()->isSelectable();
228 bool UiObject::isSelected() const
230 return getAccessibleNode()->isSelected();
233 bool UiObject::isVisible() const
235 return getAccessibleNode()->isVisible();
238 bool UiObject::isShowing() const
240 return getAccessibleNode()->isShowing();
243 bool UiObject::isActive() const
245 return getAccessibleNode()->isActive();
248 void UiObject::refresh() const
253 void UiObject::updateRoleName() const
255 mNode->updateRoleName();
258 void UiObject::updateUniqueId() const
260 mNode->updateUniqueId();
263 void UiObject::updateName() const
268 void UiObject::updateApplication() const
270 mNode->updateApplication();
273 void UiObject::updateAttributes() const
275 mNode->updateAttributes();
278 void UiObject::updateStates() const
280 mNode->updateStates();
283 void UiObject::updateExtents() const
285 mNode->updateExtents();
288 bool UiObject::isValid() const
290 return mNode->isValid();
293 const Rect<int> UiObject::getScreenBoundingBox() const
295 return mNode->getScreenBoundingBox();
298 const Rect<int> UiObject::getWindowBoundingBox() const
300 return mNode->getWindowBoundingBox();
303 void UiObject::click() const
305 mNode->updateExtents();
306 const Rect<int> rect = mNode->getScreenBoundingBox();
307 const Point2D<int> midPoint = rect.midPoint();
308 mDevice->click(midPoint.x, midPoint.y);
311 void UiObject::longClick(const unsigned int durationMs) const
313 mNode->updateExtents();
314 const Rect<int> rect = mNode->getScreenBoundingBox();
315 const Point2D<int> midPoint = rect.midPoint();
316 mDevice->click(midPoint.x, midPoint.y, durationMs);
319 bool UiObject::DoAtspiActivate() const
321 return mNode->doAction("activate");
325 std::shared_ptr<AccessibleNode> UiObject::getAccessibleNode() const
327 if (mNode == nullptr) throw;
328 // TODO : wait for animation and refresh current node
329 // mDevice->waitForIdle();