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" | 8 #include "build/build_config.h" |
| 9 #include "ui/accessibility/ax_action_data.h" | 9 #include "ui/accessibility/ax_action_data.h" |
| 10 #include "ui/accessibility/ax_node_data.h" | 10 #include "ui/accessibility/ax_node_data.h" |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 177 View* focused_view = | 177 View* focused_view = |
| 178 focus_manager ? focus_manager->GetFocusedView() : nullptr; | 178 focus_manager ? focus_manager->GetFocusedView() : nullptr; |
| 179 return focused_view ? focused_view->GetNativeViewAccessible() : nullptr; | 179 return focused_view ? focused_view->GetNativeViewAccessible() : nullptr; |
| 180 } | 180 } |
| 181 | 181 |
| 182 gfx::AcceleratedWidget | 182 gfx::AcceleratedWidget |
| 183 NativeViewAccessibility::GetTargetForNativeAccessibilityEvent() { | 183 NativeViewAccessibility::GetTargetForNativeAccessibilityEvent() { |
| 184 return gfx::kNullAcceleratedWidget; | 184 return gfx::kNullAcceleratedWidget; |
| 185 } | 185 } |
| 186 | 186 |
| 187 bool NativeViewAccessibility::AccessibilityPerformAction( | |
| 188 const ui::AXActionData& data) { | |
| 189 switch (data.action) { | |
| 190 // Handle accessible actions that apply to all Views here. | |
| 191 case ui::AX_ACTION_DO_DEFAULT: | |
| 192 DoDefaultAction(); | |
| 193 break; | |
|
tapted
2016/11/21 02:15:43
return true?
Patti Lor
2016/11/21 23:24:38
Done.
| |
| 194 case ui::AX_ACTION_SET_FOCUS: | |
| 195 SetFocused(true); | |
|
tapted
2016/11/21 02:15:43
return SetFocused? (if yes, break not required aft
Patti Lor
2016/11/21 23:24:38
Done.
| |
| 196 break; | |
| 197 case ui::AX_ACTION_BLUR: | |
| 198 SetFocused(false); | |
| 199 break; | |
| 200 | |
| 201 // Actions that only apply to specific Views should be dealt with by | |
| 202 // HandleAccessibleAction(). | |
| 203 case ui::AX_ACTION_REPLACE_SELECTED_TEXT: | |
| 204 case ui::AX_ACTION_SET_VALUE: | |
| 205 return view_->HandleAccessibleAction(data); | |
| 206 break; | |
| 207 | |
| 208 // Not yet implemented accessibility actions. | |
| 209 case ui::AX_ACTION_DECREMENT: | |
| 210 case ui::AX_ACTION_HIT_TEST: | |
| 211 case ui::AX_ACTION_INCREMENT: | |
| 212 case ui::AX_ACTION_SCROLL_TO_MAKE_VISIBLE: | |
| 213 case ui::AX_ACTION_SCROLL_TO_POINT: | |
| 214 case ui::AX_ACTION_SET_ACCESSIBILITY_FOCUS: | |
| 215 case ui::AX_ACTION_SET_SCROLL_OFFSET: | |
| 216 case ui::AX_ACTION_SET_SELECTION: | |
| 217 case ui::AX_ACTION_SHOW_CONTEXT_MENU: | |
| 218 NOTIMPLEMENTED(); | |
| 219 break; | |
| 220 | |
| 221 // Actions that are only used for the web or not used for Views. | |
| 222 case ui::AX_ACTION_SET_SEQUENTIAL_FOCUS_NAVIGATION_STARTING_POINT: | |
| 223 case ui::AX_ACTION_NONE: | |
| 224 NOTREACHED(); | |
| 225 break; | |
| 226 } | |
| 227 return false; | |
| 228 } | |
| 229 | |
| 187 void NativeViewAccessibility::DoDefaultAction() { | 230 void NativeViewAccessibility::DoDefaultAction() { |
| 188 gfx::Point center = view_->GetLocalBounds().CenterPoint(); | 231 gfx::Point center = view_->GetLocalBounds().CenterPoint(); |
| 189 view_->OnMousePressed(ui::MouseEvent(ui::ET_MOUSE_PRESSED, | 232 view_->OnMousePressed(ui::MouseEvent(ui::ET_MOUSE_PRESSED, |
| 190 center, | 233 center, |
| 191 center, | 234 center, |
| 192 ui::EventTimeForNow(), | 235 ui::EventTimeForNow(), |
| 193 ui::EF_LEFT_MOUSE_BUTTON, | 236 ui::EF_LEFT_MOUSE_BUTTON, |
| 194 ui::EF_LEFT_MOUSE_BUTTON)); | 237 ui::EF_LEFT_MOUSE_BUTTON)); |
| 195 view_->OnMouseReleased(ui::MouseEvent(ui::ET_MOUSE_RELEASED, | 238 view_->OnMouseReleased(ui::MouseEvent(ui::ET_MOUSE_RELEASED, |
| 196 center, | 239 center, |
| 197 center, | 240 center, |
| 198 ui::EventTimeForNow(), | 241 ui::EventTimeForNow(), |
| 199 ui::EF_LEFT_MOUSE_BUTTON, | 242 ui::EF_LEFT_MOUSE_BUTTON, |
| 200 ui::EF_LEFT_MOUSE_BUTTON)); | 243 ui::EF_LEFT_MOUSE_BUTTON)); |
| 201 } | 244 } |
| 202 | 245 |
| 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) { | 246 bool NativeViewAccessibility::SetFocused(bool focused) { |
|
tapted
2016/11/21 02:15:43
nit: move this to match the declaration order
Patti Lor
2016/11/21 23:24:38
Done, thanks!
| |
| 221 if (!ui::AXNodeData::IsFlagSet(GetData().state, ui::AX_STATE_FOCUSABLE)) | 247 if (!ui::AXNodeData::IsFlagSet(GetData().state, ui::AX_STATE_FOCUSABLE)) |
| 222 return false; | 248 return false; |
| 223 | 249 |
| 224 if (focused) | 250 if (focused) |
| 225 view_->RequestFocus(); | 251 view_->RequestFocus(); |
| 226 else if (view_->HasFocus()) | 252 else if (view_->HasFocus()) |
| 227 view_->GetFocusManager()->ClearFocus(); | 253 view_->GetFocusManager()->ClearFocus(); |
| 228 return true; | 254 return true; |
| 229 } | 255 } |
| 230 | 256 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 271 child_widget_platform_node->GetDelegate()); | 297 child_widget_platform_node->GetDelegate()); |
| 272 if (child_widget_view_accessibility->parent_widget() != widget) | 298 if (child_widget_view_accessibility->parent_widget() != widget) |
| 273 child_widget_view_accessibility->SetParentWidget(widget); | 299 child_widget_view_accessibility->SetParentWidget(widget); |
| 274 } | 300 } |
| 275 | 301 |
| 276 result_child_widgets->push_back(child_widget); | 302 result_child_widgets->push_back(child_widget); |
| 277 } | 303 } |
| 278 } | 304 } |
| 279 | 305 |
| 280 } // namespace views | 306 } // namespace views |
| OLD | NEW |