Commit 49dc8639 authored by dmazzoni@chromium.org's avatar dmazzoni@chromium.org

Add IPCs to allow assistive technology to scroll the page

or select text.

BUG=104468,104469
TEST=none
Review URL: http://codereview.chromium.org/8776030

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@112817 0039d316-1c4b-4281-b951-d872f2087c98
parent 9f01504e
......@@ -206,6 +206,22 @@ void BrowserAccessibilityManager::DoDefaultAction(
delegate_->AccessibilityDoDefaultAction(node.renderer_id());
}
void BrowserAccessibilityManager::ChangeScrollPosition(
const BrowserAccessibility& node, int scroll_x, int scroll_y) {
if (delegate_) {
delegate_->AccessibilityChangeScrollPosition(
node.renderer_id(), scroll_x, scroll_y);
}
}
void BrowserAccessibilityManager::SetTextSelection(
const BrowserAccessibility& node, int start_offset, int end_offset) {
if (delegate_) {
delegate_->AccessibilitySetTextSelection(
node.renderer_id(), start_offset, end_offset);
}
}
gfx::Rect BrowserAccessibilityManager::GetViewBounds() {
if (delegate_)
return delegate_->GetViewBounds();
......
......@@ -30,6 +30,10 @@ class CONTENT_EXPORT BrowserAccessibilityDelegate {
virtual ~BrowserAccessibilityDelegate() {}
virtual void SetAccessibilityFocus(int acc_obj_id) = 0;
virtual void AccessibilityDoDefaultAction(int acc_obj_id) = 0;
virtual void AccessibilityChangeScrollPosition(
int acc_obj_id, int scroll_x, int scroll_y) = 0;
virtual void AccessibilitySetTextSelection(
int acc_obj_id, int start_offset, int end_offset) = 0;
virtual bool HasFocus() const = 0;
virtual gfx::Rect GetViewBounds() const = 0;
};
......@@ -100,6 +104,14 @@ class CONTENT_EXPORT BrowserAccessibilityManager {
// Tell the renderer to do the default action for this node.
void DoDefaultAction(const BrowserAccessibility& node);
// Tell the renderer to scroll this node to the given position.
void ChangeScrollPosition(
const BrowserAccessibility& node, int scroll_x, int scroll_y);
// Tell the renderer to set the text selection on a node.
void SetTextSelection(
const BrowserAccessibility& node, int start_offset, int end_offset);
// Retrieve the bounds of the parent View in screen coordinates.
gfx::Rect GetViewBounds();
......
......@@ -1445,6 +1445,18 @@ void RenderWidgetHost::AccessibilitySetFocus(int object_id) {
Send(new ViewMsg_SetAccessibilityFocus(routing_id(), object_id));
}
void RenderWidgetHost::AccessibilityChangeScrollPosition(
int object_id, int scroll_x, int scroll_y) {
Send(new ViewMsg_AccessibilityChangeScrollPosition(
routing_id(), object_id, scroll_x, scroll_y));
}
void RenderWidgetHost::AccessibilitySetTextSelection(
int object_id, int start_offset, int end_offset) {
Send(new ViewMsg_AccessibilitySetTextSelection(
routing_id(), object_id, start_offset, end_offset));
}
void RenderWidgetHost::ExecuteEditCommand(const std::string& command,
const std::string& value) {
Send(new ViewMsg_ExecuteEditCommand(routing_id(), command, value));
......
......@@ -414,6 +414,14 @@ class CONTENT_EXPORT RenderWidgetHost : public IPC::Channel::Listener,
// Relay a request from assistive technology to set focus to a given node.
void AccessibilitySetFocus(int object_id);
// Relay a request from assistive technology to scroll.
void AccessibilityChangeScrollPosition(
int acc_obj_id, int scroll_x, int scroll_y);
// Relay a request from assistive technology to set text selection.
void AccessibilitySetTextSelection(
int acc_obj_id, int start_offset, int end_offset);
// Executes the edit command on the RenderView.
void ExecuteEditCommand(const std::string& command,
const std::string& value);
......
......@@ -2072,6 +2072,24 @@ void RenderWidgetHostViewWin::AccessibilityDoDefaultAction(int acc_obj_id) {
render_widget_host_->AccessibilityDoDefaultAction(acc_obj_id);
}
void RenderWidgetHostViewWin::AccessibilityChangeScrollPosition(
int acc_obj_id, int scroll_x, int scroll_y) {
if (!render_widget_host_)
return;
render_widget_host_->AccessibilityChangeScrollPosition(
acc_obj_id, scroll_x, scroll_y);
}
void RenderWidgetHostViewWin::AccessibilitySetTextSelection(
int acc_obj_id, int start_offset, int end_offset) {
if (!render_widget_host_)
return;
render_widget_host_->AccessibilitySetTextSelection(
acc_obj_id, start_offset, end_offset);
}
IAccessible* RenderWidgetHostViewWin::GetIAccessible() {
if (render_widget_host_ && !render_widget_host_->renderer_accessible()) {
// Attempt to detect screen readers by sending an event with our custom id.
......
......@@ -220,6 +220,10 @@ class RenderWidgetHostViewWin
// Implementation of BrowserAccessibilityDelegate:
virtual void SetAccessibilityFocus(int acc_obj_id) OVERRIDE;
virtual void AccessibilityDoDefaultAction(int acc_obj_id) OVERRIDE;
virtual void AccessibilityChangeScrollPosition(
int acc_obj_id, int scroll_x, int scroll_y) OVERRIDE;
virtual void AccessibilitySetTextSelection(
int acc_obj_id, int start_offset, int end_offset) OVERRIDE;
protected:
// Windows Message Handlers
......
......@@ -1100,6 +1100,20 @@ IPC_MESSAGE_ROUTED1(ViewMsg_SetAccessibilityFocus,
IPC_MESSAGE_ROUTED1(ViewMsg_AccessibilityDoDefaultAction,
int /* object id */)
// Relay a request from assistive technology to change the scroll position
// of a scrollable container (like the whole page, an iframe, etc.).
IPC_MESSAGE_ROUTED3(ViewMsg_AccessibilityChangeScrollPosition,
int /* object id */,
int /* New x scroll position */,
int /* New y scroll position */)
// Relay a request from assistive technology to set the cursor or
// selection within an editable text element.
IPC_MESSAGE_ROUTED3(ViewMsg_AccessibilitySetTextSelection,
int /* object id */,
int /* New start offset */,
int /* New end offset */)
// Tells the render view that a ViewHostMsg_AccessibilityNotifications
// message was processed and it can send addition notifications.
IPC_MESSAGE_ROUTED0(ViewMsg_AccessibilityNotifications_ACK)
......
......@@ -10,6 +10,8 @@
#include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityObject.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
#include "webkit/glue/webaccessibility.h"
......@@ -18,6 +20,7 @@ using WebKit::WebAccessibilityObject;
using WebKit::WebDocument;
using WebKit::WebFrame;
using WebKit::WebNode;
using WebKit::WebSize;
using WebKit::WebView;
using webkit_glue::WebAccessibility;
......@@ -104,6 +107,10 @@ bool RendererAccessibility::OnMessageReceived(const IPC::Message& message) {
OnAccessibilityDoDefaultAction)
IPC_MESSAGE_HANDLER(ViewMsg_AccessibilityNotifications_ACK,
OnAccessibilityNotificationsAck)
IPC_MESSAGE_HANDLER(ViewMsg_AccessibilityChangeScrollPosition,
OnChangeScrollPosition)
IPC_MESSAGE_HANDLER(ViewMsg_AccessibilitySetTextSelection,
OnSetTextSelection)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
......@@ -373,6 +380,75 @@ void RendererAccessibility::OnAccessibilityDoDefaultAction(int acc_obj_id) {
obj.performDefaultAction();
}
void RendererAccessibility::OnChangeScrollPosition(
int acc_obj_id, int scroll_x, int scroll_y) {
if (!WebAccessibilityObject::accessibilityEnabled())
return;
const WebDocument& document = GetMainDocument();
if (document.isNull())
return;
WebAccessibilityObject root = document.accessibilityObject();
// TODO(dmazzoni): Support scrolling of any scrollable container,
// not just the main document frame.
if (acc_obj_id != root.axID())
return;
WebFrame* frame = document.frame();
if (!frame)
return;
WebSize min_offset = frame->minimumScrollOffset();
WebSize max_offset = frame->maximumScrollOffset();
scroll_x = std::max(min_offset.width, scroll_x);
scroll_x = std::min(max_offset.width, scroll_x);
scroll_y = std::max(min_offset.height, scroll_y);
scroll_y = std::min(max_offset.height, scroll_y);
frame->setScrollOffset(WebSize(scroll_x, scroll_y));
if (frame->view())
frame->view()->layout();
// Make sure the browser gets a notification when the scroll
// position actually changes.
// TODO(dmazzoni): remove this once this bug is fixed:
// https://bugs.webkit.org/show_bug.cgi?id=73460
PostAccessibilityNotification(
root,
WebKit::WebAccessibilityNotificationLayoutComplete);
}
void RendererAccessibility::OnSetTextSelection(
int acc_obj_id, int start_offset, int end_offset) {
if (!WebAccessibilityObject::accessibilityEnabled())
return;
const WebDocument& document = GetMainDocument();
if (document.isNull())
return;
WebAccessibilityObject obj = document.accessibilityObjectFromID(acc_obj_id);
if (!obj.isValid()) {
#ifndef NDEBUG
if (logging_)
LOG(WARNING) << "SetTextSelection on invalid object id " << acc_obj_id;
#endif
return;
}
// TODO(dmazzoni): support elements other than <input>.
WebKit::WebNode node = obj.node();
if (!node.isNull() && node.isElementNode()) {
WebKit::WebElement element = node.to<WebKit::WebElement>();
WebKit::WebInputElement* input_element =
WebKit::toWebInputElement(&element);
if (input_element && input_element->isTextField())
input_element->setSelectionRange(start_offset, end_offset);
}
}
void RendererAccessibility::OnAccessibilityNotificationsAck() {
DCHECK(ack_pending_);
ack_pending_ = false;
......
......@@ -82,9 +82,12 @@ class RendererAccessibility : public content::RenderViewObserver {
// Handlers for messages from the browser to the renderer.
void OnAccessibilityDoDefaultAction(int acc_obj_id);
void OnAccessibilityNotificationsAck();
void OnChangeScrollPosition(int acc_obj_id, int scroll_x, int scroll_y);
void OnEnableAccessibility();
void OnSetAccessibilityFocus(int acc_obj_id);
void OnSetTextSelection(int acc_obj_id, int start_offset, int end_offset);
// Whether or not this notification typically needs to send
// updates to its children, too.
bool ShouldIncludeChildren(const Notification& notification);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment