Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(313)

Side by Side Diff: ui/views/accessibility/native_view_accessibility.cc

Issue 2474363002: MacViews/a11y: Accessibility actions use AXActionData in AXPlatformNodeDelegate. (Closed)
Patch Set: Review comments. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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_FOCUS:
203 return SetFocused(true);
204 case ui::AX_ACTION_BLUR:
205 return SetFocused(false);
206
207 case ui::AX_ACTION_NONE:
208 NOTREACHED();
209 break;
210
211 // All other actions can potentially be dealt with by the View itself.
212 default:
213 return view_->HandleAccessibleAction(data);
214 break;
215 }
216 return false;
217 }
218
187 void NativeViewAccessibility::DoDefaultAction() { 219 void NativeViewAccessibility::DoDefaultAction() {
188 gfx::Point center = view_->GetLocalBounds().CenterPoint(); 220 gfx::Point center = view_->GetLocalBounds().CenterPoint();
189 view_->OnMousePressed(ui::MouseEvent(ui::ET_MOUSE_PRESSED, 221 view_->OnMousePressed(ui::MouseEvent(ui::ET_MOUSE_PRESSED,
190 center, 222 center,
191 center, 223 center,
192 ui::EventTimeForNow(), 224 ui::EventTimeForNow(),
193 ui::EF_LEFT_MOUSE_BUTTON, 225 ui::EF_LEFT_MOUSE_BUTTON,
194 ui::EF_LEFT_MOUSE_BUTTON)); 226 ui::EF_LEFT_MOUSE_BUTTON));
195 view_->OnMouseReleased(ui::MouseEvent(ui::ET_MOUSE_RELEASED, 227 view_->OnMouseReleased(ui::MouseEvent(ui::ET_MOUSE_RELEASED,
196 center, 228 center,
197 center, 229 center,
198 ui::EventTimeForNow(), 230 ui::EventTimeForNow(),
199 ui::EF_LEFT_MOUSE_BUTTON, 231 ui::EF_LEFT_MOUSE_BUTTON,
200 ui::EF_LEFT_MOUSE_BUTTON)); 232 ui::EF_LEFT_MOUSE_BUTTON));
201 } 233 }
202 234
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) { 235 void NativeViewAccessibility::OnWidgetDestroying(Widget* widget) {
232 if (parent_widget_ == widget) { 236 if (parent_widget_ == widget) {
233 parent_widget_->RemoveObserver(this); 237 parent_widget_->RemoveObserver(this);
234 parent_widget_ = nullptr; 238 parent_widget_ = nullptr;
235 } 239 }
236 } 240 }
237 241
238 void NativeViewAccessibility::SetParentWidget(Widget* parent_widget) { 242 void NativeViewAccessibility::SetParentWidget(Widget* parent_widget) {
239 if (parent_widget_) 243 if (parent_widget_)
240 parent_widget_->RemoveObserver(this); 244 parent_widget_->RemoveObserver(this);
(...skipping 30 matching lines...) Expand all
271 child_widget_platform_node->GetDelegate()); 275 child_widget_platform_node->GetDelegate());
272 if (child_widget_view_accessibility->parent_widget() != widget) 276 if (child_widget_view_accessibility->parent_widget() != widget)
273 child_widget_view_accessibility->SetParentWidget(widget); 277 child_widget_view_accessibility->SetParentWidget(widget);
274 } 278 }
275 279
276 result_child_widgets->push_back(child_widget); 280 result_child_widgets->push_back(child_widget);
277 } 281 }
278 } 282 }
279 283
280 } // namespace views 284 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/accessibility/native_view_accessibility.h ('k') | ui/views/accessibility/native_view_accessibility_auralinux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698