| 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 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 BrowserAccessibilityEvent::FromChildFrameLoading, | 383 BrowserAccessibilityEvent::FromChildFrameLoading, |
| 384 ui::AX_EVENT_CHILDREN_CHANGED, | 384 ui::AX_EVENT_CHILDREN_CHANGED, |
| 385 parent); | 385 parent); |
| 386 connected_to_parent_tree_node_ = true; | 386 connected_to_parent_tree_node_ = true; |
| 387 } | 387 } |
| 388 } else { | 388 } else { |
| 389 connected_to_parent_tree_node_ = false; | 389 connected_to_parent_tree_node_ = false; |
| 390 } | 390 } |
| 391 | 391 |
| 392 // Fire any events related to changes to the tree. | 392 // Fire any events related to changes to the tree. |
| 393 for (auto& event : tree_events_) { | 393 for (auto& entry : tree_events_) { |
| 394 BrowserAccessibility* event_target = GetFromID(event.second); | 394 BrowserAccessibility* event_target = GetFromID(entry.first); |
| 395 if (!event_target) | 395 if (!event_target) |
| 396 continue; | 396 continue; |
| 397 NotifyAccessibilityEvent(BrowserAccessibilityEvent::FromTreeChange, | 397 std::set<ui::AXEvent>& events = entry.second; |
| 398 event.first, event_target); | 398 if (events.find(ui::AX_EVENT_LIVE_REGION_CREATED) != events.end() || |
| 399 events.find(ui::AX_EVENT_ALERT) != events.end()) { |
| 400 events.erase(ui::AX_EVENT_LIVE_REGION_CHANGED); |
| 401 } |
| 402 for (auto event : events) { |
| 403 NotifyAccessibilityEvent(BrowserAccessibilityEvent::FromTreeChange, event, |
| 404 event_target); |
| 405 } |
| 399 } | 406 } |
| 400 tree_events_.clear(); | 407 tree_events_.clear(); |
| 401 | 408 |
| 402 // Based on the changes to the tree, first fire focus events if needed. | 409 // Based on the changes to the tree, fire focus events if needed. |
| 403 // Screen readers might not do the right thing if they're not aware of what | 410 // Screen readers might not do the right thing if they're not aware of what |
| 404 // has focus, so always try that first. Nothing will be fired if the window | 411 // has focus, so always try that first. Nothing will be fired if the window |
| 405 // itself isn't focused or if focus hasn't changed. | 412 // itself isn't focused or if focus hasn't changed. |
| 406 GetRootManager()->FireFocusEventsIfNeeded( | 413 GetRootManager()->FireFocusEventsIfNeeded( |
| 407 BrowserAccessibilityEvent::FromBlink); | 414 BrowserAccessibilityEvent::FromBlink); |
| 408 | 415 |
| 409 // Now iterate over the events from the renderer and fire the events | 416 // We are in the process of inferring all native events from tree changes. |
| 410 // other than focus events. | 417 // Mac OS X no longer needs to iterate over the specific events coming from |
| 418 // the renderer, all needed events were fired above by iterating over |
| 419 // tree_events_. |
| 420 // |
| 421 // When all platforms have switched to inferring all events, we can delete |
| 422 // the following code, which iterates over the non-focus events from the |
| 423 // renderer and fires native events based on them. |
| 424 // |
| 425 // See http://crbug.com/699438 for details. |
| 411 for (uint32_t index = 0; index < details.size(); index++) { | 426 for (uint32_t index = 0; index < details.size(); index++) { |
| 412 const AXEventNotificationDetails& detail = details[index]; | 427 const AXEventNotificationDetails& detail = details[index]; |
| 413 | 428 |
| 414 // Find the node corresponding to the id that's the target of the | 429 // Find the node corresponding to the id that's the target of the |
| 415 // event (which may not be the root of the update tree). | 430 // event (which may not be the root of the update tree). |
| 416 ui::AXNode* node = tree_->GetFromId(detail.id); | 431 ui::AXNode* node = tree_->GetFromId(detail.id); |
| 417 if (!node) | 432 if (!node) |
| 418 continue; | 433 continue; |
| 419 | 434 |
| 420 ui::AXEvent event_type = detail.event_type; | 435 ui::AXEvent event_type = detail.event_type; |
| 436 |
| 437 #if defined(OS_MACOSX) |
| 438 if (event_type != ui::AX_EVENT_HOVER) |
| 439 continue; |
| 440 #endif // !defined(OS_MACOSX) |
| 441 |
| 421 if (event_type == ui::AX_EVENT_FOCUS || | 442 if (event_type == ui::AX_EVENT_FOCUS || |
| 422 event_type == ui::AX_EVENT_BLUR) { | 443 event_type == ui::AX_EVENT_BLUR) { |
| 423 if (osk_state_ != OSK_DISALLOWED_BECAUSE_TAB_HIDDEN && | 444 if (osk_state_ != OSK_DISALLOWED_BECAUSE_TAB_HIDDEN && |
| 424 osk_state_ != OSK_DISALLOWED_BECAUSE_TAB_JUST_APPEARED) { | 445 osk_state_ != OSK_DISALLOWED_BECAUSE_TAB_JUST_APPEARED) { |
| 425 osk_state_ = OSK_ALLOWED; | 446 osk_state_ = OSK_ALLOWED; |
| 426 } | 447 } |
| 427 | 448 |
| 428 // We already handled all focus events above. | 449 // We already handled all focus events above. |
| 429 continue; | 450 continue; |
| 430 } | 451 } |
| (...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1093 } while (current); | 1114 } while (current); |
| 1094 | 1115 |
| 1095 return result; | 1116 return result; |
| 1096 } | 1117 } |
| 1097 | 1118 |
| 1098 void BrowserAccessibilityManager::OnNodeDataWillChange( | 1119 void BrowserAccessibilityManager::OnNodeDataWillChange( |
| 1099 ui::AXTree* tree, | 1120 ui::AXTree* tree, |
| 1100 const ui::AXNodeData& old_node_data, | 1121 const ui::AXNodeData& old_node_data, |
| 1101 const ui::AXNodeData& new_node_data) {} | 1122 const ui::AXNodeData& new_node_data) {} |
| 1102 | 1123 |
| 1103 void BrowserAccessibilityManager::OnTreeDataChanged(ui::AXTree* tree) { | 1124 void BrowserAccessibilityManager::OnTreeDataChanged( |
| 1104 } | 1125 ui::AXTree* tree, |
| 1126 const ui::AXTreeData& old_tree_data, |
| 1127 const ui::AXTreeData& new_tree_data) {} |
| 1105 | 1128 |
| 1106 void BrowserAccessibilityManager::OnNodeWillBeDeleted(ui::AXTree* tree, | 1129 void BrowserAccessibilityManager::OnNodeWillBeDeleted(ui::AXTree* tree, |
| 1107 ui::AXNode* node) { | 1130 ui::AXNode* node) { |
| 1108 DCHECK(node); | 1131 DCHECK(node); |
| 1109 if (id_wrapper_map_.find(node->id()) == id_wrapper_map_.end()) | 1132 if (id_wrapper_map_.find(node->id()) == id_wrapper_map_.end()) |
| 1110 return; | 1133 return; |
| 1111 GetFromAXNode(node)->Destroy(); | 1134 GetFromAXNode(node)->Destroy(); |
| 1112 id_wrapper_map_.erase(node->id()); | 1135 id_wrapper_map_.erase(node->id()); |
| 1113 } | 1136 } |
| 1114 | 1137 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1190 for (auto& change : changes) { | 1213 for (auto& change : changes) { |
| 1191 if (change.type != NODE_CREATED && change.type != SUBTREE_CREATED) | 1214 if (change.type != NODE_CREATED && change.type != SUBTREE_CREATED) |
| 1192 continue; | 1215 continue; |
| 1193 | 1216 |
| 1194 const ui::AXNode* created_node = change.node; | 1217 const ui::AXNode* created_node = change.node; |
| 1195 DCHECK(created_node); | 1218 DCHECK(created_node); |
| 1196 BrowserAccessibility* object = GetFromAXNode(created_node); | 1219 BrowserAccessibility* object = GetFromAXNode(created_node); |
| 1197 if (object && object->HasStringAttribute(ui::AX_ATTR_LIVE_STATUS)) { | 1220 if (object && object->HasStringAttribute(ui::AX_ATTR_LIVE_STATUS)) { |
| 1198 int32_t id = object->GetId(); | 1221 int32_t id = object->GetId(); |
| 1199 if (object->GetRole() == ui::AX_ROLE_ALERT) { | 1222 if (object->GetRole() == ui::AX_ROLE_ALERT) { |
| 1200 tree_events_.push_back(std::make_pair(ui::AX_EVENT_ALERT, id)); | 1223 tree_events_[id].insert(ui::AX_EVENT_ALERT); |
| 1201 } else { | 1224 } else { |
| 1202 tree_events_.push_back( | 1225 tree_events_[id].insert(ui::AX_EVENT_LIVE_REGION_CREATED); |
| 1203 std::make_pair(ui::AX_EVENT_LIVE_REGION_CREATED, id)); | |
| 1204 } | 1226 } |
| 1205 } | 1227 } |
| 1206 } | 1228 } |
| 1207 } | 1229 } |
| 1208 | 1230 |
| 1209 BrowserAccessibilityManager* BrowserAccessibilityManager::GetRootManager() { | 1231 BrowserAccessibilityManager* BrowserAccessibilityManager::GetRootManager() { |
| 1210 BrowserAccessibility* parent = GetParentNodeFromParentTree(); | 1232 BrowserAccessibility* parent = GetParentNodeFromParentTree(); |
| 1211 if (!parent) | 1233 if (!parent) |
| 1212 return this; | 1234 return this; |
| 1213 | 1235 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1290 hit_test_result = parent; | 1312 hit_test_result = parent; |
| 1291 parent = parent->PlatformGetParent(); | 1313 parent = parent->PlatformGetParent(); |
| 1292 } | 1314 } |
| 1293 | 1315 |
| 1294 last_hover_ax_tree_id_ = hit_test_result->manager()->ax_tree_id(); | 1316 last_hover_ax_tree_id_ = hit_test_result->manager()->ax_tree_id(); |
| 1295 last_hover_node_id_ = hit_test_result->GetId(); | 1317 last_hover_node_id_ = hit_test_result->GetId(); |
| 1296 last_hover_bounds_ = hit_test_result->GetScreenBoundsRect(); | 1318 last_hover_bounds_ = hit_test_result->GetScreenBoundsRect(); |
| 1297 } | 1319 } |
| 1298 | 1320 |
| 1299 } // namespace content | 1321 } // namespace content |
| OLD | NEW |