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::shared_ptr<UiObject> UiObject::getChildAt(int index) const {
134 auto childNode = getAccessibleNode()->getChildAt(index);
136 return std::make_shared<UiObject>(mDevice, mSelector, childNode);
141 std::vector<std::shared_ptr<UiObject>> UiObject::getChildren() const
143 return this->findObjects(Sel::depth(1));
146 std::shared_ptr<Node> UiObject::getDescendant()
148 std::vector<std::shared_ptr<Node>> nodeChildren{};
150 auto children = getChildren();
151 for (auto &&child : children) {
152 nodeChildren.push_back(child->getDescendant());
154 return std::make_shared<Node>(shared_from_this(), nodeChildren);
157 std::string UiObject::getApplicationPackage() const
159 return getAccessibleNode()->getPkg();
162 std::string UiObject::getId() const
164 return getAccessibleNode()->getId();
167 std::string UiObject::getAutomationId() const
169 return getAccessibleNode()->getAutomationId();
172 std::string UiObject::getElementType() const
174 return getAccessibleNode()->getType();
177 std::string UiObject::getElementStyle() const
179 return getAccessibleNode()->getStyle();
182 std::string UiObject::getText() const
184 return getAccessibleNode()->getText();
187 std::string UiObject::getRole() const
189 return getAccessibleNode()->getRole();
192 void UiObject::setText(std::string text)
194 getAccessibleNode()->setValue(text);
197 bool UiObject::isCheckable() const
199 return getAccessibleNode()->isCheckable();
202 bool UiObject::isChecked() const
204 return getAccessibleNode()->isChecked();
207 bool UiObject::isClickable() const
209 return getAccessibleNode()->isClickable();
212 bool UiObject::isEnabled() const
214 return getAccessibleNode()->isEnabled();
217 bool UiObject::isFocusable() const
219 return getAccessibleNode()->isFocusable();
222 bool UiObject::isFocused() const
224 return getAccessibleNode()->isFocused();
227 bool UiObject::isLongClickable() const
229 return getAccessibleNode()->isLongClickable();
232 bool UiObject::isScrollable() const
234 return getAccessibleNode()->isScrollable();
237 bool UiObject::isSelectable() const
239 return getAccessibleNode()->isSelectable();
242 bool UiObject::isSelected() const
244 return getAccessibleNode()->isSelected();
247 bool UiObject::isVisible() const
249 return getAccessibleNode()->isVisible();
252 bool UiObject::isShowing() const
254 return getAccessibleNode()->isShowing();
257 bool UiObject::isActive() const
259 return getAccessibleNode()->isActive();
262 void UiObject::refresh() const
267 const Rect<int> UiObject::getBoundingBox() const
270 return mNode->getBoundingBox();
273 void UiObject::click() const
275 LOG_SCOPE_F(INFO, "click on obj %p", this);
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
284 LOG_SCOPE_F(INFO, "click on obj %p", this);
286 const Rect<int> rect = mNode->getBoundingBox();
287 const Point2D<int> midPoint = rect.midPoint();
288 mDevice->click(midPoint.x, midPoint.y, intv);
291 bool UiObject::DoAtspiActivate() const
293 return mNode->doAction("activate");
297 std::shared_ptr<AccessibleNode> UiObject::getAccessibleNode() const
299 if (mNode == nullptr) throw;
300 // TODO : wait for animation and refresh current node
301 // mDevice->waitForIdle();