| 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(AuraView* aura_view, | 95 int32_t GetIDInternal(AuraView* aura_view, |
| 82 std::map<AuraView*, int32_t>& aura_view_to_id_map); | 96 std::map<AuraView*, int32_t>& aura_view_to_id_map); |
| 83 | 97 |
| 84 template <typename AuraView> | 98 template <typename AuraView> |
| 85 void RemoveInternal(AuraView* aura_view, | 99 void RemoveInternal(AuraView* aura_view, |
| 86 std::map<AuraView*, int32_t>& aura_view_to_id_map); | 100 std::map<AuraView*, int32_t>& aura_view_to_id_map); |
| 87 | 101 |
| 88 std::map<views::View*, int32_t> view_to_id_map_; | 102 std::map<views::View*, int32_t> view_to_id_map_; |
| 89 std::map<views::Widget*, int32_t> widget_to_id_map_; | 103 std::map<views::Widget*, int32_t> widget_to_id_map_; |
| 90 std::map<aura::Window*, int32_t> window_to_id_map_; | 104 std::map<aura::Window*, int32_t> window_to_id_map_; |
| 91 | 105 |
| 92 std::map<int32_t, AXAuraObjWrapper*> cache_; | 106 std::map<int32_t, AXAuraObjWrapper*> cache_; |
| 93 int32_t current_id_; | 107 int32_t current_id_; |
| 94 | 108 |
| 109 aura::client::FocusClient* focus_client_; |
| 110 |
| 95 // True immediately when entering this object's destructor. | 111 // True immediately when entering this object's destructor. |
| 96 bool is_destroying_; | 112 bool is_destroying_; |
| 97 | 113 |
| 98 DISALLOW_COPY_AND_ASSIGN(AXAuraObjCache); | 114 DISALLOW_COPY_AND_ASSIGN(AXAuraObjCache); |
| 99 }; | 115 }; |
| 100 | 116 |
| 101 } // namespace views | 117 } // namespace views |
| 102 | 118 |
| 103 #endif // UI_VIEWS_ACCESSIBILITY_AX_AURA_OBJ_CACHE_H_ | 119 #endif // UI_VIEWS_ACCESSIBILITY_AX_AURA_OBJ_CACHE_H_ |
| OLD | NEW |