Add include.
[chromium-blink-merge.git] / ui / views / accessibility / ax_window_obj_wrapper.cc
blobb358de58c917ce4ec7c8a2328d726f83dda29349
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"
13 namespace views {
15 AXWindowObjWrapper::AXWindowObjWrapper(
16 aura::Window* window) : window_(window) {
17 window->AddObserver(this);
20 AXWindowObjWrapper::~AXWindowObjWrapper() {
21 window_->RemoveObserver(this);
22 window_ = NULL;
25 AXAuraObjWrapper* AXWindowObjWrapper::GetParent() {
26 if (!window_->parent())
27 return NULL;
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_);
42 if (widget)
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);
64 } // namespace views