12 UiObject::UiObject() : UiObject(nullptr, nullptr, nullptr) {}
16 if (mWaiter) delete mWaiter;
19 UiObject::UiObject(const std::shared_ptr<UiDevice> device, const std::shared_ptr<UiSelector> selector,
20 const AccessibleNode *node)
23 mNode(std::shared_ptr<AccessibleNode>(const_cast<AccessibleNode*>(node))),
24 mWaiter(new Waiter{this, this})
28 UiObject::UiObject(const std::shared_ptr<UiDevice> device, const std::shared_ptr<UiSelector> selector,
29 std::shared_ptr<AccessibleNode> node)
32 mNode(std::move(node)),
33 mWaiter(new Waiter{this, this})
37 // UiObject::UiObject(const UiObject &src)
38 // : mDevice(src.mDevice),
39 // mSelector(src.mSelector),
41 // mWaiter{src.mWaiter},
42 // mNode_src(std::move(src.mNode_src))
47 UiObject::UiObject(UiObject &&src)
48 : mDevice(src.mDevice),
49 mSelector(std::move(src.mSelector)),
50 mNode(std::move(src.mNode)),
53 src.mDevice = nullptr;
54 src.mSelector = nullptr;
56 src.mWaiter = nullptr;
59 std::shared_ptr<UiSelector> UiObject::getSelector()
61 return this->mSelector;
64 bool UiObject::hasObject(const std::shared_ptr<UiSelector> selector) const
66 std::shared_ptr<AccessibleNode> node =
67 Comparer::findObject(mDevice, selector, getAccessibleNode());
68 if (node != nullptr) {
69 // todo : what is this node.recycle()
75 std::shared_ptr<UiObject> UiObject::findObject(const std::shared_ptr<UiSelector> selector) const
77 std::shared_ptr<AccessibleNode> node =
78 Comparer::findObject(mDevice, selector, getAccessibleNode());
80 return std::make_shared<UiObject>(mDevice, selector, std::move(node));
82 return std::shared_ptr<UiObject>{nullptr};
85 std::vector<std::shared_ptr<UiObject>> UiObject::findObjects(
86 const std::shared_ptr<UiSelector> selector) const
88 std::vector<std::shared_ptr<UiObject>> result{};
89 auto nodes = Comparer::findObjects(mDevice, selector, getAccessibleNode());
90 for ( auto& node : nodes) {
92 LOG_F(INFO, "Skipped! (node == nullptr)");
95 result.push_back(std::make_shared<UiObject>(mDevice, selector, std::move(node)));
100 bool UiObject::waitFor(
101 const std::function<bool(const ISearchable *)> condition) const
103 return mWaiter->waitFor(condition);
106 std::shared_ptr<UiObject> UiObject::waitFor(
107 const std::function<std::shared_ptr<UiObject>(const ISearchable *)>
110 return mWaiter->waitFor(condition);
113 bool UiObject::waitFor(
114 const std::function<bool(const UiObject *)> condition) const
116 return mWaiter->waitFor(condition);
119 UiObject *UiObject::getParent() const
121 std::shared_ptr<AccessibleNode> node = getAccessibleNode()->getParent();
122 if (!node) return nullptr;
123 return new UiObject(mDevice, mSelector, std::move(node));
126 int UiObject::getChildCount() const
128 return getAccessibleNode()->getChildCount();
131 std::shared_ptr<UiObject> UiObject::getChildAt(int index) const {
132 auto childNode = getAccessibleNode()->getChildAt(index);
134 return std::make_shared<UiObject>(mDevice, mSelector, childNode);
139 std::vector<std::shared_ptr<UiObject>> UiObject::getChildren() const
141 auto sel = Sel::depth(1);
142 return this->findObjects(sel);
145 std::shared_ptr<Node> UiObject::getDescendant()
147 std::vector<std::shared_ptr<Node>> nodeChildren{};
149 auto children = getChildren();
150 for (auto &&child : children) {
151 nodeChildren.push_back(child->getDescendant());
153 return std::make_shared<Node>(shared_from_this(), nodeChildren);
156 std::string UiObject::getApplicationPackage() const
158 return getAccessibleNode()->getPkg();
161 std::string UiObject::getId() const
163 return getAccessibleNode()->getId();
166 std::string UiObject::getAutomationId() const
168 return getAccessibleNode()->getAutomationId();
171 std::string UiObject::getElementType() const
173 return getAccessibleNode()->getType();
176 std::string UiObject::getElementStyle() const
178 return getAccessibleNode()->getStyle();
181 std::string UiObject::getText() const
183 return getAccessibleNode()->getText();
186 std::string UiObject::getRole() const
188 return getAccessibleNode()->getRole();
191 void UiObject::setText(std::string text)
193 getAccessibleNode()->setValue(text);
196 bool UiObject::isCheckable() const
198 return getAccessibleNode()->isCheckable();
201 bool UiObject::isChecked() const
203 return getAccessibleNode()->isChecked();
206 bool UiObject::isClickable() const
208 return getAccessibleNode()->isClickable();
211 bool UiObject::isEnabled() const
213 return getAccessibleNode()->isEnabled();
216 bool UiObject::isFocusable() const
218 return getAccessibleNode()->isFocusable();
221 bool UiObject::isFocused() const
223 return getAccessibleNode()->isFocused();
226 bool UiObject::isLongClickable() const
228 return getAccessibleNode()->isLongClickable();
231 bool UiObject::isScrollable() const
233 return getAccessibleNode()->isScrollable();
236 bool UiObject::isSelectable() const
238 return getAccessibleNode()->isSelectable();
241 bool UiObject::isSelected() const
243 return getAccessibleNode()->isSelected();
246 bool UiObject::isVisible() const
248 return getAccessibleNode()->isVisible();
251 bool UiObject::isShowing() const
253 return getAccessibleNode()->isShowing();
256 bool UiObject::isActive() const
258 return getAccessibleNode()->isActive();
261 void UiObject::refresh() const
266 const Rect<int> UiObject::getBoundingBox() const
269 return mNode->getBoundingBox();
272 void UiObject::click() const
275 const Rect<int> rect = mNode->getBoundingBox();
276 const Point2D<int> midPoint = rect.midPoint();
277 mDevice->click(midPoint.x, midPoint.y);
280 void UiObject::longClick(const unsigned int intv) const
283 const Rect<int> rect = mNode->getBoundingBox();
284 const Point2D<int> midPoint = rect.midPoint();
285 mDevice->click(midPoint.x, midPoint.y, intv);
288 bool UiObject::DoAtspiActivate() const
290 return mNode->doAction("activate");
294 std::shared_ptr<AccessibleNode> UiObject::getAccessibleNode() const
296 if (mNode == nullptr) throw;
297 // TODO : wait for animation and refresh current node
298 // mDevice->waitForIdle();