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

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

Issue 2795843002: Move implementation of accessibility actions to views::View (Closed)
Patch Set: Fix win compile Created 3 years, 8 months 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_base.h" 5 #include "ui/views/accessibility/native_view_accessibility_base.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "ui/events/event_utils.h" 9 #include "ui/events/event_utils.h"
10 #include "ui/gfx/native_widget_types.h" 10 #include "ui/gfx/native_widget_types.h"
(...skipping 18 matching lines...) Expand all
29 29
30 gfx::NativeViewAccessible NativeViewAccessibilityBase::GetNativeObject() { 30 gfx::NativeViewAccessible NativeViewAccessibilityBase::GetNativeObject() {
31 return ax_node_->GetNativeViewAccessible(); 31 return ax_node_->GetNativeViewAccessible();
32 } 32 }
33 33
34 void NativeViewAccessibilityBase::NotifyAccessibilityEvent( 34 void NativeViewAccessibilityBase::NotifyAccessibilityEvent(
35 ui::AXEvent event_type) { 35 ui::AXEvent event_type) {
36 ax_node_->NotifyAccessibilityEvent(event_type); 36 ax_node_->NotifyAccessibilityEvent(event_type);
37 } 37 }
38 38
39 bool NativeViewAccessibilityBase::SetFocused(bool focused) {
40 if (!ui::AXNodeData::IsFlagSet(GetData().state, ui::AX_STATE_FOCUSABLE))
41 return false;
42
43 if (focused)
44 view_->RequestFocus();
45 else if (view_->HasFocus())
46 view_->GetFocusManager()->ClearFocus();
47 return true;
48 }
49
50 // ui::AXPlatformNodeDelegate 39 // ui::AXPlatformNodeDelegate
51 40
52 const ui::AXNodeData& NativeViewAccessibilityBase::GetData() const { 41 const ui::AXNodeData& NativeViewAccessibilityBase::GetData() const {
53 data_ = ui::AXNodeData(); 42 data_ = ui::AXNodeData();
54 data_.state = 0; 43 data_.state = 0;
55 44
56 // Views may misbehave if their widget is closed; return an unknown role 45 // Views may misbehave if their widget is closed; return an unknown role
57 // rather than possibly crashing. 46 // rather than possibly crashing.
58 if (!view_->GetWidget() || view_->GetWidget()->IsClosed()) { 47 if (!view_->GetWidget() || view_->GetWidget()->IsClosed()) {
59 data_.role = ui::AX_ROLE_UNKNOWN; 48 data_.role = ui::AX_ROLE_UNKNOWN;
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 return focused_view ? focused_view->GetNativeViewAccessible() : nullptr; 161 return focused_view ? focused_view->GetNativeViewAccessible() : nullptr;
173 } 162 }
174 163
175 gfx::AcceleratedWidget 164 gfx::AcceleratedWidget
176 NativeViewAccessibilityBase::GetTargetForNativeAccessibilityEvent() { 165 NativeViewAccessibilityBase::GetTargetForNativeAccessibilityEvent() {
177 return gfx::kNullAcceleratedWidget; 166 return gfx::kNullAcceleratedWidget;
178 } 167 }
179 168
180 bool NativeViewAccessibilityBase::AccessibilityPerformAction( 169 bool NativeViewAccessibilityBase::AccessibilityPerformAction(
181 const ui::AXActionData& data) { 170 const ui::AXActionData& data) {
182 switch (data.action) { 171 return view_->HandleAccessibleAction(data);
183 // Handle accessible actions that apply to all Views here.
184 case ui::AX_ACTION_DO_DEFAULT:
185 DoDefaultAction();
186 return true;
187 case ui::AX_ACTION_FOCUS:
188 return SetFocused(true);
189 case ui::AX_ACTION_BLUR:
190 return SetFocused(false);
191
192 case ui::AX_ACTION_NONE:
193 NOTREACHED();
194 break;
195
196 // All other actions can potentially be dealt with by the View itself.
197 default:
198 return view_->HandleAccessibleAction(data);
199 break;
200 }
201 return false;
202 }
203
204 void NativeViewAccessibilityBase::DoDefaultAction() {
205 gfx::Point center = view_->GetLocalBounds().CenterPoint();
206 view_->OnMousePressed(ui::MouseEvent(
207 ui::ET_MOUSE_PRESSED, center, center, ui::EventTimeForNow(),
208 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
209 view_->OnMouseReleased(ui::MouseEvent(
210 ui::ET_MOUSE_RELEASED, center, center, ui::EventTimeForNow(),
211 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
212 } 172 }
213 173
214 void NativeViewAccessibilityBase::OnWidgetDestroying(Widget* widget) { 174 void NativeViewAccessibilityBase::OnWidgetDestroying(Widget* widget) {
215 if (parent_widget_ == widget) { 175 if (parent_widget_ == widget) {
216 parent_widget_->RemoveObserver(this); 176 parent_widget_->RemoveObserver(this);
217 parent_widget_ = nullptr; 177 parent_widget_ = nullptr;
218 } 178 }
219 } 179 }
220 180
221 void NativeViewAccessibilityBase::SetParentWidget(Widget* parent_widget) { 181 void NativeViewAccessibilityBase::SetParentWidget(Widget* parent_widget) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 child_widget_platform_node->GetDelegate()); 216 child_widget_platform_node->GetDelegate());
257 if (child_widget_view_accessibility->parent_widget() != widget) 217 if (child_widget_view_accessibility->parent_widget() != widget)
258 child_widget_view_accessibility->SetParentWidget(widget); 218 child_widget_view_accessibility->SetParentWidget(widget);
259 } 219 }
260 220
261 result_child_widgets->push_back(child_widget); 221 result_child_widgets->push_back(child_widget);
262 } 222 }
263 } 223 }
264 224
265 } // namespace views 225 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/accessibility/native_view_accessibility_base.h ('k') | ui/views/accessibility/native_view_accessibility_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698