bootstrap/aurum: rework GetAttributeCommand
[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     VISIBLE = 0X0400,
45     SHOWING = 0X0800,
46     ACTIVE = 0X0800,
47 };
48
49 template <typename T>
50 class Point2D {
51 public:
52     Point2D() : x{0}, y{0} {}
53     Point2D(const Point2D &src)
54     {
55         x = src.x;
56         y = src.y;
57     }
58     Point2D(const T &x, const T &y)
59     {
60         this->x = x;
61         this->y = y;
62     }
63     T x;
64     T y;
65 };
66
67 template <typename T>
68 class Rect {
69 public:
70     Rect() : mTopLeft{0, 0}, mBottomRight{0, 0} {}
71     Rect(const Point2D<T> &tl, const Point2D<T> &br)
72         : mTopLeft(tl), mBottomRight(br)
73     {
74     }
75     Rect(const T &x1, const T &y1, const T &x2, const T &y2)
76         : mTopLeft{x1, y1}, mBottomRight{x2, y2}
77     {
78     }
79     Rect(const Rect<T> &src)
80
81     {
82         this->mTopLeft = Point2D<int>{src.mTopLeft};
83         this->mBottomRight = Point2D<int>{src.mBottomRight};
84     }
85     Point2D<T> midPoint() const
86     {
87         return Point2D<T>{mTopLeft.x + static_cast<T>(width() / 2),
88                           mTopLeft.y + static_cast<T>(height() / 2)};
89     }
90     T width() const { return mBottomRight.x - mTopLeft.x; }
91
92     T          height() const { return mBottomRight.y - mTopLeft.y; }
93     Point2D<T> mTopLeft;
94     Point2D<T> mBottomRight;
95 };
96
97 class AccessibleNode {
98 public:
99     AccessibleNode();
100     AccessibleNode(AtspiAccessible *node);
101     ~AccessibleNode();
102     static std::unique_ptr<AccessibleNode> get(AtspiAccessible *node);
103
104 public:
105     int              getChildCount() const;
106     std::unique_ptr<AccessibleNode> getChildAt(int index) const;
107     std::unique_ptr<AccessibleNode> getParent() const;
108     AtspiAccessible *getAccessible() const;
109
110 public:
111     std::string getDesc() const;
112     std::string getText() const;
113     std::string getPkg() const;
114     std::string getRes() const;
115     std::string getType() const;
116     std::string getStyle() const;
117     Rect<int>   getBoundingBox() const;
118
119     bool isCheckable() const;
120     bool isChecked() const;
121     bool isClickable() const;
122     bool isEnabled() const;
123     bool isFocusable() const;
124     bool isFocused() const;
125     bool isLongClickable() const;
126     bool isScrollable() const;
127     bool isSelectable() const;
128     bool isSelected() const;
129     bool isVisible() const;
130
131 public:
132     void print(int) const;
133     void print(int, int) const;
134     void refresh() const;
135
136     void setValue(std::string &text) const;
137
138 private:
139     bool isSupporting(AccessibleNodeInterface thisIface) const;
140     bool hasFeatureProperty(NodeFeatureProperties prop) const;
141     void setFeatureProperty(NodeFeatureProperties prop, bool has) const;
142     void setFeatureProperty(AtspiStateType type) const;
143     static std::map<AtspiAccessible *, AccessibleNode *> mNodeMap;
144
145 private:
146     unique_ptr_gobj<AtspiAccessible> mNode;
147
148     mutable std::string mText;
149     mutable std::string mPkg;
150     mutable std::string mRole;
151     mutable std::string mDesc;
152     mutable std::string mRes;
153     mutable std::string mType;
154     mutable std::string mStyle;
155
156     mutable Rect<int> mBoundingBox;
157
158     int  mSupportingIfaces;
159     mutable int  mFeatureProperty;
160     bool mIsAlive;
161 };
162
163 #endif