aurum: add getXPath method
[platform/core/uifw/aurum.git] / libaurum / inc / Accessibility / AccessibleNode.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 _ACCESSIBLE_NODE_H_
19 #define _ACCESSIBLE_NODE_H_
20
21 #include <map>
22 #include <memory>
23 #include <string>
24 #include <vector>
25 #include <mutex>
26
27 #include "IEventConsumer.h"
28 #include "Rect.h"
29 #include "config.h"
30
31 namespace Aurum {
32
33 /**
34  * @brief AccessibleNodeInterface enum class
35  *
36  * @since_tizen 6.5
37  */
38 enum class AccessibleNodeInterface {
39     ACTION          = 0x0001,
40     COLLECTION      = 0X0002,
41     COMPONENT       = 0X0004,
42     DOCUMENT        = 0X0008,
43
44     EDITABLETEXT    = 0X0010,
45     HYPERTEXT       = 0X0020,
46     IMAGE           = 0X0040,
47     SELECTION       = 0X0080,
48
49     TEXT            = 0X0100,
50     VALUE           = 0X0200,
51     ACCESSIBLE      = 0X0400,
52     TABLE           = 0X0800,
53
54     TABLECELL       = 0X1000,
55 };
56
57 /**
58  * @brief NodeFeatureProperties enum class
59  *
60  * @since_tizen 6.5
61  */
62 enum class NodeFeatureProperties {
63     CHECKABLE       = 0x0001,
64     CHECKED         = 0X0002,
65     CLICKABLE       = 0X0004,
66     ENABLED         = 0X0008,
67
68     FOCUSABLE       = 0X0010,
69     FOCUSED         = 0X0020,
70     LONGCLICKABLE   = 0X0040,
71     SCROLLABLE      = 0X0080,
72
73     SELECTABLE      = 0X0100,
74     SELECTED        = 0X0200,
75     VISIBLE         = 0X0400,
76     SHOWING         = 0X0800,
77     ACTIVE          = 0X1000,
78     INVALID         = 0X2000,
79 };
80
81 /**
82  * @brief AccessibleNode Class that provides the abstracted object information to uses.
83  *
84  * @since_tizen 6.5
85  */
86 class AccessibleNode : public std::enable_shared_from_this<AccessibleNode>, public IEventConsumer  {
87 public:
88     /**
89      * @brief AccessibleNode constructor.
90      *
91      * @since_tizen 6.5
92      */
93     AccessibleNode();
94
95     /**
96      * @brief AccessibleNode desctructor.
97      *
98      * @since_tizen 6.5
99      */
100     virtual ~AccessibleNode();
101
102     /**
103      * @brief Gets Node information as string.
104      *
105      * @return string
106      *
107      * @since_tizen 6.5
108      */
109     std::string description();
110
111 public:
112     /**
113      * @copydoc UiObject::getChildCount()
114      */
115     virtual int getChildCount() const = 0;
116
117     /**
118      * @copydoc UiObject::getChildAt()
119      */
120     virtual std::shared_ptr<AccessibleNode> getChildAt(int index) const = 0;
121
122     /**
123      * @copydoc UiObject::getChildren()
124      */
125     virtual std::vector<std::shared_ptr<AccessibleNode>> getChildren() const = 0;
126
127     /**
128      * @copydoc UiObject::getParent()
129      */
130     virtual std::shared_ptr<AccessibleNode> getParent() const = 0;
131
132     /**
133      * @brief Called by @AccessibleWatcher::notifyAll.
134      *        Changes Node property If it's @EventType, @ObjectEventType are matches.
135      *
136      * @param[in] type @EventType
137      * @param[in] type2 @ObjectEventType
138      * @param[in] src Atspi Node ptr
139      *
140      * @since_tizen 6.5
141      */
142     void notify(int type, int type2, void *src) override;
143
144     /**
145      * @brief Changes Node state to invalidate.
146      *
147      * @since_tizen 6.5
148      */
149     void invalidate();
150
151 public:
152     /**
153      * @copydoc UiObject::getText()
154      */
155     std::string getText() const;
156
157     /**
158      * @copydoc UiObject::getPkg()
159      */
160     std::string getPkg() const;
161
162     /**
163      * @copydoc UiObject::getId()
164      */
165     std::string getId() const;
166
167     /**
168      * @copydoc UiObject::getAutomationId()
169      */
170     std::string getAutomationId() const;
171
172     /**
173      * @copydoc UiObject::getRole()
174      */
175     std::string getRole() const;
176
177     /**
178      * @copydoc UiObject::getType()
179      */
180     std::string getType() const;
181
182     /**
183      * @copydoc UiObject::getStyle()
184      */
185     std::string getStyle() const;
186     /**
187      * @copydoc UiObject::getXPath()
188      */
189     std::string getXPath() const;
190
191     /**
192      * @copydoc UiObject::getScreenBoundingBox()
193      */
194     Rect<int> getScreenBoundingBox() const;
195
196     /**
197      * @copydoc UiObject::getWindowBoundingBox()
198      */
199     Rect<int> getWindowBoundingBox() const;
200
201     /**
202      * @copydoc UiObject::isCheckable()
203      */
204     bool isCheckable() const;
205
206     /**
207      * @copydoc UiObject::isChecked()
208      */
209     bool isChecked() const;
210
211     /**
212      * @copydoc UiObject::isClickable()
213      */
214     bool isClickable() const;
215
216     /**
217      * @copydoc UiObject::isEnabled()
218      */
219     bool isEnabled() const;
220
221     /**
222      * @copydoc UiObject::isFocusable()
223      */
224     bool isFocusable() const;
225
226     /**
227      * @copydoc UiObject::isFocused()
228      */
229     bool isFocused() const;
230
231     /**
232      * @copydoc UiObject::isLongClickable()
233      */
234     bool isLongClickable() const;
235
236     /**
237      * @copydoc UiObject::isScrollable()
238      */
239     bool isScrollable() const;
240
241     /**
242      * @copydoc UiObject::isSelectable()
243      */
244     bool isSelectable() const;
245
246     /**
247      * @copydoc UiObject::isSelected()
248      */
249     bool isSelected() const;
250
251     /**
252      * @copydoc UiObject::isVisible()
253      */
254     bool isVisible() const;
255
256     /**
257      * @copydoc UiObject::isShowing()
258      */
259     bool isShowing() const;
260
261     /**
262      * @copydoc UiObject::isActive()
263      */
264     bool isActive() const;
265
266 public:
267     /**
268      * @brief Print Node information.
269      *
270      * @param[in] int depth
271      *
272      * @since_tizen 6.5
273      */
274     void print(int);
275
276     /**
277      * @brief Print Node information.
278      *
279      * @param[in] int depth
280      * @param[in] int maxdepth
281      *
282      * @since_tizen 6.5
283      */
284     void print(int, int);
285
286     /**
287      * @brief Gets matched Atspi node ptr.
288      *
289      * @return Atspi node ptr
290      *
291      * @since_tizen 6.5
292      */
293     virtual void* getRawHandler(void) const = 0;
294
295     /**
296      * @copydoc UiObject::updateRoleName()
297      */
298     virtual void updateRoleName() = 0;
299
300     /**
301      * @copydoc UiObject::updateUniqueId()
302      */
303     virtual void updateUniqueId() = 0;
304
305     /**
306      * @copydoc UiObject::updateName()
307      */
308     virtual void updateName() = 0;
309
310     /**
311      * @copydoc UiObject::updateApplication()
312      */
313     virtual void updateApplication() = 0;
314
315     /**
316      * @copydoc UiObject::updateAttributes()
317      */
318     virtual void updateAttributes() = 0;
319
320     /**
321      * @copydoc UiObject::updateStates()
322      */
323     virtual void updateStates() = 0;
324
325     /**
326      * @copydoc UiObject::updateExtents()
327      */
328     virtual void updateExtents() = 0;
329
330     /**
331      * @copydoc UiObject::updateXPath()
332      */
333     virtual void updateXPath() = 0;
334
335     /**
336      * @copydoc UiObject::setFocus()
337      */
338     virtual bool setFocus() = 0;
339
340     /**
341      * @brief Updates Node information from atspi server.
342      *
343      * @since_tizen 6.5
344      */
345     virtual void refresh(bool updateAll = true) = 0;
346
347     /**
348      * @brief Gets available atspi action name.
349      *
350      * @return string vector
351      *
352      * @since_tizen 6.5
353      */
354     virtual std::vector<std::string> getActions() const = 0;
355
356     /**
357      * @brief Do atspi action.
358      *
359      * @param[in] action name of action
360      *
361      * @return true if success, else false
362      *
363      * @since_tizen 6.5
364      */
365     virtual bool doAction(std::string action) = 0;
366
367     /**
368      * @brief Sets Node's value.
369      *
370      * @param[in] text string
371          *
372          * @return true if success, else false
373      *
374      * @since_tizen 6.5
375      */
376     virtual bool setValue(std::string text) = 0;
377
378     /**
379      * @brief Check object valid or not.
380      *
381      * @return true if valid, else false
382      *
383      * @since_tizen 6.5
384      */
385     virtual bool isValid() const;
386
387 public:
388     /**
389      * @brief Check Node support given interface or not.
390      *
391      * @param[in] thisIface @AccessibleNodeInterface
392      *
393      * @return true if supporting, else false
394      *
395      * @since_tizen 6.5
396      */
397     bool isSupporting(AccessibleNodeInterface thisIface) const;
398
399     /**
400      * @brief Check Node has given property or not.
401      *
402      * @param[in] prop @NodeFeatureProperties
403      *
404      * @return true if has, else false
405      *
406      * @since_tizen 6.5
407      */
408     bool hasFeatureProperty(NodeFeatureProperties prop) const;
409
410     /**
411      * @brief Sets Node's property.
412      *
413      * @param[in] prop @NodeFeatureProperties
414      * @param[in] has Node has given property ot not
415      *
416      * @since_tizen 6.5
417      */
418     void setFeatureProperty(NodeFeatureProperties prop, bool has);
419
420     /**
421      * @brief Resets all the property value on Node.
422      *
423      * @since_tizen 6.5
424      */
425     void resetFeatureProperty();
426
427 protected:
428     std::string mText;
429     std::string mPkg;
430     std::string mRole;
431     std::string mId;
432     std::string mAutomationId;
433     std::string mType;
434     std::string mStyle;
435     std::string mXPath;
436     Rect<int> mScreenBoundingBox;
437     Rect<int> mWindowBoundingBox;
438     int mSupportingIfaces;
439     int mFeatureProperty;
440
441 private:
442     bool mValid;
443     mutable std::mutex mLock;
444 };
445
446 }
447
448 #endif