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_window_obj_wrapper.h" 6 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" 12 13 namespace views { 14 AXWindowObjWrapper(aura::Window * window)15AXWindowObjWrapper::AXWindowObjWrapper( 16 aura::Window* window) : window_(window) { 17 window->AddObserver(this); 18 } 19 ~AXWindowObjWrapper()20AXWindowObjWrapper::~AXWindowObjWrapper() { 21 window_->RemoveObserver(this); 22 window_ = NULL; 23 } 24 GetParent()25AXAuraObjWrapper* AXWindowObjWrapper::GetParent() { 26 if (!window_->parent()) 27 return NULL; 28 29 return AXAuraObjCache::GetInstance()->GetOrCreate(window_->parent()); 30 } 31 GetChildren(std::vector<AXAuraObjWrapper * > * out_children)32void 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])); 38 } 39 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)); 44 } 45 Serialize(ui::AXNodeData * out_node_data)46void 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())); 54 } 55 GetID()56int32 AXWindowObjWrapper::GetID() { 57 return AXAuraObjCache::GetInstance()->GetID(window_); 58 } 59 OnWindowDestroying(aura::Window * window)60void AXWindowObjWrapper::OnWindowDestroying(aura::Window* window) { 61 AXAuraObjCache::GetInstance()->Remove(window); 62 } 63 64 } // namespace views 65