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

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

Issue 2957973003: Automatically fire AX events on Win based on tree changes (Closed)
Patch Set: Audit all events, manually test with JAWS and NVDA Created 3 years, 4 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>
11 11
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/win/scoped_comptr.h" 13 #include "base/win/scoped_comptr.h"
14 #include "base/win/windows_version.h" 14 #include "base/win/windows_version.h"
15 #include "content/browser/accessibility/browser_accessibility_event_win.h" 15 #include "content/browser/accessibility/browser_accessibility_event_win.h"
16 #include "content/browser/accessibility/browser_accessibility_state_impl.h" 16 #include "content/browser/accessibility/browser_accessibility_state_impl.h"
17 #include "content/browser/accessibility/browser_accessibility_win.h" 17 #include "content/browser/accessibility/browser_accessibility_win.h"
18 #include "content/browser/renderer_host/legacy_render_widget_host_win.h" 18 #include "content/browser/renderer_host/legacy_render_widget_host_win.h"
19 #include "content/common/accessibility_messages.h" 19 #include "content/common/accessibility_messages.h"
20 #include "ui/base/win/atl_module.h" 20 #include "ui/base/win/atl_module.h"
21 21
22 namespace content { 22 namespace content {
23 23
24 namespace {
25
26 bool IsContainerWithSelectableChildrenRole(ui::AXRole role) {
27 switch (role) {
28 case ui::AX_ROLE_COMBO_BOX:
29 case ui::AX_ROLE_GRID:
30 case ui::AX_ROLE_LIST_BOX:
31 case ui::AX_ROLE_MENU:
32 case ui::AX_ROLE_MENU_BAR:
33 case ui::AX_ROLE_RADIO_GROUP:
34 case ui::AX_ROLE_TAB_LIST:
35 case ui::AX_ROLE_TOOLBAR:
36 case ui::AX_ROLE_TREE:
37 case ui::AX_ROLE_TREE_GRID:
38 return true;
39 default:
40 return false;
41 }
42 }
43
44 } // namespace
45
24 // static 46 // static
25 BrowserAccessibilityManager* BrowserAccessibilityManager::Create( 47 BrowserAccessibilityManager* BrowserAccessibilityManager::Create(
26 const ui::AXTreeUpdate& initial_tree, 48 const ui::AXTreeUpdate& initial_tree,
27 BrowserAccessibilityDelegate* delegate, 49 BrowserAccessibilityDelegate* delegate,
28 BrowserAccessibilityFactory* factory) { 50 BrowserAccessibilityFactory* factory) {
29 return new BrowserAccessibilityManagerWin(initial_tree, delegate, factory); 51 return new BrowserAccessibilityManagerWin(initial_tree, delegate, factory);
30 } 52 }
31 53
32 BrowserAccessibilityManagerWin* 54 BrowserAccessibilityManagerWin*
33 BrowserAccessibilityManager::ToBrowserAccessibilityManagerWin() { 55 BrowserAccessibilityManager::ToBrowserAccessibilityManagerWin() {
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 BrowserAccessibilityDelegate* delegate = GetDelegateFromRootManager(); 258 BrowserAccessibilityDelegate* delegate = GetDelegateFromRootManager();
237 if (delegate) { 259 if (delegate) {
238 gfx::Rect bounds = delegate->AccessibilityGetViewBounds(); 260 gfx::Rect bounds = delegate->AccessibilityGetViewBounds();
239 if (device_scale_factor() > 0.0 && device_scale_factor() != 1.0) 261 if (device_scale_factor() > 0.0 && device_scale_factor() != 1.0)
240 bounds = ScaleToEnclosingRect(bounds, device_scale_factor()); 262 bounds = ScaleToEnclosingRect(bounds, device_scale_factor());
241 return bounds; 263 return bounds;
242 } 264 }
243 return gfx::Rect(); 265 return gfx::Rect();
244 } 266 }
245 267
268 void BrowserAccessibilityManagerWin::OnTreeDataChanged(
269 ui::AXTree* tree,
270 const ui::AXTreeData& old_tree_data,
271 const ui::AXTreeData& new_tree_data) {
272 BrowserAccessibilityManager::OnTreeDataChanged(tree, old_tree_data,
273 new_tree_data);
274 if (new_tree_data.loaded && !old_tree_data.loaded)
275 tree_events_[tree->root()->id()].insert(ui::AX_EVENT_LOAD_COMPLETE);
276 if (new_tree_data.sel_anchor_object_id !=
277 old_tree_data.sel_anchor_object_id ||
278 new_tree_data.sel_anchor_offset != old_tree_data.sel_anchor_offset ||
279 new_tree_data.sel_anchor_affinity != old_tree_data.sel_anchor_affinity ||
280 new_tree_data.sel_focus_object_id != old_tree_data.sel_focus_object_id ||
281 new_tree_data.sel_focus_offset != old_tree_data.sel_focus_offset ||
282 new_tree_data.sel_focus_affinity != old_tree_data.sel_focus_affinity) {
283 tree_events_[tree->root()->id()].insert(
284 ui::AX_EVENT_DOCUMENT_SELECTION_CHANGED);
285 }
286 }
287
246 void BrowserAccessibilityManagerWin::OnNodeCreated(ui::AXTree* tree, 288 void BrowserAccessibilityManagerWin::OnNodeCreated(ui::AXTree* tree,
247 ui::AXNode* node) { 289 ui::AXNode* node) {
248 DCHECK(node); 290 DCHECK(node);
249 BrowserAccessibilityManager::OnNodeCreated(tree, node); 291 BrowserAccessibilityManager::OnNodeCreated(tree, node);
250 BrowserAccessibility* obj = GetFromAXNode(node); 292 BrowserAccessibility* obj = GetFromAXNode(node);
251 if (!obj) 293 if (!obj)
252 return; 294 return;
253 if (!obj->IsNative()) 295 if (!obj->IsNative())
254 return; 296 return;
255 } 297 }
256 298
299 void BrowserAccessibilityManagerWin::OnNodeDataWillChange(
300 ui::AXTree* tree,
301 const ui::AXNodeData& old_node_data,
302 const ui::AXNodeData& new_node_data) {
303 if (new_node_data.child_ids != old_node_data.child_ids &&
304 new_node_data.role != ui::AX_ROLE_STATIC_TEXT) {
305 tree_events_[new_node_data.id].insert(ui::AX_EVENT_CHILDREN_CHANGED);
306 }
307 }
308
309 void BrowserAccessibilityManagerWin::OnStateChanged(ui::AXTree* tree,
310 ui::AXNode* node,
311 ui::AXState state,
312 bool new_value) {
313 if (state == ui::AX_STATE_SELECTED) {
314 ui::AXNode* container = node;
315 while (container &&
316 !IsContainerWithSelectableChildrenRole(container->data().role))
317 container = container->parent();
318 if (container) {
319 tree_events_[container->id()].insert(
320 ui::AX_EVENT_SELECTED_CHILDREN_CHANGED);
321 }
322 }
323 }
324
325 void BrowserAccessibilityManagerWin::OnIntAttributeChanged(
326 ui::AXTree* tree,
327 ui::AXNode* node,
328 ui::AXIntAttribute attr,
329 int32_t old_value,
330 int32_t new_value) {
331 BrowserAccessibilityManager::OnIntAttributeChanged(tree, node, attr,
332 old_value, new_value);
333 switch (attr) {
334 case ui::AX_ATTR_ACTIVEDESCENDANT_ID:
335 tree_events_[node->id()].insert(ui::AX_EVENT_ACTIVEDESCENDANTCHANGED);
336 break;
337 case ui::AX_ATTR_SCROLL_X:
338 case ui::AX_ATTR_SCROLL_Y:
339 tree_events_[node->id()].insert(ui::AX_EVENT_SCROLL_POSITION_CHANGED);
340 break;
341 default:
342 break;
343 }
344 }
345
257 void BrowserAccessibilityManagerWin::OnAtomicUpdateFinished( 346 void BrowserAccessibilityManagerWin::OnAtomicUpdateFinished(
258 ui::AXTree* tree, 347 ui::AXTree* tree,
259 bool root_changed, 348 bool root_changed,
260 const std::vector<ui::AXTreeDelegate::Change>& changes) { 349 const std::vector<ui::AXTreeDelegate::Change>& changes) {
261 BrowserAccessibilityManager::OnAtomicUpdateFinished( 350 BrowserAccessibilityManager::OnAtomicUpdateFinished(
262 tree, root_changed, changes); 351 tree, root_changed, changes);
263 352
353 if (root_changed && tree->data().loaded)
354 tree_events_[tree->root()->id()].insert(ui::AX_EVENT_LOAD_COMPLETE);
355
356 // Handle live region changes.
357 for (size_t i = 0; i < changes.size(); ++i) {
358 const ui::AXNode* node = changes[i].node;
359 DCHECK(node);
360 if (node->data().HasStringAttribute(ui::AX_ATTR_CONTAINER_LIVE_STATUS)) {
361 const ui::AXNode* container = node;
362 while (container &&
363 !container->data().HasStringAttribute(ui::AX_ATTR_LIVE_STATUS)) {
364 container = container->parent();
365 }
366 if (container)
367 tree_events_[container->id()].insert(ui::AX_EVENT_LIVE_REGION_CHANGED);
368 }
369 }
370
264 // Do a sequence of Windows-specific updates on each node. Each one is 371 // Do a sequence of Windows-specific updates on each node. Each one is
265 // done in a single pass that must complete before the next step starts. 372 // done in a single pass that must complete before the next step starts.
266 // The first step moves win_attributes_ to old_win_attributes_ and then 373 // The first step moves win_attributes_ to old_win_attributes_ and then
267 // recomputes all of win_attributes_ other than IAccessibleText. 374 // recomputes all of win_attributes_ other than IAccessibleText.
268 for (size_t i = 0; i < changes.size(); ++i) { 375 for (size_t i = 0; i < changes.size(); ++i) {
269 const ui::AXNode* changed_node = changes[i].node; 376 const ui::AXNode* changed_node = changes[i].node;
270 DCHECK(changed_node); 377 DCHECK(changed_node);
271 BrowserAccessibility* obj = GetFromAXNode(changed_node); 378 BrowserAccessibility* obj = GetFromAXNode(changed_node);
272 if (obj && obj->IsNative() && !obj->PlatformIsChildOfLeaf()) 379 if (obj && obj->IsNative() && !obj->PlatformIsChildOfLeaf())
273 ToBrowserAccessibilityWin(obj) 380 ToBrowserAccessibilityWin(obj)
(...skipping 25 matching lines...) Expand all
299 DCHECK(changed_node); 406 DCHECK(changed_node);
300 BrowserAccessibility* obj = GetFromAXNode(changed_node); 407 BrowserAccessibility* obj = GetFromAXNode(changed_node);
301 if (obj && obj->IsNative() && !obj->PlatformIsChildOfLeaf()) { 408 if (obj && obj->IsNative() && !obj->PlatformIsChildOfLeaf()) {
302 ToBrowserAccessibilityWin(obj)->GetCOM()->UpdateStep3FireEvents( 409 ToBrowserAccessibilityWin(obj)->GetCOM()->UpdateStep3FireEvents(
303 changes[i].type == AXTreeDelegate::SUBTREE_CREATED); 410 changes[i].type == AXTreeDelegate::SUBTREE_CREATED);
304 } 411 }
305 } 412 }
306 } 413 }
307 414
308 } // namespace content 415 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698