Chromium Code Reviews| Index: ui/views/accessibility/ax_obj_cache.cc |
| diff --git a/ui/views/accessibility/ax_obj_cache.cc b/ui/views/accessibility/ax_obj_cache.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..45f1fa8d2fea19949d09d9b8d60ddea260423aed |
| --- /dev/null |
| +++ b/ui/views/accessibility/ax_obj_cache.cc |
| @@ -0,0 +1,122 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "ui/views/accessibility/ax_obj_cache.h" |
| + |
| +#include "base/memory/singleton.h" |
| +#include "ui/aura/window.h" |
| +#include "ui/views/accessibility/ax_node_source_obj_wrapper.h" |
| +#include "ui/views/accessibility/ax_view_obj_wrapper.h" |
| +#include "ui/views/accessibility/ax_widget_obj_wrapper.h" |
| +#include "ui/views/accessibility/ax_window_obj_wrapper.h" |
| +#include "ui/views/view.h" |
| +#include "ui/views/widget/widget.h" |
| + |
| +namespace views { |
| + |
| +// static |
| +AXObjCache* AXObjCache::GetInstance() { |
| + return Singleton<AXObjCache>::get(); |
| +} |
| + |
| +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
|
| + if (!view) |
| + return NULL; |
| + |
| + std::map<View*, uint32>::iterator it = |
| + view_to_id_map_.find(view); |
| + |
| + if (it != view_to_id_map_.end()) |
| + return Get(it->second); |
| + |
| + AXNodeSourceObjWrapper* wrapper = new AXViewObjWrapper(view); |
| + view_to_id_map_[view] = current_id_; |
| + cache_[current_id_] = wrapper; |
| + current_id_++; |
| + return wrapper; |
| +} |
| + |
| +AXNodeSourceObjWrapper* AXObjCache::GetOrCreate(Widget* widget) { |
| + if (!widget) |
| + return NULL; |
| + |
| + std::map<Widget*, uint32>::iterator it = |
| + widget_to_id_map_.find(widget); |
| + |
| + if (it != widget_to_id_map_.end()) |
| + return Get(it->second); |
| + |
| + AXNodeSourceObjWrapper* wrapper = new AXWidgetObjWrapper(widget); |
| + widget_to_id_map_[widget] = current_id_; |
| + cache_[current_id_] = wrapper; |
| + current_id_++; |
| + return wrapper; |
| +} |
| + |
| +AXNodeSourceObjWrapper* AXObjCache::GetOrCreate(aura::Window* window) { |
| + if (!window) |
| + return NULL; |
| + |
| + std::map<aura::Window*, uint32>::iterator it = |
| + window_to_id_map_.find(window); |
| + |
| + if (it != window_to_id_map_.end()) |
| + return Get(it->second); |
| + |
| + AXNodeSourceObjWrapper* wrapper = new AXWindowObjWrapper(window); |
| + window_to_id_map_[window] = current_id_; |
| + cache_[current_id_] = wrapper; |
| + current_id_++; |
| + return wrapper; |
| +} |
| + |
| +uint32 AXObjCache::GetID(View* view) { |
| + if (!view) |
| + return -1; |
| + |
| + std::map<View*, uint32>::iterator it = |
| + view_to_id_map_.find(view); |
| + |
| + if (it != view_to_id_map_.end()) |
| + return it->second; |
| + |
| + return -1; |
| +} |
| + |
| +uint32 AXObjCache::GetID(Widget* widget) { |
| + if (!widget) |
| + return -1; |
| + |
| + std::map<Widget*, uint32>::iterator it = |
| + widget_to_id_map_.find(widget); |
| + |
| + if (it != widget_to_id_map_.end()) |
| + return it->second; |
| + |
| + return -1; |
| +} |
| + |
| +uint32 AXObjCache::GetID(aura::Window* window) { |
| + if (!window) |
| + return -1; |
| + |
| + std::map<aura::Window*, uint32>::iterator it = |
| + window_to_id_map_.find(window); |
| + |
| + if (it != window_to_id_map_.end()) |
| + return it->second; |
| + |
| + return -1; |
| +} |
| + |
| +AXNodeSourceObjWrapper* AXObjCache::Get(uint32 id) { |
| + std::map<uint32, AXNodeSourceObjWrapper*>::iterator it = cache_.find(id); |
| + |
| + if (it == cache_.end()) |
| + return NULL; |
| + |
| + return it->second; |
| +} |
| + |
| +} // namespace views |