7e3a3a836e285db634e0eecb59fdf99d4e20b926
[platform/core/uifw/aurum.git] / libaurum / inc / AccessibleWatcher.h
1 #ifndef ACCESSIBLE_H
2 #define ACCESSIBLE_H
3
4 #include <atspi/atspi.h>
5 #include "AccessibleNode.h"
6
7 #include <list>
8 #include <map>
9 #include <memory>
10 #include <vector>
11 #include <set>
12
13
14 #include <gio/gio.h>
15 #include <mutex>
16 #include <shared_mutex>
17 #include "config.h"
18
19
20
21 enum class WindowActivateInfoType {
22     DEFAULT_LABEL_ENALBED = 0x00,
23     DEFAULT_LABEL_ENALBED_WITHOUT_WINDOW = 0x01,
24     DEFAULT_LABEL_DISABLED = 0x02,
25     KEYBOARD = 0x04,
26 };
27
28 class IAtspiEvents {
29 public:
30     virtual ~IAtspiEvents() {}
31     virtual void onWindowActivated(AtspiAccessible *      node,
32                                    WindowActivateInfoType type) = 0;
33     virtual void onWindowDeactivated(AtspiAccessible *node) = 0;
34
35     virtual void onWindowCreated(AtspiAccessible *node) = 0;
36     virtual void onWindowDestroyed(AtspiAccessible *node) = 0;
37
38     virtual void onVisibilityChanged(AtspiAccessible *node,
39                                      bool             visible) = 0;
40     virtual void onObjectDefunct(AtspiAccessible *node) = 0;
41 };
42
43 class AccessibleWatcher : public IAtspiEvents {
44 private:
45     AccessibleWatcher();
46
47 public:
48     static const AccessibleWatcher *getInstance();
49     virtual ~AccessibleWatcher();
50
51 public:
52     AccessibleNode *getRootNode() const;
53     AccessibleNode *getTopNode() const;
54
55     void onWindowActivated(AtspiAccessible *      node,
56                                    WindowActivateInfoType type) override;
57     void onWindowDeactivated(AtspiAccessible *node) override;
58
59     void onWindowCreated(AtspiAccessible *node) override;
60     void onWindowDestroyed(AtspiAccessible *node) override;
61
62     void onVisibilityChanged(AtspiAccessible *node,
63                                      bool             visible) override;
64     void onObjectDefunct(AtspiAccessible *node) override;
65
66     void printDbgInformation() const;
67
68 private:
69     void        clearWindowList() const;
70     static void onAtspiWindowEvent(AtspiEvent *event, void *user_data);
71
72     bool removeFromActivatedList(AtspiAccessible *node);
73     bool addToActivatedList(AtspiAccessible *node);
74     bool removeFromWindowSet(AtspiAccessible *node);
75     bool addToWindowSet(AtspiAccessible *node);
76
77 private:
78     static AtspiEventListener *                   listener;
79     mutable std::list<AtspiAccessible *>          mActivatedWindowList;
80     mutable std::list<AtspiAccessible *>          mActivatedApplicationList;
81     mutable std::set<AtspiAccessible *>           mWindowSet;;
82
83     GDBusProxy *                                  mDbusProxy;
84     std::map<AtspiAccessible *, AccessibleNode *> mAccessibleNode;
85     mutable std::mutex                            mLock;
86 };
87
88 #endif