Dictation JS can toggle Dictation and listen for toggles.
Adds AccessibilityCommon API listener onToggleDictation which is called when Dictation is toggled. Dictation C++ is no longer activated on toggle, instead Dictation JS listens for onToggleDictation and, as a placeholder, turns Dictation off again once it is turned on. This behavior only occurs when Chrome is run with the flag --enable-experimental-accessibility-dictation-extension. Bug: 1216111 Change-Id: I0ba8b295de0d209c19d84a177057cfe98fc3ad03 AX-Relnotes: N/A Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2936124 Commit-Queue: Katie Dektar <katie@chromium.org> Reviewed-by: Xiyuan Xia <xiyuan@chromium.org> Reviewed-by: Akihiro Ota <akihiroota@chromium.org> Cr-Commit-Position: refs/heads/master@{#889521}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
53f3766a6c
commit
e724e5bacf
ash/public/cpp
chrome
browser
accessibility
ash
accessibility
resources
chromeos
accessibility
accessibility_common
dictation
common
extensions
extensions/browser
third_party/closure_compiler/externs
tools/metrics/histograms
@ -68,7 +68,10 @@ enum class DictationToggleSource {
|
||||
// Chromevox chrome extension.
|
||||
kChromevox,
|
||||
|
||||
kMaxValue = kChromevox
|
||||
// Accessibility Common chrome extension.
|
||||
kAccessibilityCommon,
|
||||
|
||||
kMaxValue = kAccessibilityCommon
|
||||
};
|
||||
|
||||
enum class SelectToSpeakState {
|
||||
|
@ -494,6 +494,8 @@ AccessibilityPrivateToggleDictationFunction::Run() {
|
||||
source = ash::DictationToggleSource::kSwitchAccess;
|
||||
else if (extension()->id() == extension_misc::kChromeVoxExtensionId)
|
||||
source = ash::DictationToggleSource::kChromevox;
|
||||
else if (extension()->id() == extension_misc::kAccessibilityCommonExtensionId)
|
||||
source = ash::DictationToggleSource::kAccessibilityCommon;
|
||||
else
|
||||
NOTREACHED();
|
||||
|
||||
|
@ -1584,10 +1584,29 @@ bool AccessibilityManager::ToggleDictation() {
|
||||
if (!profile_)
|
||||
return false;
|
||||
|
||||
if (!dictation_.get())
|
||||
dictation_ = std::make_unique<Dictation>(profile_);
|
||||
if (!::switches::IsExperimentalAccessibilityDictationExtensionEnabled()) {
|
||||
if (!dictation_.get())
|
||||
dictation_ = std::make_unique<Dictation>(profile_);
|
||||
|
||||
return dictation_->OnToggleDictation();
|
||||
return dictation_->OnToggleDictation();
|
||||
}
|
||||
|
||||
// We are using AccessibilityCommon extension instead of Dictation C++,
|
||||
// so track Dictation state and simply send a notification to the
|
||||
// AccessibilityPrivate API.
|
||||
dictation_active_ = !dictation_active_;
|
||||
extensions::EventRouter* event_router =
|
||||
extensions::EventRouter::Get(profile_);
|
||||
auto event_args = std::vector<base::Value>();
|
||||
event_args.emplace_back(dictation_active_);
|
||||
auto event = std::make_unique<extensions::Event>(
|
||||
extensions::events::ACCESSIBILITY_PRIVATE_ON_TOGGLE_DICTATION,
|
||||
extensions::api::accessibility_private::OnToggleDictation::kEventName,
|
||||
std::move(event_args));
|
||||
event_router->DispatchEventWithLazyListener(
|
||||
extension_misc::kAccessibilityCommonExtensionId, std::move(event));
|
||||
|
||||
return dictation_active_;
|
||||
}
|
||||
|
||||
const std::string AccessibilityManager::GetFocusRingId(
|
||||
|
@ -497,6 +497,7 @@ class AccessibilityManager
|
||||
bool app_terminating_ = false;
|
||||
|
||||
std::unique_ptr<Dictation> dictation_;
|
||||
bool dictation_active_ = false;
|
||||
|
||||
base::RepeatingCallback<void()> focus_ring_observer_for_test_;
|
||||
base::RepeatingCallback<void()> select_to_speak_state_observer_for_test_;
|
||||
|
@ -8,5 +8,21 @@
|
||||
* --enable-experimental-accessibility-dictation-extension
|
||||
*/
|
||||
export class Dictation {
|
||||
constructor() {}
|
||||
constructor() {
|
||||
chrome.accessibilityPrivate.onToggleDictation.addListener(
|
||||
this.onToggleDictation_.bind(this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when Dictation is toggled.
|
||||
* @param {boolean} activated Whether Dictation was just activated.
|
||||
* @private
|
||||
*/
|
||||
onToggleDictation_(activated) {
|
||||
if (activated) {
|
||||
// Dictation as a JS extension isn't actually implemented yet, so just
|
||||
// turn off again.
|
||||
chrome.accessibilityPrivate.toggleDictation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -789,6 +789,19 @@
|
||||
"description": "Fired when ChromeVox should show its tutorial.",
|
||||
"parameters": [],
|
||||
"platforms": ["chromeos"]
|
||||
},
|
||||
{
|
||||
"name": "onToggleDictation",
|
||||
"type": "function",
|
||||
"description": "Fired when Dictation is activated or deactivated using a keyboard shortcut, the button in the tray, or after a call from accessibilityPrivate.toggleDictation",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "activated",
|
||||
"type": "boolean",
|
||||
"description": "True if Dictation was activated, false if it was deactivated."
|
||||
}
|
||||
],
|
||||
"platforms": ["chromeos"]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -498,6 +498,7 @@ enum HistogramValue {
|
||||
TTS_ENGINE_ON_SPEAK_WITH_AUDIO_STREAM = 476,
|
||||
ACCESSIBILITY_PRIVATE_ON_SHOW_CHROMEVOX_TUTORIAL = 477,
|
||||
STORAGE_SESSION_ON_CHANGE = 478,
|
||||
ACCESSIBILITY_PRIVATE_ON_TOGGLE_DICTATION = 479,
|
||||
// Last entry: Add new entries above, then run:
|
||||
// python tools/metrics/histograms/update_extension_histograms.py
|
||||
ENUM_BOUNDARY
|
||||
|
@ -7,7 +7,7 @@
|
||||
// NOTE: The format of types has changed. 'FooType' is now
|
||||
// 'chrome.accessibilityPrivate.FooType'.
|
||||
// Please run the closure compiler before committing changes.
|
||||
// See https://chromium.googlesource.com/chromium/src/+/master/docs/closure_compilation.md
|
||||
// See https://chromium.googlesource.com/chromium/src/+/main/docs/closure_compilation.md
|
||||
|
||||
/** @fileoverview Externs generated from namespace: accessibilityPrivate */
|
||||
|
||||
@ -561,3 +561,11 @@ chrome.accessibilityPrivate.onCustomSpokenFeedbackToggled;
|
||||
* @type {!ChromeEvent}
|
||||
*/
|
||||
chrome.accessibilityPrivate.onShowChromeVoxTutorial;
|
||||
|
||||
/**
|
||||
* Fired when Dictation is activated or deactivated using a keyboard shortcut,
|
||||
* the button in the tray, or after a call from
|
||||
* accessibilityPrivate.toggleDictation
|
||||
* @type {!ChromeEvent}
|
||||
*/
|
||||
chrome.accessibilityPrivate.onToggleDictation;
|
||||
|
@ -15618,6 +15618,7 @@ metrics consent we also won't be able to send UMA metrics. -->
|
||||
<int value="1" label="Click onscreen button"/>
|
||||
<int value="2" label="Select the button in the SwitchAccess context menu"/>
|
||||
<int value="3" label="ChromeVox gesture"/>
|
||||
<int value="4" label="AccessibilityCommon extension"/>
|
||||
</enum>
|
||||
|
||||
<enum name="CrosDisksArchiveType">
|
||||
@ -26043,6 +26044,7 @@ Called by update_extension_histograms.py.-->
|
||||
<int value="476" label="TTS_ENGINE_ON_SPEAK_WITH_AUDIO_STREAM"/>
|
||||
<int value="477" label="ACCESSIBILITY_PRIVATE_ON_SHOW_CHROMEVOX_TUTORIAL"/>
|
||||
<int value="478" label="STORAGE_SESSION_ON_CHANGE"/>
|
||||
<int value="479" label="ACCESSIBILITY_PRIVATE_ON_TOGGLE_DICTATION"/>
|
||||
</enum>
|
||||
|
||||
<enum name="ExtensionFileWriteResult">
|
||||
|
Reference in New Issue
Block a user