| 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" | 8 #include "build/build_config.h" |
| 9 #include "ui/accessibility/ax_view_state.h" | 9 #include "ui/accessibility/ax_action_data.h" |
| 10 #include "ui/accessibility/ax_node_data.h" |
| 10 #include "ui/events/event_utils.h" | 11 #include "ui/events/event_utils.h" |
| 11 #include "ui/gfx/native_widget_types.h" | 12 #include "ui/gfx/native_widget_types.h" |
| 12 #include "ui/views/controls/native/native_view_host.h" | 13 #include "ui/views/controls/native/native_view_host.h" |
| 13 #include "ui/views/view.h" | 14 #include "ui/views/view.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 #if !defined(PLATFORM_HAS_NATIVE_VIEW_ACCESSIBILITY_IMPL) | 19 #if !defined(PLATFORM_HAS_NATIVE_VIEW_ACCESSIBILITY_IMPL) |
| 19 // static | 20 // static |
| (...skipping 26 matching lines...) Expand all Loading... |
| 46 | 47 |
| 47 void NativeViewAccessibility::NotifyAccessibilityEvent(ui::AXEvent event_type) { | 48 void NativeViewAccessibility::NotifyAccessibilityEvent(ui::AXEvent event_type) { |
| 48 if (ax_node_) | 49 if (ax_node_) |
| 49 ax_node_->NotifyAccessibilityEvent(event_type); | 50 ax_node_->NotifyAccessibilityEvent(event_type); |
| 50 } | 51 } |
| 51 | 52 |
| 52 // ui::AXPlatformNodeDelegate | 53 // ui::AXPlatformNodeDelegate |
| 53 | 54 |
| 54 const ui::AXNodeData& NativeViewAccessibility::GetData() { | 55 const ui::AXNodeData& NativeViewAccessibility::GetData() { |
| 55 data_ = ui::AXNodeData(); | 56 data_ = ui::AXNodeData(); |
| 57 data_.state = 0; |
| 56 | 58 |
| 57 // Views may misbehave if their widget is closed; return an unknown role | 59 // Views may misbehave if their widget is closed; return an unknown role |
| 58 // rather than possibly crashing. | 60 // rather than possibly crashing. |
| 59 if (!view_->GetWidget() || view_->GetWidget()->IsClosed()) { | 61 if (!view_->GetWidget() || view_->GetWidget()->IsClosed()) { |
| 60 data_.role = ui::AX_ROLE_UNKNOWN; | 62 data_.role = ui::AX_ROLE_UNKNOWN; |
| 61 data_.state = 1 << ui::AX_STATE_DISABLED; | 63 data_.state = 1 << ui::AX_STATE_DISABLED; |
| 62 return data_; | 64 return data_; |
| 63 } | 65 } |
| 64 | 66 |
| 65 ui::AXViewState state; | 67 view_->GetAccessibleNodeData(&data_); |
| 66 view_->GetAccessibleState(&state); | |
| 67 data_.role = state.role; | |
| 68 data_.state = state.state(); | |
| 69 data_.location = gfx::RectF(view_->GetBoundsInScreen()); | 68 data_.location = gfx::RectF(view_->GetBoundsInScreen()); |
| 70 data_.AddStringAttribute(ui::AX_ATTR_NAME, base::UTF16ToUTF8(state.name)); | 69 base::string16 description; |
| 71 data_.AddStringAttribute(ui::AX_ATTR_VALUE, base::UTF16ToUTF8(state.value)); | 70 view_->GetTooltipText(gfx::Point(), &description); |
| 72 data_.AddStringAttribute(ui::AX_ATTR_ACTION, | 71 data_.AddStringAttribute(ui::AX_ATTR_DESCRIPTION, |
| 73 base::UTF16ToUTF8(state.default_action)); | 72 base::UTF16ToUTF8(description)); |
| 74 data_.AddStringAttribute(ui::AX_ATTR_SHORTCUT, | |
| 75 base::UTF16ToUTF8(state.keyboard_shortcut)); | |
| 76 data_.AddStringAttribute(ui::AX_ATTR_PLACEHOLDER, | |
| 77 base::UTF16ToUTF8(state.placeholder)); | |
| 78 | |
| 79 if (state.description.empty() && | |
| 80 view_->GetTooltipText(gfx::Point(), &state.description)) | |
| 81 data_.AddStringAttribute(ui::AX_ATTR_DESCRIPTION, | |
| 82 base::UTF16ToUTF8(state.description)); | |
| 83 | |
| 84 data_.AddIntAttribute(ui::AX_ATTR_TEXT_SEL_START, state.selection_start); | |
| 85 data_.AddIntAttribute(ui::AX_ATTR_TEXT_SEL_END, state.selection_end); | |
| 86 | 73 |
| 87 data_.state |= (1 << ui::AX_STATE_FOCUSABLE); | 74 data_.state |= (1 << ui::AX_STATE_FOCUSABLE); |
| 88 | 75 |
| 89 if (!view_->enabled()) | 76 if (!view_->enabled()) |
| 90 data_.state |= (1 << ui::AX_STATE_DISABLED); | 77 data_.state |= (1 << ui::AX_STATE_DISABLED); |
| 91 | 78 |
| 92 if (!view_->visible()) | 79 if (!view_->visible()) |
| 93 data_.state |= (1 << ui::AX_STATE_INVISIBLE); | 80 data_.state |= (1 << ui::AX_STATE_INVISIBLE); |
| 94 | 81 |
| 95 return data_; | 82 return data_; |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 ui::EF_LEFT_MOUSE_BUTTON, | 199 ui::EF_LEFT_MOUSE_BUTTON, |
| 213 ui::EF_LEFT_MOUSE_BUTTON)); | 200 ui::EF_LEFT_MOUSE_BUTTON)); |
| 214 } | 201 } |
| 215 | 202 |
| 216 bool NativeViewAccessibility::SetStringValue(const base::string16& new_value, | 203 bool NativeViewAccessibility::SetStringValue(const base::string16& new_value, |
| 217 bool clear_first) { | 204 bool clear_first) { |
| 218 // Return an error if the view can't set the value. | 205 // Return an error if the view can't set the value. |
| 219 if (!CanSetStringValue()) | 206 if (!CanSetStringValue()) |
| 220 return false; | 207 return false; |
| 221 | 208 |
| 222 ui::AXViewState state; | 209 ui::AXActionData action_data; |
| 223 view_->GetAccessibleState(&state); | 210 action_data.value = new_value; |
| 224 state.set_value_callback.Run(new_value, clear_first); | 211 action_data.action = clear_first ? ui::AX_ACTION_SET_VALUE |
| 225 return true; | 212 : ui::AX_ACTION_REPLACE_SELECTED_TEXT; |
| 213 return view_->HandleAccessibleAction(action_data); |
| 226 } | 214 } |
| 227 | 215 |
| 228 bool NativeViewAccessibility::CanSetStringValue() { | 216 bool NativeViewAccessibility::CanSetStringValue() { |
| 229 ui::AXViewState state; | 217 return !ui::AXNodeData::IsFlagSet(GetData().state, ui::AX_STATE_READ_ONLY); |
| 230 view_->GetAccessibleState(&state); | |
| 231 return !ui::AXViewState::IsFlagSet(GetData().state, ui::AX_STATE_READ_ONLY) && | |
| 232 !state.set_value_callback.is_null(); | |
| 233 } | 218 } |
| 234 | 219 |
| 235 void NativeViewAccessibility::OnWidgetDestroying(Widget* widget) { | 220 void NativeViewAccessibility::OnWidgetDestroying(Widget* widget) { |
| 236 if (parent_widget_ == widget) { | 221 if (parent_widget_ == widget) { |
| 237 parent_widget_->RemoveObserver(this); | 222 parent_widget_->RemoveObserver(this); |
| 238 parent_widget_ = nullptr; | 223 parent_widget_ = nullptr; |
| 239 } | 224 } |
| 240 } | 225 } |
| 241 | 226 |
| 242 void NativeViewAccessibility::SetParentWidget(Widget* parent_widget) { | 227 void NativeViewAccessibility::SetParentWidget(Widget* parent_widget) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 child_widget_platform_node->GetDelegate()); | 260 child_widget_platform_node->GetDelegate()); |
| 276 if (child_widget_view_accessibility->parent_widget() != widget) | 261 if (child_widget_view_accessibility->parent_widget() != widget) |
| 277 child_widget_view_accessibility->SetParentWidget(widget); | 262 child_widget_view_accessibility->SetParentWidget(widget); |
| 278 } | 263 } |
| 279 | 264 |
| 280 result_child_widgets->push_back(child_widget); | 265 result_child_widgets->push_back(child_widget); |
| 281 } | 266 } |
| 282 } | 267 } |
| 283 | 268 |
| 284 } // namespace views | 269 } // namespace views |
| OLD | NEW |