Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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/native_view_accessibility.h" | 5 #include "ui/views/accessibility/native_view_accessibility.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "build/build_config.h" | |
| 9 #include "ui/accessibility/ax_action_data.h" | |
| 10 #include "ui/accessibility/ax_node_data.h" | |
| 11 #include "ui/events/event_utils.h" | 8 #include "ui/events/event_utils.h" |
| 12 #include "ui/gfx/native_widget_types.h" | 9 #include "ui/gfx/native_widget_types.h" |
| 13 #include "ui/views/controls/native/native_view_host.h" | 10 #include "ui/views/controls/native/native_view_host.h" |
| 14 #include "ui/views/view.h" | 11 #include "ui/views/view.h" |
| 15 #include "ui/views/widget/widget.h" | 12 #include "ui/views/widget/widget.h" |
| 16 | 13 |
| 17 namespace views { | 14 namespace views { |
| 18 | 15 |
| 19 #if !defined(PLATFORM_HAS_NATIVE_VIEW_ACCESSIBILITY_IMPL) | 16 #if !defined(PLATFORM_HAS_NATIVE_VIEW_ACCESSIBILITY_IMPL) |
| 20 // static | 17 // static |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 43 | 40 |
| 44 void NativeViewAccessibility::Destroy() { | 41 void NativeViewAccessibility::Destroy() { |
| 45 delete this; | 42 delete this; |
| 46 } | 43 } |
| 47 | 44 |
| 48 void NativeViewAccessibility::NotifyAccessibilityEvent(ui::AXEvent event_type) { | 45 void NativeViewAccessibility::NotifyAccessibilityEvent(ui::AXEvent event_type) { |
| 49 if (ax_node_) | 46 if (ax_node_) |
| 50 ax_node_->NotifyAccessibilityEvent(event_type); | 47 ax_node_->NotifyAccessibilityEvent(event_type); |
| 51 } | 48 } |
| 52 | 49 |
| 50 bool NativeViewAccessibility::SetFocused(bool focused) { | |
| 51 if (!ui::AXNodeData::IsFlagSet(GetData().state, ui::AX_STATE_FOCUSABLE)) | |
| 52 return false; | |
| 53 | |
| 54 if (focused) | |
| 55 view_->RequestFocus(); | |
| 56 else if (view_->HasFocus()) | |
| 57 view_->GetFocusManager()->ClearFocus(); | |
| 58 return true; | |
| 59 } | |
| 60 | |
| 53 // ui::AXPlatformNodeDelegate | 61 // ui::AXPlatformNodeDelegate |
| 54 | 62 |
| 55 const ui::AXNodeData& NativeViewAccessibility::GetData() { | 63 const ui::AXNodeData& NativeViewAccessibility::GetData() { |
| 56 data_ = ui::AXNodeData(); | 64 data_ = ui::AXNodeData(); |
| 57 data_.state = 0; | 65 data_.state = 0; |
| 58 | 66 |
| 59 // Views may misbehave if their widget is closed; return an unknown role | 67 // Views may misbehave if their widget is closed; return an unknown role |
| 60 // rather than possibly crashing. | 68 // rather than possibly crashing. |
| 61 if (!view_->GetWidget() || view_->GetWidget()->IsClosed()) { | 69 if (!view_->GetWidget() || view_->GetWidget()->IsClosed()) { |
| 62 data_.role = ui::AX_ROLE_UNKNOWN; | 70 data_.role = ui::AX_ROLE_UNKNOWN; |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 177 View* focused_view = | 185 View* focused_view = |
| 178 focus_manager ? focus_manager->GetFocusedView() : nullptr; | 186 focus_manager ? focus_manager->GetFocusedView() : nullptr; |
| 179 return focused_view ? focused_view->GetNativeViewAccessible() : nullptr; | 187 return focused_view ? focused_view->GetNativeViewAccessible() : nullptr; |
| 180 } | 188 } |
| 181 | 189 |
| 182 gfx::AcceleratedWidget | 190 gfx::AcceleratedWidget |
| 183 NativeViewAccessibility::GetTargetForNativeAccessibilityEvent() { | 191 NativeViewAccessibility::GetTargetForNativeAccessibilityEvent() { |
| 184 return gfx::kNullAcceleratedWidget; | 192 return gfx::kNullAcceleratedWidget; |
| 185 } | 193 } |
| 186 | 194 |
| 195 bool NativeViewAccessibility::AccessibilityPerformAction( | |
| 196 const ui::AXActionData& data) { | |
| 197 switch (data.action) { | |
| 198 // Handle accessible actions that apply to all Views here. | |
| 199 case ui::AX_ACTION_DO_DEFAULT: | |
| 200 DoDefaultAction(); | |
| 201 return true; | |
| 202 case ui::AX_ACTION_SET_FOCUS: | |
| 203 return SetFocused(true); | |
| 204 case ui::AX_ACTION_BLUR: | |
| 205 return SetFocused(false); | |
| 206 | |
| 207 // Actions that only apply to specific Views should be dealt with by | |
| 208 // HandleAccessibleAction(). | |
| 209 case ui::AX_ACTION_REPLACE_SELECTED_TEXT: | |
| 210 case ui::AX_ACTION_SET_VALUE: | |
| 211 return view_->HandleAccessibleAction(data); | |
| 212 break; | |
| 213 | |
| 214 // Not yet implemented accessibility actions. | |
| 215 case ui::AX_ACTION_DECREMENT: | |
| 216 case ui::AX_ACTION_HIT_TEST: | |
| 217 case ui::AX_ACTION_INCREMENT: | |
| 218 case ui::AX_ACTION_SCROLL_TO_MAKE_VISIBLE: | |
| 219 case ui::AX_ACTION_SCROLL_TO_POINT: | |
| 220 case ui::AX_ACTION_SET_ACCESSIBILITY_FOCUS: | |
| 221 case ui::AX_ACTION_SET_SCROLL_OFFSET: | |
| 222 case ui::AX_ACTION_SET_SELECTION: | |
| 223 case ui::AX_ACTION_SHOW_CONTEXT_MENU: | |
| 224 NOTIMPLEMENTED(); | |
|
dmazzoni
2016/11/21 04:53:38
It might be better to just call view_->HandleAcces
Patti Lor
2016/11/21 23:24:39
Done.
| |
| 225 break; | |
| 226 | |
| 227 // Actions that are only used for the web or not used for Views. | |
| 228 case ui::AX_ACTION_SET_SEQUENTIAL_FOCUS_NAVIGATION_STARTING_POINT: | |
| 229 case ui::AX_ACTION_NONE: | |
|
dmazzoni
2016/11/21 04:53:38
nit: the comment above implies AX_ACTION_NONE is u
Patti Lor
2016/11/21 23:24:39
Deleted!
| |
| 230 NOTREACHED(); | |
| 231 break; | |
| 232 } | |
| 233 return false; | |
| 234 } | |
| 235 | |
| 187 void NativeViewAccessibility::DoDefaultAction() { | 236 void NativeViewAccessibility::DoDefaultAction() { |
| 188 gfx::Point center = view_->GetLocalBounds().CenterPoint(); | 237 gfx::Point center = view_->GetLocalBounds().CenterPoint(); |
| 189 view_->OnMousePressed(ui::MouseEvent(ui::ET_MOUSE_PRESSED, | 238 view_->OnMousePressed(ui::MouseEvent(ui::ET_MOUSE_PRESSED, |
| 190 center, | 239 center, |
| 191 center, | 240 center, |
| 192 ui::EventTimeForNow(), | 241 ui::EventTimeForNow(), |
| 193 ui::EF_LEFT_MOUSE_BUTTON, | 242 ui::EF_LEFT_MOUSE_BUTTON, |
| 194 ui::EF_LEFT_MOUSE_BUTTON)); | 243 ui::EF_LEFT_MOUSE_BUTTON)); |
| 195 view_->OnMouseReleased(ui::MouseEvent(ui::ET_MOUSE_RELEASED, | 244 view_->OnMouseReleased(ui::MouseEvent(ui::ET_MOUSE_RELEASED, |
| 196 center, | 245 center, |
| 197 center, | 246 center, |
| 198 ui::EventTimeForNow(), | 247 ui::EventTimeForNow(), |
| 199 ui::EF_LEFT_MOUSE_BUTTON, | 248 ui::EF_LEFT_MOUSE_BUTTON, |
| 200 ui::EF_LEFT_MOUSE_BUTTON)); | 249 ui::EF_LEFT_MOUSE_BUTTON)); |
| 201 } | 250 } |
| 202 | 251 |
| 203 bool NativeViewAccessibility::SetStringValue(const base::string16& new_value, | |
| 204 bool clear_first) { | |
| 205 // Return an error if the view can't set the value. | |
| 206 if (!CanSetStringValue()) | |
| 207 return false; | |
| 208 | |
| 209 ui::AXActionData action_data; | |
| 210 action_data.value = new_value; | |
| 211 action_data.action = clear_first ? ui::AX_ACTION_SET_VALUE | |
| 212 : ui::AX_ACTION_REPLACE_SELECTED_TEXT; | |
| 213 return view_->HandleAccessibleAction(action_data); | |
| 214 } | |
| 215 | |
| 216 bool NativeViewAccessibility::CanSetStringValue() { | |
| 217 return !ui::AXNodeData::IsFlagSet(GetData().state, ui::AX_STATE_READ_ONLY); | |
| 218 } | |
| 219 | |
| 220 bool NativeViewAccessibility::SetFocused(bool focused) { | |
| 221 if (!ui::AXNodeData::IsFlagSet(GetData().state, ui::AX_STATE_FOCUSABLE)) | |
| 222 return false; | |
| 223 | |
| 224 if (focused) | |
| 225 view_->RequestFocus(); | |
| 226 else if (view_->HasFocus()) | |
| 227 view_->GetFocusManager()->ClearFocus(); | |
| 228 return true; | |
| 229 } | |
| 230 | |
| 231 void NativeViewAccessibility::OnWidgetDestroying(Widget* widget) { | 252 void NativeViewAccessibility::OnWidgetDestroying(Widget* widget) { |
| 232 if (parent_widget_ == widget) { | 253 if (parent_widget_ == widget) { |
| 233 parent_widget_->RemoveObserver(this); | 254 parent_widget_->RemoveObserver(this); |
| 234 parent_widget_ = nullptr; | 255 parent_widget_ = nullptr; |
| 235 } | 256 } |
| 236 } | 257 } |
| 237 | 258 |
| 238 void NativeViewAccessibility::SetParentWidget(Widget* parent_widget) { | 259 void NativeViewAccessibility::SetParentWidget(Widget* parent_widget) { |
| 239 if (parent_widget_) | 260 if (parent_widget_) |
| 240 parent_widget_->RemoveObserver(this); | 261 parent_widget_->RemoveObserver(this); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 271 child_widget_platform_node->GetDelegate()); | 292 child_widget_platform_node->GetDelegate()); |
| 272 if (child_widget_view_accessibility->parent_widget() != widget) | 293 if (child_widget_view_accessibility->parent_widget() != widget) |
| 273 child_widget_view_accessibility->SetParentWidget(widget); | 294 child_widget_view_accessibility->SetParentWidget(widget); |
| 274 } | 295 } |
| 275 | 296 |
| 276 result_child_widgets->push_back(child_widget); | 297 result_child_widgets->push_back(child_widget); |
| 277 } | 298 } |
| 278 } | 299 } |
| 279 | 300 |
| 280 } // namespace views | 301 } // namespace views |
| OLD | NEW |