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/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
8 #include "base/memory/singleton.h" | 8 #include "base/memory/singleton.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "ui/aura/client/aura_constants.h" | 10 #include "ui/aura/client/aura_constants.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 AXAuraObjWrapper* AXAuraObjCache::GetOrCreate(View* view) { | 27 AXAuraObjWrapper* AXAuraObjCache::GetOrCreate(View* view) { |
28 return CreateInternal<AXViewObjWrapper>(view, view_to_id_map_); | 28 return CreateInternal<AXViewObjWrapper>(view, view_to_id_map_); |
29 } | 29 } |
30 | 30 |
31 AXAuraObjWrapper* AXAuraObjCache::GetOrCreate(Widget* widget) { | 31 AXAuraObjWrapper* AXAuraObjCache::GetOrCreate(Widget* widget) { |
32 return CreateInternal<AXWidgetObjWrapper>(widget, widget_to_id_map_); | 32 return CreateInternal<AXWidgetObjWrapper>(widget, widget_to_id_map_); |
33 } | 33 } |
34 | 34 |
35 AXAuraObjWrapper* AXAuraObjCache::GetOrCreate(aura::Window* window) { | 35 AXAuraObjWrapper* AXAuraObjCache::GetOrCreate(aura::Window* window) { |
36 if (!focus_client_) { | 36 if (!focus_client_) { |
| 37 // Note: On Chrome OS, there's exactly one root window per screen, |
| 38 // it's the same as ash::Shell::Get()->GetPrimaryRootWindow() when |
| 39 // there's only one screen. Observing the root window allows us to |
| 40 // detect any time a window is added or removed. |
| 41 // |
| 42 // TODO(dmazzoni): Explicitly observe each root window on Chrome OS |
| 43 // and track as root windows are added and removed. |
| 44 // http://crbug.com/713278 |
37 aura::Window* root_window = window->GetRootWindow(); | 45 aura::Window* root_window = window->GetRootWindow(); |
38 if (root_window) { | 46 if (root_window) { |
39 focus_client_ = aura::client::GetFocusClient(root_window); | 47 focus_client_ = aura::client::GetFocusClient(root_window); |
40 root_window->AddObserver(this); | 48 root_window->AddObserver(this); |
41 if (focus_client_) | 49 if (focus_client_) |
42 focus_client_->AddObserver(this); | 50 focus_client_->AddObserver(this); |
43 } | 51 } |
44 } | 52 } |
45 return CreateInternal<AXWindowObjWrapper>(window, window_to_id_map_); | 53 return CreateInternal<AXWindowObjWrapper>(window, window_to_id_map_); |
46 } | 54 } |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 return GetOrCreate(focused_view); | 125 return GetOrCreate(focused_view); |
118 return nullptr; | 126 return nullptr; |
119 } | 127 } |
120 | 128 |
121 void AXAuraObjCache::OnFocusedViewChanged() { | 129 void AXAuraObjCache::OnFocusedViewChanged() { |
122 View* view = GetFocusedView(); | 130 View* view = GetFocusedView(); |
123 if (view) | 131 if (view) |
124 view->NotifyAccessibilityEvent(ui::AX_EVENT_FOCUS, true); | 132 view->NotifyAccessibilityEvent(ui::AX_EVENT_FOCUS, true); |
125 } | 133 } |
126 | 134 |
| 135 void AXAuraObjCache::FireEvent(AXAuraObjWrapper* aura_obj, |
| 136 ui::AXEvent event_type) { |
| 137 if (delegate_) |
| 138 delegate_->OnEvent(aura_obj, event_type); |
| 139 } |
| 140 |
127 AXAuraObjCache::AXAuraObjCache() | 141 AXAuraObjCache::AXAuraObjCache() |
128 : current_id_(1), | 142 : current_id_(1), |
129 focus_client_(nullptr), | 143 focus_client_(nullptr), |
130 is_destroying_(false), | 144 is_destroying_(false), |
131 delegate_(nullptr) {} | 145 delegate_(nullptr) {} |
132 | 146 |
133 AXAuraObjCache::~AXAuraObjCache() { | 147 AXAuraObjCache::~AXAuraObjCache() { |
134 is_destroying_ = true; | 148 is_destroying_ = true; |
135 cache_.clear(); | 149 cache_.clear(); |
136 } | 150 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 | 188 |
175 void AXAuraObjCache::OnWindowFocused(aura::Window* gained_focus, | 189 void AXAuraObjCache::OnWindowFocused(aura::Window* gained_focus, |
176 aura::Window* lost_focus) { | 190 aura::Window* lost_focus) { |
177 OnFocusedViewChanged(); | 191 OnFocusedViewChanged(); |
178 } | 192 } |
179 | 193 |
180 void AXAuraObjCache::OnWindowDestroying(aura::Window* window) { | 194 void AXAuraObjCache::OnWindowDestroying(aura::Window* window) { |
181 focus_client_ = nullptr; | 195 focus_client_ = nullptr; |
182 } | 196 } |
183 | 197 |
| 198 void AXAuraObjCache::OnWindowHierarchyChanged( |
| 199 const HierarchyChangeParams& params) { |
| 200 aura::Window* window = params.target; |
| 201 if (window->parent()) { |
| 202 delegate_->OnEvent(GetOrCreate(window->parent()), |
| 203 ui::AX_EVENT_CHILDREN_CHANGED); |
| 204 } |
| 205 } |
| 206 |
184 template <typename AuraViewWrapper, typename AuraView> | 207 template <typename AuraViewWrapper, typename AuraView> |
185 AXAuraObjWrapper* AXAuraObjCache::CreateInternal( | 208 AXAuraObjWrapper* AXAuraObjCache::CreateInternal( |
186 AuraView* aura_view, | 209 AuraView* aura_view, |
187 std::map<AuraView*, int32_t>& aura_view_to_id_map) { | 210 std::map<AuraView*, int32_t>& aura_view_to_id_map) { |
188 if (!aura_view) | 211 if (!aura_view) |
189 return nullptr; | 212 return nullptr; |
190 | 213 |
191 auto it = aura_view_to_id_map.find(aura_view); | 214 auto it = aura_view_to_id_map.find(aura_view); |
192 | 215 |
193 if (it != aura_view_to_id_map.end()) | 216 if (it != aura_view_to_id_map.end()) |
(...skipping 25 matching lines...) Expand all Loading... |
219 AuraView* aura_view, | 242 AuraView* aura_view, |
220 std::map<AuraView*, int32_t>& aura_view_to_id_map) { | 243 std::map<AuraView*, int32_t>& aura_view_to_id_map) { |
221 int32_t id = GetID(aura_view); | 244 int32_t id = GetID(aura_view); |
222 if (id == -1) | 245 if (id == -1) |
223 return; | 246 return; |
224 aura_view_to_id_map.erase(aura_view); | 247 aura_view_to_id_map.erase(aura_view); |
225 Remove(id); | 248 Remove(id); |
226 } | 249 } |
227 | 250 |
228 } // namespace views | 251 } // namespace views |
OLD | NEW |