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 "chrome/browser/ui/aura/accessibility/ax_tree_source_aura.h" | 5 #include "chrome/browser/ui/ash/accessibility/ax_tree_source_ash.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "chrome/browser/accessibility/ax_tree_id_registry.h" | 9 #include "chrome/browser/accessibility/ax_tree_id_registry.h" |
10 #include "chrome/browser/ui/aura/accessibility/automation_manager_aura.h" | 10 #include "chrome/browser/ui/ash/accessibility/automation_manager_ash.h" |
11 #include "content/public/browser/render_frame_host.h" | 11 #include "content/public/browser/render_frame_host.h" |
12 #include "content/public/browser/render_process_host.h" | 12 #include "content/public/browser/render_process_host.h" |
13 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
14 #include "ui/views/accessibility/ax_aura_obj_cache.h" | 14 #include "ui/views/accessibility/ax_aura_obj_cache.h" |
15 #include "ui/views/accessibility/ax_aura_obj_wrapper.h" | 15 #include "ui/views/accessibility/ax_aura_obj_wrapper.h" |
16 #include "ui/views/accessibility/ax_view_obj_wrapper.h" | 16 #include "ui/views/accessibility/ax_view_obj_wrapper.h" |
17 #include "ui/views/controls/webview/webview.h" | 17 #include "ui/views/controls/webview/webview.h" |
18 | 18 |
19 using views::AXAuraObjCache; | 19 using views::AXAuraObjCache; |
20 using views::AXAuraObjWrapper; | 20 using views::AXAuraObjWrapper; |
21 | 21 |
22 AXTreeSourceAura::AXTreeSourceAura() { | 22 AXTreeSourceAsh::AXTreeSourceAsh() { |
23 root_.reset(new AXRootObjWrapper(AXAuraObjCache::GetInstance()->GetNextID())); | 23 root_.reset( |
| 24 new AXRootObjWrapper(AXAuraObjCache::GetInstance()->GetNextID())); |
24 } | 25 } |
25 | 26 |
26 AXTreeSourceAura::~AXTreeSourceAura() { | 27 AXTreeSourceAsh::~AXTreeSourceAsh() { |
27 root_.reset(); | 28 root_.reset(); |
28 } | 29 } |
29 | 30 |
30 void AXTreeSourceAura::DoDefault(int32 id) { | 31 void AXTreeSourceAsh::DoDefault(int32 id) { |
31 AXAuraObjWrapper* obj = AXAuraObjCache::GetInstance()->Get(id); | 32 AXAuraObjWrapper* obj = AXAuraObjCache::GetInstance()->Get(id); |
32 CHECK(obj); | 33 CHECK(obj); |
33 obj->DoDefault(); | 34 obj->DoDefault(); |
34 } | 35 } |
35 | 36 |
36 void AXTreeSourceAura::Focus(int32 id) { | 37 void AXTreeSourceAsh::Focus(int32 id) { |
37 AXAuraObjWrapper* obj = AXAuraObjCache::GetInstance()->Get(id); | 38 AXAuraObjWrapper* obj = AXAuraObjCache::GetInstance()->Get(id); |
38 CHECK(obj); | 39 CHECK(obj); |
39 obj->Focus(); | 40 obj->Focus(); |
40 } | 41 } |
41 | 42 |
42 void AXTreeSourceAura::MakeVisible(int32 id) { | 43 void AXTreeSourceAsh::MakeVisible(int32 id) { |
43 AXAuraObjWrapper* obj = AXAuraObjCache::GetInstance()->Get(id); | 44 AXAuraObjWrapper* obj = AXAuraObjCache::GetInstance()->Get(id); |
44 CHECK(obj); | 45 CHECK(obj); |
45 obj->MakeVisible(); | 46 obj->MakeVisible(); |
46 } | 47 } |
47 | 48 |
48 void AXTreeSourceAura::SetSelection(int32 id, int32 start, int32 end) { | 49 void AXTreeSourceAsh::SetSelection(int32 id, int32 start, int32 end) { |
49 AXAuraObjWrapper* obj = AXAuraObjCache::GetInstance()->Get(id); | 50 AXAuraObjWrapper* obj = AXAuraObjCache::GetInstance()->Get(id); |
50 CHECK(obj); | 51 CHECK(obj); |
51 obj->SetSelection(start, end); | 52 obj->SetSelection(start, end); |
52 } | 53 } |
53 | 54 |
54 AXAuraObjWrapper* AXTreeSourceAura::GetRoot() const { | 55 AXAuraObjWrapper* AXTreeSourceAsh::GetRoot() const { |
55 return root_.get(); | 56 return root_.get(); |
56 } | 57 } |
57 | 58 |
58 AXAuraObjWrapper* AXTreeSourceAura::GetFromId(int32 id) const { | 59 AXAuraObjWrapper* AXTreeSourceAsh::GetFromId(int32 id) const { |
59 if (id == root_->GetID()) | 60 if (id == root_->GetID()) |
60 return root_.get(); | 61 return root_.get(); |
61 return AXAuraObjCache::GetInstance()->Get(id); | 62 return AXAuraObjCache::GetInstance()->Get(id); |
62 } | 63 } |
63 | 64 |
64 int32 AXTreeSourceAura::GetId(AXAuraObjWrapper* node) const { | 65 int32 AXTreeSourceAsh::GetId(AXAuraObjWrapper* node) const { |
65 return node->GetID(); | 66 return node->GetID(); |
66 } | 67 } |
67 | 68 |
68 void AXTreeSourceAura::GetChildren( | 69 void AXTreeSourceAsh::GetChildren(AXAuraObjWrapper* node, |
69 AXAuraObjWrapper* node, | |
70 std::vector<AXAuraObjWrapper*>* out_children) const { | 70 std::vector<AXAuraObjWrapper*>* out_children) const { |
71 node->GetChildren(out_children); | 71 node->GetChildren(out_children); |
72 } | 72 } |
73 | 73 |
74 AXAuraObjWrapper* AXTreeSourceAura::GetParent(AXAuraObjWrapper* node) const { | 74 AXAuraObjWrapper* AXTreeSourceAsh::GetParent(AXAuraObjWrapper* node) const { |
75 AXAuraObjWrapper* parent = node->GetParent(); | 75 AXAuraObjWrapper* parent = node->GetParent(); |
76 if (!parent && node->GetID() != root_->GetID()) | 76 if (!parent && node->GetID() != root_->GetID()) |
77 parent = root_.get(); | 77 parent = root_.get(); |
78 return parent; | 78 return parent; |
79 } | 79 } |
80 | 80 |
81 bool AXTreeSourceAura::IsValid(AXAuraObjWrapper* node) const { | 81 bool AXTreeSourceAsh::IsValid(AXAuraObjWrapper* node) const { |
82 return node && node->GetID() != -1; | 82 return node && node->GetID() != -1; |
83 } | 83 } |
84 | 84 |
85 bool AXTreeSourceAura::IsEqual(AXAuraObjWrapper* node1, | 85 bool AXTreeSourceAsh::IsEqual(AXAuraObjWrapper* node1, |
86 AXAuraObjWrapper* node2) const { | 86 AXAuraObjWrapper* node2) const { |
87 if (!node1 || !node2) | 87 if (!node1 || !node2) |
88 return false; | 88 return false; |
89 | 89 |
90 return node1->GetID() == node2->GetID() && node1->GetID() != -1; | 90 return node1->GetID() == node2->GetID() && node1->GetID() != -1; |
91 } | 91 } |
92 | 92 |
93 AXAuraObjWrapper* AXTreeSourceAura::GetNull() const { | 93 AXAuraObjWrapper* AXTreeSourceAsh::GetNull() const { |
94 return NULL; | 94 return NULL; |
95 } | 95 } |
96 | 96 |
97 void AXTreeSourceAura::SerializeNode(AXAuraObjWrapper* node, | 97 void AXTreeSourceAsh::SerializeNode( |
98 ui::AXNodeData* out_data) const { | 98 AXAuraObjWrapper* node, ui::AXNodeData* out_data) const { |
99 node->Serialize(out_data); | 99 node->Serialize(out_data); |
100 | 100 |
101 if (out_data->role == ui::AX_ROLE_WEB_VIEW) { | 101 if (out_data->role == ui::AX_ROLE_WEB_VIEW) { |
102 views::View* view = static_cast<views::AXViewObjWrapper*>(node)->view(); | 102 views::View* view = static_cast<views::AXViewObjWrapper*>(node)->view(); |
103 content::WebContents* contents = | 103 content::WebContents* contents = |
104 static_cast<views::WebView*>(view)->GetWebContents(); | 104 static_cast<views::WebView*>(view)->GetWebContents(); |
105 content::RenderFrameHost* rfh = contents->GetMainFrame(); | 105 content::RenderFrameHost* rfh = contents->GetMainFrame(); |
106 if (rfh) { | 106 if (rfh) { |
107 int process_id = rfh->GetProcess()->GetID(); | 107 int process_id = rfh->GetProcess()->GetID(); |
108 int routing_id = rfh->GetRoutingID(); | 108 int routing_id = rfh->GetRoutingID(); |
109 int ax_tree_id = AXTreeIDRegistry::GetInstance()->GetOrCreateAXTreeID( | 109 int ax_tree_id = AXTreeIDRegistry::GetInstance()->GetOrCreateAXTreeID( |
110 process_id, routing_id); | 110 process_id, routing_id); |
111 out_data->AddIntAttribute(ui::AX_ATTR_CHILD_TREE_ID, ax_tree_id); | 111 out_data->AddIntAttribute(ui::AX_ATTR_CHILD_TREE_ID, ax_tree_id); |
112 } | 112 } |
113 } | 113 } |
114 } | 114 } |
115 | 115 |
116 std::string AXTreeSourceAura::ToString(AXAuraObjWrapper* root, | 116 std::string AXTreeSourceAsh::ToString( |
117 std::string prefix) { | 117 AXAuraObjWrapper* root, std::string prefix) { |
118 ui::AXNodeData data; | 118 ui::AXNodeData data; |
119 root->Serialize(&data); | 119 root->Serialize(&data); |
120 std::string output = prefix + data.ToString() + '\n'; | 120 std::string output = prefix + data.ToString() + '\n'; |
121 | 121 |
122 std::vector<AXAuraObjWrapper*> children; | 122 std::vector<AXAuraObjWrapper*> children; |
123 root->GetChildren(&children); | 123 root->GetChildren(&children); |
124 | 124 |
125 prefix += prefix[0]; | 125 prefix += prefix[0]; |
126 for (size_t i = 0; i < children.size(); ++i) | 126 for (size_t i = 0; i < children.size(); ++i) |
127 output += ToString(children[i], prefix); | 127 output += ToString(children[i], prefix); |
128 | 128 |
129 return output; | 129 return output; |
130 } | 130 } |
OLD | NEW |