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> | 8 #include <stdint.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "ui/aura/client/focus_change_observer.h" |
14 #include "ui/views/views_export.h" | 15 #include "ui/views/views_export.h" |
15 | 16 |
16 namespace base { | 17 namespace base { |
17 template <typename T> struct DefaultSingletonTraits; | 18 template <typename T> struct DefaultSingletonTraits; |
18 } | 19 } |
19 | 20 |
20 namespace aura { | 21 namespace aura { |
| 22 namespace client { |
| 23 class FocusClient; |
| 24 } |
21 class Window; | 25 class Window; |
22 } // namespace aura | 26 } // namespace aura |
23 | 27 |
24 namespace views { | 28 namespace views { |
25 class AXAuraObjWrapper; | 29 class AXAuraObjWrapper; |
26 class View; | 30 class View; |
27 class Widget; | 31 class Widget; |
28 | 32 |
29 // A cache responsible for assigning id's to a set of interesting Aura views. | 33 // A cache responsible for assigning id's to a set of interesting Aura views. |
30 class VIEWS_EXPORT AXAuraObjCache { | 34 class VIEWS_EXPORT AXAuraObjCache |
| 35 : public aura::client::FocusChangeObserver { |
31 public: | 36 public: |
32 // Get the single instance of this class. | 37 // Get the single instance of this class. |
33 static AXAuraObjCache* GetInstance(); | 38 static AXAuraObjCache* GetInstance(); |
34 | 39 |
35 // Get or create an entry in the cache based on an Aura view. | 40 // Get or create an entry in the cache based on an Aura view. |
36 AXAuraObjWrapper* GetOrCreate(View* view); | 41 AXAuraObjWrapper* GetOrCreate(View* view); |
37 AXAuraObjWrapper* GetOrCreate(Widget* widget); | 42 AXAuraObjWrapper* GetOrCreate(Widget* widget); |
38 AXAuraObjWrapper* GetOrCreate(aura::Window* window); | 43 AXAuraObjWrapper* GetOrCreate(aura::Window* window); |
39 | 44 |
40 // Gets an id given an Aura view. | 45 // Gets an id given an Aura view. |
(...skipping 15 matching lines...) Expand all Loading... |
56 | 61 |
57 // Lookup a cached entry based on an id. | 62 // Lookup a cached entry based on an id. |
58 AXAuraObjWrapper* Get(int32_t id); | 63 AXAuraObjWrapper* Get(int32_t id); |
59 | 64 |
60 // Remove a cached entry based on an id. | 65 // Remove a cached entry based on an id. |
61 void Remove(int32_t id); | 66 void Remove(int32_t id); |
62 | 67 |
63 // Get all top level windows this cache knows about. | 68 // Get all top level windows this cache knows about. |
64 void GetTopLevelWindows(std::vector<AXAuraObjWrapper*>* children); | 69 void GetTopLevelWindows(std::vector<AXAuraObjWrapper*>* children); |
65 | 70 |
| 71 // Get the object that has focus. |
| 72 AXAuraObjWrapper* GetFocus(); |
| 73 |
66 // Indicates if this object's currently being destroyed. | 74 // Indicates if this object's currently being destroyed. |
67 bool is_destroying() { return is_destroying_; } | 75 bool is_destroying() { return is_destroying_; } |
68 | 76 |
69 private: | 77 private: |
70 friend struct base::DefaultSingletonTraits<AXAuraObjCache>; | 78 friend struct base::DefaultSingletonTraits<AXAuraObjCache>; |
71 | 79 |
72 AXAuraObjCache(); | 80 AXAuraObjCache(); |
73 virtual ~AXAuraObjCache(); | 81 ~AXAuraObjCache() override; |
| 82 |
| 83 View* GetFocusedView(); |
| 84 |
| 85 // aura::client::FocusChangeObserver override. |
| 86 void OnWindowFocused(aura::Window* gained_focus, |
| 87 aura::Window* lost_focus) override; |
74 | 88 |
75 template <typename AuraViewWrapper, typename AuraView> | 89 template <typename AuraViewWrapper, typename AuraView> |
76 AXAuraObjWrapper* CreateInternal( | 90 AXAuraObjWrapper* CreateInternal( |
77 AuraView* aura_view, | 91 AuraView* aura_view, |
78 std::map<AuraView*, int32_t>& aura_view_to_id_map); | 92 std::map<AuraView*, int32_t>& aura_view_to_id_map); |
79 | 93 |
80 template <typename AuraView> | 94 template <typename AuraView> |
81 int32_t GetIDInternal( | 95 int32_t GetIDInternal( |
82 AuraView* aura_view, | 96 AuraView* aura_view, |
83 const std::map<AuraView*, int32_t>& aura_view_to_id_map) const; | 97 const std::map<AuraView*, int32_t>& aura_view_to_id_map) const; |
84 | 98 |
85 template <typename AuraView> | 99 template <typename AuraView> |
86 void RemoveInternal(AuraView* aura_view, | 100 void RemoveInternal(AuraView* aura_view, |
87 std::map<AuraView*, int32_t>& aura_view_to_id_map); | 101 std::map<AuraView*, int32_t>& aura_view_to_id_map); |
88 | 102 |
89 std::map<views::View*, int32_t> view_to_id_map_; | 103 std::map<views::View*, int32_t> view_to_id_map_; |
90 std::map<views::Widget*, int32_t> widget_to_id_map_; | 104 std::map<views::Widget*, int32_t> widget_to_id_map_; |
91 std::map<aura::Window*, int32_t> window_to_id_map_; | 105 std::map<aura::Window*, int32_t> window_to_id_map_; |
92 | 106 |
93 std::map<int32_t, AXAuraObjWrapper*> cache_; | 107 std::map<int32_t, AXAuraObjWrapper*> cache_; |
94 int32_t current_id_; | 108 int32_t current_id_; |
95 | 109 |
| 110 aura::client::FocusClient* focus_client_; |
| 111 |
96 // True immediately when entering this object's destructor. | 112 // True immediately when entering this object's destructor. |
97 bool is_destroying_; | 113 bool is_destroying_; |
98 | 114 |
99 DISALLOW_COPY_AND_ASSIGN(AXAuraObjCache); | 115 DISALLOW_COPY_AND_ASSIGN(AXAuraObjCache); |
100 }; | 116 }; |
101 | 117 |
102 } // namespace views | 118 } // namespace views |
103 | 119 |
104 #endif // UI_VIEWS_ACCESSIBILITY_AX_AURA_OBJ_CACHE_H_ | 120 #endif // UI_VIEWS_ACCESSIBILITY_AX_AURA_OBJ_CACHE_H_ |
OLD | NEW |