Sort unlaunched apps on app list start page by apps grid order.
[chromium-blink-merge.git] / ui / views / accessibility / ax_window_obj_wrapper.cc
blobde0dcf2ec4b0f3776088ea349ddaa13ce506b963
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(aura::Window* window)
16 : window_(window), is_alert_(false) {
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 = is_alert_ ? ui::AX_ROLE_ALERT : ui::AX_ROLE_WINDOW;
49 // TODO(dtseng): Set better states.
50 out_node_data->state = 0;
51 out_node_data->location = window_->bounds();
53 // Root windows currently have a non readable name (e.g. Display1234...);
54 // ignore them unless the window is the only node in the tree.
55 if (window_->parent() || window_->children().size() == 0) {
56 out_node_data->AddStringAttribute(ui::AX_ATTR_NAME,
57 base::UTF16ToUTF8(window_->title()));
61 int32 AXWindowObjWrapper::GetID() {
62 return AXAuraObjCache::GetInstance()->GetID(window_);
65 void AXWindowObjWrapper::OnWindowDestroying(aura::Window* window) {
66 AXAuraObjCache::GetInstance()->Remove(window);
69 } // namespace views