| 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 | 13 |
| 13 namespace ui { | 14 namespace ui { |
| 14 | 15 |
| 15 namespace { | 16 namespace { |
| 16 | 17 |
| 17 using UniqueIdMap = base::hash_map<int32_t, AXPlatformNode*>; | 18 using UniqueIdMap = base::hash_map<int32_t, AXPlatformNode*>; |
| 18 // Map from each AXPlatformNode's unique id to its instance. | 19 // Map from each AXPlatformNode's unique id to its instance. |
| 19 base::LazyInstance<UniqueIdMap>::DestructorAtExit g_unique_id_map = | 20 base::LazyInstance<UniqueIdMap>::DestructorAtExit g_unique_id_map = |
| 20 LAZY_INSTANCE_INITIALIZER; | 21 LAZY_INSTANCE_INITIALIZER; |
| 21 } | 22 } |
| 22 | 23 |
| 23 #if !defined(PLATFORM_HAS_AX_PLATFORM_NODE_IMPL) | |
| 24 // static | |
| 25 AXPlatformNode* AXPlatformNode::Create(AXPlatformNodeDelegate* delegate) { | |
| 26 return nullptr; | |
| 27 } | |
| 28 #endif // !defined(PLATFORM_HAS_AX_PLATFORM_NODE_IMPL) | |
| 29 | |
| 30 #if !defined(OS_WIN) | 24 #if !defined(OS_WIN) |
| 31 // This is the default implementation for platforms where native views | 25 // This is the default implementation for platforms where native views |
| 32 // accessibility is unsupported or unfinished. | 26 // accessibility is unsupported or unfinished. |
| 33 // | 27 // |
| 34 // static | 28 // static |
| 35 AXPlatformNode* AXPlatformNode::FromNativeViewAccessible( | 29 AXPlatformNode* AXPlatformNode::FromNativeViewAccessible( |
| 36 gfx::NativeViewAccessible accessible) { | 30 gfx::NativeViewAccessible accessible) { |
| 37 return nullptr; | 31 return nullptr; |
| 38 } | 32 } |
| 39 #endif | 33 #endif |
| 40 | 34 |
| 41 // static | 35 AXPlatformNode::AXPlatformNode() : unique_id_(GetNextAXPlatformNodeUniqueId()) { |
| 42 int32_t AXPlatformNode::GetNextUniqueId() { | |
| 43 static int32_t next_unique_id = 1; | |
| 44 int32_t unique_id = next_unique_id; | |
| 45 if (next_unique_id == INT32_MAX) | |
| 46 next_unique_id = 1; | |
| 47 else | |
| 48 next_unique_id++; | |
| 49 | |
| 50 return unique_id; | |
| 51 } | |
| 52 | |
| 53 AXPlatformNode::AXPlatformNode() : unique_id_(GetNextUniqueId()) { | |
| 54 g_unique_id_map.Get()[unique_id_] = this; | 36 g_unique_id_map.Get()[unique_id_] = this; |
| 55 } | 37 } |
| 56 | 38 |
| 57 AXPlatformNode::~AXPlatformNode() { | 39 AXPlatformNode::~AXPlatformNode() { |
| 58 if (unique_id_) | 40 if (unique_id_) |
| 59 g_unique_id_map.Get().erase(unique_id_); | 41 g_unique_id_map.Get().erase(unique_id_); |
| 60 } | 42 } |
| 61 | 43 |
| 62 void AXPlatformNode::Destroy() { | 44 void AXPlatformNode::Destroy() { |
| 63 g_unique_id_map.Get().erase(unique_id_); | 45 g_unique_id_map.Get().erase(unique_id_); |
| 64 unique_id_ = 0; | 46 unique_id_ = 0; |
| 65 } | 47 } |
| 66 | 48 |
| 67 AXPlatformNode* AXPlatformNode::GetFromUniqueId(int32_t unique_id) { | 49 AXPlatformNode* AXPlatformNode::GetFromUniqueId(int32_t unique_id) { |
| 68 UniqueIdMap* unique_ids = g_unique_id_map.Pointer(); | 50 UniqueIdMap* unique_ids = g_unique_id_map.Pointer(); |
| 69 auto iter = unique_ids->find(unique_id); | 51 auto iter = unique_ids->find(unique_id); |
| 70 if (iter != unique_ids->end()) | 52 if (iter != unique_ids->end()) |
| 71 return iter->second; | 53 return iter->second; |
| 72 | 54 |
| 73 return nullptr; | 55 return nullptr; |
| 74 } | 56 } |
| 75 | 57 |
| 76 } // namespace ui | 58 } // namespace ui |
| OLD | NEW |