OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef UI_VIEWS_ACCESSIBILITY_AX_AURA_OBJ_CACHE_H_ | 5 #ifndef UI_VIEWS_ACCESSIBILITY_AX_AURA_OBJ_CACHE_H_ |
6 #define UI_VIEWS_ACCESSIBILITY_AX_AURA_OBJ_CACHE_H_ | 6 #define UI_VIEWS_ACCESSIBILITY_AX_AURA_OBJ_CACHE_H_ |
7 | 7 |
| 8 #include <stdint.h> |
| 9 |
8 #include <map> | 10 #include <map> |
9 #include <vector> | 11 #include <vector> |
10 | 12 |
11 #include "base/basictypes.h" | 13 #include "base/macros.h" |
12 #include "ui/views/views_export.h" | 14 #include "ui/views/views_export.h" |
13 | 15 |
14 namespace base { | 16 namespace base { |
15 template <typename T> struct DefaultSingletonTraits; | 17 template <typename T> struct DefaultSingletonTraits; |
16 } | 18 } |
17 | 19 |
18 namespace aura { | 20 namespace aura { |
19 class Window; | 21 class Window; |
20 } // namespace aura | 22 } // namespace aura |
21 | 23 |
22 namespace views { | 24 namespace views { |
23 class AXAuraObjWrapper; | 25 class AXAuraObjWrapper; |
24 class View; | 26 class View; |
25 class Widget; | 27 class Widget; |
26 | 28 |
27 // A cache responsible for assigning id's to a set of interesting Aura views. | 29 // A cache responsible for assigning id's to a set of interesting Aura views. |
28 class VIEWS_EXPORT AXAuraObjCache { | 30 class VIEWS_EXPORT AXAuraObjCache { |
29 public: | 31 public: |
30 // Get the single instance of this class. | 32 // Get the single instance of this class. |
31 static AXAuraObjCache* GetInstance(); | 33 static AXAuraObjCache* GetInstance(); |
32 | 34 |
33 // Get or create an entry in the cache based on an Aura view. | 35 // Get or create an entry in the cache based on an Aura view. |
34 AXAuraObjWrapper* GetOrCreate(View* view); | 36 AXAuraObjWrapper* GetOrCreate(View* view); |
35 AXAuraObjWrapper* GetOrCreate(Widget* widget); | 37 AXAuraObjWrapper* GetOrCreate(Widget* widget); |
36 AXAuraObjWrapper* GetOrCreate(aura::Window* window); | 38 AXAuraObjWrapper* GetOrCreate(aura::Window* window); |
37 | 39 |
38 // Gets an id given an Aura view. | 40 // Gets an id given an Aura view. |
39 int32 GetID(View* view); | 41 int32_t GetID(View* view); |
40 int32 GetID(Widget* widget); | 42 int32_t GetID(Widget* widget); |
41 int32 GetID(aura::Window* window); | 43 int32_t GetID(aura::Window* window); |
42 | 44 |
43 // Gets the next unique id for this cache. Useful for non-Aura view backed | 45 // Gets the next unique id for this cache. Useful for non-Aura view backed |
44 // views. | 46 // views. |
45 int32 GetNextID() { return current_id_++; } | 47 int32_t GetNextID() { return current_id_++; } |
46 | 48 |
47 // Removes an entry from this cache based on an Aura view. | 49 // Removes an entry from this cache based on an Aura view. |
48 void Remove(View* view); | 50 void Remove(View* view); |
49 void Remove(Widget* widget); | 51 void Remove(Widget* widget); |
50 void Remove(aura::Window* window); | 52 void Remove(aura::Window* window); |
51 | 53 |
52 // Removes a view and all of its descendants from the cache. | 54 // Removes a view and all of its descendants from the cache. |
53 void RemoveViewSubtree(View* view); | 55 void RemoveViewSubtree(View* view); |
54 | 56 |
55 // Lookup a cached entry based on an id. | 57 // Lookup a cached entry based on an id. |
56 AXAuraObjWrapper* Get(int32 id); | 58 AXAuraObjWrapper* Get(int32_t id); |
57 | 59 |
58 // Remove a cached entry based on an id. | 60 // Remove a cached entry based on an id. |
59 void Remove(int32 id); | 61 void Remove(int32_t id); |
60 | 62 |
61 // Get all top level windows this cache knows about. | 63 // Get all top level windows this cache knows about. |
62 void GetTopLevelWindows(std::vector<AXAuraObjWrapper*>* children); | 64 void GetTopLevelWindows(std::vector<AXAuraObjWrapper*>* children); |
63 | 65 |
64 // Indicates if this object's currently being destroyed. | 66 // Indicates if this object's currently being destroyed. |
65 bool is_destroying() { return is_destroying_; } | 67 bool is_destroying() { return is_destroying_; } |
66 | 68 |
67 private: | 69 private: |
68 friend struct base::DefaultSingletonTraits<AXAuraObjCache>; | 70 friend struct base::DefaultSingletonTraits<AXAuraObjCache>; |
69 | 71 |
70 AXAuraObjCache(); | 72 AXAuraObjCache(); |
71 virtual ~AXAuraObjCache(); | 73 virtual ~AXAuraObjCache(); |
72 | 74 |
73 template <typename AuraViewWrapper, typename AuraView> | 75 template <typename AuraViewWrapper, typename AuraView> |
74 AXAuraObjWrapper* CreateInternal( | 76 AXAuraObjWrapper* CreateInternal( |
75 AuraView* aura_view, std::map<AuraView*, int32>& aura_view_to_id_map); | 77 AuraView* aura_view, |
| 78 std::map<AuraView*, int32_t>& aura_view_to_id_map); |
76 | 79 |
77 template<typename AuraView> int32 GetIDInternal( | 80 template <typename AuraView> |
78 AuraView* aura_view, std::map<AuraView*, int32>& aura_view_to_id_map); | 81 int32_t GetIDInternal(AuraView* aura_view, |
| 82 std::map<AuraView*, int32_t>& aura_view_to_id_map); |
79 | 83 |
80 template<typename AuraView> void RemoveInternal( | 84 template <typename AuraView> |
81 AuraView* aura_view, std::map<AuraView*, int32>& aura_view_to_id_map); | 85 void RemoveInternal(AuraView* aura_view, |
| 86 std::map<AuraView*, int32_t>& aura_view_to_id_map); |
82 | 87 |
83 std::map<views::View*, int32> view_to_id_map_; | 88 std::map<views::View*, int32_t> view_to_id_map_; |
84 std::map<views::Widget*, int32> widget_to_id_map_; | 89 std::map<views::Widget*, int32_t> widget_to_id_map_; |
85 std::map<aura::Window*, int32> window_to_id_map_; | 90 std::map<aura::Window*, int32_t> window_to_id_map_; |
86 | 91 |
87 std::map<int32, AXAuraObjWrapper*> cache_; | 92 std::map<int32_t, AXAuraObjWrapper*> cache_; |
88 int32 current_id_; | 93 int32_t current_id_; |
89 | 94 |
90 // True immediately when entering this object's destructor. | 95 // True immediately when entering this object's destructor. |
91 bool is_destroying_; | 96 bool is_destroying_; |
92 | 97 |
93 DISALLOW_COPY_AND_ASSIGN(AXAuraObjCache); | 98 DISALLOW_COPY_AND_ASSIGN(AXAuraObjCache); |
94 }; | 99 }; |
95 | 100 |
96 } // namespace views | 101 } // namespace views |
97 | 102 |
98 #endif // UI_VIEWS_ACCESSIBILITY_AX_AURA_OBJ_CACHE_H_ | 103 #endif // UI_VIEWS_ACCESSIBILITY_AX_AURA_OBJ_CACHE_H_ |
OLD | NEW |