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

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

Issue 8770021: Initial implementation of IAccessible2 scrollTo and setTextSelection and (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
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/WebView.h" 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
14 #include "webkit/glue/webaccessibility.h" 14 #include "webkit/glue/webaccessibility.h"
15 15
16 using WebKit::WebAccessibilityNotification; 16 using WebKit::WebAccessibilityNotification;
17 using WebKit::WebAccessibilityObject; 17 using WebKit::WebAccessibilityObject;
18 using WebKit::WebDocument; 18 using WebKit::WebDocument;
19 using WebKit::WebFrame; 19 using WebKit::WebFrame;
20 using WebKit::WebNode; 20 using WebKit::WebNode;
21 using WebKit::WebSize;
21 using WebKit::WebView; 22 using WebKit::WebView;
22 using webkit_glue::WebAccessibility; 23 using webkit_glue::WebAccessibility;
23 24
24 bool WebAccessibilityNotificationToViewHostMsg( 25 bool WebAccessibilityNotificationToViewHostMsg(
25 WebAccessibilityNotification notification, 26 WebAccessibilityNotification notification,
26 ViewHostMsg_AccEvent::Value* type) { 27 ViewHostMsg_AccEvent::Value* type) {
27 switch (notification) { 28 switch (notification) {
28 case WebKit::WebAccessibilityNotificationActiveDescendantChanged: 29 case WebKit::WebAccessibilityNotificationActiveDescendantChanged:
29 *type = ViewHostMsg_AccEvent::ACTIVE_DESCENDANT_CHANGED; 30 *type = ViewHostMsg_AccEvent::ACTIVE_DESCENDANT_CHANGED;
30 break; 31 break;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 98
98 bool RendererAccessibility::OnMessageReceived(const IPC::Message& message) { 99 bool RendererAccessibility::OnMessageReceived(const IPC::Message& message) {
99 bool handled = true; 100 bool handled = true;
100 IPC_BEGIN_MESSAGE_MAP(RendererAccessibility, message) 101 IPC_BEGIN_MESSAGE_MAP(RendererAccessibility, message)
101 IPC_MESSAGE_HANDLER(ViewMsg_EnableAccessibility, OnEnableAccessibility) 102 IPC_MESSAGE_HANDLER(ViewMsg_EnableAccessibility, OnEnableAccessibility)
102 IPC_MESSAGE_HANDLER(ViewMsg_SetAccessibilityFocus, OnSetAccessibilityFocus) 103 IPC_MESSAGE_HANDLER(ViewMsg_SetAccessibilityFocus, OnSetAccessibilityFocus)
103 IPC_MESSAGE_HANDLER(ViewMsg_AccessibilityDoDefaultAction, 104 IPC_MESSAGE_HANDLER(ViewMsg_AccessibilityDoDefaultAction,
104 OnAccessibilityDoDefaultAction) 105 OnAccessibilityDoDefaultAction)
105 IPC_MESSAGE_HANDLER(ViewMsg_AccessibilityNotifications_ACK, 106 IPC_MESSAGE_HANDLER(ViewMsg_AccessibilityNotifications_ACK,
106 OnAccessibilityNotificationsAck) 107 OnAccessibilityNotificationsAck)
108 IPC_MESSAGE_HANDLER(ViewMsg_AccessibilityChangeScrollPosition,
109 OnChangeScrollPosition)
110 IPC_MESSAGE_HANDLER(ViewMsg_AccessibilitySetTextSelection,
111 OnSetTextSelection)
107 IPC_MESSAGE_UNHANDLED(handled = false) 112 IPC_MESSAGE_UNHANDLED(handled = false)
108 IPC_END_MESSAGE_MAP() 113 IPC_END_MESSAGE_MAP()
109 return handled; 114 return handled;
110 } 115 }
111 116
112 void RendererAccessibility::FocusedNodeChanged(const WebNode& node) { 117 void RendererAccessibility::FocusedNodeChanged(const WebNode& node) {
113 if (!WebAccessibilityObject::accessibilityEnabled()) 118 if (!WebAccessibilityObject::accessibilityEnabled())
114 return; 119 return;
115 120
116 const WebDocument& document = GetMainDocument(); 121 const WebDocument& document = GetMainDocument();
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 #ifndef NDEBUG 364 #ifndef NDEBUG
360 if (logging_) 365 if (logging_)
361 LOG(WARNING) << "DoDefaultAction on invalid object id " << acc_obj_id; 366 LOG(WARNING) << "DoDefaultAction on invalid object id " << acc_obj_id;
362 #endif 367 #endif
363 return; 368 return;
364 } 369 }
365 370
366 obj.performDefaultAction(); 371 obj.performDefaultAction();
367 } 372 }
368 373
374 void RendererAccessibility::OnChangeScrollPosition(
375 int acc_obj_id, int scroll_x, int scroll_y) {
376 if (!WebAccessibilityObject::accessibilityEnabled())
377 return;
378
379 const WebDocument& document = GetMainDocument();
380 if (document.isNull())
381 return;
382
383 WebAccessibilityObject root = document.accessibilityObject();
384
385 // TODO(dmazzoni): Support scrolling of any scrollable container,
386 // not just the main document frame.
387 if (acc_obj_id != root.axID())
388 return;
389
390 WebFrame* frame = document.frame();
391 if (!frame)
392 return;
393
394 WebSize min_offset = frame->minimumScrollOffset();
395 WebSize max_offset = frame->maximumScrollOffset();
396 scroll_x = std::max(min_offset.width, scroll_x);
397 scroll_x = std::min(max_offset.width, scroll_x);
398 scroll_y = std::max(min_offset.height, scroll_y);
399 scroll_y = std::min(max_offset.height, scroll_y);
400
401 frame->setScrollOffset(WebSize(scroll_x, scroll_y));
402 if (frame->view())
403 frame->view()->layout();
404
405 PostAccessibilityNotification(
406 root,
407 WebKit::WebAccessibilityNotificationLayoutComplete);
408 }
409
410 void RendererAccessibility::OnSetTextSelection(
411 int acc_obj_id, int start_offset, int end_offset) {
412 if (!WebAccessibilityObject::accessibilityEnabled())
413 return;
414
415 const WebDocument& document = GetMainDocument();
416 if (document.isNull())
417 return;
418
419 WebAccessibilityObject obj = document.accessibilityObjectFromID(acc_obj_id);
420 if (!obj.isValid()) {
421 #ifndef NDEBUG
422 if (logging_)
423 LOG(WARNING) << "SetTextSelection on invalid object id " << acc_obj_id;
424 #endif
425 return;
426 }
427 }
428
369 void RendererAccessibility::OnAccessibilityNotificationsAck() { 429 void RendererAccessibility::OnAccessibilityNotificationsAck() {
370 DCHECK(ack_pending_); 430 DCHECK(ack_pending_);
371 ack_pending_ = false; 431 ack_pending_ = false;
372 SendPendingAccessibilityNotifications(); 432 SendPendingAccessibilityNotifications();
373 } 433 }
374 434
375 void RendererAccessibility::OnEnableAccessibility() { 435 void RendererAccessibility::OnEnableAccessibility() {
376 if (WebAccessibilityObject::accessibilityEnabled()) 436 if (WebAccessibilityObject::accessibilityEnabled())
377 return; 437 return;
378 438
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 499
440 WebDocument RendererAccessibility::GetMainDocument() { 500 WebDocument RendererAccessibility::GetMainDocument() {
441 WebView* view = render_view()->GetWebView(); 501 WebView* view = render_view()->GetWebView();
442 WebFrame* main_frame = view ? view->mainFrame() : NULL; 502 WebFrame* main_frame = view ? view->mainFrame() : NULL;
443 503
444 if (main_frame) 504 if (main_frame)
445 return main_frame->document(); 505 return main_frame->document();
446 else 506 else
447 return WebDocument(); 507 return WebDocument();
448 } 508 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698