| Index: ui/views/accessibility/ax_aura_obj_cache.cc
|
| diff --git a/ui/views/accessibility/ax_aura_obj_cache.cc b/ui/views/accessibility/ax_aura_obj_cache.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..f18279ce713a11ee2a0cb8540c5922a416c352f2
|
| --- /dev/null
|
| +++ b/ui/views/accessibility/ax_aura_obj_cache.cc
|
| @@ -0,0 +1,162 @@
|
| +// 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_aura_obj_cache.h"
|
| +
|
| +#include "base/memory/singleton.h"
|
| +#include "ui/aura/window.h"
|
| +#include "ui/views/accessibility/ax_aura_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
|
| +AXAuraObjCache* AXAuraObjCache::GetInstance() {
|
| + return Singleton<AXAuraObjCache>::get();
|
| +}
|
| +
|
| +AXAuraObjWrapper* AXAuraObjCache::GetOrCreate(View* view) {
|
| + if (!view)
|
| + return NULL;
|
| +
|
| + std::map<View*, int32>::iterator it =
|
| + view_to_id_map_.find(view);
|
| +
|
| + if (it != view_to_id_map_.end())
|
| + return Get(it->second);
|
| +
|
| + AXAuraObjWrapper* wrapper = new AXViewObjWrapper(view);
|
| + view_to_id_map_[view] = current_id_;
|
| + cache_[current_id_] = wrapper;
|
| + current_id_++;
|
| + return wrapper;
|
| +}
|
| +
|
| +AXAuraObjWrapper* AXAuraObjCache::GetOrCreate(Widget* widget) {
|
| + if (!widget)
|
| + return NULL;
|
| +
|
| + std::map<Widget*, int32>::iterator it =
|
| + widget_to_id_map_.find(widget);
|
| +
|
| + if (it != widget_to_id_map_.end())
|
| + return Get(it->second);
|
| +
|
| + AXAuraObjWrapper* wrapper = new AXWidgetObjWrapper(widget);
|
| + widget_to_id_map_[widget] = current_id_;
|
| + cache_[current_id_] = wrapper;
|
| + current_id_++;
|
| + return wrapper;
|
| +}
|
| +
|
| +AXAuraObjWrapper* AXAuraObjCache::GetOrCreate(aura::Window* window) {
|
| + if (!window)
|
| + return NULL;
|
| +
|
| + std::map<aura::Window*, int32>::iterator it =
|
| + window_to_id_map_.find(window);
|
| +
|
| + if (it != window_to_id_map_.end())
|
| + return Get(it->second);
|
| +
|
| + AXAuraObjWrapper* wrapper = new AXWindowObjWrapper(window);
|
| + window_to_id_map_[window] = current_id_;
|
| + cache_[current_id_] = wrapper;
|
| + current_id_++;
|
| + return wrapper;
|
| +}
|
| +
|
| +int32 AXAuraObjCache::GetID(View* view) {
|
| + if (!view)
|
| + return -1;
|
| +
|
| + std::map<View*, int32>::iterator it =
|
| + view_to_id_map_.find(view);
|
| +
|
| + if (it != view_to_id_map_.end())
|
| + return it->second;
|
| +
|
| + return -1;
|
| +}
|
| +
|
| +int32 AXAuraObjCache::GetID(Widget* widget) {
|
| + if (!widget)
|
| + return -1;
|
| +
|
| + std::map<Widget*, int32>::iterator it =
|
| + widget_to_id_map_.find(widget);
|
| +
|
| + if (it != widget_to_id_map_.end())
|
| + return it->second;
|
| +
|
| + return -1;
|
| +}
|
| +
|
| +int32 AXAuraObjCache::GetID(aura::Window* window) {
|
| + if (!window)
|
| + return -1;
|
| +
|
| + std::map<aura::Window*, int32>::iterator it =
|
| + window_to_id_map_.find(window);
|
| +
|
| + if (it != window_to_id_map_.end())
|
| + return it->second;
|
| +
|
| + return -1;
|
| +}
|
| +
|
| +void AXAuraObjCache::Remove(View* view) {
|
| + int32 id = GetID(view);
|
| +
|
| + if (id == -1)
|
| + return;
|
| +
|
| + view_to_id_map_.erase(view);
|
| + Remove(id);
|
| +}
|
| +
|
| +void AXAuraObjCache::Remove(Widget* widget) {
|
| + int32 id = GetID(widget);
|
| +
|
| + if (id == -1)
|
| + return;
|
| +
|
| + widget_to_id_map_.erase(widget);
|
| + Remove(id);
|
| +}
|
| +
|
| +void AXAuraObjCache::Remove(aura::Window* window) {
|
| + int32 id = GetID(window);
|
| +
|
| + if (id == -1)
|
| + return;
|
| +
|
| + window_to_id_map_.erase(window);
|
| + Remove(id);
|
| +}
|
| +
|
| +AXAuraObjWrapper* AXAuraObjCache::Get(int32 id) {
|
| + std::map<int32, AXAuraObjWrapper*>::iterator it = cache_.find(id);
|
| +
|
| + if (it == cache_.end())
|
| + return NULL;
|
| +
|
| + return it->second;
|
| +}
|
| +
|
| +void AXAuraObjCache::Remove(int32 id) {
|
| + AXAuraObjWrapper* obj = Get(id);
|
| +
|
| + if (id == -1 || !obj)
|
| + return;
|
| +
|
| + cache_.erase(id);
|
| + delete obj;
|
| +}
|
| +
|
| +} // namespace views
|
|
|