OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #include "ui/views/accessibility/ax_view_obj_wrapper.h" | |
6 | |
7 #include "base/strings/utf_string_conversions.h" | |
8 #include "ui/accessibility/ax_node_data.h" | |
9 #include "ui/accessibility/ax_view_state.h" | |
10 #include "ui/views/accessibility/ax_aura_obj_cache.h" | |
11 #include "ui/views/view.h" | |
12 #include "ui/views/widget/widget.h" | |
13 | |
14 namespace views { | |
15 | |
16 AXViewObjWrapper::AXViewObjWrapper(View* view) : view_(view) { | |
17 DCHECK(view->GetWidget()); | |
18 if (view->GetWidget()) | |
19 AXAuraObjCache::GetInstance()->GetOrCreate(view->GetWidget()); | |
20 } | |
21 | |
22 AXViewObjWrapper::~AXViewObjWrapper() {} | |
23 | |
24 AXAuraObjWrapper* AXViewObjWrapper::GetParent() { | |
25 AXAuraObjCache* cache = AXAuraObjCache::GetInstance(); | |
26 if (view_->parent()) | |
27 return cache->GetOrCreate(view_->parent()); | |
28 | |
29 return cache->GetOrCreate(view_->GetWidget()); | |
30 } | |
31 | |
32 void AXViewObjWrapper::GetChildren( | |
33 std::vector<AXAuraObjWrapper*>* out_children) { | |
34 // TODO(dtseng): Need to handle |Widget| child of |View|. | |
35 for (int i = 0; i < view_->child_count(); ++i) { | |
36 AXAuraObjWrapper* child = | |
37 AXAuraObjCache::GetInstance()->GetOrCreate(view_->child_at(i)); | |
38 out_children->push_back(child); | |
39 } | |
40 } | |
41 | |
42 void AXViewObjWrapper::Serialize(ui::AXNodeData* out_node_data) { | |
43 ui::AXViewState view_data; | |
44 const_cast<View*>(view_)->GetAccessibleState(&view_data); | |
aboxhall
2014/04/28 19:50:38
Why is this cast necessary?
David Tseng
2014/04/29 01:35:03
Removed; (not sure, at some point, it was needed).
| |
45 out_node_data->id = GetID(); | |
46 out_node_data->role = view_data.role; | |
47 out_node_data->state = view_data.state(); | |
48 out_node_data->location = view_->GetBoundsInScreen(); | |
49 | |
50 out_node_data->AddStringAttribute( | |
51 ui::AX_ATTR_NAME, base::UTF16ToUTF8(view_data.name)); | |
52 out_node_data->AddStringAttribute( | |
53 ui::AX_ATTR_VALUE, base::UTF16ToUTF8(view_data.value)); | |
54 | |
55 out_node_data->AddIntAttribute(ui::AX_ATTR_TEXT_SEL_START, | |
56 view_data.selection_start); | |
57 out_node_data->AddIntAttribute(ui::AX_ATTR_TEXT_SEL_END, | |
58 view_data.selection_end); | |
59 } | |
60 | |
61 int32 AXViewObjWrapper::GetID() { | |
62 return AXAuraObjCache::GetInstance()->GetID(view_); | |
63 } | |
64 | |
65 } // namespace views | |
OLD | NEW |