0

Generalize chrome.accessibilityPrivate.enableMouseEvents

Previously, chrome.accessibilityPrivate.enableChromeVoxMouseEvents only sent mouse events through the accessibility -> chrome.automation layer only when ChromeVox was enabled.

Make it so that we also send (when requested) to the accessibility common extension when magnifier is enabled.

R=josiahk@chromium.org

Test: browser_tests --gtest_filter=*Spoken*.SpeakingTextUnderMouseForShelfItem* for ChromeVox. Magnifier tests tbd when it gets used for upcoming features.
Change-Id: If620e69d3d7a0d0480afac412ae9c4d52b8cfba8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2572797
Commit-Queue: David Tseng <dtseng@chromium.org>
Reviewed-by: Xiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#833815}
This commit is contained in:
David Tseng
2020-12-04 19:53:31 +00:00
committed by Chromium LUCI CQ
parent 00d42fc6ea
commit ff047835ae
17 changed files with 70 additions and 61 deletions

@ -168,9 +168,6 @@ bool AccessibilityEventRewriter::RewriteEventForChromeVox(
return capture;
}
if (chromevox_send_mouse_events_ && event.IsMouseEvent())
delegate_->DispatchMouseEventToChromeVox(ui::Event::Clone(event));
return false;
}
@ -273,6 +270,16 @@ void AccessibilityEventRewriter::UpdateKeyboardDeviceIds() {
}
}
void AccessibilityEventRewriter::MaybeSendMouseEvent(const ui::Event& event) {
// Mouse moves are the only pertinent event for accessibility component
// extensions.
if (send_mouse_events_ && event.type() == ui::ET_MOUSE_MOVED &&
(Shell::Get()->magnification_controller()->IsEnabled() ||
Shell::Get()->accessibility_controller()->spoken_feedback().enabled())) {
delegate_->DispatchMouseEvent(ui::Event::Clone(event));
}
}
ui::EventDispatchDetails AccessibilityEventRewriter::RewriteEvent(
const ui::Event& event,
const Continuation continuation) {
@ -297,6 +304,10 @@ ui::EventDispatchDetails AccessibilityEventRewriter::RewriteEvent(
captured = RewriteEventForChromeVox(event, continuation);
}
if (!captured) {
MaybeSendMouseEvent(event);
}
return captured ? DiscardEvent(continuation)
: SendEvent(continuation, &event);
}

@ -56,9 +56,8 @@ class ASH_EXPORT AccessibilityEventRewriter
void set_chromevox_capture_all_keys(bool value) {
chromevox_capture_all_keys_ = value;
}
void set_chromevox_send_mouse_events(bool value) {
chromevox_send_mouse_events_ = value;
}
void set_send_mouse_events(bool value) { send_mouse_events_ = value; }
void set_suspend_switch_access_key_handling(bool suspend) {
suspend_switch_access_key_handling_ = suspend;
@ -89,6 +88,10 @@ class ASH_EXPORT AccessibilityEventRewriter
// keyboard input types.
void UpdateKeyboardDeviceIds();
// Maybe sends a mouse event to be dispatched to accessibility component
// extensions.
void MaybeSendMouseEvent(const ui::Event& event);
// ui::EventRewriter:
ui::EventDispatchDetails RewriteEvent(
const ui::Event& event,
@ -104,8 +107,8 @@ class ASH_EXPORT AccessibilityEventRewriter
// extensions.
AccessibilityEventRewriterDelegate* delegate_ = nullptr;
// Whether to send mouse events to the ChromeVox extension.
bool chromevox_send_mouse_events_ = false;
// Whether to send mouse events to accessibility component extensions.
bool send_mouse_events_ = false;
// Whether to capture all keys for ChromeVox.
bool chromevox_capture_all_keys_ = false;

@ -55,8 +55,7 @@ class ChromeVoxTestDelegate : public AccessibilityEventRewriterDelegate {
if (capture)
chromevox_captured_event_count_++;
}
void DispatchMouseEventToChromeVox(
std::unique_ptr<ui::Event> event) override {
void DispatchMouseEvent(std::unique_ptr<ui::Event> event) override {
chromevox_recorded_event_count_++;
}
void SendSwitchAccessCommand(SwitchAccessCommand command) override {}
@ -411,7 +410,7 @@ class SwitchAccessTestDelegate : public AccessibilityEventRewriterDelegate {
}
void SendPointScanPoint(const gfx::PointF& point) override {}
void DispatchKeyEventToChromeVox(std::unique_ptr<ui::Event>, bool) override {}
void DispatchMouseEventToChromeVox(std::unique_ptr<ui::Event>) override {}
void DispatchMouseEvent(std::unique_ptr<ui::Event>) override {}
private:
std::vector<SwitchAccessCommand> commands_;

@ -108,8 +108,8 @@ void EventRewriterControllerImpl::CaptureAllKeysForSpokenFeedback(
accessibility_event_rewriter_->set_chromevox_capture_all_keys(capture);
}
void EventRewriterControllerImpl::SetSendMouseEventsToDelegate(bool value) {
accessibility_event_rewriter_->set_chromevox_send_mouse_events(value);
void EventRewriterControllerImpl::SetSendMouseEvents(bool value) {
accessibility_event_rewriter_->set_send_mouse_events(value);
}
void EventRewriterControllerImpl::OnHostInitialized(

@ -40,7 +40,7 @@ class ASH_EXPORT EventRewriterControllerImpl : public EventRewriterController,
void OnUnhandledSpokenFeedbackEvent(
std::unique_ptr<ui::Event> event) override;
void CaptureAllKeysForSpokenFeedback(bool capture) override;
void SetSendMouseEventsToDelegate(bool value) override;
void SetSendMouseEvents(bool value) override;
// aura::EnvObserver:
void OnHostInitialized(aura::WindowTreeHost* host) override;

@ -28,9 +28,8 @@ class ASH_PUBLIC_EXPORT AccessibilityEventRewriterDelegate {
virtual void DispatchKeyEventToChromeVox(std::unique_ptr<ui::Event> event,
bool capture) = 0;
// Used to send mouse events to the ChromeVox extension.
virtual void DispatchMouseEventToChromeVox(
std::unique_ptr<ui::Event> event) = 0;
// Used to send mouse events to accessibility component extensions.
virtual void DispatchMouseEvent(std::unique_ptr<ui::Event> event) = 0;
// Sends a command to Switch Access.
virtual void SendSwitchAccessCommand(SwitchAccessCommand command) = 0;

@ -51,8 +51,8 @@ class ASH_EXPORT EventRewriterController {
// Discards key events and sends to spoken feedback when true.
virtual void CaptureAllKeysForSpokenFeedback(bool capture) = 0;
// Sends mouse events to ChromeVox when true.
virtual void SetSendMouseEventsToDelegate(bool value) = 0;
// Sends mouse events to accessibility component extensions when true.
virtual void SetSendMouseEvents(bool value) = 0;
protected:
virtual ~EventRewriterController() {}

@ -298,10 +298,10 @@ AccessibilityPrivateSendSyntheticKeyEventFunction::Run() {
}
ExtensionFunction::ResponseAction
AccessibilityPrivateEnableChromeVoxMouseEventsFunction::Run() {
AccessibilityPrivateEnableMouseEventsFunction::Run() {
bool enabled = false;
EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(0, &enabled));
ash::EventRewriterController::Get()->SetSendMouseEventsToDelegate(enabled);
ash::EventRewriterController::Get()->SetSendMouseEvents(enabled);
return RespondNow(NoArguments());
}

@ -83,12 +83,11 @@ class AccessibilityPrivateSendSyntheticKeyEventFunction
};
// API function that enables or disables mouse events in ChromeVox.
class AccessibilityPrivateEnableChromeVoxMouseEventsFunction
: public ExtensionFunction {
~AccessibilityPrivateEnableChromeVoxMouseEventsFunction() override {}
class AccessibilityPrivateEnableMouseEventsFunction : public ExtensionFunction {
~AccessibilityPrivateEnableMouseEventsFunction() override {}
ResponseAction Run() override;
DECLARE_EXTENSION_FUNCTION("accessibilityPrivate.enableChromeVoxMouseEvents",
ACCESSIBILITY_PRIVATE_ENABLECHROMEVOXMOUSEEVENTS)
DECLARE_EXTENSION_FUNCTION("accessibilityPrivate.enableMouseEvents",
ACCESSIBILITY_PRIVATE_ENABLEMOUSEEVENTS)
};
// API function that injects mouse events.

@ -75,15 +75,13 @@ void AccessibilityEventRewriterDelegate::DispatchKeyEventToChromeVox(
chromeos::ForwardKeyToExtension(*(event->AsKeyEvent()), host);
}
void AccessibilityEventRewriterDelegate::DispatchMouseEventToChromeVox(
void AccessibilityEventRewriterDelegate::DispatchMouseEvent(
std::unique_ptr<ui::Event> event) {
if (is_arc_window_active_)
return;
if (event->type() == ui::ET_MOUSE_MOVED) {
AutomationManagerAura::GetInstance()->HandleEvent(
ax::mojom::Event::kMouseMoved);
}
AutomationManagerAura::GetInstance()->HandleEvent(
ax::mojom::Event::kMouseMoved);
}
void AccessibilityEventRewriterDelegate::SendSwitchAccessCommand(

@ -36,7 +36,7 @@ class AccessibilityEventRewriterDelegate
// ash::AccessibilityEventRewriterDelegate:
void DispatchKeyEventToChromeVox(std::unique_ptr<ui::Event> event,
bool capture) override;
void DispatchMouseEventToChromeVox(std::unique_ptr<ui::Event> event) override;
void DispatchMouseEvent(std::unique_ptr<ui::Event> event) override;
void SendSwitchAccessCommand(ash::SwitchAccessCommand command) override;
void SendPointScanPoint(const gfx::PointF& point) override;

@ -435,7 +435,7 @@ IN_PROC_BROWSER_TEST_P(SpokenFeedbackTest, SpeakingTextUnderMouseForShelfItem) {
}
// Enable the function of speaking text under mouse.
ash::EventRewriterController::Get()->SetSendMouseEventsToDelegate(true);
ash::EventRewriterController::Get()->SetSendMouseEvents(true);
// Focus on the Shelf because voice text for focusing on Shelf is fixed.
// Wait until voice announcements are finished.

@ -47,7 +47,7 @@ PointerHandler = class extends BaseAutomationHandler {
});
if (localStorage['speakTextUnderMouse'] === String(true)) {
chrome.accessibilityPrivate.enableChromeVoxMouseEvents(true);
chrome.accessibilityPrivate.enableMouseEvents(true);
}
}

@ -402,14 +402,14 @@
"platforms": ["chromeos"]
},
{
"name": "enableChromeVoxMouseEvents",
"name": "enableMouseEvents",
"type": "function",
"description": "Enables or disables mouse events in ChromeVox.",
"description": "Enables or disables mouse events in accessibility extensions",
"parameters": [
{
"name": "enabled",
"type": "boolean",
"description": "True if ChromeVox should receive mouse events."
"description": "True if accessibility component extensions should receive mouse events."
}
],
"platforms": ["chromeos"]

@ -1345,7 +1345,7 @@ enum HistogramValue {
AUTOTESTPRIVATE_RUNCROSTINIUNINSTALLER = 1282,
AUTOTESTPRIVATE_TAKESCREENSHOT = 1283,
ACCESSIBILITY_PRIVATE_TOGGLEDICTATION = 1284,
ACCESSIBILITY_PRIVATE_ENABLECHROMEVOXMOUSEEVENTS = 1285,
ACCESSIBILITY_PRIVATE_ENABLEMOUSEEVENTS = 1285,
ACCESSIBILITY_PRIVATE_SENDSYNTHETICMOUSEEVENT = 1286,
FILEMANAGERPRIVATE_DETECTCHARACTERENCODING = 1287,
FILEMANAGERPRIVATEINTERNAL_GETLINUXPACKAGEINFO = 1288,

@ -188,20 +188,6 @@ chrome.accessibilityPrivate.SelectToSpeakState = {
INACTIVE: 'inactive',
};
/**
* @enum {string}
*/
chrome.accessibilityPrivate.SelectToSpeakPanelAction = {
PREVIOUS_PARAGRAPH: 'previousParagraph',
PREVIOUS_SENTENCE: 'previousSentence',
PAUSE: 'pause',
RESUME: 'resume',
NEXT_SENTENCE: 'nextSentence',
NEXT_PARAGRAPH: 'nextParagraph',
EXIT: 'exit',
CHANGESPEED: 'changeSpeed',
};
/**
* @enum {string}
*/
@ -238,6 +224,20 @@ chrome.accessibilityPrivate.AccessibilityFeature = {
SELECT_TO_SPEAK_NAVIGATION_CONTROL: 'selectToSpeakNavigationControl',
};
/**
* @enum {string}
*/
chrome.accessibilityPrivate.SelectToSpeakPanelAction = {
PREVIOUS_PARAGRAPH: 'previousParagraph',
PREVIOUS_SENTENCE: 'previousSentence',
PAUSE: 'pause',
RESUME: 'resume',
NEXT_SENTENCE: 'nextSentence',
NEXT_PARAGRAPH: 'nextParagraph',
EXIT: 'exit',
CHANGE_SPEED: 'changeSpeed',
};
/**
* Called to translate localeCodeToTranslate into human-readable string in the
* locale specified by displayLocaleCode
@ -335,10 +335,11 @@ chrome.accessibilityPrivate.setNativeChromeVoxArcSupportForCurrentApp = function
chrome.accessibilityPrivate.sendSyntheticKeyEvent = function(keyEvent) {};
/**
* Enables or disables mouse events in ChromeVox.
* @param {boolean} enabled True if ChromeVox should receive mouse events.
* Enables or disables mouse events in accessibility extensions
* @param {boolean} enabled True if accessibility component extensions should
* receive mouse events.
*/
chrome.accessibilityPrivate.enableChromeVoxMouseEvents = function(enabled) {};
chrome.accessibilityPrivate.enableMouseEvents = function(enabled) {};
/**
* Sends a fabricated mouse event.
@ -414,11 +415,10 @@ chrome.accessibilityPrivate.isFeatureEnabled = function(feature, callback) {};
* @param {!chrome.accessibilityPrivate.ScreenRect=} anchor A rectangle
* indicating the bounds of the object the panel should be displayed next
* to.
* @param {boolean=} isPaused Whether Select-to-speak playback is paused.
* @param {number=} speed Current reading speed.
* @param {boolean=} isPaused True if Select-to-speak playback is paused.
* @param {number=} speed Current reading speed (TTS speech rate).
*/
chrome.accessibilityPrivate.updateSelectToSpeakPanel = function(
show, anchor, isPaused, speed) {};
chrome.accessibilityPrivate.updateSelectToSpeakPanel = function(show, anchor, isPaused, speed) {};
/**
* Fired whenever ChromeVox should output introduction.
@ -455,7 +455,7 @@ chrome.accessibilityPrivate.onTwoFingerTouchStop;
chrome.accessibilityPrivate.onSelectToSpeakStateChangeRequested;
/**
* Fired when an action is performed on the Select-to-speak panel.
* Fired when an action is performed in the Select-to-speak panel.
* @type {!ChromeEvent}
*/
chrome.accessibilityPrivate.onSelectToSpeakPanelAction;

@ -25289,7 +25289,7 @@ Called by update_extension_histograms.py.-->
<int value="1282" label="AUTOTESTPRIVATE_RUNCROSTINIUNINSTALLER"/>
<int value="1283" label="AUTOTESTPRIVATE_TAKESCREENSHOT"/>
<int value="1284" label="ACCESSIBILITY_PRIVATE_TOGGLEDICTATION"/>
<int value="1285" label="ACCESSIBILITY_PRIVATE_ENABLECHROMEVOXMOUSEEVENTS"/>
<int value="1285" label="ACCESSIBILITY_PRIVATE_ENABLEMOUSEEVENTS"/>
<int value="1286" label="ACCESSIBILITY_PRIVATE_SENDSYNTHETICMOUSEEVENT"/>
<int value="1287" label="FILEMANAGERPRIVATE_DETECTCHARACTERENCODING"/>
<int value="1288" label="FILEMANAGERPRIVATEINTERNAL_GETLINUXPACKAGEINFO"/>