Commit 67d437dd authored by David Tseng's avatar David Tseng Committed by Commit Bot

Use settings as a backing store for ChromeVox tts properties

This change:
- writes to settings each time ChromeVox changes a tts property
- updates from prefs on startup
- observes pref changes and announces when rate, pitch, and volume changes
- adds a new key binding (Search+o, s) which opens the tts settings
- adds a new menu item in the ChromeVox menus opening tts settings

There should be no functional change for ChromeVox commands (e.g. keyboard shortcut to change pitch).

Changes to global tts settings should be reflected in ChromeVox immediately once changed.

Change-Id: Ic701c6f7b4422194ac8a957fbaf4fe0fd60e00af
Reviewed-on: https://chromium-review.googlesource.com/1157173
Commit-Queue: David Tseng <dtseng@chromium.org>
Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Reviewed-by: default avatarKatie Dektar <katie@chromium.org>
Cr-Commit-Position: refs/heads/master@{#579868}
parent 6b74593b
......@@ -950,6 +950,15 @@
},
"doubleTap": true
}
},
{
"command": "showTtsSettings",
"sequence": {
"cvoxModifier": true,
"keys": {
"keyCode": [79, 83]
}
}
}
]
}
......@@ -431,6 +431,8 @@ cvox.CommandStore.CMD_WHITELIST = {
'disallowOOBE': true,
category: 'help_commands'
},
'showTtsSettings':
{announce: false, msgId: 'show_tts_settings', category: 'help_commands'},
'toggleBrailleCaptions':
{announce: false, msgId: 'braille_captions', category: 'help_commands'},
'reportIssue': {
......
......@@ -233,6 +233,10 @@ CommandHandler.onCommand = function(command) {
chrome.accessibilityPrivate.setNativeChromeVoxArcSupportForCurrentApp(
false);
break;
case 'showTtsSettings':
var ttsSettings = {url: 'chrome://settings/manageAccessibility/tts'};
chrome.windows.create(ttsSettings);
break;
default:
break;
}
......@@ -906,25 +910,6 @@ CommandHandler.onCommand = function(command) {
CommandHandler.increaseOrDecreaseSpeechProperty_ = function(
propertyName, increase) {
cvox.ChromeVox.tts.increaseOrDecreaseProperty(propertyName, increase);
var announcement;
var valueAsPercent =
Math.round(cvox.ChromeVox.tts.propertyToPercentage(propertyName) * 100);
switch (propertyName) {
case cvox.AbstractTts.RATE:
announcement = Msgs.getMsg('announce_rate', [valueAsPercent]);
break;
case cvox.AbstractTts.PITCH:
announcement = Msgs.getMsg('announce_pitch', [valueAsPercent]);
break;
case cvox.AbstractTts.VOLUME:
announcement = Msgs.getMsg('announce_volume', [valueAsPercent]);
break;
}
if (announcement) {
cvox.ChromeVox.tts.speak(
announcement, cvox.QueueMode.FLUSH,
cvox.AbstractTts.PERSONALITY_ANNOTATION);
}
};
/**
......
......@@ -46,13 +46,6 @@ cvox.TtsBackground = function(opt_enableMath) {
opt_enableMath = opt_enableMath == undefined ? true : opt_enableMath;
goog.base(this);
this.ttsProperties['rate'] =
(parseFloat(localStorage['rate']) || this.propertyDefault['rate']);
this.ttsProperties['pitch'] =
(parseFloat(localStorage['pitch']) || this.propertyDefault['pitch']);
this.ttsProperties['volume'] =
(parseFloat(localStorage['volume']) || this.propertyDefault['volume']);
// Use the current locale as the speech language if not otherwise
// specified.
if (this.ttsProperties['lang'] == undefined) {
......@@ -188,6 +181,30 @@ cvox.TtsBackground = function(opt_enableMath) {
this.updateVoice_(changes.voiceName.newValue);
}
}.bind(this));
// Migration: localStorage tts properties -> Chrome pref settings.
if (localStorage['rate']) {
chrome.settingsPrivate.setPref(
'settings.tts.speech_rate', parseFloat(localStorage['rate']));
delete localStorage['rate'];
}
if (localStorage['pitch']) {
chrome.settingsPrivate.setPref(
'settings.tts.speech_pitch', parseFloat(localStorage['pitch']));
delete localStorage['pitch'];
}
if (localStorage['volume']) {
chrome.settingsPrivate.setPref(
'settings.tts.speech_volume', parseFloat(localStorage['volume']));
delete localStorage['volume'];
}
// At startup.
chrome.settingsPrivate.getAllPrefs(this.updateFromPrefs_.bind(this, false));
// At runtime.
chrome.settingsPrivate.onPrefsChanged.addListener(
this.updateFromPrefs_.bind(this, true));
};
goog.inherits(cvox.TtsBackground, cvox.ChromeTtsBase);
......@@ -479,7 +496,23 @@ cvox.TtsBackground.prototype.cancelUtterance_ = function(utterance) {
cvox.TtsBackground.prototype.increaseOrDecreaseProperty = function(
propertyName, increase) {
goog.base(this, 'increaseOrDecreaseProperty', propertyName, increase);
localStorage[propertyName] = this.ttsProperties[propertyName];
var pref;
switch (propertyName) {
case cvox.AbstractTts.RATE:
pref = 'settings.tts.speech_rate';
break;
case cvox.AbstractTts.PITCH:
pref = 'settings.tts.speech_pitch';
break;
case cvox.AbstractTts.VOLUME:
pref = 'settings.tts.speech_volume';
break;
default:
return;
}
var value = this.ttsProperties[propertyName];
chrome.settingsPrivate.setPref(pref, value);
};
/** @override */
......@@ -732,3 +765,43 @@ cvox.TtsBackground.prototype.updateVoice_ = function(voiceName, opt_callback) {
opt_callback(this.currentVoice);
}, this));
};
/**
* @param {boolean} announce
* @param {Array<chrome.settingsPrivate.PrefObject>} prefs
* @private
*/
cvox.TtsBackground.prototype.updateFromPrefs_ = function(announce, prefs) {
prefs.forEach((pref) => {
var msg;
var propertyName;
switch (pref.key) {
case 'settings.tts.speech_rate':
propertyName = cvox.AbstractTts.RATE;
msg = 'announce_rate';
break;
case 'settings.tts.speech_pitch':
propertyName = cvox.AbstractTts.PITCH;
msg = 'announce_pitch';
break;
case 'settings.tts.speech_volume':
propertyName = cvox.AbstractTts.VOLUME;
msg = 'announce_volume';
break;
default:
return;
}
this.ttsProperties[propertyName] = pref.value;
if (!announce)
return;
var valueAsPercent =
Math.round(this.propertyToPercentage(propertyName) * 100);
var announcement = Msgs.getMsg(msg, [valueAsPercent]);
cvox.ChromeVox.tts.speak(
announcement, cvox.QueueMode.FLUSH,
cvox.AbstractTts.PERSONALITY_ANNOTATION);
});
};
......@@ -23,6 +23,7 @@
"history",
"metricsPrivate",
"notifications",
"settingsPrivate",
"storage",
"tabs",
"tts",
......
......@@ -2999,6 +2999,9 @@ If you're done with the tutorial, use ChromeVox to navigate to the Close button
<message desc="Voice name for the system default Text-to-Speech voice" name="IDS_CHROMEVOX_SYSTEM_VOICE">
System Text-to-Speech voice
</message>
<message desc="Menu item text for a command to open the text to speech settings page" name="IDS_CHROMEVOX_SHOW_TTS_SETTINGS">
Open text-to-speech settings
</message>
</messages>
</release>
</grit>
......@@ -54,6 +54,9 @@ _AUTOMATION_EXTERNS = (
_METRICS_PRIVATE_EXTERNS = (
ChromeRootPath('third_party/closure_compiler/externs/metrics_private.js'))
# Settings private API externs file.
_SETTINGS_PRIVATE_EXTERNS = (
ChromeRootPath('third_party/closure_compiler/externs/settings_private.js'))
# Additional chrome api externs file.
_CHROME_EXTERNS = (
......@@ -75,7 +78,8 @@ _COMMON_EXTERNS = [
_AUTOMATION_EXTERNS,
_CHROME_EXTERNS,
_CHROME_EXTENSIONS_EXTERNS,
_METRICS_PRIVATE_EXTERNS]
_METRICS_PRIVATE_EXTERNS,
_SETTINGS_PRIVATE_EXTERNS,]
# List of top-level scripts and externs that we can check.
_TOP_LEVEL_SCRIPTS = [
......
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