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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/aura/accessibility/ax_tree_source_aura.h"
9 #include "chrome/browser/accessibility/ax_tree_id_registry.h"
10 #include "chrome/browser/ui/aura/accessibility/automation_manager_aura.h"
11 #include "content/public/browser/render_frame_host.h"
12 #include "content/public/browser/render_process_host.h"
13 #include "content/public/browser/web_contents.h"
14 #include "ui/views/accessibility/ax_aura_obj_cache.h"
15 #include "ui/views/accessibility/ax_aura_obj_wrapper.h"
16 #include "ui/views/accessibility/ax_view_obj_wrapper.h"
17 #include "ui/views/controls/webview/webview.h"
19 using views::AXAuraObjCache
;
20 using views::AXAuraObjWrapper
;
22 AXTreeSourceAura::AXTreeSourceAura() {
23 root_
.reset(new AXRootObjWrapper(AXAuraObjCache::GetInstance()->GetNextID()));
26 AXTreeSourceAura::~AXTreeSourceAura() {
30 void AXTreeSourceAura::DoDefault(int32 id
) {
31 AXAuraObjWrapper
* obj
= AXAuraObjCache::GetInstance()->Get(id
);
36 void AXTreeSourceAura::Focus(int32 id
) {
37 AXAuraObjWrapper
* obj
= AXAuraObjCache::GetInstance()->Get(id
);
42 void AXTreeSourceAura::MakeVisible(int32 id
) {
43 AXAuraObjWrapper
* obj
= AXAuraObjCache::GetInstance()->Get(id
);
48 void AXTreeSourceAura::SetSelection(int32 id
, int32 start
, int32 end
) {
49 AXAuraObjWrapper
* obj
= AXAuraObjCache::GetInstance()->Get(id
);
51 obj
->SetSelection(start
, end
);
54 AXAuraObjWrapper
* AXTreeSourceAura::GetRoot() const {
58 AXAuraObjWrapper
* AXTreeSourceAura::GetFromId(int32 id
) const {
59 if (id
== root_
->GetID())
61 return AXAuraObjCache::GetInstance()->Get(id
);
64 int32
AXTreeSourceAura::GetId(AXAuraObjWrapper
* node
) const {
68 void AXTreeSourceAura::GetChildren(
69 AXAuraObjWrapper
* node
,
70 std::vector
<AXAuraObjWrapper
*>* out_children
) const {
71 node
->GetChildren(out_children
);
74 AXAuraObjWrapper
* AXTreeSourceAura::GetParent(AXAuraObjWrapper
* node
) const {
75 AXAuraObjWrapper
* parent
= node
->GetParent();
76 if (!parent
&& node
->GetID() != root_
->GetID())
81 bool AXTreeSourceAura::IsValid(AXAuraObjWrapper
* node
) const {
82 return node
&& node
->GetID() != -1;
85 bool AXTreeSourceAura::IsEqual(AXAuraObjWrapper
* node1
,
86 AXAuraObjWrapper
* node2
) const {
90 return node1
->GetID() == node2
->GetID() && node1
->GetID() != -1;
93 AXAuraObjWrapper
* AXTreeSourceAura::GetNull() const {
97 void AXTreeSourceAura::SerializeNode(AXAuraObjWrapper
* node
,
98 ui::AXNodeData
* out_data
) const {
99 node
->Serialize(out_data
);
101 if (out_data
->role
== ui::AX_ROLE_WEB_VIEW
) {
102 views::View
* view
= static_cast<views::AXViewObjWrapper
*>(node
)->view();
103 content::WebContents
* contents
=
104 static_cast<views::WebView
*>(view
)->GetWebContents();
105 content::RenderFrameHost
* rfh
= contents
->GetMainFrame();
107 int process_id
= rfh
->GetProcess()->GetID();
108 int routing_id
= rfh
->GetRoutingID();
109 int ax_tree_id
= AXTreeIDRegistry::GetInstance()->GetOrCreateAXTreeID(
110 process_id
, routing_id
);
111 out_data
->AddIntAttribute(ui::AX_ATTR_CHILD_TREE_ID
, ax_tree_id
);
116 std::string
AXTreeSourceAura::ToString(AXAuraObjWrapper
* root
,
117 std::string prefix
) {
119 root
->Serialize(&data
);
120 std::string output
= prefix
+ data
.ToString() + '\n';
122 std::vector
<AXAuraObjWrapper
*> children
;
123 root
->GetChildren(&children
);
126 for (size_t i
= 0; i
< children
.size(); ++i
)
127 output
+= ToString(children
[i
], prefix
);