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/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 Loading... |
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 AXAuraObjCache::GetID(View* view) { | 36 int32_t AXAuraObjCache::GetID(View* view) { |
37 return GetIDInternal(view, view_to_id_map_); | 37 return GetIDInternal(view, view_to_id_map_); |
38 } | 38 } |
39 | 39 |
40 int32 AXAuraObjCache::GetID(Widget* widget) { | 40 int32_t AXAuraObjCache::GetID(Widget* widget) { |
41 return GetIDInternal(widget, widget_to_id_map_); | 41 return GetIDInternal(widget, widget_to_id_map_); |
42 } | 42 } |
43 | 43 |
44 int32 AXAuraObjCache::GetID(aura::Window* window) { | 44 int32_t AXAuraObjCache::GetID(aura::Window* window) { |
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) |
55 RemoveViewSubtree(view->child_at(i)); | 55 RemoveViewSubtree(view->child_at(i)); |
56 } | 56 } |
57 | 57 |
58 void AXAuraObjCache::Remove(Widget* widget) { | 58 void AXAuraObjCache::Remove(Widget* widget) { |
59 RemoveInternal(widget, widget_to_id_map_); | 59 RemoveInternal(widget, widget_to_id_map_); |
60 | 60 |
61 // When an entire widget is deleted, it doesn't always send a notification | 61 // When an entire widget is deleted, it doesn't always send a notification |
62 // on each of its views, so we need to explore them recursively. | 62 // on each of its views, so we need to explore them recursively. |
63 if (widget->GetRootView()) | 63 if (widget->GetRootView()) |
64 RemoveViewSubtree(widget->GetRootView()); | 64 RemoveViewSubtree(widget->GetRootView()); |
65 } | 65 } |
66 | 66 |
67 void AXAuraObjCache::Remove(aura::Window* window) { | 67 void AXAuraObjCache::Remove(aura::Window* window) { |
68 RemoveInternal(window, window_to_id_map_); | 68 RemoveInternal(window, window_to_id_map_); |
69 } | 69 } |
70 | 70 |
71 AXAuraObjWrapper* AXAuraObjCache::Get(int32 id) { | 71 AXAuraObjWrapper* AXAuraObjCache::Get(int32_t id) { |
72 std::map<int32, AXAuraObjWrapper*>::iterator it = cache_.find(id); | 72 std::map<int32_t, AXAuraObjWrapper*>::iterator it = cache_.find(id); |
73 | 73 |
74 if (it == cache_.end()) | 74 if (it == cache_.end()) |
75 return NULL; | 75 return NULL; |
76 | 76 |
77 return it->second; | 77 return it->second; |
78 } | 78 } |
79 | 79 |
80 void AXAuraObjCache::Remove(int32 id) { | 80 void AXAuraObjCache::Remove(int32_t id) { |
81 AXAuraObjWrapper* obj = Get(id); | 81 AXAuraObjWrapper* obj = Get(id); |
82 | 82 |
83 if (id == -1 || !obj) | 83 if (id == -1 || !obj) |
84 return; | 84 return; |
85 | 85 |
86 cache_.erase(id); | 86 cache_.erase(id); |
87 delete obj; | 87 delete obj; |
88 } | 88 } |
89 | 89 |
90 void AXAuraObjCache::GetTopLevelWindows( | 90 void AXAuraObjCache::GetTopLevelWindows( |
91 std::vector<AXAuraObjWrapper*>* children) { | 91 std::vector<AXAuraObjWrapper*>* children) { |
92 for (std::map<aura::Window*, int32>::iterator it = window_to_id_map_.begin(); | 92 for (std::map<aura::Window*, int32_t>::iterator it = |
| 93 window_to_id_map_.begin(); |
93 it != window_to_id_map_.end(); ++it) { | 94 it != window_to_id_map_.end(); ++it) { |
94 if (!it->first->parent()) | 95 if (!it->first->parent()) |
95 children->push_back(GetOrCreate(it->first)); | 96 children->push_back(GetOrCreate(it->first)); |
96 } | 97 } |
97 } | 98 } |
98 | 99 |
99 AXAuraObjCache::AXAuraObjCache() : current_id_(1), is_destroying_(false) { | 100 AXAuraObjCache::AXAuraObjCache() : current_id_(1), is_destroying_(false) { |
100 } | 101 } |
101 | 102 |
102 AXAuraObjCache::~AXAuraObjCache() { | 103 AXAuraObjCache::~AXAuraObjCache() { |
103 is_destroying_ = true; | 104 is_destroying_ = true; |
104 STLDeleteContainerPairSecondPointers(cache_.begin(), cache_.end()); | 105 STLDeleteContainerPairSecondPointers(cache_.begin(), cache_.end()); |
105 cache_.clear(); | 106 cache_.clear(); |
106 } | 107 } |
107 | 108 |
108 template <typename AuraViewWrapper, typename AuraView> | 109 template <typename AuraViewWrapper, typename AuraView> |
109 AXAuraObjWrapper* AXAuraObjCache::CreateInternal( | 110 AXAuraObjWrapper* AXAuraObjCache::CreateInternal( |
110 AuraView* aura_view, std::map<AuraView*, int32>& aura_view_to_id_map) { | 111 AuraView* aura_view, |
| 112 std::map<AuraView*, int32_t>& aura_view_to_id_map) { |
111 if (!aura_view) | 113 if (!aura_view) |
112 return NULL; | 114 return NULL; |
113 | 115 |
114 typename std::map<AuraView*, int32>::iterator it = | 116 typename std::map<AuraView*, int32_t>::iterator it = |
115 aura_view_to_id_map.find(aura_view); | 117 aura_view_to_id_map.find(aura_view); |
116 | 118 |
117 if (it != aura_view_to_id_map.end()) | 119 if (it != aura_view_to_id_map.end()) |
118 return Get(it->second); | 120 return Get(it->second); |
119 | 121 |
120 AXAuraObjWrapper* wrapper = new AuraViewWrapper(aura_view); | 122 AXAuraObjWrapper* wrapper = new AuraViewWrapper(aura_view); |
121 aura_view_to_id_map[aura_view] = current_id_; | 123 aura_view_to_id_map[aura_view] = current_id_; |
122 cache_[current_id_] = wrapper; | 124 cache_[current_id_] = wrapper; |
123 current_id_++; | 125 current_id_++; |
124 return wrapper; | 126 return wrapper; |
125 } | 127 } |
126 | 128 |
127 template<typename AuraView> int32 AXAuraObjCache::GetIDInternal( | 129 template <typename AuraView> |
128 AuraView* aura_view, std::map<AuraView*, int32>& aura_view_to_id_map) { | 130 int32_t AXAuraObjCache::GetIDInternal( |
| 131 AuraView* aura_view, |
| 132 std::map<AuraView*, int32_t>& aura_view_to_id_map) { |
129 if (!aura_view) | 133 if (!aura_view) |
130 return -1; | 134 return -1; |
131 | 135 |
132 typename std::map<AuraView*, int32>::iterator it = | 136 typename std::map<AuraView*, int32_t>::iterator it = |
133 aura_view_to_id_map.find(aura_view); | 137 aura_view_to_id_map.find(aura_view); |
134 | 138 |
135 if (it != aura_view_to_id_map.end()) | 139 if (it != aura_view_to_id_map.end()) |
136 return it->second; | 140 return it->second; |
137 | 141 |
138 return -1; | 142 return -1; |
139 } | 143 } |
140 | 144 |
141 template<typename AuraView> | 145 template <typename AuraView> |
142 void AXAuraObjCache::RemoveInternal( | 146 void AXAuraObjCache::RemoveInternal( |
143 AuraView* aura_view, std::map<AuraView*, int32>& aura_view_to_id_map) { | 147 AuraView* aura_view, |
144 int32 id = GetID(aura_view); | 148 std::map<AuraView*, int32_t>& aura_view_to_id_map) { |
| 149 int32_t id = GetID(aura_view); |
145 if (id == -1) | 150 if (id == -1) |
146 return; | 151 return; |
147 aura_view_to_id_map.erase(aura_view); | 152 aura_view_to_id_map.erase(aura_view); |
148 Remove(id); | 153 Remove(id); |
149 } | 154 } |
150 | 155 |
151 } // namespace views | 156 } // namespace views |
OLD | NEW |