Commit a71aa4a0 authored by James Wallace-Lee's avatar James Wallace-Lee Committed by Commit Bot

ChromeVox: send mousemove as AutomationEvent

We had some issues handling mouse move events as UI events, so fire an
AutomationEvent instead. Makes mouse_handler.js a BaseAutomationHandler.

As a follow-up, let's experiment with rate-limiting these events, since
they seem to come in more frequently than the dom events did.

Bug: 853581
Change-Id: I0606421e5284fcb9803c6428d51b7288393babd9
Reviewed-on: https://chromium-review.googlesource.com/c/1287098
Commit-Queue: James Wallace-Lee <jamwalla@chromium.org>
Reviewed-by: default avatarDavid Tseng <dtseng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#601325}
parent 73c3bd8b
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "ash/public/interfaces/constants.mojom.h" #include "ash/public/interfaces/constants.mojom.h"
#include "chrome/browser/chromeos/accessibility/accessibility_manager.h" #include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
#include "chrome/browser/chromeos/accessibility/event_handler_common.h" #include "chrome/browser/chromeos/accessibility/event_handler_common.h"
#include "chrome/browser/ui/aura/accessibility/automation_manager_aura.h"
#include "content/public/browser/native_web_keyboard_event.h" #include "content/public/browser/native_web_keyboard_event.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/common/service_manager_connection.h" #include "content/public/common/service_manager_connection.h"
...@@ -48,13 +49,10 @@ void SpokenFeedbackEventRewriterDelegate::DispatchKeyEventToChromeVox( ...@@ -48,13 +49,10 @@ void SpokenFeedbackEventRewriterDelegate::DispatchKeyEventToChromeVox(
void SpokenFeedbackEventRewriterDelegate::DispatchMouseEventToChromeVox( void SpokenFeedbackEventRewriterDelegate::DispatchMouseEventToChromeVox(
std::unique_ptr<ui::Event> event) { std::unique_ptr<ui::Event> event) {
extensions::ExtensionHost* host = chromeos::GetAccessibilityExtensionHost( if (event->type() == ui::ET_MOUSE_MOVED) {
extension_misc::kChromeVoxExtensionId); AutomationManagerAura::GetInstance()->HandleEvent(
if (!host) ax::mojom::Event::kMouseMoved);
return; }
// Forward the event to ChromeVox's background page.
chromeos::ForwardMouseToExtension(*(event->AsMouseEvent()), host);
} }
bool SpokenFeedbackEventRewriterDelegate::ShouldDispatchKeyEventToChromeVox( bool SpokenFeedbackEventRewriterDelegate::ShouldDispatchKeyEventToChromeVox(
......
...@@ -8,13 +8,18 @@ ...@@ -8,13 +8,18 @@
goog.provide('BackgroundMouseHandler'); goog.provide('BackgroundMouseHandler');
goog.require('BaseAutomationHandler');
var AutomationEvent = chrome.automation.AutomationEvent;
var EventType = chrome.automation.EventType; var EventType = chrome.automation.EventType;
/** @constructor */ /**
* @constructor
* @extends {BaseAutomationHandler}
*/
BackgroundMouseHandler = function() { BackgroundMouseHandler = function() {
document.addEventListener('mousemove', this.onMouseMove.bind(this));
chrome.automation.getDesktop(function(desktop) { chrome.automation.getDesktop(function(desktop) {
BaseAutomationHandler.call(this, desktop);
/** /**
* *
* The desktop node. * The desktop node.
...@@ -22,18 +27,18 @@ BackgroundMouseHandler = function() { ...@@ -22,18 +27,18 @@ BackgroundMouseHandler = function() {
* @private {!chrome.automation.AutomationNode} * @private {!chrome.automation.AutomationNode}
*/ */
this.desktop_ = desktop; this.desktop_ = desktop;
this.addListener_(EventType.MOUSE_MOVED, this.onMouseMove);
}.bind(this)); }.bind(this));
}; };
BackgroundMouseHandler.prototype = { BackgroundMouseHandler.prototype = {
__proto__: BaseAutomationHandler.prototype,
/** /**
* Handles mouse move events. * Handles mouse move events.
* @param {Event} evt The mouse move event to process. * @param {AutomationEvent} evt The mouse move event to process.
* @return {boolean} True if the default action should be performed.
*/ */
onMouseMove: function(evt) { onMouseMove: function(evt) {
// Immediately save the most recent mouse coordinates. this.desktop_.hitTest(evt.mouseX, evt.mouseY, EventType.HOVER);
this.desktop_.hitTest(evt.screenX, evt.screenY, EventType.HOVER);
return false;
}, },
}; };
...@@ -92,6 +92,15 @@ void AutomationManagerAura::HandleEvent(views::View* view, ...@@ -92,6 +92,15 @@ void AutomationManagerAura::HandleEvent(views::View* view,
weak_ptr_factory_.GetWeakPtr(), id, event_type)); weak_ptr_factory_.GetWeakPtr(), id, event_type));
} }
void AutomationManagerAura::HandleEvent(ax::mojom::Event event_type) {
#if defined(OS_CHROMEOS)
aura::Window* root_window = ash::wm::GetActiveWindow();
views::Widget* widget = views::Widget::GetWidgetForNativeView(root_window);
if (widget)
HandleEvent(widget->GetRootView(), event_type);
#endif
}
void AutomationManagerAura::SendEventOnObjectById(int32_t id, void AutomationManagerAura::SendEventOnObjectById(int32_t id,
ax::mojom::Event event_type) { ax::mojom::Event event_type) {
views::AXAuraObjWrapper* obj = views::AXAuraObjCache::GetInstance()->Get(id); views::AXAuraObjWrapper* obj = views::AXAuraObjCache::GetInstance()->Get(id);
......
...@@ -50,6 +50,9 @@ class AutomationManagerAura : public ui::AXHostDelegate, ...@@ -50,6 +50,9 @@ class AutomationManagerAura : public ui::AXHostDelegate,
// Handle an event fired upon a |View|. // Handle an event fired upon a |View|.
void HandleEvent(views::View* view, ax::mojom::Event event_type); void HandleEvent(views::View* view, ax::mojom::Event event_type);
// Handle an event fired upon the root view.
void HandleEvent(ax::mojom::Event event_type);
void HandleAlert(const std::string& text); void HandleAlert(const std::string& text);
// AXHostDelegate implementation. // AXHostDelegate implementation.
......
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