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 #include "ui/views/accessibility/ax_aura_obj_cache.h" | 5 #include "ui/views/accessibility/ax_aura_obj_cache.h" |
6 | 6 |
7 #include "base/memory/singleton.h" | 7 #include "base/memory/singleton.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "ui/aura/client/focus_client.h" |
9 #include "ui/aura/window.h" | 10 #include "ui/aura/window.h" |
10 #include "ui/views/accessibility/ax_aura_obj_wrapper.h" | 11 #include "ui/views/accessibility/ax_aura_obj_wrapper.h" |
11 #include "ui/views/accessibility/ax_view_obj_wrapper.h" | 12 #include "ui/views/accessibility/ax_view_obj_wrapper.h" |
12 #include "ui/views/accessibility/ax_widget_obj_wrapper.h" | 13 #include "ui/views/accessibility/ax_widget_obj_wrapper.h" |
13 #include "ui/views/accessibility/ax_window_obj_wrapper.h" | 14 #include "ui/views/accessibility/ax_window_obj_wrapper.h" |
14 #include "ui/views/view.h" | 15 #include "ui/views/view.h" |
15 #include "ui/views/widget/widget.h" | 16 #include "ui/views/widget/widget.h" |
16 | 17 |
17 namespace views { | 18 namespace views { |
18 | 19 |
19 // static | 20 // static |
20 AXAuraObjCache* AXAuraObjCache::GetInstance() { | 21 AXAuraObjCache* AXAuraObjCache::GetInstance() { |
21 return base::Singleton<AXAuraObjCache>::get(); | 22 return base::Singleton<AXAuraObjCache>::get(); |
22 } | 23 } |
23 | 24 |
24 AXAuraObjWrapper* AXAuraObjCache::GetOrCreate(View* view) { | 25 AXAuraObjWrapper* AXAuraObjCache::GetOrCreate(View* view) { |
25 return CreateInternal<AXViewObjWrapper>(view, view_to_id_map_); | 26 return CreateInternal<AXViewObjWrapper>(view, view_to_id_map_); |
26 } | 27 } |
27 | 28 |
28 AXAuraObjWrapper* AXAuraObjCache::GetOrCreate(Widget* widget) { | 29 AXAuraObjWrapper* AXAuraObjCache::GetOrCreate(Widget* widget) { |
29 return CreateInternal<AXWidgetObjWrapper>(widget, widget_to_id_map_); | 30 return CreateInternal<AXWidgetObjWrapper>(widget, widget_to_id_map_); |
30 } | 31 } |
31 | 32 |
32 AXAuraObjWrapper* AXAuraObjCache::GetOrCreate(aura::Window* window) { | 33 AXAuraObjWrapper* AXAuraObjCache::GetOrCreate(aura::Window* window) { |
| 34 if (!focus_client_) { |
| 35 aura::Window* root_window = window->GetRootWindow(); |
| 36 if (root_window) { |
| 37 focus_client_ = aura::client::GetFocusClient(root_window); |
| 38 if (focus_client_) |
| 39 focus_client_->AddObserver(this); |
| 40 } |
| 41 } |
33 return CreateInternal<AXWindowObjWrapper>(window, window_to_id_map_); | 42 return CreateInternal<AXWindowObjWrapper>(window, window_to_id_map_); |
34 } | 43 } |
35 | 44 |
36 int32_t AXAuraObjCache::GetID(View* view) const { | 45 int32_t AXAuraObjCache::GetID(View* view) const { |
37 return GetIDInternal(view, view_to_id_map_); | 46 return GetIDInternal(view, view_to_id_map_); |
38 } | 47 } |
39 | 48 |
40 int32_t AXAuraObjCache::GetID(Widget* widget) const { | 49 int32_t AXAuraObjCache::GetID(Widget* widget) const { |
41 return GetIDInternal(widget, widget_to_id_map_); | 50 return GetIDInternal(widget, widget_to_id_map_); |
42 } | 51 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 void AXAuraObjCache::GetTopLevelWindows( | 99 void AXAuraObjCache::GetTopLevelWindows( |
91 std::vector<AXAuraObjWrapper*>* children) { | 100 std::vector<AXAuraObjWrapper*>* children) { |
92 for (std::map<aura::Window*, int32_t>::iterator it = | 101 for (std::map<aura::Window*, int32_t>::iterator it = |
93 window_to_id_map_.begin(); | 102 window_to_id_map_.begin(); |
94 it != window_to_id_map_.end(); ++it) { | 103 it != window_to_id_map_.end(); ++it) { |
95 if (!it->first->parent()) | 104 if (!it->first->parent()) |
96 children->push_back(GetOrCreate(it->first)); | 105 children->push_back(GetOrCreate(it->first)); |
97 } | 106 } |
98 } | 107 } |
99 | 108 |
100 AXAuraObjCache::AXAuraObjCache() : current_id_(1), is_destroying_(false) { | 109 AXAuraObjWrapper* AXAuraObjCache::GetFocus() { |
| 110 View* focused_view = GetFocusedView(); |
| 111 if (focused_view) |
| 112 return GetOrCreate(focused_view); |
| 113 return nullptr; |
| 114 } |
| 115 |
| 116 AXAuraObjCache::AXAuraObjCache() |
| 117 : current_id_(1), |
| 118 focus_client_(nullptr), |
| 119 is_destroying_(false) { |
101 } | 120 } |
102 | 121 |
103 AXAuraObjCache::~AXAuraObjCache() { | 122 AXAuraObjCache::~AXAuraObjCache() { |
104 is_destroying_ = true; | 123 is_destroying_ = true; |
105 STLDeleteContainerPairSecondPointers(cache_.begin(), cache_.end()); | 124 STLDeleteContainerPairSecondPointers(cache_.begin(), cache_.end()); |
106 cache_.clear(); | 125 cache_.clear(); |
107 } | 126 } |
108 | 127 |
| 128 View* AXAuraObjCache::GetFocusedView() { |
| 129 if (!focus_client_) |
| 130 return nullptr; |
| 131 |
| 132 aura::Window* focused_window = focus_client_->GetFocusedWindow(); |
| 133 if (!focused_window) |
| 134 return nullptr; |
| 135 |
| 136 Widget* focused_widget = Widget::GetWidgetForNativeView(focused_window); |
| 137 while (!focused_widget) { |
| 138 focused_window = focused_window->parent(); |
| 139 if (!focused_window) |
| 140 break; |
| 141 |
| 142 focused_widget = Widget::GetWidgetForNativeView(focused_window); |
| 143 } |
| 144 |
| 145 if (!focused_widget) |
| 146 return nullptr; |
| 147 |
| 148 FocusManager* focus_manager = focused_widget->GetFocusManager(); |
| 149 if (!focus_manager) |
| 150 return nullptr; |
| 151 |
| 152 return focus_manager->GetFocusedView(); |
| 153 } |
| 154 |
| 155 void AXAuraObjCache::OnWindowFocused(aura::Window* gained_focus, |
| 156 aura::Window* lost_focus) { |
| 157 View* view = GetFocusedView(); |
| 158 if (view) |
| 159 view->NotifyAccessibilityEvent(ui::AX_EVENT_FOCUS, true); |
| 160 } |
| 161 |
109 template <typename AuraViewWrapper, typename AuraView> | 162 template <typename AuraViewWrapper, typename AuraView> |
110 AXAuraObjWrapper* AXAuraObjCache::CreateInternal( | 163 AXAuraObjWrapper* AXAuraObjCache::CreateInternal( |
111 AuraView* aura_view, | 164 AuraView* aura_view, |
112 std::map<AuraView*, int32_t>& aura_view_to_id_map) { | 165 std::map<AuraView*, int32_t>& aura_view_to_id_map) { |
113 if (!aura_view) | 166 if (!aura_view) |
114 return NULL; | 167 return NULL; |
115 | 168 |
116 typename std::map<AuraView*, int32_t>::iterator it = | 169 typename std::map<AuraView*, int32_t>::iterator it = |
117 aura_view_to_id_map.find(aura_view); | 170 aura_view_to_id_map.find(aura_view); |
118 | 171 |
(...skipping 26 matching lines...) Expand all Loading... |
145 AuraView* aura_view, | 198 AuraView* aura_view, |
146 std::map<AuraView*, int32_t>& aura_view_to_id_map) { | 199 std::map<AuraView*, int32_t>& aura_view_to_id_map) { |
147 int32_t id = GetID(aura_view); | 200 int32_t id = GetID(aura_view); |
148 if (id == -1) | 201 if (id == -1) |
149 return; | 202 return; |
150 aura_view_to_id_map.erase(aura_view); | 203 aura_view_to_id_map.erase(aura_view); |
151 Remove(id); | 204 Remove(id); |
152 } | 205 } |
153 | 206 |
154 } // namespace views | 207 } // namespace views |
OLD | NEW |