0c47a2e66189e28f3eecc3cbffb801020f0ebfdf
[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     /**
188      * @copydoc UiObject::getScreenBoundingBox()
189      */
190     Rect<int> getScreenBoundingBox() const;
191
192     /**
193      * @copydoc UiObject::getWindowBoundingBox()
194      */
195     Rect<int> getWindowBoundingBox() const;
196
197     /**
198      * @copydoc UiObject::isCheckable()
199      */
200     bool isCheckable() const;
201
202     /**
203      * @copydoc UiObject::isChecked()
204      */
205     bool isChecked() const;
206
207     /**
208      * @copydoc UiObject::isClickable()
209      */
210     bool isClickable() const;
211
212     /**
213      * @copydoc UiObject::isEnabled()
214      */
215     bool isEnabled() const;
216
217     /**
218      * @copydoc UiObject::isFocusable()
219      */
220     bool isFocusable() const;
221
222     /**
223      * @copydoc UiObject::isFocused()
224      */
225     bool isFocused() const;
226
227     /**
228      * @copydoc UiObject::isLongClickable()
229      */
230     bool isLongClickable() const;
231
232     /**
233      * @copydoc UiObject::isScrollable()
234      */
235     bool isScrollable() const;
236
237     /**
238      * @copydoc UiObject::isSelectable()
239      */
240     bool isSelectable() const;
241
242     /**
243      * @copydoc UiObject::isSelected()
244      */
245     bool isSelected() const;
246
247     /**
248      * @copydoc UiObject::isVisible()
249      */
250     bool isVisible() const;
251
252     /**
253      * @copydoc UiObject::isShowing()
254      */
255     bool isShowing() const;
256
257     /**
258      * @copydoc UiObject::isActive()
259      */
260     bool isActive() const;
261
262 public:
263     /**
264      * @brief Print Node information.
265      *
266      * @param[in] int depth
267      *
268      * @since_tizen 6.5
269      */
270     void print(int);
271
272     /**
273      * @brief Print Node information.
274      *
275      * @param[in] int depth
276      * @param[in] int maxdepth
277      *
278      * @since_tizen 6.5
279      */
280     void print(int, int);
281
282     /**
283      * @brief Gets matched Atspi node ptr.
284      *
285      * @return Atspi node ptr
286      *
287      * @since_tizen 6.5
288      */
289     virtual void* getRawHandler(void) const = 0;
290
291     /**
292      * @copydoc UiObject::updateRoleName()
293      */
294     virtual void updateRoleName() = 0;
295
296     /**
297      * @copydoc UiObject::updateUniqueId()
298      */
299     virtual void updateUniqueId() = 0;
300
301     /**
302      * @copydoc UiObject::updateName()
303      */
304     virtual void updateName() = 0;
305
306     /**
307      * @copydoc UiObject::updateApplication()
308      */
309     virtual void updateApplication() = 0;
310
311     /**
312      * @copydoc UiObject::updateAttributes()
313      */
314     virtual void updateAttributes() = 0;
315
316     /**
317      * @copydoc UiObject::updateStates()
318      */
319     virtual void updateStates() = 0;
320
321     /**
322      * @copydoc UiObject::updateExtents()
323      */
324     virtual void updateExtents() = 0;
325
326     /**
327      * @copydoc UiObject::updateXPath()
328      */
329     virtual void updateXPath() = 0;
330
331     /**
332      * @copydoc UiObject::setFocus()
333      */
334     virtual bool setFocus() = 0;
335
336     /**
337      * @brief Updates Node information from atspi server.
338      *
339      * @since_tizen 6.5
340      */
341     virtual void refresh(bool updateAll = true) = 0;
342
343     /**
344      * @brief Gets available atspi action name.
345      *
346      * @return string vector
347      *
348      * @since_tizen 6.5
349      */
350     virtual std::vector<std::string> getActions() const = 0;
351
352     /**
353      * @brief Do atspi action.
354      *
355      * @param[in] action name of action
356      *
357      * @return true if success, else false
358      *
359      * @since_tizen 6.5
360      */
361     virtual bool doAction(std::string action) = 0;
362
363     /**
364      * @brief Sets Node's value.
365      *
366      * @param[in] text string
367          *
368          * @return true if success, else false
369      *
370      * @since_tizen 6.5
371      */
372     virtual bool setValue(std::string text) = 0;
373
374     /**
375      * @brief Check object valid or not.
376      *
377      * @return true if valid, else false
378      *
379      * @since_tizen 6.5
380      */
381     virtual bool isValid() const;
382
383 public:
384     /**
385      * @brief Check Node support given interface or not.
386      *
387      * @param[in] thisIface @AccessibleNodeInterface
388      *
389      * @return true if supporting, else false
390      *
391      * @since_tizen 6.5
392      */
393     bool isSupporting(AccessibleNodeInterface thisIface) const;
394
395     /**
396      * @brief Check Node has given property or not.
397      *
398      * @param[in] prop @NodeFeatureProperties
399      *
400      * @return true if has, else false
401      *
402      * @since_tizen 6.5
403      */
404     bool hasFeatureProperty(NodeFeatureProperties prop) const;
405
406     /**
407      * @brief Sets Node's property.
408      *
409      * @param[in] prop @NodeFeatureProperties
410      * @param[in] has Node has given property ot not
411      *
412      * @since_tizen 6.5
413      */
414     void setFeatureProperty(NodeFeatureProperties prop, bool has);
415
416     /**
417      * @brief Resets all the property value on Node.
418      *
419      * @since_tizen 6.5
420      */
421     void resetFeatureProperty();
422
423 protected:
424     std::string mText;
425     std::string mPkg;
426     std::string mRole;
427     std::string mId;
428     std::string mAutomationId;
429     std::string mType;
430     std::string mStyle;
431     std::string mXPath;
432     Rect<int> mScreenBoundingBox;
433     Rect<int> mWindowBoundingBox;
434     int mSupportingIfaces;
435     int mFeatureProperty;
436
437 private:
438     bool mValid;
439     mutable std::mutex mLock;
440 };
441
442 }
443
444 #endif