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

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

Issue 246433012: Extend AXTreeSourceViews to handle aura::Window and views::Widget. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move files from c/b/u/views/accessibility to c/b/u/ash/accessibility Created 6 years, 7 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 | Annotate | Revision Log
OLDNEW
(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_aura_obj_cache.h"
6
7 #include "base/memory/singleton.h"
8 #include "ui/aura/window.h"
9 #include "ui/views/accessibility/ax_aura_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 AXAuraObjCache* AXAuraObjCache::GetInstance() {
20 return Singleton<AXAuraObjCache>::get();
21 }
22
23 AXAuraObjWrapper* AXAuraObjCache::GetOrCreate(View* view) {
24 return CreateInternal<AXViewObjWrapper>(view, view_to_id_map_);
25 }
26
27 AXAuraObjWrapper* AXAuraObjCache::GetOrCreate(Widget* widget) {
28 return CreateInternal<AXWidgetObjWrapper>(widget, widget_to_id_map_);
29 }
30
31 AXAuraObjWrapper* AXAuraObjCache::GetOrCreate(aura::Window* window) {
32 return CreateInternal<AXWindowObjWrapper>(window, window_to_id_map_);
33 }
34
35 int32 AXAuraObjCache::GetID(View* view) {
36 return GetIDInternal(view, view_to_id_map_);
37 }
38
39 int32 AXAuraObjCache::GetID(Widget* widget) {
40 return GetIDInternal(widget, widget_to_id_map_);
41 }
42
43 int32 AXAuraObjCache::GetID(aura::Window* window) {
44 return GetIDInternal(window, window_to_id_map_);
45 }
46
47 void AXAuraObjCache::Remove(View* view) {
48 RemoveInternal(view, view_to_id_map_);
49 }
50
51 void AXAuraObjCache::Remove(Widget* widget) {
52 RemoveInternal(widget, widget_to_id_map_);
53 }
54
55 void AXAuraObjCache::Remove(aura::Window* window) {
56 RemoveInternal(window, window_to_id_map_);
57 }
58
59 AXAuraObjWrapper* AXAuraObjCache::Get(int32 id) {
60 std::map<int32, AXAuraObjWrapper*>::iterator it = cache_.find(id);
61
62 if (it == cache_.end())
63 return NULL;
64
65 return it->second;
66 }
67
68 void AXAuraObjCache::Remove(int32 id) {
69 AXAuraObjWrapper* obj = Get(id);
70
71 if (id == -1 || !obj)
72 return;
73
74 cache_.erase(id);
75 delete obj;
76 }
77
78 AXAuraObjCache::AXAuraObjCache() : current_id_(1) {
79 }
80
81 AXAuraObjCache::~AXAuraObjCache() {}
82
83 template <typename AuraViewWrapper, typename AuraView>
84 AXAuraObjWrapper* AXAuraObjCache::CreateInternal(
85 AuraView* aura_view, std::map<AuraView*, int32>& aura_view_to_id_map) {
86 if (!aura_view)
87 return NULL;
88
89 typename std::map<AuraView*, int32>::iterator it =
90 aura_view_to_id_map.find(aura_view);
91
92 if (it != aura_view_to_id_map.end())
93 return Get(it->second);
94
95 AXAuraObjWrapper* wrapper = new AuraViewWrapper(aura_view);
96 aura_view_to_id_map[aura_view] = current_id_;
97 cache_[current_id_] = wrapper;
98 current_id_++;
99 return wrapper;
100 }
101
102 template<typename AuraView> int32 AXAuraObjCache::GetIDInternal(
103 AuraView* aura_view, std::map<AuraView*, int32>& aura_view_to_id_map) {
104 if (!aura_view)
105 return -1;
106
107 typename std::map<AuraView*, int32>::iterator it =
108 aura_view_to_id_map.find(aura_view);
109
110 if (it != aura_view_to_id_map.end())
111 return it->second;
112
113 return -1;
114 }
115
116 template<typename AuraView>
117 void AXAuraObjCache::RemoveInternal(
118 AuraView* aura_view, std::map<AuraView*, int32>& aura_view_to_id_map) {
119 int32 id = GetID(aura_view);
120 if (id == -1)
121 return;
122 aura_view_to_id_map.erase(aura_view);
123 Remove(id);
124 }
125
126 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/accessibility/ax_aura_obj_cache.h ('k') | ui/views/accessibility/ax_aura_obj_wrapper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698