a9eddc1257de896924fa7231b641d45d4dc1e11d
[platform/core/uifw/aurum.git] / libaurum / inc / AccessibleNode.h
1 #ifndef ACCESSIBLE_NODE_H
2 #define ACCESSIBLE_NODE_H
3 #include "config.h"
4
5 #include "AccessibleUtils.h"
6
7 #include <atspi/atspi.h>
8 #include <map>
9 #include <memory>
10 #include <string>
11 #include <vector>
12
13 enum class AccessibleNodeInterface {
14     ACTION = 0x0001,
15     COLLECTION = 0X0002,
16     COMPONENT = 0X0004,
17     DOCUMENT = 0X0008,
18
19     EDITABLETEXT = 0X0010,
20     HYPERTEXT = 0X0020,
21     IMAGE = 0X0040,
22     SELECTION = 0X0080,
23
24     TEXT = 0X0100,
25     VALUE = 0X0200,
26     ACCESSIBLE = 0X0400,
27     TABLE = 0X0800,
28
29     TABLECELL = 0X1000,
30 };
31
32 enum class NodeFeatureProperties {
33     CHECKABLE = 0x0001,
34     CHECKED = 0X0002,
35     CLICKABLE = 0X0004,
36     ENABLED = 0X0008,
37     FOCUSABLE = 0X0010,
38     FOCUSED = 0X0020,
39     LONGCLICKABLE = 0X0040,
40     SCROLLABLE = 0X0080,
41
42     SELECTABLE = 0X0100,
43     SELECTED = 0X0200,
44     VISIBILITY = 0X0400,
45 };
46
47 template <typename T>
48 class Point2D {
49 public:
50     Point2D() : x{0}, y{0} {}
51     Point2D(const Point2D &src)
52     {
53         x = src.x;
54         y = src.y;
55     }
56     Point2D(const T &x, const T &y)
57     {
58         this->x = x;
59         this->y = y;
60     }
61     T x;
62     T y;
63 };
64
65 template <typename T>
66 class Rect {
67 public:
68     Rect() : mTopLeft{0, 0}, mBottomRight{0, 0} {}
69     Rect(const Point2D<T> &tl, const Point2D<T> &br)
70         : mTopLeft(tl), mBottomRight(br)
71     {
72     }
73     Rect(const T &x1, const T &y1, const T &x2, const T &y2)
74         : mTopLeft{x1, y1}, mBottomRight{x2, y2}
75     {
76     }
77     Rect(const Rect<T> &src)
78
79     {
80         this->mTopLeft = Point2D<int>{src.mTopLeft};
81         this->mBottomRight = Point2D<int>{src.mBottomRight};
82     }
83     Point2D<T> midPoint() const
84     {
85         return Point2D<T>{mTopLeft.x + static_cast<T>(width() / 2),
86                           mTopLeft.y + static_cast<T>(height() / 2)};
87     }
88     T width() const { return mBottomRight.x - mTopLeft.x; }
89
90     T          height() const { return mBottomRight.y - mTopLeft.y; }
91     Point2D<T> mTopLeft;
92     Point2D<T> mBottomRight;
93 };
94
95 class AccessibleNode {
96 public:
97     AccessibleNode();
98     AccessibleNode(AtspiAccessible *node);
99     ~AccessibleNode();
100     static std::unique_ptr<AccessibleNode> get(AtspiAccessible *node);
101
102 public:
103     int              getChildCount() const;
104     std::unique_ptr<AccessibleNode> getChildAt(int index) const;
105     std::unique_ptr<AccessibleNode> getParent() const;
106     AtspiAccessible *getAccessible() const;
107
108 public:
109     std::string getDesc() const;
110     std::string getText() const;
111     std::string getPkg() const;
112     std::string getRes() const;
113     std::string getType() const;
114     std::string getStyle() const;
115     Rect<int>   getBoundingBox() const;
116
117     bool isCheckable() const;
118     bool isChecked() const;
119     bool isClickable() const;
120     bool isEnabled() const;
121     bool isFocusable() const;
122     bool isFocused() const;
123     bool isLongClickable() const;
124     bool isScrollable() const;
125     bool isSelectable() const;
126     bool isSelected() const;
127     bool isVisible() const;
128
129 public:
130     void print(int) const;
131     void print(int, int) const;
132     void refresh() const;
133
134     void setValue(std::string &text) const;
135
136 private:
137     bool isSupporting(AccessibleNodeInterface thisIface) const;
138     bool hasFeatureProperty(NodeFeatureProperties prop) const;
139     void setFeatureProperty(NodeFeatureProperties prop, bool has);
140     static std::map<AtspiAccessible *, AccessibleNode *> mNodeMap;
141
142 private:
143     unique_ptr_gobj<AtspiAccessible> mNode;
144
145     mutable std::string mText;
146     mutable std::string mPkg;
147     mutable std::string mRole;
148     mutable std::string mDesc;
149     mutable std::string mRes;
150     mutable std::string mType;
151     mutable std::string mStyle;
152
153     mutable Rect<int> mBoundingBox;
154
155     int  mSupportingIfaces;
156     int  mFeatureProperty;
157     bool mIsAlive;
158 };
159
160 #endif