Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(209)

Side by Side Diff: ui/views/accessibility/ax_aura_obj_cache.cc

Issue 1629403004: Remove all descendant views from AXAuraObjCache when a view is removed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Only compile unit tests on aura platforms Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/window.h" 9 #include "ui/aura/window.h"
10 #include "ui/views/accessibility/ax_aura_obj_wrapper.h" 10 #include "ui/views/accessibility/ax_aura_obj_wrapper.h"
(...skipping 15 matching lines...) Expand all
26 } 26 }
27 27
28 AXAuraObjWrapper* AXAuraObjCache::GetOrCreate(Widget* widget) { 28 AXAuraObjWrapper* AXAuraObjCache::GetOrCreate(Widget* widget) {
29 return CreateInternal<AXWidgetObjWrapper>(widget, widget_to_id_map_); 29 return CreateInternal<AXWidgetObjWrapper>(widget, widget_to_id_map_);
30 } 30 }
31 31
32 AXAuraObjWrapper* AXAuraObjCache::GetOrCreate(aura::Window* window) { 32 AXAuraObjWrapper* AXAuraObjCache::GetOrCreate(aura::Window* window) {
33 return CreateInternal<AXWindowObjWrapper>(window, window_to_id_map_); 33 return CreateInternal<AXWindowObjWrapper>(window, window_to_id_map_);
34 } 34 }
35 35
36 int32_t AXAuraObjCache::GetID(View* view) { 36 int32_t AXAuraObjCache::GetID(View* view) const {
37 return GetIDInternal(view, view_to_id_map_); 37 return GetIDInternal(view, view_to_id_map_);
38 } 38 }
39 39
40 int32_t AXAuraObjCache::GetID(Widget* widget) { 40 int32_t AXAuraObjCache::GetID(Widget* widget) const {
41 return GetIDInternal(widget, widget_to_id_map_); 41 return GetIDInternal(widget, widget_to_id_map_);
42 } 42 }
43 43
44 int32_t AXAuraObjCache::GetID(aura::Window* window) { 44 int32_t AXAuraObjCache::GetID(aura::Window* window) const {
45 return GetIDInternal(window, window_to_id_map_); 45 return GetIDInternal(window, window_to_id_map_);
46 } 46 }
47 47
48 void AXAuraObjCache::Remove(View* view) { 48 void AXAuraObjCache::Remove(View* view) {
49 RemoveInternal(view, view_to_id_map_); 49 RemoveInternal(view, view_to_id_map_);
50 } 50 }
51 51
52 void AXAuraObjCache::RemoveViewSubtree(View* view) { 52 void AXAuraObjCache::RemoveViewSubtree(View* view) {
53 Remove(view); 53 Remove(view);
54 for (int i = 0; i < view->child_count(); ++i) 54 for (int i = 0; i < view->child_count(); ++i)
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 AXAuraObjWrapper* wrapper = new AuraViewWrapper(aura_view); 122 AXAuraObjWrapper* wrapper = new AuraViewWrapper(aura_view);
123 aura_view_to_id_map[aura_view] = current_id_; 123 aura_view_to_id_map[aura_view] = current_id_;
124 cache_[current_id_] = wrapper; 124 cache_[current_id_] = wrapper;
125 current_id_++; 125 current_id_++;
126 return wrapper; 126 return wrapper;
127 } 127 }
128 128
129 template <typename AuraView> 129 template <typename AuraView>
130 int32_t AXAuraObjCache::GetIDInternal( 130 int32_t AXAuraObjCache::GetIDInternal(
131 AuraView* aura_view, 131 AuraView* aura_view,
132 std::map<AuraView*, int32_t>& aura_view_to_id_map) { 132 const std::map<AuraView*, int32_t>& aura_view_to_id_map) const {
133 if (!aura_view) 133 if (!aura_view)
134 return -1; 134 return -1;
135 135
136 typename std::map<AuraView*, int32_t>::iterator it = 136 auto it = aura_view_to_id_map.find(aura_view);
137 aura_view_to_id_map.find(aura_view);
138
139 if (it != aura_view_to_id_map.end()) 137 if (it != aura_view_to_id_map.end())
140 return it->second; 138 return it->second;
141 139
142 return -1; 140 return -1;
143 } 141 }
144 142
145 template <typename AuraView> 143 template <typename AuraView>
146 void AXAuraObjCache::RemoveInternal( 144 void AXAuraObjCache::RemoveInternal(
147 AuraView* aura_view, 145 AuraView* aura_view,
148 std::map<AuraView*, int32_t>& aura_view_to_id_map) { 146 std::map<AuraView*, int32_t>& aura_view_to_id_map) {
149 int32_t id = GetID(aura_view); 147 int32_t id = GetID(aura_view);
150 if (id == -1) 148 if (id == -1)
151 return; 149 return;
152 aura_view_to_id_map.erase(aura_view); 150 aura_view_to_id_map.erase(aura_view);
153 Remove(id); 151 Remove(id);
154 } 152 }
155 153
156 } // namespace views 154 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/accessibility/ax_aura_obj_cache.h ('k') | ui/views/accessibility/ax_aura_obj_cache_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698