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 return this->findObjects(Sel::depth(1));
138 std::shared_ptr<Node> UiObject::getDescendant()
140 std::vector<std::shared_ptr<Node>> nodeChildren{};
142 auto children = getChildren();
143 for (auto &&child : children) {
144 nodeChildren.push_back(child->getDescendant());
146 return std::make_shared<Node>(shared_from_this(), nodeChildren);
149 std::string UiObject::getApplicationPackage() const
151 return getAccessibleNode()->getPkg();
154 std::string UiObject::getId() const
156 return getAccessibleNode()->getId();
159 std::string UiObject::getAutomationId() const
161 return getAccessibleNode()->getAutomationId();
164 std::string UiObject::getElementType() const
166 return getAccessibleNode()->getType();
169 std::string UiObject::getElementStyle() const
171 return getAccessibleNode()->getStyle();
174 std::string UiObject::getText() const
176 return getAccessibleNode()->getText();
179 std::string UiObject::getRole() const
181 return getAccessibleNode()->getRole();
184 void UiObject::setText(std::string text)
186 getAccessibleNode()->setValue(text);
189 bool UiObject::isCheckable() const
191 return getAccessibleNode()->isCheckable();
194 bool UiObject::isChecked() const
196 return getAccessibleNode()->isChecked();
199 bool UiObject::isClickable() const
201 return getAccessibleNode()->isClickable();
204 bool UiObject::isEnabled() const
206 return getAccessibleNode()->isEnabled();
209 bool UiObject::isFocusable() const
211 return getAccessibleNode()->isFocusable();
214 bool UiObject::isFocused() const
216 return getAccessibleNode()->isFocused();
219 bool UiObject::isLongClickable() const
221 return getAccessibleNode()->isLongClickable();
224 bool UiObject::isScrollable() const
226 return getAccessibleNode()->isScrollable();
229 bool UiObject::isSelectable() const
231 return getAccessibleNode()->isSelectable();
234 bool UiObject::isSelected() const
236 return getAccessibleNode()->isSelected();
239 bool UiObject::isVisible() const
241 return getAccessibleNode()->isVisible();
244 bool UiObject::isShowing() const
246 return getAccessibleNode()->isShowing();
249 bool UiObject::isActive() const
251 return getAccessibleNode()->isActive();
254 void UiObject::refresh() const
259 const Rect<int> UiObject::getBoundingBox() const
262 return mNode->getBoundingBox();
265 void UiObject::click() const
267 LOG_SCOPE_F(INFO, "click on obj %p", this);
269 const Rect<int> rect = mNode->getBoundingBox();
270 const Point2D<int> midPoint = rect.midPoint();
271 mDevice->click(midPoint.x, midPoint.y);
274 void UiObject::longClick(const unsigned int intv) const
276 LOG_SCOPE_F(INFO, "click on obj %p", this);
278 const Rect<int> rect = mNode->getBoundingBox();
279 const Point2D<int> midPoint = rect.midPoint();
280 mDevice->click(midPoint.x, midPoint.y, intv);
283 bool UiObject::DoAtspiActivate() const
285 return mNode->doAction("activate");
289 std::shared_ptr<AccessibleNode> UiObject::getAccessibleNode() const
291 if (mNode == nullptr) throw;
292 // TODO : wait for animation and refresh current node
293 // mDevice->waitForIdle();