| 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/singleton.h" | 8 #include "base/memory/singleton.h" |
| 8 #include "base/stl_util.h" | |
| 9 #include "ui/aura/client/focus_client.h" | 9 #include "ui/aura/client/focus_client.h" |
| 10 #include "ui/aura/window.h" | 10 #include "ui/aura/window.h" |
| 11 #include "ui/views/accessibility/ax_aura_obj_wrapper.h" | 11 #include "ui/views/accessibility/ax_aura_obj_wrapper.h" |
| 12 #include "ui/views/accessibility/ax_view_obj_wrapper.h" | 12 #include "ui/views/accessibility/ax_view_obj_wrapper.h" |
| 13 #include "ui/views/accessibility/ax_widget_obj_wrapper.h" | 13 #include "ui/views/accessibility/ax_widget_obj_wrapper.h" |
| 14 #include "ui/views/accessibility/ax_window_obj_wrapper.h" | 14 #include "ui/views/accessibility/ax_window_obj_wrapper.h" |
| 15 #include "ui/views/view.h" | 15 #include "ui/views/view.h" |
| 16 #include "ui/views/widget/widget.h" | 16 #include "ui/views/widget/widget.h" |
| 17 | 17 |
| 18 namespace views { | 18 namespace views { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 | 76 |
| 77 void AXAuraObjCache::Remove(aura::Window* window, aura::Window* parent) { | 77 void AXAuraObjCache::Remove(aura::Window* window, aura::Window* parent) { |
| 78 int id = GetIDInternal(parent, window_to_id_map_); | 78 int id = GetIDInternal(parent, window_to_id_map_); |
| 79 AXAuraObjWrapper* parent_window_obj = Get(id); | 79 AXAuraObjWrapper* parent_window_obj = Get(id); |
| 80 RemoveInternal(window, window_to_id_map_); | 80 RemoveInternal(window, window_to_id_map_); |
| 81 if (parent && delegate_) | 81 if (parent && delegate_) |
| 82 delegate_->OnChildWindowRemoved(parent_window_obj); | 82 delegate_->OnChildWindowRemoved(parent_window_obj); |
| 83 } | 83 } |
| 84 | 84 |
| 85 AXAuraObjWrapper* AXAuraObjCache::Get(int32_t id) { | 85 AXAuraObjWrapper* AXAuraObjCache::Get(int32_t id) { |
| 86 std::map<int32_t, AXAuraObjWrapper*>::iterator it = cache_.find(id); | 86 auto it = cache_.find(id); |
| 87 | 87 |
| 88 if (it == cache_.end()) | 88 if (it == cache_.end()) |
| 89 return NULL; | 89 return nullptr; |
| 90 | 90 |
| 91 return it->second; | 91 return it->second.get(); |
| 92 } | 92 } |
| 93 | 93 |
| 94 void AXAuraObjCache::Remove(int32_t id) { | 94 void AXAuraObjCache::Remove(int32_t id) { |
| 95 AXAuraObjWrapper* obj = Get(id); | 95 AXAuraObjWrapper* obj = Get(id); |
| 96 | 96 |
| 97 if (id == -1 || !obj) | 97 if (id == -1 || !obj) |
| 98 return; | 98 return; |
| 99 | 99 |
| 100 cache_.erase(id); | 100 cache_.erase(id); |
| 101 delete obj; | |
| 102 } | 101 } |
| 103 | 102 |
| 104 void AXAuraObjCache::GetTopLevelWindows( | 103 void AXAuraObjCache::GetTopLevelWindows( |
| 105 std::vector<AXAuraObjWrapper*>* children) { | 104 std::vector<AXAuraObjWrapper*>* children) { |
| 106 for (std::map<aura::Window*, int32_t>::iterator it = | 105 for (auto it = window_to_id_map_.begin(); it != window_to_id_map_.end(); |
| 107 window_to_id_map_.begin(); | 106 ++it) { |
| 108 it != window_to_id_map_.end(); ++it) { | |
| 109 if (!it->first->parent()) | 107 if (!it->first->parent()) |
| 110 children->push_back(GetOrCreate(it->first)); | 108 children->push_back(GetOrCreate(it->first)); |
| 111 } | 109 } |
| 112 } | 110 } |
| 113 | 111 |
| 114 AXAuraObjWrapper* AXAuraObjCache::GetFocus() { | 112 AXAuraObjWrapper* AXAuraObjCache::GetFocus() { |
| 115 View* focused_view = GetFocusedView(); | 113 View* focused_view = GetFocusedView(); |
| 116 if (focused_view) | 114 if (focused_view) |
| 117 return GetOrCreate(focused_view); | 115 return GetOrCreate(focused_view); |
| 118 return nullptr; | 116 return nullptr; |
| 119 } | 117 } |
| 120 | 118 |
| 121 AXAuraObjCache::AXAuraObjCache() | 119 AXAuraObjCache::AXAuraObjCache() |
| 122 : current_id_(1), | 120 : current_id_(1), |
| 123 focus_client_(nullptr), | 121 focus_client_(nullptr), |
| 124 is_destroying_(false), | 122 is_destroying_(false), |
| 125 delegate_(nullptr) {} | 123 delegate_(nullptr) {} |
| 126 | 124 |
| 127 AXAuraObjCache::~AXAuraObjCache() { | 125 AXAuraObjCache::~AXAuraObjCache() { |
| 128 is_destroying_ = true; | 126 is_destroying_ = true; |
| 129 base::STLDeleteContainerPairSecondPointers(cache_.begin(), cache_.end()); | |
| 130 cache_.clear(); | 127 cache_.clear(); |
| 131 } | 128 } |
| 132 | 129 |
| 133 View* AXAuraObjCache::GetFocusedView() { | 130 View* AXAuraObjCache::GetFocusedView() { |
| 134 if (!focus_client_) | 131 if (!focus_client_) |
| 135 return nullptr; | 132 return nullptr; |
| 136 | 133 |
| 137 aura::Window* focused_window = focus_client_->GetFocusedWindow(); | 134 aura::Window* focused_window = focus_client_->GetFocusedWindow(); |
| 138 if (!focused_window) | 135 if (!focused_window) |
| 139 return nullptr; | 136 return nullptr; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 166 | 163 |
| 167 void AXAuraObjCache::OnWindowDestroying(aura::Window* window) { | 164 void AXAuraObjCache::OnWindowDestroying(aura::Window* window) { |
| 168 focus_client_ = nullptr; | 165 focus_client_ = nullptr; |
| 169 } | 166 } |
| 170 | 167 |
| 171 template <typename AuraViewWrapper, typename AuraView> | 168 template <typename AuraViewWrapper, typename AuraView> |
| 172 AXAuraObjWrapper* AXAuraObjCache::CreateInternal( | 169 AXAuraObjWrapper* AXAuraObjCache::CreateInternal( |
| 173 AuraView* aura_view, | 170 AuraView* aura_view, |
| 174 std::map<AuraView*, int32_t>& aura_view_to_id_map) { | 171 std::map<AuraView*, int32_t>& aura_view_to_id_map) { |
| 175 if (!aura_view) | 172 if (!aura_view) |
| 176 return NULL; | 173 return nullptr; |
| 177 | 174 |
| 178 typename std::map<AuraView*, int32_t>::iterator it = | 175 auto it = aura_view_to_id_map.find(aura_view); |
| 179 aura_view_to_id_map.find(aura_view); | |
| 180 | 176 |
| 181 if (it != aura_view_to_id_map.end()) | 177 if (it != aura_view_to_id_map.end()) |
| 182 return Get(it->second); | 178 return Get(it->second); |
| 183 | 179 |
| 184 AXAuraObjWrapper* wrapper = new AuraViewWrapper(aura_view); | 180 AXAuraObjWrapper* wrapper = new AuraViewWrapper(aura_view); |
| 185 aura_view_to_id_map[aura_view] = current_id_; | 181 aura_view_to_id_map[aura_view] = current_id_; |
| 186 cache_[current_id_] = wrapper; | 182 cache_[current_id_] = base::WrapUnique(wrapper); |
| 187 current_id_++; | 183 current_id_++; |
| 188 return wrapper; | 184 return wrapper; |
| 189 } | 185 } |
| 190 | 186 |
| 191 template <typename AuraView> | 187 template <typename AuraView> |
| 192 int32_t AXAuraObjCache::GetIDInternal( | 188 int32_t AXAuraObjCache::GetIDInternal( |
| 193 AuraView* aura_view, | 189 AuraView* aura_view, |
| 194 const std::map<AuraView*, int32_t>& aura_view_to_id_map) const { | 190 const std::map<AuraView*, int32_t>& aura_view_to_id_map) const { |
| 195 if (!aura_view) | 191 if (!aura_view) |
| 196 return -1; | 192 return -1; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 207 AuraView* aura_view, | 203 AuraView* aura_view, |
| 208 std::map<AuraView*, int32_t>& aura_view_to_id_map) { | 204 std::map<AuraView*, int32_t>& aura_view_to_id_map) { |
| 209 int32_t id = GetID(aura_view); | 205 int32_t id = GetID(aura_view); |
| 210 if (id == -1) | 206 if (id == -1) |
| 211 return; | 207 return; |
| 212 aura_view_to_id_map.erase(aura_view); | 208 aura_view_to_id_map.erase(aura_view); |
| 213 Remove(id); | 209 Remove(id); |
| 214 } | 210 } |
| 215 | 211 |
| 216 } // namespace views | 212 } // namespace views |
| OLD | NEW |