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

Side by Side Diff: ui/accessibility/platform/ax_platform_node.cc

Issue 1762143002: Use unique IDs for accessibility nodes on Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix null obj deref in DCHECK Created 4 years, 9 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 unified diff | Download patch
OLDNEW
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"
8 #include "base/lazy_instance.h"
7 #include "build/build_config.h" 9 #include "build/build_config.h"
8 #include "ui/accessibility/ax_node_data.h" 10 #include "ui/accessibility/ax_node_data.h"
9 #include "ui/accessibility/platform/ax_platform_node_delegate.h" 11 #include "ui/accessibility/platform/ax_platform_node_delegate.h"
10 12
11 namespace ui { 13 namespace ui {
12 14
15 namespace {
16
17 using UniqueIdMap = base::hash_map<int32_t, AXPlatformNode*>;
18 // Map from each AXPlatformNode's unique id to its instance.
19 base::LazyInstance<UniqueIdMap> g_unique_id_map =
20 LAZY_INSTANCE_INITIALIZER;
21
22 }
23
13 #if !defined(PLATFORM_HAS_AX_PLATFORM_NODE_IMPL) 24 #if !defined(PLATFORM_HAS_AX_PLATFORM_NODE_IMPL)
14 // static 25 // static
15 AXPlatformNode* AXPlatformNode::Create(AXPlatformNodeDelegate* delegate) { 26 AXPlatformNode* AXPlatformNode::Create(AXPlatformNodeDelegate* delegate) {
16 return nullptr; 27 return nullptr;
17 } 28 }
18 #endif // !defined(PLATFORM_HAS_AX_PLATFORM_NODE_IMPL) 29 #endif // !defined(PLATFORM_HAS_AX_PLATFORM_NODE_IMPL)
19 30
20 #if !defined(OS_WIN) 31 #if !defined(OS_WIN)
21 // This is the default implementation for platforms where native views 32 // This is the default implementation for platforms where native views
22 // accessibility is unsupported or unfinished. 33 // accessibility is unsupported or unfinished.
23 // 34 //
24 // static 35 // static
25 AXPlatformNode* AXPlatformNode::FromNativeViewAccessible( 36 AXPlatformNode* AXPlatformNode::FromNativeViewAccessible(
26 gfx::NativeViewAccessible accessible) { 37 gfx::NativeViewAccessible accessible) {
27 return nullptr; 38 return nullptr;
28 } 39 }
29 #endif 40 #endif
30 41
31 AXPlatformNode::AXPlatformNode() { 42 // static
43 int32_t AXPlatformNode::GetNextUniqueId() {
44 static int32_t next_unique_id = 1;
45 int32_t unique_id = next_unique_id;
46 if (next_unique_id == INT32_MAX)
47 next_unique_id = 1;
48 else
49 next_unique_id++;
50
51 return unique_id;
52 }
53
54 AXPlatformNode::AXPlatformNode() : unique_id_(GetNextUniqueId()) {
55 g_unique_id_map.Get()[unique_id_] = this;
32 } 56 }
33 57
34 AXPlatformNode::~AXPlatformNode() { 58 AXPlatformNode::~AXPlatformNode() {
59 if (unique_id_)
60 g_unique_id_map.Get().erase(unique_id_);
61 }
62
63 void AXPlatformNode::Destroy() {
64 g_unique_id_map.Get().erase(unique_id_);
65 unique_id_ = 0;
66 }
67
68 AXPlatformNode* AXPlatformNode::GetFromUniqueId(int32_t unique_id) {
69 UniqueIdMap* unique_ids = g_unique_id_map.Pointer();
70 auto iter = unique_ids->find(unique_id);
71 if (iter != unique_ids->end())
72 return iter->second;
73
74 return nullptr;
35 } 75 }
36 76
37 } // namespace ui 77 } // namespace ui
OLDNEW
« no previous file with comments | « ui/accessibility/platform/ax_platform_node.h ('k') | ui/accessibility/platform/ax_platform_node_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698