Aurum  0.1.1
 All Classes Functions Variables Pages
AccessibleNode.h
1 #ifndef ACCESSIBLE_NODE_H
2 #define ACCESSIBLE_NODE_H
3 #include <atspi/atspi.h>
4 
5 #include <map>
6 #include <memory>
7 #include <string>
8 #include <vector>
9 
10 #include "AccessibleUtils.h"
11 #include "config.h"
12 
17 enum class AccessibleNodeInterface {
18  ACTION = 0x0001,
19  COLLECTION = 0X0002,
20  COMPONENT = 0X0004,
21  DOCUMENT = 0X0008,
22 
23  EDITABLETEXT = 0X0010,
24  HYPERTEXT = 0X0020,
25  IMAGE = 0X0040,
26  SELECTION = 0X0080,
27 
28  TEXT = 0X0100,
29  VALUE = 0X0200,
30  ACCESSIBLE = 0X0400,
31  TABLE = 0X0800,
32 
33  TABLECELL = 0X1000,
34 };
35 
40 enum class NodeFeatureProperties {
41  CHECKABLE = 0x0001,
42  CHECKED = 0X0002,
43  CLICKABLE = 0X0004,
44  ENABLED = 0X0008,
45  FOCUSABLE = 0X0010,
46  FOCUSED = 0X0020,
47  LONGCLICKABLE = 0X0040,
48  SCROLLABLE = 0X0080,
49 
50  SELECTABLE = 0X0100,
51  SELECTED = 0X0200,
52  VISIBLE = 0X0400,
53  SHOWING = 0X0800,
54  ACTIVE = 0X0800,
55 };
56 
61 template <typename T>
62 class Point2D {
63 public:
68  Point2D() : x{0}, y{0} {}
69 
74  Point2D(const Point2D &src)
75  {
76  x = src.x;
77  y = src.y;
78  }
79 
84  Point2D(const T &x, const T &y)
85  {
86  this->x = x;
87  this->y = y;
88  }
89 
93  T x;
94 
98  T y;
99 };
100 
105 template <typename T>
106 class Rect {
107 public:
112  Rect() : mTopLeft{0, 0}, mBottomRight{0, 0} {}
113 
118  Rect(const Point2D<T> &tl, const Point2D<T> &br)
119  : mTopLeft(tl), mBottomRight(br)
120  {
121  }
122 
127  Rect(const T &x1, const T &y1, const T &x2, const T &y2)
128  : mTopLeft{x1, y1}, mBottomRight{x2, y2}
129  {
130  }
131 
136  Rect(const Rect<T> &src)
137 
138  {
139  this->mTopLeft = Point2D<int>{src.mTopLeft};
140  this->mBottomRight = Point2D<int>{src.mBottomRight};
141  }
142 
147  Point2D<T> midPoint() const
148  {
149  return Point2D<T>{mTopLeft.x + static_cast<T>(width() / 2),
150  mTopLeft.y + static_cast<T>(height() / 2)};
151  }
152 
157  T width() const { return mBottomRight.x - mTopLeft.x; }
158 
163  T height() const { return mBottomRight.y - mTopLeft.y; }
164 
168  Point2D<T> mTopLeft;
169 
174 };
175 
181 public: // Constructor & Destructor
186  AccessibleNode();
187 
192  AccessibleNode(AtspiAccessible *node);
193 
198  ~AccessibleNode();
199 
204  static std::unique_ptr<AccessibleNode> get(AtspiAccessible *node);
205 
206 public:
211  int getChildCount() const;
212 
217  std::unique_ptr<AccessibleNode> getChildAt(int index) const;
218 
223  std::unique_ptr<AccessibleNode> getParent() const;
224 
229  AtspiAccessible *getAccessible() const;
230 
231 public:
236  std::string getDesc() const;
237 
242  std::string getText() const;
243 
248  std::string getPkg() const;
249 
254  std::string getRes() const;
255 
260  std::string getType() const;
261 
266  std::string getStyle() const;
267 
272  Rect<int> getBoundingBox() const;
273 
278  bool isCheckable() const;
279 
284  bool isChecked() const;
285 
290  bool isClickable() const;
291 
296  bool isEnabled() const;
297 
302  bool isFocusable() const;
303 
308  bool isFocused() const;
309 
314  bool isLongClickable() const;
315 
320  bool isScrollable() const;
321 
326  bool isSelectable() const;
327 
332  bool isSelected() const;
333 
338  bool isVisible() const;
339 
344  bool isShowing() const;
345 
350  bool isActive() const;
351 
356  std::vector<std::string> getActions() const;
357 
358 public:
363  void print(int) const;
364 
369  void print(int, int) const;
370 
375  void refresh() const;
376 
381  void setValue(std::string text) const;
382 
387  bool doAction(std::string action) const;
388 
389 private:
394  bool isSupporting(AccessibleNodeInterface thisIface) const;
395 
400  bool hasFeatureProperty(NodeFeatureProperties prop) const;
401 
406  void setFeatureProperty(NodeFeatureProperties prop, bool has) const;
407 
412  void setFeatureProperty(AtspiStateType type) const;
413 
418  static std::map<AtspiAccessible *, AccessibleNode *> mNodeMap;
419 
420 private:
424  unique_ptr_gobj<AtspiAccessible> mNode;
425 
426  mutable std::string mText;
427 
431  mutable std::string mPkg;
432 
436  mutable std::string mRole;
437 
441  mutable std::string mDesc;
442 
446  mutable std::string mRes;
447 
451  mutable std::string mType;
452 
456  mutable std::string mStyle;
457 
461  mutable Rect<int> mBoundingBox;
462 
466  int mSupportingIfaces;
467 
471  mutable int mFeatureProperty;
472 
476  bool mIsAlive;
477 };
478 
479 #endif