1 // Copyright (c) 2013 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/native_view_accessibility.h" 6 7 #include "ui/accessibility/ax_view_state.h" 8 #include "ui/views/view.h" 9 #include "ui/views/widget/widget.h" 10 11 namespace views { 12 13 #if !defined(OS_WIN) 14 // static Create(View * view)15NativeViewAccessibility* NativeViewAccessibility::Create(View* view) { 16 DCHECK(view); 17 NativeViewAccessibility* instance = new NativeViewAccessibility(); 18 instance->set_view(view); 19 return instance; 20 } 21 #endif 22 NativeViewAccessibility()23NativeViewAccessibility::NativeViewAccessibility() 24 : view_(NULL), ax_node_(ui::AXPlatformNode::Create(this)) { 25 } 26 ~NativeViewAccessibility()27NativeViewAccessibility::~NativeViewAccessibility() { 28 if (ax_node_) 29 ax_node_->Destroy(); 30 } 31 GetNativeObject()32gfx::NativeViewAccessible NativeViewAccessibility::GetNativeObject() { 33 return ax_node_ ? ax_node_->GetNativeViewAccessible() : NULL; 34 } 35 Destroy()36void NativeViewAccessibility::Destroy() { 37 delete this; 38 } 39 40 #if !defined(OS_WIN) 41 // static RegisterWebView(View * web_view)42void NativeViewAccessibility::RegisterWebView(View* web_view) { 43 } 44 45 // static UnregisterWebView(View * web_view)46void NativeViewAccessibility::UnregisterWebView(View* web_view) { 47 } 48 #endif 49 50 // ui::AXPlatformNodeDelegate 51 GetData()52ui::AXNodeData* NativeViewAccessibility::GetData() { 53 ui::AXViewState state; 54 view_->GetAccessibleState(&state); 55 data_.role = state.role; 56 data_.location = view_->GetBoundsInScreen(); 57 return &data_; 58 } 59 GetChildCount()60int NativeViewAccessibility::GetChildCount() { 61 return view_->child_count(); 62 } 63 ChildAtIndex(int index)64gfx::NativeViewAccessible NativeViewAccessibility::ChildAtIndex(int index) { 65 if (index < 0 || index >= view_->child_count()) 66 return NULL; 67 return view_->child_at(index)->GetNativeViewAccessible(); 68 } 69 GetParent()70gfx::NativeViewAccessible NativeViewAccessibility::GetParent() { 71 if (view_->parent()) 72 return view_->parent()->GetNativeViewAccessible(); 73 74 #if defined(OS_MACOSX) 75 if (view_->GetWidget()) 76 return view_->GetWidget()->GetNativeView(); 77 #endif 78 79 return NULL; 80 } 81 GetGlobalCoordinateOffset()82gfx::Vector2d NativeViewAccessibility::GetGlobalCoordinateOffset() { 83 return gfx::Vector2d(0, 0); // location is already in screen coordinates. 84 } 85 NotifyAccessibilityEvent(ui::AXEvent event_type)86void NativeViewAccessibility::NotifyAccessibilityEvent(ui::AXEvent event_type) { 87 } 88 89 } // namespace views 90