ea84cad9668056cb69eb6272acde137e2cf95840
[platform/core/uifw/aurum.git] / libaurum / inc / UiObject.h
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *  Licensed under the Apache License, Version 2.0 (the "License");
5  *  you may not use this file except in compliance with the License.
6  *  You may obtain a copy of the License at
7  *
8  *               http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License.
15  *
16  */
17
18 #ifndef _UI_OBJECT_H_
19 #define _UI_OBJECT_H_
20
21 #include "config.h"
22
23 #include "Accessible.h"
24 #include "ISearchable.h"
25 #include "UiSelector.h"
26 #include "Waiter.h"
27
28 #include <memory>
29 #include <vector>
30
31 namespace Aurum {
32
33 class UiDevice;
34
35 /**
36  * @brief This class keep object's descendant tree.
37  */
38 class Node : public std::enable_shared_from_this<Node> {
39 public:
40     Node(std::shared_ptr<UiObject> node, std::vector<std::shared_ptr<Node>> children)
41     :mNode{node}, mChildren{children}{}
42
43     std::shared_ptr<UiObject> mNode;
44     std::vector<std::shared_ptr<Node>> mChildren;
45 };
46
47 /**
48  * @class UiObject
49  *
50  * @ingroup aurum
51  *
52  * @brief A UiObject is a representation of a actual object in view.
53  *        As a class that abstracts the actual object, it has the information of the object
54  *        such as object's properties, states, geometry information.
55  *        also user can send and receive event via this class.
56  */
57 class UiObject : public ISearchable , public std::enable_shared_from_this<UiObject> {
58 public:
59     /**
60      * @brief UiObject constructor with device, selector, node pointer.
61      *
62      * @since_tizen 6.5
63      */
64     UiObject(const std::shared_ptr<UiDevice> device, const std::shared_ptr<UiSelector> selector,
65              const AccessibleNode *node);
66
67     /**
68      * @brief UiObject constructor with device, selector, node.
69      *
70      * @since_tizen 6.5
71      */
72     UiObject(const std::shared_ptr<UiDevice> device, const std::shared_ptr<UiSelector> selector,
73              std::shared_ptr<AccessibleNode> node);
74
75     /**
76      * @brief UiObject constructor with object source.
77      *
78      * @since_tizen 6.5
79      */
80     UiObject(UiObject &&src);
81
82     /**
83      * @brief UiObject constructor. (default constructor)
84      *
85      * @since_tizen 6.5
86      */
87     UiObject();
88
89     /**
90      * @brief UiObject destructor.
91      *
92      * @since_tizen 6.5
93      */
94     virtual ~UiObject();
95
96     /**
97      * @brief Gets selector.
98      *
99      * @return UiSelector pointer
100      *
101      * @since_tizen 6.5
102      */
103     std::shared_ptr<UiSelector> getSelector();
104
105     /**
106      * @brief Checks that there is object that satisfied with the selector condition in the object tree.
107      *
108      * @param[in] selector @UiSelector
109      *
110      * @return true if object exist, otherwise false
111      *
112      * @since_tizen 6.5
113      */
114     bool hasObject(const std::shared_ptr<UiSelector> selector) const override;
115
116     /**
117      * @brief Finds that object that satisfied with the selector condition in the object tree.
118      *
119      * @param[in] selector @UiSelector
120      *
121      * @return Found UiObject pointer
122      *
123      * @since_tizen 6.5
124      */
125     std::shared_ptr<UiObject> findObject(
126         const std::shared_ptr<UiSelector> selector) const override;
127
128     /**
129      * @brief Finds that objects that satisfied with the selector condition in the object tree.
130      *
131      * @param[in] selector @UiSelector
132      *
133      * @return the list of found UiObject pointer vector
134      *
135      * @since_tizen 6.5
136      */
137     std::vector<std::shared_ptr<UiObject>> findObjects(
138         const std::shared_ptr<UiSelector> selector) const override;
139
140     /**
141      * TODO
142      */
143     bool waitFor(
144         const std::function<bool(const ISearchable *)> condition) const;
145
146     /**
147      * TODO
148      */
149     std::shared_ptr<UiObject> waitFor(
150         const std::function<std::shared_ptr<UiObject>(const ISearchable *)>
151             condition) const;
152
153     /**
154      * TODO
155      */
156     bool waitFor(const std::function<bool(const UiObject *)> condition) const;
157
158 public:
159     /**
160      * @brief Gets object's parent.
161      *
162      * @return UiObject pointer
163      *
164      * @since_tizen 6.5
165      */
166     UiObject *getParent() const;
167
168     /**
169      * @brief Gets object's child count.
170      *
171      * @return number of child
172      *
173      * @since_tizen 6.5
174      */
175     int getChildCount() const;
176
177     /**
178      * @brief Gets object's children.
179      *
180      * @return UiObject pointer vector
181      *
182      * @since_tizen 6.5
183      */
184     std::vector<std::shared_ptr<UiObject>> getChildren() const;
185
186     /**
187      * @brief Gets object's child at specific index.
188      *
189      * @return UiObject pointer
190      *
191      * @since_tizen 6.5
192      */
193     std::shared_ptr<UiObject> getChildAt(int index) const;
194
195     /**
196      * @brief Gets object's Descendant tree .
197      *
198      * @return Node pointer vector
199      *
200      * @since_tizen 6.5
201      */
202     std::shared_ptr<Node> getDescendant();
203
204     /**
205      * @brief Gets object's package name.
206      *
207      * @return string
208      *
209      * @since_tizen 6.5
210      */
211     std::string getApplicationPackage() const;
212
213     /**
214      * @brief Gets object's Id.
215      *
216      * @return string
217      *
218      * @since_tizen 6.5
219      */
220     std::string getId() const;
221
222     /**
223      * @brief Gets object's automation Id.
224      *
225      * @return string
226      *
227      * @since_tizen 6.5
228      */
229     std::string getAutomationId() const;
230
231     /**
232      * @brief Gets object's type.
233      *
234      * @return string
235      *
236      * @since_tizen 6.5
237      */
238     std::string getElementType() const;
239
240     /**
241      * @brief Gets object's style.
242      *
243      * @return string
244      *
245      * @since_tizen 6.5
246      */
247     std::string getElementStyle() const;
248
249     /**
250      * @brief Gets object's text.
251      *
252      * @return string
253      *
254      * @since_tizen 6.5
255      */
256     std::string getText() const;
257
258     /**
259      * @brief Gets object's role.
260      *
261      * @return string
262      *
263      * @since_tizen 6.5
264      */
265     std::string getRole() const;
266
267     /**
268      * @brief Sets object's text.
269      *
270      * @param[in] text string
271      *
272      * @return true if success else false
273      *
274      * @since_tizen 6.5
275      */
276     bool setText(std::string text);
277
278     /**
279      * @brief Gets object's geometry of the screen.
280      *
281      * @return @Rect
282      *
283      * @since_tizen 6.5
284      */
285     const Rect<int> getScreenBoundingBox() const;
286
287     /**
288      * @brief Gets object's geometry of the window.
289      *
290      * @return @Rect
291      *
292      * @since_tizen 6.5
293      */
294     const Rect<int> getWindowBoundingBox() const;
295
296     /**
297      * @brief Gets object's checkable property.
298      *
299      * @return true if checkable else false
300      *
301      * @since_tizen 6.5
302      */
303     bool isCheckable() const;
304
305     /**
306      * @brief Gets object's checked property.
307      *
308      * @return true if checked else false
309      *
310      * @since_tizen 6.5
311      */
312     bool isChecked() const;
313
314     /**
315      * @brief Gets object's clickable property.
316      *
317      * @return true if clickable else false
318      *
319      * @since_tizen 6.5
320      */
321     bool isClickable() const;
322
323     /**
324      * @brief Gets object's enabled property. (to get object enabled. disabled state)
325      *
326      * @return true if enabled else false
327      *
328      * @since_tizen 6.5
329      */
330     bool isEnabled() const;
331
332     /**
333      * @brief Gets object's focusable property.
334      *
335      * @return true if focusable else false
336      *
337      * @since_tizen 6.5
338      */
339     bool isFocusable() const;
340
341     /**
342      * @brief Gets object's focused property.
343      *
344      * @return true if focused else false
345      *
346      * @since_tizen 6.5
347      */
348     bool isFocused() const;
349
350     /**
351      * @brief Gets object's longclickable property.
352      *
353      * @return true if longclickable else false
354      *
355      * @since_tizen 6.5
356      */
357     bool isLongClickable() const;
358
359     /**
360      * @brief Gets object's scrollable property.
361      *
362      * @return true if scrollable else false
363      *
364      * @since_tizen 6.5
365      */
366     bool isScrollable() const;
367
368     /**
369      * @brief Gets object's selectable property.
370      *
371      * @return true if selectable else false
372      *
373      * @since_tizen 6.5
374      */
375     bool isSelectable() const;
376
377     /**
378      * @brief Gets object's selected property.
379      *
380      * @return true if selected else false
381      *
382      * @since_tizen 6.5
383      */
384     bool isSelected() const;
385
386     /**
387      * @brief Gets object's visible property.
388      *
389      * @return true if visible else false
390      *
391      * @since_tizen 6.5
392      */
393     bool isVisible() const;
394
395     /**
396      * @brief Gets object's showing property.
397      *
398      * @return true if showing else false
399      *
400      * @since_tizen 6.5
401      */
402     bool isShowing() const;
403
404     /**
405      * @brief Gets object's active property.
406      *
407      * @return true if active else false
408      *
409      * @since_tizen 6.5
410      */
411     bool isActive() const;
412
413     /**
414      * @brief Performs a click action on object.
415      *
416      * @since_tizen 6.5
417      */
418     void click() const;
419
420     /**
421      * @brief Performs a long click action on object.
422      *
423      * @param[in] durationMs total time to maintain down action (default = 500ms)
424      *
425      * @since_tizen 6.5
426      */
427     void longClick(const unsigned int durationMs = LOGNCLICK_INTERVAL) const;
428
429     /**
430      * TODO
431      */
432     bool DoAtspiActivate() const;
433
434     /**
435      * @brief Updates object's role name information from atspi server.
436      *
437      * @since_tizen 6.5
438      */
439     void updateRoleName() const;
440
441     /**
442      * @brief Updates object's Id information from atspi server.
443      *
444      * @since_tizen 6.5
445      */
446     void updateUniqueId() const;
447
448     /**
449      * @brief Updates object's name information from atspi server.
450      *
451      * @since_tizen 6.5
452      */
453     void updateName() const;
454
455     /**
456      * @brief Updates object's application name information from atspi server.
457      *
458      * @since_tizen 6.5
459      */
460     void updateApplication() const;
461
462     /**
463      * @brief Updates object's attributes information from atspi server.
464      *
465      * @since_tizen 6.5
466      */
467     void updateAttributes() const;
468
469     /**
470      * @brief Updates object's states information from atspi server.
471      *
472      * @since_tizen 6.5
473      */
474     void updateStates() const;
475
476     /**
477      * @brief Updates object's geometry information from atspi server.
478      *
479      * @since_tizen 6.5
480      */
481     void updateExtents() const;
482
483     /**
484      * @brief Updates object's XPath information.
485      *
486      * @since_tizen 7.0
487      */
488     void updateXPath() const;
489
490     /**
491      * @brief Sets focus to object.
492      *
493      * @since_tizen 7.0
494      */
495     bool setFocus() const;
496
497     /**
498      * @brief Updates object's information from atspi server.
499      *
500      * @since_tizen 6.5
501      */
502     void refresh() const;
503
504     /**
505      * @brief Checks object is valid or not.
506      *
507      * @return true if valid else false
508      *
509      * @since_tizen 6.5
510      */
511     bool isValid() const;
512
513     /**
514      * @brief Gets object's AccessibleNode class
515      *
516      * @return AccessibleNode pointer
517      *
518      * @since_tizen 6.5
519      */
520     std::shared_ptr<AccessibleNode> getAccessibleNode() const;
521
522 private:
523     std::shared_ptr<UiDevice> mDevice;
524     std::shared_ptr<UiSelector>  mSelector;
525     std::shared_ptr<AccessibleNode> mNode;
526     const Waiter *mWaiter;
527     static const unsigned int LOGNCLICK_INTERVAL = 500;
528 };
529
530 }
531
532 #endif