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 LOG_SCOPE_F(INFO, "findObjects");
89 std::vector<std::shared_ptr<UiObject>> result{};
90 auto nodes = Comparer::findObjects(mDevice, selector, getAccessibleNode());
91 LOG_SCOPE_F(INFO, "size : %d", nodes.size());
92 for ( auto& node : nodes) {
94 LOG_F(INFO, "skipped(node == nullptr)");
97 result.push_back(std::make_shared<UiObject>(mDevice, selector, std::move(node)));
102 bool UiObject::waitFor(
103 const std::function<bool(const ISearchable *)> condition) const
105 return mWaiter->waitFor(condition);
108 std::shared_ptr<UiObject> UiObject::waitFor(
109 const std::function<std::shared_ptr<UiObject>(const ISearchable *)>
112 return mWaiter->waitFor(condition);
115 bool UiObject::waitFor(
116 const std::function<bool(const UiObject *)> condition) const
118 return mWaiter->waitFor(condition);
121 UiObject *UiObject::getParent() const
123 std::shared_ptr<AccessibleNode> node = getAccessibleNode()->getParent();
124 if (!node) return nullptr;
125 return new UiObject(mDevice, mSelector, std::move(node));
128 int UiObject::getChildCount() const
130 return getAccessibleNode()->getChildCount();
133 std::vector<std::shared_ptr<UiObject>> UiObject::getChildren() const
135 auto sel = std::make_shared<UiSelector>();
137 sel->isShowing(true);
138 return this->findObjects(sel);
141 std::string UiObject::getApplicationPackage() const
143 return getAccessibleNode()->getPkg();
146 std::string UiObject::getResourceName() const
148 return getAccessibleNode()->getRes();
151 std::string UiObject::getElementType() const
153 return getAccessibleNode()->getType();
156 std::string UiObject::getElementStyle() const
158 return getAccessibleNode()->getStyle();
161 std::string UiObject::getText() const
163 return getAccessibleNode()->getText();
166 std::string UiObject::getRole() const
168 return getAccessibleNode()->getRole();
171 void UiObject::setText(std::string text)
173 getAccessibleNode()->setValue(text);
176 bool UiObject::isCheckable() const
178 return getAccessibleNode()->isCheckable();
181 bool UiObject::isChecked() const
183 return getAccessibleNode()->isChecked();
186 bool UiObject::isClickable() const
188 return getAccessibleNode()->isClickable();
191 bool UiObject::isEnabled() const
193 return getAccessibleNode()->isEnabled();
196 bool UiObject::isFocusable() const
198 return getAccessibleNode()->isFocusable();
201 bool UiObject::isFocused() const
203 return getAccessibleNode()->isFocused();
206 bool UiObject::isLongClickable() const
208 return getAccessibleNode()->isLongClickable();
211 bool UiObject::isScrollable() const
213 return getAccessibleNode()->isScrollable();
216 bool UiObject::isSelectable() const
218 return getAccessibleNode()->isSelectable();
221 bool UiObject::isSelected() const
223 return getAccessibleNode()->isSelected();
226 bool UiObject::isVisible() const
228 return getAccessibleNode()->isVisible();
231 bool UiObject::isShowing() const
233 return getAccessibleNode()->isShowing();
236 bool UiObject::isActive() const
238 return getAccessibleNode()->isActive();
241 void UiObject::refresh() const
246 const Rect<int> UiObject::getBoundingBox() const
249 return mNode->getBoundingBox();
252 void UiObject::click() const
254 LOG_SCOPE_F(INFO, "click on obj %p", this);
256 const Rect<int> rect = mNode->getBoundingBox();
257 const Point2D<int> midPoint = rect.midPoint();
258 mDevice->click(midPoint.x, midPoint.y);
261 void UiObject::longClick(const unsigned int intv) const
263 LOG_SCOPE_F(INFO, "click on obj %p", this);
265 const Rect<int> rect = mNode->getBoundingBox();
266 const Point2D<int> midPoint = rect.midPoint();
267 mDevice->click(midPoint.x, midPoint.y, intv);
270 bool UiObject::DoAtspiActivate() const
272 return mNode->doAction("activate");
276 std::shared_ptr<AccessibleNode> UiObject::getAccessibleNode() const
278 if (mNode == nullptr) throw;
279 // TODO : wait for animation and refresh current node
280 // mDevice->waitForIdle();