| OLD | NEW |
| 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.h" | 5 #include "content/browser/accessibility/browser_accessibility_manager.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 for (unsigned int i = 0; i < node->InternalChildCount(); ++i) { | 31 for (unsigned int i = 0; i < node->InternalChildCount(); ++i) { |
| 32 BrowserAccessibility* child = node->InternalGetChild(i); | 32 BrowserAccessibility* child = node->InternalGetChild(i); |
| 33 BrowserAccessibility* result = FindNodeWithChildTreeId(child, ax_tree_id); | 33 BrowserAccessibility* result = FindNodeWithChildTreeId(child, ax_tree_id); |
| 34 if (result) | 34 if (result) |
| 35 return result; | 35 return result; |
| 36 } | 36 } |
| 37 | 37 |
| 38 return nullptr; | 38 return nullptr; |
| 39 } | 39 } |
| 40 | 40 |
| 41 } // namespace | |
| 42 | |
| 43 // Map from AXTreeID to BrowserAccessibilityManager | 41 // Map from AXTreeID to BrowserAccessibilityManager |
| 44 using AXTreeIDMap = base::hash_map<ui::AXTreeIDRegistry::AXTreeID, | 42 using AXTreeIDMap = base::hash_map<ui::AXTreeIDRegistry::AXTreeID, |
| 45 BrowserAccessibilityManager*>; | 43 BrowserAccessibilityManager*>; |
| 46 base::LazyInstance<AXTreeIDMap>::DestructorAtExit g_ax_tree_id_map = | 44 base::LazyInstance<AXTreeIDMap>::DestructorAtExit g_ax_tree_id_map = |
| 47 LAZY_INSTANCE_INITIALIZER; | 45 LAZY_INSTANCE_INITIALIZER; |
| 48 | 46 |
| 49 // A function to call when focus changes, for testing only. | 47 // A function to call when focus changes, for testing only. |
| 50 base::LazyInstance<base::Closure>::DestructorAtExit | 48 base::LazyInstance<base::Closure>::DestructorAtExit |
| 51 g_focus_change_callback_for_testing = LAZY_INSTANCE_INITIALIZER; | 49 g_focus_change_callback_for_testing = LAZY_INSTANCE_INITIALIZER; |
| 52 | 50 |
| 51 // A flag for use in tests to ensure focus events aren't suppressed. |
| 52 bool g_never_suppress_focus_events_for_testing = false; |
| 53 |
| 54 } // namespace |
| 55 |
| 53 ui::AXTreeUpdate MakeAXTreeUpdate( | 56 ui::AXTreeUpdate MakeAXTreeUpdate( |
| 54 const ui::AXNodeData& node1, | 57 const ui::AXNodeData& node1, |
| 55 const ui::AXNodeData& node2 /* = ui::AXNodeData() */, | 58 const ui::AXNodeData& node2 /* = ui::AXNodeData() */, |
| 56 const ui::AXNodeData& node3 /* = ui::AXNodeData() */, | 59 const ui::AXNodeData& node3 /* = ui::AXNodeData() */, |
| 57 const ui::AXNodeData& node4 /* = ui::AXNodeData() */, | 60 const ui::AXNodeData& node4 /* = ui::AXNodeData() */, |
| 58 const ui::AXNodeData& node5 /* = ui::AXNodeData() */, | 61 const ui::AXNodeData& node5 /* = ui::AXNodeData() */, |
| 59 const ui::AXNodeData& node6 /* = ui::AXNodeData() */, | 62 const ui::AXNodeData& node6 /* = ui::AXNodeData() */, |
| 60 const ui::AXNodeData& node7 /* = ui::AXNodeData() */, | 63 const ui::AXNodeData& node7 /* = ui::AXNodeData() */, |
| 61 const ui::AXNodeData& node8 /* = ui::AXNodeData() */, | 64 const ui::AXNodeData& node8 /* = ui::AXNodeData() */, |
| 62 const ui::AXNodeData& node9 /* = ui::AXNodeData() */, | 65 const ui::AXNodeData& node9 /* = ui::AXNodeData() */, |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 ui::AXEvent event_type, | 203 ui::AXEvent event_type, |
| 201 BrowserAccessibility* node) { | 204 BrowserAccessibility* node) { |
| 202 BrowserAccessibilityEvent::Create(source, event_type, node)->Fire(); | 205 BrowserAccessibilityEvent::Create(source, event_type, node)->Fire(); |
| 203 } | 206 } |
| 204 | 207 |
| 205 void BrowserAccessibilityManager::FireFocusEventsIfNeeded( | 208 void BrowserAccessibilityManager::FireFocusEventsIfNeeded( |
| 206 BrowserAccessibilityEvent::Source source) { | 209 BrowserAccessibilityEvent::Source source) { |
| 207 BrowserAccessibility* focus = GetFocus(); | 210 BrowserAccessibility* focus = GetFocus(); |
| 208 | 211 |
| 209 // Don't fire focus events if the window itself doesn't have focus. | 212 // Don't fire focus events if the window itself doesn't have focus. |
| 210 // Bypass this check if a global focus listener was set up for testing | 213 // Bypass this check for some tests. |
| 211 // so that the test passes whether the window is active or not. | 214 if (!g_never_suppress_focus_events_for_testing && |
| 212 if (g_focus_change_callback_for_testing.Get().is_null()) { | 215 !g_focus_change_callback_for_testing.Get()) { |
| 213 if (delegate_ && !delegate_->AccessibilityViewHasFocus()) | 216 if (delegate_ && !delegate_->AccessibilityViewHasFocus()) |
| 214 focus = nullptr; | 217 focus = nullptr; |
| 215 | 218 |
| 216 if (!CanFireEvents()) | 219 if (!CanFireEvents()) |
| 217 focus = nullptr; | 220 focus = nullptr; |
| 218 } | 221 } |
| 219 | 222 |
| 220 // Don't allow the document to be focused if it has no children and | 223 // Don't allow the document to be focused if it has no children and |
| 221 // hasn't finished loading yet. Wait for at least a tiny bit of content, | 224 // hasn't finished loading yet. Wait for at least a tiny bit of content, |
| 222 // or for the document to actually finish loading. | 225 // or for the document to actually finish loading. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 237 | 240 |
| 238 bool BrowserAccessibilityManager::CanFireEvents() { | 241 bool BrowserAccessibilityManager::CanFireEvents() { |
| 239 return true; | 242 return true; |
| 240 } | 243 } |
| 241 | 244 |
| 242 void BrowserAccessibilityManager::FireFocusEvent( | 245 void BrowserAccessibilityManager::FireFocusEvent( |
| 243 BrowserAccessibilityEvent::Source source, | 246 BrowserAccessibilityEvent::Source source, |
| 244 BrowserAccessibility* node) { | 247 BrowserAccessibility* node) { |
| 245 NotifyAccessibilityEvent(source, ui::AX_EVENT_FOCUS, node); | 248 NotifyAccessibilityEvent(source, ui::AX_EVENT_FOCUS, node); |
| 246 | 249 |
| 247 if (!g_focus_change_callback_for_testing.Get().is_null()) | 250 if (g_focus_change_callback_for_testing.Get()) |
| 248 g_focus_change_callback_for_testing.Get().Run(); | 251 g_focus_change_callback_for_testing.Get().Run(); |
| 249 } | 252 } |
| 250 | 253 |
| 251 BrowserAccessibility* BrowserAccessibilityManager::GetRoot() { | 254 BrowserAccessibility* BrowserAccessibilityManager::GetRoot() { |
| 252 // tree_ can be null during destruction. | 255 // tree_ can be null during destruction. |
| 253 if (!tree_) | 256 if (!tree_) |
| 254 return nullptr; | 257 return nullptr; |
| 255 | 258 |
| 256 // tree_->root() can be null during AXTreeDelegate callbacks. | 259 // tree_->root() can be null during AXTreeDelegate callbacks. |
| 257 ui::AXNode* root = tree_->root(); | 260 ui::AXNode* root = tree_->root(); |
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 596 data.focus_id = node->GetId(); | 599 data.focus_id = node->GetId(); |
| 597 tree_->UpdateData(data); | 600 tree_->UpdateData(data); |
| 598 } | 601 } |
| 599 | 602 |
| 600 // static | 603 // static |
| 601 void BrowserAccessibilityManager::SetFocusChangeCallbackForTesting( | 604 void BrowserAccessibilityManager::SetFocusChangeCallbackForTesting( |
| 602 const base::Closure& callback) { | 605 const base::Closure& callback) { |
| 603 g_focus_change_callback_for_testing.Get() = callback; | 606 g_focus_change_callback_for_testing.Get() = callback; |
| 604 } | 607 } |
| 605 | 608 |
| 609 // static |
| 610 void BrowserAccessibilityManager::NeverSuppressFocusEventsForTesting() { |
| 611 g_never_suppress_focus_events_for_testing = true; |
| 612 } |
| 613 |
| 606 void BrowserAccessibilityManager::Decrement( | 614 void BrowserAccessibilityManager::Decrement( |
| 607 const BrowserAccessibility& node) { | 615 const BrowserAccessibility& node) { |
| 608 if (!delegate_) | 616 if (!delegate_) |
| 609 return; | 617 return; |
| 610 | 618 |
| 611 ui::AXActionData action_data; | 619 ui::AXActionData action_data; |
| 612 action_data.action = ui::AX_ACTION_DECREMENT; | 620 action_data.action = ui::AX_ACTION_DECREMENT; |
| 613 action_data.target_node_id = node.GetId(); | 621 action_data.target_node_id = node.GetId(); |
| 614 delegate_->AccessibilityPerformAction(action_data); | 622 delegate_->AccessibilityPerformAction(action_data); |
| 615 } | 623 } |
| (...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1270 hit_test_result = parent; | 1278 hit_test_result = parent; |
| 1271 parent = parent->PlatformGetParent(); | 1279 parent = parent->PlatformGetParent(); |
| 1272 } | 1280 } |
| 1273 | 1281 |
| 1274 last_hover_ax_tree_id_ = hit_test_result->manager()->ax_tree_id(); | 1282 last_hover_ax_tree_id_ = hit_test_result->manager()->ax_tree_id(); |
| 1275 last_hover_node_id_ = hit_test_result->GetId(); | 1283 last_hover_node_id_ = hit_test_result->GetId(); |
| 1276 last_hover_bounds_ = hit_test_result->GetScreenBoundsRect(); | 1284 last_hover_bounds_ = hit_test_result->GetScreenBoundsRect(); |
| 1277 } | 1285 } |
| 1278 | 1286 |
| 1279 } // namespace content | 1287 } // namespace content |
| OLD | NEW |