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

Unified Diff: ui/views/accessibility/ax_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: Created 6 years, 8 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 side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698