| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/accessibility/platform/ax_platform_node.h" | 5 #include "ui/accessibility/platform/ax_platform_node.h" |
| 6 | 6 |
| 7 #include "base/containers/hash_tables.h" | 7 #include "base/containers/hash_tables.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 #include "ui/accessibility/ax_node_data.h" | 10 #include "ui/accessibility/ax_node_data.h" |
| 11 #include "ui/accessibility/platform/ax_platform_node_delegate.h" | 11 #include "ui/accessibility/platform/ax_platform_node_delegate.h" |
| 12 #include "ui/accessibility/platform/ax_platform_unique_id.h" | 12 #include "ui/accessibility/platform/ax_platform_unique_id.h" |
| 13 | 13 |
| 14 namespace ui { | 14 namespace ui { |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 using UniqueIdMap = base::hash_map<int32_t, AXPlatformNode*>; | 18 using UniqueIdMap = base::hash_map<int32_t, AXPlatformNode*>; |
| 19 // Map from each AXPlatformNode's unique id to its instance. | 19 // Map from each AXPlatformNode's unique id to its instance. |
| 20 base::LazyInstance<UniqueIdMap>::DestructorAtExit g_unique_id_map = | 20 base::LazyInstance<UniqueIdMap>::DestructorAtExit g_unique_id_map = |
| 21 LAZY_INSTANCE_INITIALIZER; | 21 LAZY_INSTANCE_INITIALIZER; |
| 22 } | 22 } |
| 23 | 23 |
| 24 #if !defined(OS_WIN) | |
| 25 // This is the default implementation for platforms where native views | |
| 26 // accessibility is unsupported or unfinished. | |
| 27 // | |
| 28 // static | |
| 29 AXPlatformNode* AXPlatformNode::FromNativeViewAccessible( | |
| 30 gfx::NativeViewAccessible accessible) { | |
| 31 return nullptr; | |
| 32 } | |
| 33 #endif | |
| 34 | |
| 35 AXPlatformNode::AXPlatformNode() : unique_id_(GetNextAXPlatformNodeUniqueId()) { | 24 AXPlatformNode::AXPlatformNode() : unique_id_(GetNextAXPlatformNodeUniqueId()) { |
| 36 g_unique_id_map.Get()[unique_id_] = this; | 25 g_unique_id_map.Get()[unique_id_] = this; |
| 37 } | 26 } |
| 38 | 27 |
| 39 AXPlatformNode::~AXPlatformNode() { | 28 AXPlatformNode::~AXPlatformNode() { |
| 40 if (unique_id_) | 29 if (unique_id_) |
| 41 g_unique_id_map.Get().erase(unique_id_); | 30 g_unique_id_map.Get().erase(unique_id_); |
| 42 } | 31 } |
| 43 | 32 |
| 44 void AXPlatformNode::Destroy() { | 33 void AXPlatformNode::Destroy() { |
| 45 g_unique_id_map.Get().erase(unique_id_); | 34 g_unique_id_map.Get().erase(unique_id_); |
| 46 unique_id_ = 0; | 35 unique_id_ = 0; |
| 47 } | 36 } |
| 48 | 37 |
| 49 AXPlatformNode* AXPlatformNode::GetFromUniqueId(int32_t unique_id) { | 38 AXPlatformNode* AXPlatformNode::GetFromUniqueId(int32_t unique_id) { |
| 50 UniqueIdMap* unique_ids = g_unique_id_map.Pointer(); | 39 UniqueIdMap* unique_ids = g_unique_id_map.Pointer(); |
| 51 auto iter = unique_ids->find(unique_id); | 40 auto iter = unique_ids->find(unique_id); |
| 52 if (iter != unique_ids->end()) | 41 if (iter != unique_ids->end()) |
| 53 return iter->second; | 42 return iter->second; |
| 54 | 43 |
| 55 return nullptr; | 44 return nullptr; |
| 56 } | 45 } |
| 57 | 46 |
| 58 } // namespace ui | 47 } // namespace ui |
| OLD | NEW |