| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "content/public/common/content_switches.h" | 8 #include "content/public/common/content_switches.h" |
| 9 #include "content/renderer/render_view_impl.h" | 9 #include "content/renderer/render_view_impl.h" |
| 10 #include "content/renderer/renderer_accessibility.h" | 10 #include "content/renderer/renderer_accessibility.h" |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 IPC_MESSAGE_HANDLER(AccessibilityMsg_ScrollToPoint, | 116 IPC_MESSAGE_HANDLER(AccessibilityMsg_ScrollToPoint, |
| 117 OnScrollToPoint) | 117 OnScrollToPoint) |
| 118 IPC_MESSAGE_HANDLER(AccessibilityMsg_SetTextSelection, | 118 IPC_MESSAGE_HANDLER(AccessibilityMsg_SetTextSelection, |
| 119 OnSetTextSelection) | 119 OnSetTextSelection) |
| 120 IPC_MESSAGE_UNHANDLED(handled = false) | 120 IPC_MESSAGE_UNHANDLED(handled = false) |
| 121 IPC_END_MESSAGE_MAP() | 121 IPC_END_MESSAGE_MAP() |
| 122 return handled; | 122 return handled; |
| 123 } | 123 } |
| 124 | 124 |
| 125 void RendererAccessibility::FocusedNodeChanged(const WebNode& node) { | 125 void RendererAccessibility::FocusedNodeChanged(const WebNode& node) { |
| 126 if (!WebAccessibilityObject::accessibilityEnabled()) | 126 if (mode_ == AccessibilityModeOff) |
| 127 return; | 127 return; |
| 128 | 128 |
| 129 const WebDocument& document = GetMainDocument(); | 129 const WebDocument& document = GetMainDocument(); |
| 130 if (document.isNull()) | 130 if (document.isNull()) |
| 131 return; | 131 return; |
| 132 | 132 |
| 133 if (node.isNull()) { | 133 if (node.isNull()) { |
| 134 // When focus is cleared, implicitly focus the document. | 134 // When focus is cleared, implicitly focus the document. |
| 135 // TODO(dmazzoni): Make WebKit send this notification instead. | 135 // TODO(dmazzoni): Make WebKit send this notification instead. |
| 136 PostAccessibilityNotification( | 136 PostAccessibilityNotification( |
| 137 document.accessibilityObject(), | 137 document.accessibilityObject(), |
| 138 AccessibilityNotificationBlur); | 138 AccessibilityNotificationBlur); |
| 139 } | 139 } |
| 140 } | 140 } |
| 141 | 141 |
| 142 void RendererAccessibility::DidFinishLoad(WebKit::WebFrame* frame) { | 142 void RendererAccessibility::DidFinishLoad(WebKit::WebFrame* frame) { |
| 143 if (!WebAccessibilityObject::accessibilityEnabled()) | 143 if (mode_ == AccessibilityModeOff) |
| 144 return; | 144 return; |
| 145 | 145 |
| 146 const WebDocument& document = GetMainDocument(); | 146 const WebDocument& document = GetMainDocument(); |
| 147 if (document.isNull()) | 147 if (document.isNull()) |
| 148 return; | 148 return; |
| 149 | 149 |
| 150 // Check to see if the root accessibility object has changed, to work | 150 // Check to see if the root accessibility object has changed, to work |
| 151 // around WebKit bugs that cause AXObjectCache to be cleared | 151 // around WebKit bugs that cause AXObjectCache to be cleared |
| 152 // unnecessarily. | 152 // unnecessarily. |
| 153 // TODO(dmazzoni): remove this once rdar://5794454 is fixed. | 153 // TODO(dmazzoni): remove this once rdar://5794454 is fixed. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 167 notification, &temp)) { | 167 notification, &temp)) { |
| 168 return; | 168 return; |
| 169 } | 169 } |
| 170 | 170 |
| 171 PostAccessibilityNotification(obj, temp); | 171 PostAccessibilityNotification(obj, temp); |
| 172 } | 172 } |
| 173 | 173 |
| 174 void RendererAccessibility::PostAccessibilityNotification( | 174 void RendererAccessibility::PostAccessibilityNotification( |
| 175 const WebKit::WebAccessibilityObject& obj, | 175 const WebKit::WebAccessibilityObject& obj, |
| 176 AccessibilityNotification notification) { | 176 AccessibilityNotification notification) { |
| 177 if (!WebAccessibilityObject::accessibilityEnabled()) | 177 if (mode_ == AccessibilityModeOff) |
| 178 return; | 178 return; |
| 179 | 179 |
| 180 const WebDocument& document = GetMainDocument(); | 180 const WebDocument& document = GetMainDocument(); |
| 181 if (document.isNull()) | 181 if (document.isNull()) |
| 182 return; | 182 return; |
| 183 | 183 |
| 184 gfx::Size scroll_offset = document.frame()->scrollOffset(); | 184 gfx::Size scroll_offset = document.frame()->scrollOffset(); |
| 185 if (scroll_offset != last_scroll_offset_) { | 185 if (scroll_offset != last_scroll_offset_) { |
| 186 // Make sure the browser is always aware of the scroll position of | 186 // Make sure the browser is always aware of the scroll position of |
| 187 // the root document element by posting a generic notification that | 187 // the root document element by posting a generic notification that |
| (...skipping 29 matching lines...) Expand all Loading... |
| 217 // up additional notifications. | 217 // up additional notifications. |
| 218 MessageLoop::current()->PostTask( | 218 MessageLoop::current()->PostTask( |
| 219 FROM_HERE, | 219 FROM_HERE, |
| 220 base::Bind( | 220 base::Bind( |
| 221 &RendererAccessibility::SendPendingAccessibilityNotifications, | 221 &RendererAccessibility::SendPendingAccessibilityNotifications, |
| 222 weak_factory_.GetWeakPtr())); | 222 weak_factory_.GetWeakPtr())); |
| 223 } | 223 } |
| 224 } | 224 } |
| 225 | 225 |
| 226 void RendererAccessibility::SendPendingAccessibilityNotifications() { | 226 void RendererAccessibility::SendPendingAccessibilityNotifications() { |
| 227 if (mode_ == AccessibilityModeOff) |
| 228 return; |
| 229 |
| 227 const WebDocument& document = GetMainDocument(); | 230 const WebDocument& document = GetMainDocument(); |
| 228 if (document.isNull()) | 231 if (document.isNull()) |
| 229 return; | 232 return; |
| 230 | 233 |
| 231 if (pending_notifications_.empty()) | 234 if (pending_notifications_.empty()) |
| 232 return; | 235 return; |
| 233 | 236 |
| 234 ack_pending_ = true; | 237 ack_pending_ = true; |
| 235 | 238 |
| 236 // Make a copy of the notifications, because it's possible that | 239 // Make a copy of the notifications, because it's possible that |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 BrowserTreeNode* browser_node) { | 377 BrowserTreeNode* browser_node) { |
| 375 for (size_t i = 0; i < browser_node->children.size(); ++i) { | 378 for (size_t i = 0; i < browser_node->children.size(); ++i) { |
| 376 browser_id_map_.erase(browser_node->children[i]->id); | 379 browser_id_map_.erase(browser_node->children[i]->id); |
| 377 ClearBrowserTreeNode(browser_node->children[i]); | 380 ClearBrowserTreeNode(browser_node->children[i]); |
| 378 delete browser_node->children[i]; | 381 delete browser_node->children[i]; |
| 379 } | 382 } |
| 380 browser_node->children.clear(); | 383 browser_node->children.clear(); |
| 381 } | 384 } |
| 382 | 385 |
| 383 void RendererAccessibility::OnDoDefaultAction(int acc_obj_id) { | 386 void RendererAccessibility::OnDoDefaultAction(int acc_obj_id) { |
| 384 if (!WebAccessibilityObject::accessibilityEnabled()) | 387 if (mode_ == AccessibilityModeOff) |
| 385 return; | 388 return; |
| 386 | 389 |
| 387 const WebDocument& document = GetMainDocument(); | 390 const WebDocument& document = GetMainDocument(); |
| 388 if (document.isNull()) | 391 if (document.isNull()) |
| 389 return; | 392 return; |
| 390 | 393 |
| 391 WebAccessibilityObject obj = document.accessibilityObjectFromID(acc_obj_id); | 394 WebAccessibilityObject obj = document.accessibilityObjectFromID(acc_obj_id); |
| 392 if (!obj.isValid()) { | 395 if (!obj.isValid()) { |
| 393 #ifndef NDEBUG | 396 #ifndef NDEBUG |
| 394 if (logging_) | 397 if (logging_) |
| 395 LOG(WARNING) << "DoDefaultAction on invalid object id " << acc_obj_id; | 398 LOG(WARNING) << "DoDefaultAction on invalid object id " << acc_obj_id; |
| 396 #endif | 399 #endif |
| 397 return; | 400 return; |
| 398 } | 401 } |
| 399 | 402 |
| 400 obj.performDefaultAction(); | 403 obj.performDefaultAction(); |
| 401 } | 404 } |
| 402 | 405 |
| 403 void RendererAccessibility::OnScrollToMakeVisible( | 406 void RendererAccessibility::OnScrollToMakeVisible( |
| 404 int acc_obj_id, gfx::Rect subfocus) { | 407 int acc_obj_id, gfx::Rect subfocus) { |
| 405 if (!WebAccessibilityObject::accessibilityEnabled()) | 408 if (mode_ == AccessibilityModeOff) |
| 406 return; | 409 return; |
| 407 | 410 |
| 408 const WebDocument& document = GetMainDocument(); | 411 const WebDocument& document = GetMainDocument(); |
| 409 if (document.isNull()) | 412 if (document.isNull()) |
| 410 return; | 413 return; |
| 411 | 414 |
| 412 WebAccessibilityObject obj = document.accessibilityObjectFromID(acc_obj_id); | 415 WebAccessibilityObject obj = document.accessibilityObjectFromID(acc_obj_id); |
| 413 if (!obj.isValid()) { | 416 if (!obj.isValid()) { |
| 414 #ifndef NDEBUG | 417 #ifndef NDEBUG |
| 415 if (logging_) | 418 if (logging_) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 426 // position actually changes. | 429 // position actually changes. |
| 427 // TODO(dmazzoni): remove this once this bug is fixed: | 430 // TODO(dmazzoni): remove this once this bug is fixed: |
| 428 // https://bugs.webkit.org/show_bug.cgi?id=73460 | 431 // https://bugs.webkit.org/show_bug.cgi?id=73460 |
| 429 PostAccessibilityNotification( | 432 PostAccessibilityNotification( |
| 430 document.accessibilityObject(), | 433 document.accessibilityObject(), |
| 431 WebKit::WebAccessibilityNotificationLayoutComplete); | 434 WebKit::WebAccessibilityNotificationLayoutComplete); |
| 432 } | 435 } |
| 433 | 436 |
| 434 void RendererAccessibility::OnScrollToPoint( | 437 void RendererAccessibility::OnScrollToPoint( |
| 435 int acc_obj_id, gfx::Point point) { | 438 int acc_obj_id, gfx::Point point) { |
| 436 if (!WebAccessibilityObject::accessibilityEnabled()) | 439 if (mode_ == AccessibilityModeOff) |
| 437 return; | 440 return; |
| 438 | 441 |
| 439 const WebDocument& document = GetMainDocument(); | 442 const WebDocument& document = GetMainDocument(); |
| 440 if (document.isNull()) | 443 if (document.isNull()) |
| 441 return; | 444 return; |
| 442 | 445 |
| 443 WebAccessibilityObject obj = document.accessibilityObjectFromID(acc_obj_id); | 446 WebAccessibilityObject obj = document.accessibilityObjectFromID(acc_obj_id); |
| 444 if (!obj.isValid()) { | 447 if (!obj.isValid()) { |
| 445 #ifndef NDEBUG | 448 #ifndef NDEBUG |
| 446 if (logging_) | 449 if (logging_) |
| 447 LOG(WARNING) << "ScrollToPoint on invalid object id " << acc_obj_id; | 450 LOG(WARNING) << "ScrollToPoint on invalid object id " << acc_obj_id; |
| 448 #endif | 451 #endif |
| 449 return; | 452 return; |
| 450 } | 453 } |
| 451 | 454 |
| 452 obj.scrollToGlobalPoint(WebPoint(point.x(), point.y())); | 455 obj.scrollToGlobalPoint(WebPoint(point.x(), point.y())); |
| 453 | 456 |
| 454 // Make sure the browser gets a notification when the scroll | 457 // Make sure the browser gets a notification when the scroll |
| 455 // position actually changes. | 458 // position actually changes. |
| 456 // TODO(dmazzoni): remove this once this bug is fixed: | 459 // TODO(dmazzoni): remove this once this bug is fixed: |
| 457 // https://bugs.webkit.org/show_bug.cgi?id=73460 | 460 // https://bugs.webkit.org/show_bug.cgi?id=73460 |
| 458 PostAccessibilityNotification( | 461 PostAccessibilityNotification( |
| 459 document.accessibilityObject(), | 462 document.accessibilityObject(), |
| 460 WebKit::WebAccessibilityNotificationLayoutComplete); | 463 WebKit::WebAccessibilityNotificationLayoutComplete); |
| 461 } | 464 } |
| 462 | 465 |
| 463 void RendererAccessibility::OnSetTextSelection( | 466 void RendererAccessibility::OnSetTextSelection( |
| 464 int acc_obj_id, int start_offset, int end_offset) { | 467 int acc_obj_id, int start_offset, int end_offset) { |
| 465 if (!WebAccessibilityObject::accessibilityEnabled()) | 468 if (mode_ == AccessibilityModeOff) |
| 466 return; | 469 return; |
| 467 | 470 |
| 468 const WebDocument& document = GetMainDocument(); | 471 const WebDocument& document = GetMainDocument(); |
| 469 if (document.isNull()) | 472 if (document.isNull()) |
| 470 return; | 473 return; |
| 471 | 474 |
| 472 WebAccessibilityObject obj = document.accessibilityObjectFromID(acc_obj_id); | 475 WebAccessibilityObject obj = document.accessibilityObjectFromID(acc_obj_id); |
| 473 if (!obj.isValid()) { | 476 if (!obj.isValid()) { |
| 474 #ifndef NDEBUG | 477 #ifndef NDEBUG |
| 475 if (logging_) | 478 if (logging_) |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 514 // It's possible that the webview has already loaded a webpage without | 517 // It's possible that the webview has already loaded a webpage without |
| 515 // accessibility being enabled. Initialize the browser's cached | 518 // accessibility being enabled. Initialize the browser's cached |
| 516 // accessibility tree by sending it a 'load complete' notification. | 519 // accessibility tree by sending it a 'load complete' notification. |
| 517 PostAccessibilityNotification( | 520 PostAccessibilityNotification( |
| 518 document.accessibilityObject(), | 521 document.accessibilityObject(), |
| 519 WebKit::WebAccessibilityNotificationLayoutComplete); | 522 WebKit::WebAccessibilityNotificationLayoutComplete); |
| 520 } | 523 } |
| 521 } | 524 } |
| 522 | 525 |
| 523 void RendererAccessibility::OnSetFocus(int acc_obj_id) { | 526 void RendererAccessibility::OnSetFocus(int acc_obj_id) { |
| 524 if (!WebAccessibilityObject::accessibilityEnabled()) | 527 if (mode_ == AccessibilityModeOff) |
| 525 return; | 528 return; |
| 526 | 529 |
| 527 const WebDocument& document = GetMainDocument(); | 530 const WebDocument& document = GetMainDocument(); |
| 528 if (document.isNull()) | 531 if (document.isNull()) |
| 529 return; | 532 return; |
| 530 | 533 |
| 531 WebAccessibilityObject obj = document.accessibilityObjectFromID(acc_obj_id); | 534 WebAccessibilityObject obj = document.accessibilityObjectFromID(acc_obj_id); |
| 532 if (!obj.isValid()) { | 535 if (!obj.isValid()) { |
| 533 #ifndef NDEBUG | 536 #ifndef NDEBUG |
| 534 if (logging_) { | 537 if (logging_) { |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 case AccessibilityNotificationTextRemoved: | 678 case AccessibilityNotificationTextRemoved: |
| 676 return "text removed"; | 679 return "text removed"; |
| 677 case AccessibilityNotificationValueChanged: | 680 case AccessibilityNotificationValueChanged: |
| 678 return "value changed"; | 681 return "value changed"; |
| 679 default: | 682 default: |
| 680 NOTREACHED(); | 683 NOTREACHED(); |
| 681 } | 684 } |
| 682 return ""; | 685 return ""; |
| 683 } | 686 } |
| 684 #endif | 687 #endif |
| OLD | NEW |