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

Side by Side Diff: content/renderer/renderer_accessibility.cc

Issue 8776030: Add IPCs to allow assistive technology to scroll the page (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years 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 | Annotate | Revision Log
« no previous file with comments | « content/renderer/renderer_accessibility.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/command_line.h" 5 #include "base/command_line.h"
6 #include "content/common/view_messages.h" 6 #include "content/common/view_messages.h"
7 #include "content/public/common/content_switches.h" 7 #include "content/public/common/content_switches.h"
8 #include "content/renderer/render_view_impl.h" 8 #include "content/renderer/render_view_impl.h"
9 #include "content/renderer/renderer_accessibility.h" 9 #include "content/renderer/renderer_accessibility.h"
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityObjec t.h" 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityObjec t.h"
11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h"
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h"
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
14 #include "webkit/glue/webaccessibility.h" 16 #include "webkit/glue/webaccessibility.h"
15 17
16 using WebKit::WebAccessibilityNotification; 18 using WebKit::WebAccessibilityNotification;
17 using WebKit::WebAccessibilityObject; 19 using WebKit::WebAccessibilityObject;
18 using WebKit::WebDocument; 20 using WebKit::WebDocument;
19 using WebKit::WebFrame; 21 using WebKit::WebFrame;
20 using WebKit::WebNode; 22 using WebKit::WebNode;
23 using WebKit::WebSize;
21 using WebKit::WebView; 24 using WebKit::WebView;
22 using webkit_glue::WebAccessibility; 25 using webkit_glue::WebAccessibility;
23 26
24 bool WebAccessibilityNotificationToViewHostMsg( 27 bool WebAccessibilityNotificationToViewHostMsg(
25 WebAccessibilityNotification notification, 28 WebAccessibilityNotification notification,
26 ViewHostMsg_AccEvent::Value* type) { 29 ViewHostMsg_AccEvent::Value* type) {
27 switch (notification) { 30 switch (notification) {
28 case WebKit::WebAccessibilityNotificationActiveDescendantChanged: 31 case WebKit::WebAccessibilityNotificationActiveDescendantChanged:
29 *type = ViewHostMsg_AccEvent::ACTIVE_DESCENDANT_CHANGED; 32 *type = ViewHostMsg_AccEvent::ACTIVE_DESCENDANT_CHANGED;
30 break; 33 break;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 100
98 bool RendererAccessibility::OnMessageReceived(const IPC::Message& message) { 101 bool RendererAccessibility::OnMessageReceived(const IPC::Message& message) {
99 bool handled = true; 102 bool handled = true;
100 IPC_BEGIN_MESSAGE_MAP(RendererAccessibility, message) 103 IPC_BEGIN_MESSAGE_MAP(RendererAccessibility, message)
101 IPC_MESSAGE_HANDLER(ViewMsg_EnableAccessibility, OnEnableAccessibility) 104 IPC_MESSAGE_HANDLER(ViewMsg_EnableAccessibility, OnEnableAccessibility)
102 IPC_MESSAGE_HANDLER(ViewMsg_SetAccessibilityFocus, OnSetAccessibilityFocus) 105 IPC_MESSAGE_HANDLER(ViewMsg_SetAccessibilityFocus, OnSetAccessibilityFocus)
103 IPC_MESSAGE_HANDLER(ViewMsg_AccessibilityDoDefaultAction, 106 IPC_MESSAGE_HANDLER(ViewMsg_AccessibilityDoDefaultAction,
104 OnAccessibilityDoDefaultAction) 107 OnAccessibilityDoDefaultAction)
105 IPC_MESSAGE_HANDLER(ViewMsg_AccessibilityNotifications_ACK, 108 IPC_MESSAGE_HANDLER(ViewMsg_AccessibilityNotifications_ACK,
106 OnAccessibilityNotificationsAck) 109 OnAccessibilityNotificationsAck)
110 IPC_MESSAGE_HANDLER(ViewMsg_AccessibilityChangeScrollPosition,
111 OnChangeScrollPosition)
112 IPC_MESSAGE_HANDLER(ViewMsg_AccessibilitySetTextSelection,
113 OnSetTextSelection)
107 IPC_MESSAGE_UNHANDLED(handled = false) 114 IPC_MESSAGE_UNHANDLED(handled = false)
108 IPC_END_MESSAGE_MAP() 115 IPC_END_MESSAGE_MAP()
109 return handled; 116 return handled;
110 } 117 }
111 118
112 void RendererAccessibility::FocusedNodeChanged(const WebNode& node) { 119 void RendererAccessibility::FocusedNodeChanged(const WebNode& node) {
113 if (!WebAccessibilityObject::accessibilityEnabled()) 120 if (!WebAccessibilityObject::accessibilityEnabled())
114 return; 121 return;
115 122
116 const WebDocument& document = GetMainDocument(); 123 const WebDocument& document = GetMainDocument();
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 #ifndef NDEBUG 373 #ifndef NDEBUG
367 if (logging_) 374 if (logging_)
368 LOG(WARNING) << "DoDefaultAction on invalid object id " << acc_obj_id; 375 LOG(WARNING) << "DoDefaultAction on invalid object id " << acc_obj_id;
369 #endif 376 #endif
370 return; 377 return;
371 } 378 }
372 379
373 obj.performDefaultAction(); 380 obj.performDefaultAction();
374 } 381 }
375 382
383 void RendererAccessibility::OnChangeScrollPosition(
384 int acc_obj_id, int scroll_x, int scroll_y) {
385 if (!WebAccessibilityObject::accessibilityEnabled())
386 return;
387
388 const WebDocument& document = GetMainDocument();
389 if (document.isNull())
390 return;
391
392 WebAccessibilityObject root = document.accessibilityObject();
393
394 // TODO(dmazzoni): Support scrolling of any scrollable container,
395 // not just the main document frame.
396 if (acc_obj_id != root.axID())
397 return;
398
399 WebFrame* frame = document.frame();
400 if (!frame)
401 return;
402
403 WebSize min_offset = frame->minimumScrollOffset();
404 WebSize max_offset = frame->maximumScrollOffset();
405 scroll_x = std::max(min_offset.width, scroll_x);
406 scroll_x = std::min(max_offset.width, scroll_x);
407 scroll_y = std::max(min_offset.height, scroll_y);
408 scroll_y = std::min(max_offset.height, scroll_y);
409
410 frame->setScrollOffset(WebSize(scroll_x, scroll_y));
411 if (frame->view())
412 frame->view()->layout();
413
414 // Make sure the browser gets a notification when the scroll
415 // position actually changes.
416 // TODO(dmazzoni): remove this once this bug is fixed:
417 // https://bugs.webkit.org/show_bug.cgi?id=73460
418 PostAccessibilityNotification(
419 root,
420 WebKit::WebAccessibilityNotificationLayoutComplete);
421 }
422
423 void RendererAccessibility::OnSetTextSelection(
424 int acc_obj_id, int start_offset, int end_offset) {
425 if (!WebAccessibilityObject::accessibilityEnabled())
426 return;
427
428 const WebDocument& document = GetMainDocument();
429 if (document.isNull())
430 return;
431
432 WebAccessibilityObject obj = document.accessibilityObjectFromID(acc_obj_id);
433 if (!obj.isValid()) {
434 #ifndef NDEBUG
435 if (logging_)
436 LOG(WARNING) << "SetTextSelection on invalid object id " << acc_obj_id;
437 #endif
438 return;
439 }
440
441 // TODO(dmazzoni): support elements other than <input>.
442 WebKit::WebNode node = obj.node();
443 if (!node.isNull() && node.isElementNode()) {
444 WebKit::WebElement element = node.to<WebKit::WebElement>();
445 WebKit::WebInputElement* input_element =
446 WebKit::toWebInputElement(&element);
447 if (input_element && input_element->isTextField())
448 input_element->setSelectionRange(start_offset, end_offset);
449 }
450 }
451
376 void RendererAccessibility::OnAccessibilityNotificationsAck() { 452 void RendererAccessibility::OnAccessibilityNotificationsAck() {
377 DCHECK(ack_pending_); 453 DCHECK(ack_pending_);
378 ack_pending_ = false; 454 ack_pending_ = false;
379 SendPendingAccessibilityNotifications(); 455 SendPendingAccessibilityNotifications();
380 } 456 }
381 457
382 void RendererAccessibility::OnEnableAccessibility() { 458 void RendererAccessibility::OnEnableAccessibility() {
383 if (WebAccessibilityObject::accessibilityEnabled()) 459 if (WebAccessibilityObject::accessibilityEnabled())
384 return; 460 return;
385 461
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 522
447 WebDocument RendererAccessibility::GetMainDocument() { 523 WebDocument RendererAccessibility::GetMainDocument() {
448 WebView* view = render_view()->GetWebView(); 524 WebView* view = render_view()->GetWebView();
449 WebFrame* main_frame = view ? view->mainFrame() : NULL; 525 WebFrame* main_frame = view ? view->mainFrame() : NULL;
450 526
451 if (main_frame) 527 if (main_frame)
452 return main_frame->document(); 528 return main_frame->document();
453 else 529 else
454 return WebDocument(); 530 return WebDocument();
455 } 531 }
OLDNEW
« no previous file with comments | « content/renderer/renderer_accessibility.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698