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

Side by Side Diff: content/browser/accessibility/browser_accessibility_manager_win.cc

Issue 1899823002: Uses the activedescendant_changed event received from Blink to fire the right focus event (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed extraneous focus events. Created 4 years, 7 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/browser/accessibility/browser_accessibility_manager_win.h" 5 #include "content/browser/accessibility/browser_accessibility_manager_win.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <vector> 10 #include <vector>
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 } 131 }
132 132
133 void BrowserAccessibilityManagerWin::UserIsReloading() { 133 void BrowserAccessibilityManagerWin::UserIsReloading() {
134 if (GetRoot()) 134 if (GetRoot())
135 MaybeCallNotifyWinEvent(IA2_EVENT_DOCUMENT_RELOAD, GetRoot()); 135 MaybeCallNotifyWinEvent(IA2_EVENT_DOCUMENT_RELOAD, GetRoot());
136 } 136 }
137 137
138 void BrowserAccessibilityManagerWin::NotifyAccessibilityEvent( 138 void BrowserAccessibilityManagerWin::NotifyAccessibilityEvent(
139 ui::AXEvent event_type, 139 ui::AXEvent event_type,
140 BrowserAccessibility* node) { 140 BrowserAccessibility* node) {
141 if (!node)
dmazzoni 2016/04/26 20:24:24 How about DCHECK(node)? This should never be calle
142 return;
143
141 BrowserAccessibilityDelegate* root_delegate = GetDelegateFromRootManager(); 144 BrowserAccessibilityDelegate* root_delegate = GetDelegateFromRootManager();
142 if (!root_delegate || !root_delegate->AccessibilityGetAcceleratedWidget()) { 145 if (!root_delegate || !root_delegate->AccessibilityGetAcceleratedWidget()) {
143 DLOG(WARNING) << "Not firing AX event because of no root_delegate or hwnd"; 146 DLOG(WARNING) << "Not firing AX event because of no root_delegate or hwnd";
144 return; 147 return;
145 } 148 }
146 149
147 // Don't fire events when this document might be stale as the user has 150 // Don't fire events when this document might be stale as the user has
148 // started navigating to a new document. 151 // started navigating to a new document.
149 if (user_is_navigating_away_) 152 if (user_is_navigating_away_)
150 return; 153 return;
151 154
152 // Inline text boxes are an internal implementation detail, we don't 155 // Inline text boxes are an internal implementation detail, we don't
153 // expose them to Windows. 156 // expose them to Windows.
154 if (node->GetRole() == ui::AX_ROLE_INLINE_TEXT_BOX) 157 if (node->GetRole() == ui::AX_ROLE_INLINE_TEXT_BOX)
155 return; 158 return;
156 159
157 // Don't fire focus, blur, or load complete notifications if the 160 // Don't fire focus, blur, or load complete notifications if the
158 // window isn't focused, because that can confuse screen readers into 161 // window isn't focused, because that can confuse screen readers into
159 // entering their "browse" mode. 162 // entering their "browse" mode.
160 if ((event_type == ui::AX_EVENT_FOCUS || 163 if ((event_type == ui::AX_EVENT_FOCUS ||
161 event_type == ui::AX_EVENT_BLUR || 164 event_type == ui::AX_EVENT_BLUR ||
162 event_type == ui::AX_EVENT_LOAD_COMPLETE) && 165 event_type == ui::AX_EVENT_LOAD_COMPLETE) &&
163 !NativeViewHasFocus()) { 166 !NativeViewHasFocus()) {
164 return; 167 return;
165 } 168 }
166 169
167 LONG event_id = EVENT_MIN; 170 LONG event_id = EVENT_MIN;
168 switch (event_type) { 171 switch (event_type) {
169 case ui::AX_EVENT_ACTIVEDESCENDANTCHANGED: 172 case ui::AX_EVENT_ACTIVEDESCENDANTCHANGED: {
170 event_id = IA2_EVENT_ACTIVE_DESCENDANT_CHANGED; 173 event_id = IA2_EVENT_ACTIVE_DESCENDANT_CHANGED;
174 BrowserAccessibility* active_descendant = GetActiveDescendantFocus(node);
175 if (active_descendant)
176 FireFocusEvent(active_descendant);
dmazzoni 2016/04/26 20:24:24 Same - I think this shouldn't be needed.
171 break; 177 break;
178 }
172 case ui::AX_EVENT_ALERT: 179 case ui::AX_EVENT_ALERT:
173 event_id = EVENT_SYSTEM_ALERT; 180 event_id = EVENT_SYSTEM_ALERT;
174 break; 181 break;
175 case ui::AX_EVENT_AUTOCORRECTION_OCCURED: 182 case ui::AX_EVENT_AUTOCORRECTION_OCCURED:
176 event_id = IA2_EVENT_OBJECT_ATTRIBUTE_CHANGED; 183 event_id = IA2_EVENT_OBJECT_ATTRIBUTE_CHANGED;
177 break; 184 break;
178 case ui::AX_EVENT_BLUR: 185 case ui::AX_EVENT_BLUR:
179 // Equivalent to focus on the root. 186 // Equivalent to focus on the root.
180 event_id = EVENT_OBJECT_FOCUS; 187 event_id = EVENT_OBJECT_FOCUS;
181 node = GetRoot(); 188 node = GetRoot();
(...skipping 29 matching lines...) Expand all
211 node = focus_object; 218 node = focus_object;
212 event_id = IA2_EVENT_TEXT_CARET_MOVED; 219 event_id = IA2_EVENT_TEXT_CARET_MOVED;
213 break; 220 break;
214 } 221 }
215 default: 222 default:
216 // Not all WebKit accessibility events result in a Windows 223 // Not all WebKit accessibility events result in a Windows
217 // accessibility notification. 224 // accessibility notification.
218 break; 225 break;
219 } 226 }
220 227
221 if (!node)
222 return;
223
224 if (event_id != EVENT_MIN) 228 if (event_id != EVENT_MIN)
225 MaybeCallNotifyWinEvent(event_id, node); 229 MaybeCallNotifyWinEvent(event_id, node);
226 230
227 // If this is a layout complete notification (sent when a container scrolls) 231 // If this is a layout complete notification (sent when a container scrolls)
228 // and there is a descendant tracked object, send a notification on it. 232 // and there is a descendant tracked object, send a notification on it.
229 // TODO(dmazzoni): remove once http://crbug.com/113483 is fixed. 233 // TODO(dmazzoni): remove once http://crbug.com/113483 is fixed.
230 if (event_type == ui::AX_EVENT_LAYOUT_COMPLETE && 234 if (event_type == ui::AX_EVENT_LAYOUT_COMPLETE &&
231 tracked_scroll_object_ && 235 tracked_scroll_object_ &&
232 tracked_scroll_object_->IsDescendantOf(node)) { 236 tracked_scroll_object_->IsDescendantOf(node)) {
233 MaybeCallNotifyWinEvent( 237 MaybeCallNotifyWinEvent(
234 IA2_EVENT_VISIBLE_DATA_CHANGED, tracked_scroll_object_); 238 IA2_EVENT_VISIBLE_DATA_CHANGED, tracked_scroll_object_);
235 tracked_scroll_object_->Release(); 239 tracked_scroll_object_->Release();
236 tracked_scroll_object_ = NULL; 240 tracked_scroll_object_ = NULL;
237 } 241 }
238 } 242 }
239 243
240 bool BrowserAccessibilityManagerWin::CanFireEvents() { 244 bool BrowserAccessibilityManagerWin::CanFireEvents() {
241 BrowserAccessibilityDelegate* root_delegate = GetDelegateFromRootManager(); 245 BrowserAccessibilityDelegate* root_delegate = GetDelegateFromRootManager();
242 if (!root_delegate) 246 if (!root_delegate)
243 return false; 247 return false;
244 HWND hwnd = root_delegate->AccessibilityGetAcceleratedWidget(); 248 HWND hwnd = root_delegate->AccessibilityGetAcceleratedWidget();
245 return hwnd != nullptr; 249 return hwnd != nullptr;
246 } 250 }
247 251
248 void BrowserAccessibilityManagerWin::FireFocusEvent( 252 void BrowserAccessibilityManagerWin::FireFocusEvent(
249 BrowserAccessibility* node) { 253 BrowserAccessibility* node) {
254 DCHECK(node);
250 // On Windows, we always fire a FOCUS event on the root of a frame before 255 // On Windows, we always fire a FOCUS event on the root of a frame before
251 // firing a focus event within that frame. 256 // firing a focus event within that frame.
252 if (node->manager() != last_focused_manager_ && 257 if (node->manager() != last_focused_manager_ &&
253 node != node->manager()->GetRoot()) { 258 node != node->manager()->GetRoot()) {
254 NotifyAccessibilityEvent(ui::AX_EVENT_FOCUS, node->manager()->GetRoot()); 259 NotifyAccessibilityEvent(ui::AX_EVENT_FOCUS, node->manager()->GetRoot());
255 } 260 }
256 261
257 BrowserAccessibilityManager::FireFocusEvent(node); 262 BrowserAccessibilityManager::FireFocusEvent(node);
258 } 263 }
259 264
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 340
336 void BrowserAccessibilityManagerWin::TrackScrollingObject( 341 void BrowserAccessibilityManagerWin::TrackScrollingObject(
337 BrowserAccessibilityWin* node) { 342 BrowserAccessibilityWin* node) {
338 if (tracked_scroll_object_) 343 if (tracked_scroll_object_)
339 tracked_scroll_object_->Release(); 344 tracked_scroll_object_->Release();
340 tracked_scroll_object_ = node; 345 tracked_scroll_object_ = node;
341 tracked_scroll_object_->AddRef(); 346 tracked_scroll_object_->AddRef();
342 } 347 }
343 348
344 } // namespace content 349 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698