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 "ui/views/accessibility/ax_window_obj_wrapper.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "ui/accessibility/ax_node_data.h"
9 #include "ui/aura/window.h"
10 #include "ui/views/accessibility/ax_aura_obj_cache.h"
11 #include "ui/views/widget/widget.h"
15 AXWindowObjWrapper::AXWindowObjWrapper(
16 aura::Window
* window
) : window_(window
) {
17 window
->AddObserver(this);
20 AXWindowObjWrapper::~AXWindowObjWrapper() {
21 window_
->RemoveObserver(this);
25 AXAuraObjWrapper
* AXWindowObjWrapper::GetParent() {
26 if (!window_
->parent())
29 return AXAuraObjCache::GetInstance()->GetOrCreate(window_
->parent());
32 void AXWindowObjWrapper::GetChildren(
33 std::vector
<AXAuraObjWrapper
*>* out_children
) {
34 aura::Window::Windows children
= window_
->children();
35 for (size_t i
= 0; i
< children
.size(); ++i
) {
36 out_children
->push_back(
37 AXAuraObjCache::GetInstance()->GetOrCreate(children
[i
]));
40 // Also consider any associated widgets as children.
41 Widget
* widget
= Widget::GetWidgetForNativeView(window_
);
43 out_children
->push_back(AXAuraObjCache::GetInstance()->GetOrCreate(widget
));
46 void AXWindowObjWrapper::Serialize(ui::AXNodeData
* out_node_data
) {
47 out_node_data
->id
= GetID();
48 out_node_data
->role
= ui::AX_ROLE_WINDOW
;
49 // TODO(dtseng): Set better states.
50 out_node_data
->state
= 0;
51 out_node_data
->location
= window_
->bounds();
52 out_node_data
->AddStringAttribute(
53 ui::AX_ATTR_NAME
, base::UTF16ToUTF8(window_
->title()));
56 int32
AXWindowObjWrapper::GetID() {
57 return AXAuraObjCache::GetInstance()->GetID(window_
);
60 void AXWindowObjWrapper::OnWindowDestroying(aura::Window
* window
) {
61 AXAuraObjCache::GetInstance()->Remove(window
);