Home | History | Annotate | Download | only in accessibility
      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
     15 NativeViewAccessibility* NativeViewAccessibility::Create(View* view) {
     16   DCHECK(view);
     17   NativeViewAccessibility* instance = new NativeViewAccessibility();
     18   instance->set_view(view);
     19   return instance;
     20 }
     21 #endif
     22 
     23 NativeViewAccessibility::NativeViewAccessibility()
     24     : view_(NULL), ax_node_(ui::AXPlatformNode::Create(this)) {
     25 }
     26 
     27 NativeViewAccessibility::~NativeViewAccessibility() {
     28   if (ax_node_)
     29     ax_node_->Destroy();
     30 }
     31 
     32 gfx::NativeViewAccessible NativeViewAccessibility::GetNativeObject() {
     33   return ax_node_ ? ax_node_->GetNativeViewAccessible() : NULL;
     34 }
     35 
     36 void NativeViewAccessibility::Destroy() {
     37   delete this;
     38 }
     39 
     40 #if !defined(OS_WIN)
     41 // static
     42 void NativeViewAccessibility::RegisterWebView(View* web_view) {
     43 }
     44 
     45 // static
     46 void NativeViewAccessibility::UnregisterWebView(View* web_view) {
     47 }
     48 #endif
     49 
     50 // ui::AXPlatformNodeDelegate
     51 
     52 ui::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 
     60 int NativeViewAccessibility::GetChildCount() {
     61   return view_->child_count();
     62 }
     63 
     64 gfx::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 
     70 gfx::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 
     82 gfx::Vector2d NativeViewAccessibility::GetGlobalCoordinateOffset() {
     83   return gfx::Vector2d(0, 0);  // location is already in screen coordinates.
     84 }
     85 
     86 void NativeViewAccessibility::NotifyAccessibilityEvent(ui::AXEvent event_type) {
     87 }
     88 
     89 }  // namespace views
     90