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) { | 45 int32_t AXAuraObjCache::GetID(View* view) { |
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) { | 49 int32_t AXAuraObjCache::GetID(Widget* widget) { |
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() { |
123 //if (focus_client_) | |
David Tseng
2016/01/28 02:00:56
nit: remove
dmazzoni
2016/01/30 00:02:41
Done.
| |
124 // focus_client_->RemoveObserver(this); | |
104 is_destroying_ = true; | 125 is_destroying_ = true; |
105 STLDeleteContainerPairSecondPointers(cache_.begin(), cache_.end()); | 126 STLDeleteContainerPairSecondPointers(cache_.begin(), cache_.end()); |
106 cache_.clear(); | 127 cache_.clear(); |
107 } | 128 } |
108 | 129 |
130 View* AXAuraObjCache::GetFocusedView() { | |
131 if (!focus_client_) | |
132 return nullptr; | |
133 | |
134 aura::Window* focused_window = focus_client_->GetFocusedWindow(); | |
135 if (!focused_window) | |
136 return nullptr; | |
137 | |
138 Widget* focused_widget = Widget::GetWidgetForNativeView(focused_window); | |
139 while (!focused_widget) { | |
140 focused_window = focused_window->parent(); | |
141 if (!focused_window) | |
142 break; | |
143 | |
144 focused_widget = Widget::GetWidgetForNativeView(focused_window); | |
David Tseng
2016/01/28 02:00:56
Do we want to break once we find a non-null widget
dmazzoni
2016/01/30 00:02:41
Not necessary since this is at the bottom of the w
| |
145 } | |
146 | |
147 if (!focused_widget) | |
148 return nullptr; | |
149 | |
150 FocusManager* focus_manager = focused_widget->GetFocusManager(); | |
151 if (!focus_manager) | |
152 return nullptr; | |
153 | |
154 return focus_manager->GetFocusedView(); | |
155 } | |
156 | |
157 void AXAuraObjCache::OnWindowFocused(aura::Window* gained_focus, | |
158 aura::Window* lost_focus) { | |
159 View* view = GetFocusedView(); | |
160 if (view) | |
161 view->NotifyAccessibilityEvent(ui::AX_EVENT_FOCUS, true); | |
162 } | |
163 | |
109 template <typename AuraViewWrapper, typename AuraView> | 164 template <typename AuraViewWrapper, typename AuraView> |
110 AXAuraObjWrapper* AXAuraObjCache::CreateInternal( | 165 AXAuraObjWrapper* AXAuraObjCache::CreateInternal( |
111 AuraView* aura_view, | 166 AuraView* aura_view, |
112 std::map<AuraView*, int32_t>& aura_view_to_id_map) { | 167 std::map<AuraView*, int32_t>& aura_view_to_id_map) { |
113 if (!aura_view) | 168 if (!aura_view) |
114 return NULL; | 169 return NULL; |
115 | 170 |
116 typename std::map<AuraView*, int32_t>::iterator it = | 171 typename std::map<AuraView*, int32_t>::iterator it = |
117 aura_view_to_id_map.find(aura_view); | 172 aura_view_to_id_map.find(aura_view); |
118 | 173 |
(...skipping 28 matching lines...) Expand all Loading... | |
147 AuraView* aura_view, | 202 AuraView* aura_view, |
148 std::map<AuraView*, int32_t>& aura_view_to_id_map) { | 203 std::map<AuraView*, int32_t>& aura_view_to_id_map) { |
149 int32_t id = GetID(aura_view); | 204 int32_t id = GetID(aura_view); |
150 if (id == -1) | 205 if (id == -1) |
151 return; | 206 return; |
152 aura_view_to_id_map.erase(aura_view); | 207 aura_view_to_id_map.erase(aura_view); |
153 Remove(id); | 208 Remove(id); |
154 } | 209 } |
155 | 210 |
156 } // namespace views | 211 } // namespace views |
OLD | NEW |