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(const UiObject &src)
35 // : mDevice(src.mDevice),
36 // mSelector(src.mSelector),
38 // mWaiter{src.mWaiter},
39 // mNode_src(std::move(src.mNode_src))
44 UiObject::UiObject(UiObject &&src)
45 : mDevice(src.mDevice),
46 mSelector(std::move(src.mSelector)),
47 mNode(std::move(src.mNode)),
50 src.mDevice = nullptr;
51 src.mSelector = nullptr;
53 src.mWaiter = nullptr;
56 std::shared_ptr<UiSelector> UiObject::getSelector()
58 return this->mSelector;
61 bool UiObject::hasObject(const std::shared_ptr<UiSelector> selector) const
63 std::shared_ptr<AccessibleNode> node =
64 Comparer::findObject(mDevice, selector, getAccessibleNode());
65 if (node != nullptr) {
66 // todo : what is this node.recycle()
72 std::shared_ptr<UiObject> UiObject::findObject(const std::shared_ptr<UiSelector> selector) const
74 std::shared_ptr<AccessibleNode> node =
75 Comparer::findObject(mDevice, selector, getAccessibleNode());
77 return std::make_shared<UiObject>(mDevice, selector, std::move(node));
79 return std::shared_ptr<UiObject>{nullptr};
82 std::vector<std::shared_ptr<UiObject>> UiObject::findObjects(
83 const std::shared_ptr<UiSelector> selector) const
85 std::vector<std::shared_ptr<UiObject>> result{};
86 auto nodes = Comparer::findObjects(mDevice, selector, getAccessibleNode());
87 for ( auto& node : nodes) {
89 LOGI("Skipped! (node == nullptr)");
92 result.push_back(std::make_shared<UiObject>(mDevice, selector, std::move(node)));
97 bool UiObject::waitFor(
98 const std::function<bool(const ISearchable *)> condition) const
100 return mWaiter->waitFor(condition);
103 std::shared_ptr<UiObject> UiObject::waitFor(
104 const std::function<std::shared_ptr<UiObject>(const ISearchable *)>
107 return mWaiter->waitFor(condition);
110 bool UiObject::waitFor(
111 const std::function<bool(const UiObject *)> condition) const
113 return mWaiter->waitFor(condition);
116 UiObject *UiObject::getParent() const
118 std::shared_ptr<AccessibleNode> node = getAccessibleNode()->getParent();
119 if (!node) return nullptr;
120 return new UiObject(mDevice, mSelector, std::move(node));
123 int UiObject::getChildCount() const
125 return getAccessibleNode()->getChildCount();
128 std::shared_ptr<UiObject> UiObject::getChildAt(int index) const {
129 auto childNode = getAccessibleNode()->getChildAt(index);
131 return std::make_shared<UiObject>(mDevice, mSelector, childNode);
136 std::vector<std::shared_ptr<UiObject>> UiObject::getChildren() const
138 auto sel = Sel::depth(1);
139 return this->findObjects(sel);
142 std::shared_ptr<Node> UiObject::getDescendant()
144 std::vector<std::shared_ptr<Node>> nodeChildren{};
146 auto children = getChildren();
147 for (auto &&child : children) {
148 nodeChildren.push_back(child->getDescendant());
150 return std::make_shared<Node>(shared_from_this(), nodeChildren);
153 std::string UiObject::getApplicationPackage() const
155 return getAccessibleNode()->getPkg();
158 std::string UiObject::getId() const
160 return getAccessibleNode()->getId();
163 std::string UiObject::getAutomationId() const
165 return getAccessibleNode()->getAutomationId();
168 std::string UiObject::getElementType() const
170 return getAccessibleNode()->getType();
173 std::string UiObject::getElementStyle() const
175 return getAccessibleNode()->getStyle();
178 std::string UiObject::getText() const
180 return getAccessibleNode()->getText();
183 std::string UiObject::getRole() const
185 return getAccessibleNode()->getRole();
188 void UiObject::setText(std::string text)
190 getAccessibleNode()->setValue(text);
193 bool UiObject::isCheckable() const
195 return getAccessibleNode()->isCheckable();
198 bool UiObject::isChecked() const
200 return getAccessibleNode()->isChecked();
203 bool UiObject::isClickable() const
205 return getAccessibleNode()->isClickable();
208 bool UiObject::isEnabled() const
210 return getAccessibleNode()->isEnabled();
213 bool UiObject::isFocusable() const
215 return getAccessibleNode()->isFocusable();
218 bool UiObject::isFocused() const
220 return getAccessibleNode()->isFocused();
223 bool UiObject::isLongClickable() const
225 return getAccessibleNode()->isLongClickable();
228 bool UiObject::isScrollable() const
230 return getAccessibleNode()->isScrollable();
233 bool UiObject::isSelectable() const
235 return getAccessibleNode()->isSelectable();
238 bool UiObject::isSelected() const
240 return getAccessibleNode()->isSelected();
243 bool UiObject::isVisible() const
245 return getAccessibleNode()->isVisible();
248 bool UiObject::isShowing() const
250 return getAccessibleNode()->isShowing();
253 bool UiObject::isActive() const
255 return getAccessibleNode()->isActive();
258 void UiObject::refresh() const
263 bool UiObject::isValid() const
265 return mNode->isValid();
268 const Rect<int> UiObject::getBoundingBox() const
271 return mNode->getBoundingBox();
274 void UiObject::click() const
277 const Rect<int> rect = mNode->getBoundingBox();
278 const Point2D<int> midPoint = rect.midPoint();
279 mDevice->click(midPoint.x, midPoint.y);
282 void UiObject::longClick(const unsigned int intv) const
285 const Rect<int> rect = mNode->getBoundingBox();
286 const Point2D<int> midPoint = rect.midPoint();
287 mDevice->click(midPoint.x, midPoint.y, intv);
290 bool UiObject::DoAtspiActivate() const
292 return mNode->doAction("activate");
296 std::shared_ptr<AccessibleNode> UiObject::getAccessibleNode() const
298 if (mNode == nullptr) throw;
299 // TODO : wait for animation and refresh current node
300 // mDevice->waitForIdle();