OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/views/accessibility/ax_window_obj_wrapper.h" | 5 #include "ui/views/accessibility/ax_window_obj_wrapper.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "ui/accessibility/ax_action_data.h" |
10 #include "ui/accessibility/ax_node_data.h" | 11 #include "ui/accessibility/ax_node_data.h" |
11 #include "ui/accessibility/platform/aura_window_properties.h" | 12 #include "ui/accessibility/platform/aura_window_properties.h" |
12 #include "ui/aura/window.h" | 13 #include "ui/aura/window.h" |
13 #include "ui/views/accessibility/ax_aura_obj_cache.h" | 14 #include "ui/views/accessibility/ax_aura_obj_cache.h" |
14 #include "ui/views/widget/widget.h" | 15 #include "ui/views/widget/widget.h" |
15 | 16 |
16 namespace views { | 17 namespace views { |
17 | 18 |
18 AXWindowObjWrapper::AXWindowObjWrapper(aura::Window* window) | 19 AXWindowObjWrapper::AXWindowObjWrapper(aura::Window* window) |
19 : window_(window), is_alert_(false) { | 20 : window_(window), is_alert_(false) { |
(...skipping 27 matching lines...) Expand all Loading... |
47 if (widget && widget->IsVisible()) | 48 if (widget && widget->IsVisible()) |
48 out_children->push_back(AXAuraObjCache::GetInstance()->GetOrCreate(widget)); | 49 out_children->push_back(AXAuraObjCache::GetInstance()->GetOrCreate(widget)); |
49 } | 50 } |
50 | 51 |
51 void AXWindowObjWrapper::Serialize(ui::AXNodeData* out_node_data) { | 52 void AXWindowObjWrapper::Serialize(ui::AXNodeData* out_node_data) { |
52 out_node_data->id = GetID(); | 53 out_node_data->id = GetID(); |
53 out_node_data->role = is_alert_ ? ui::AX_ROLE_ALERT : ui::AX_ROLE_WINDOW; | 54 out_node_data->role = is_alert_ ? ui::AX_ROLE_ALERT : ui::AX_ROLE_WINDOW; |
54 out_node_data->AddStringAttribute(ui::AX_ATTR_NAME, | 55 out_node_data->AddStringAttribute(ui::AX_ATTR_NAME, |
55 base::UTF16ToUTF8(window_->GetTitle())); | 56 base::UTF16ToUTF8(window_->GetTitle())); |
56 out_node_data->state = 0; | 57 out_node_data->state = 0; |
57 out_node_data->location = gfx::RectF(window_->bounds()); | 58 out_node_data->location = gfx::RectF(window_->GetBoundsInScreen()); |
58 | 59 |
59 ui::AXTreeIDRegistry::AXTreeID child_ax_tree_id = | 60 ui::AXTreeIDRegistry::AXTreeID child_ax_tree_id = |
60 window_->GetProperty(ui::kChildAXTreeID); | 61 window_->GetProperty(ui::kChildAXTreeID); |
61 if (child_ax_tree_id != ui::AXTreeIDRegistry::kNoAXTreeID) | 62 if (child_ax_tree_id != ui::AXTreeIDRegistry::kNoAXTreeID) |
62 out_node_data->AddIntAttribute(ui::AX_ATTR_CHILD_TREE_ID, child_ax_tree_id); | 63 out_node_data->AddIntAttribute(ui::AX_ATTR_CHILD_TREE_ID, child_ax_tree_id); |
63 } | 64 } |
64 | 65 |
65 int32_t AXWindowObjWrapper::GetID() { | 66 int32_t AXWindowObjWrapper::GetID() { |
66 return AXAuraObjCache::GetInstance()->GetID(window_); | 67 return AXAuraObjCache::GetInstance()->GetID(window_); |
67 } | 68 } |
68 | 69 |
| 70 bool AXWindowObjWrapper::HandleAccessibleAction( |
| 71 const ui::AXActionData& action) { |
| 72 if (action.action == ui::AX_ACTION_HIT_TEST) { |
| 73 // For a hit test event, try to delegate to a widget, and if that |
| 74 // fails fire the event directly. |
| 75 views::Widget* widget = views::Widget::GetWidgetForNativeView(window_); |
| 76 if (widget) { |
| 77 AXAuraObjWrapper* widget_wrapper = |
| 78 AXAuraObjCache::GetInstance()->GetOrCreate(widget); |
| 79 if (widget_wrapper) |
| 80 return widget_wrapper->HandleAccessibleAction(action); |
| 81 } |
| 82 |
| 83 AXAuraObjCache::GetInstance()->FireEvent(this, |
| 84 action.hit_test_event_to_fire); |
| 85 return true; |
| 86 } |
| 87 |
| 88 return false; |
| 89 } |
| 90 |
69 void AXWindowObjWrapper::OnWindowDestroyed(aura::Window* window) { | 91 void AXWindowObjWrapper::OnWindowDestroyed(aura::Window* window) { |
70 AXAuraObjCache::GetInstance()->Remove(window, nullptr); | 92 AXAuraObjCache::GetInstance()->Remove(window, nullptr); |
71 } | 93 } |
72 | 94 |
73 void AXWindowObjWrapper::OnWindowDestroying(aura::Window* window) { | 95 void AXWindowObjWrapper::OnWindowDestroying(aura::Window* window) { |
74 Widget* widget = Widget::GetWidgetForNativeView(window); | 96 Widget* widget = Widget::GetWidgetForNativeView(window); |
75 if (widget) | 97 if (widget) |
76 AXAuraObjCache::GetInstance()->Remove(widget); | 98 AXAuraObjCache::GetInstance()->Remove(widget); |
77 } | 99 } |
78 | 100 |
79 void AXWindowObjWrapper::OnWindowHierarchyChanged( | 101 void AXWindowObjWrapper::OnWindowHierarchyChanged( |
80 const HierarchyChangeParams& params) { | 102 const HierarchyChangeParams& params) { |
81 if (params.phase == WindowObserver::HierarchyChangeParams::HIERARCHY_CHANGED) | 103 if (params.phase == WindowObserver::HierarchyChangeParams::HIERARCHY_CHANGED) |
82 AXAuraObjCache::GetInstance()->Remove(params.target, params.old_parent); | 104 AXAuraObjCache::GetInstance()->Remove(params.target, params.old_parent); |
83 } | 105 } |
84 | 106 |
85 void AXWindowObjWrapper::OnWindowBoundsChanged(aura::Window* window, | 107 void AXWindowObjWrapper::OnWindowBoundsChanged(aura::Window* window, |
86 const gfx::Rect& old_bounds, | 108 const gfx::Rect& old_bounds, |
87 const gfx::Rect& new_bounds) { | 109 const gfx::Rect& new_bounds) { |
| 110 AXAuraObjCache::GetInstance()->FireEvent(this, ui::AX_EVENT_LOCATION_CHANGED); |
| 111 |
88 Widget* widget = Widget::GetWidgetForNativeView(window); | 112 Widget* widget = Widget::GetWidgetForNativeView(window); |
89 if (widget) { | 113 if (widget) { |
90 widget->GetRootView()->NotifyAccessibilityEvent( | 114 widget->GetRootView()->NotifyAccessibilityEvent( |
91 ui::AX_EVENT_LOCATION_CHANGED, true); | 115 ui::AX_EVENT_LOCATION_CHANGED, true); |
92 } | 116 } |
93 } | 117 } |
94 | 118 |
95 } // namespace views | 119 } // namespace views |
OLD | NEW |