OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ui/views/accessibility/ax_obj_cache.h" | |
6 | |
7 #include "base/memory/singleton.h" | |
8 #include "ui/aura/window.h" | |
9 #include "ui/views/accessibility/ax_node_source_obj_wrapper.h" | |
10 #include "ui/views/accessibility/ax_view_obj_wrapper.h" | |
11 #include "ui/views/accessibility/ax_widget_obj_wrapper.h" | |
12 #include "ui/views/accessibility/ax_window_obj_wrapper.h" | |
13 #include "ui/views/view.h" | |
14 #include "ui/views/widget/widget.h" | |
15 | |
16 namespace views { | |
17 | |
18 // static | |
19 AXObjCache* AXObjCache::GetInstance() { | |
20 return Singleton<AXObjCache>::get(); | |
21 } | |
22 | |
23 AXNodeSourceObjWrapper* AXObjCache::GetOrCreate(View* view) { | |
dmazzoni
2014/04/23 05:06:44
I'm assuming these functions will register observe
David Tseng
2014/04/23 18:20:01
The widgets and windows will observe for destructi
| |
24 if (!view) | |
25 return NULL; | |
26 | |
27 std::map<View*, uint32>::iterator it = | |
28 view_to_id_map_.find(view); | |
29 | |
30 if (it != view_to_id_map_.end()) | |
31 return Get(it->second); | |
32 | |
33 AXNodeSourceObjWrapper* wrapper = new AXViewObjWrapper(view); | |
34 view_to_id_map_[view] = current_id_; | |
35 cache_[current_id_] = wrapper; | |
36 current_id_++; | |
37 return wrapper; | |
38 } | |
39 | |
40 AXNodeSourceObjWrapper* AXObjCache::GetOrCreate(Widget* widget) { | |
41 if (!widget) | |
42 return NULL; | |
43 | |
44 std::map<Widget*, uint32>::iterator it = | |
45 widget_to_id_map_.find(widget); | |
46 | |
47 if (it != widget_to_id_map_.end()) | |
48 return Get(it->second); | |
49 | |
50 AXNodeSourceObjWrapper* wrapper = new AXWidgetObjWrapper(widget); | |
51 widget_to_id_map_[widget] = current_id_; | |
52 cache_[current_id_] = wrapper; | |
53 current_id_++; | |
54 return wrapper; | |
55 } | |
56 | |
57 AXNodeSourceObjWrapper* AXObjCache::GetOrCreate(aura::Window* window) { | |
58 if (!window) | |
59 return NULL; | |
60 | |
61 std::map<aura::Window*, uint32>::iterator it = | |
62 window_to_id_map_.find(window); | |
63 | |
64 if (it != window_to_id_map_.end()) | |
65 return Get(it->second); | |
66 | |
67 AXNodeSourceObjWrapper* wrapper = new AXWindowObjWrapper(window); | |
68 window_to_id_map_[window] = current_id_; | |
69 cache_[current_id_] = wrapper; | |
70 current_id_++; | |
71 return wrapper; | |
72 } | |
73 | |
74 uint32 AXObjCache::GetID(View* view) { | |
75 if (!view) | |
76 return -1; | |
77 | |
78 std::map<View*, uint32>::iterator it = | |
79 view_to_id_map_.find(view); | |
80 | |
81 if (it != view_to_id_map_.end()) | |
82 return it->second; | |
83 | |
84 return -1; | |
85 } | |
86 | |
87 uint32 AXObjCache::GetID(Widget* widget) { | |
88 if (!widget) | |
89 return -1; | |
90 | |
91 std::map<Widget*, uint32>::iterator it = | |
92 widget_to_id_map_.find(widget); | |
93 | |
94 if (it != widget_to_id_map_.end()) | |
95 return it->second; | |
96 | |
97 return -1; | |
98 } | |
99 | |
100 uint32 AXObjCache::GetID(aura::Window* window) { | |
101 if (!window) | |
102 return -1; | |
103 | |
104 std::map<aura::Window*, uint32>::iterator it = | |
105 window_to_id_map_.find(window); | |
106 | |
107 if (it != window_to_id_map_.end()) | |
108 return it->second; | |
109 | |
110 return -1; | |
111 } | |
112 | |
113 AXNodeSourceObjWrapper* AXObjCache::Get(uint32 id) { | |
114 std::map<uint32, AXNodeSourceObjWrapper*>::iterator it = cache_.find(id); | |
115 | |
116 if (it == cache_.end()) | |
117 return NULL; | |
118 | |
119 return it->second; | |
120 } | |
121 | |
122 } // namespace views | |
OLD | NEW |