Skip to content

Commit

Permalink
Add settings and start and stop speech metrics to Select-to-Speak.
Browse files Browse the repository at this point in the history
Bug: 790045
Cq-Include-Trybots: master.tryserver.chromium.linux:closure_compilation
Change-Id: I438b266980762eff52a81968ae9fb53d8acc4f04
Reviewed-on: https://chromium-review.googlesource.com/801335
Reviewed-by: Dominic Mazzoni <dmazzoni@chromium.org>
Reviewed-by: Ilya Sherman <isherman@chromium.org>
Commit-Queue: Katie D <katie@chromium.org>
Cr-Commit-Position: refs/heads/master@{#520702}
  • Loading branch information
dektar authored and Commit Bot committed Nov 30, 2017
1 parent 748a0f5 commit 0f2b9d8
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
'<(EXTERNS_GYP):accessibility_private',
'<(EXTERNS_GYP):automation',
'<(EXTERNS_GYP):chrome_extensions',
'<(EXTERNS_GYP):metrics_private',
],
'includes': ['../../../../../third_party/closure_compiler/compile_js2.gypi'],
},
Expand All @@ -21,6 +22,7 @@
'<(EXTERNS_GYP):accessibility_private',
'<(EXTERNS_GYP):automation',
'<(EXTERNS_GYP):chrome_extensions',
'<(EXTERNS_GYP):metrics_private',
],
'includes': ['../../../../../third_party/closure_compiler/compile_js2.gypi'],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
},
"permissions": [
"accessibilityPrivate",
"metricsPrivate",
"storage",
"tts"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ function getNodeState(node) {
* Regular expression to find the start of the next word after a word boundary.
* We cannot use \b\W to find the next word because it does not match many
* unicode characters.
* TODO: Extract word boundaries from the Accessibility node and use that
* instead.
* @type {RegExp}
*/
const WORD_START_REGEXP = /\b\S/;
Expand All @@ -120,8 +118,6 @@ const WORD_START_REGEXP = /\b\S/;
* Regular expression to find the end of the next word, which is followed by
* whitespace. We cannot use \w\b to find the end of the previous word because
* \w does not know about many unicode characters.
* TODO: Extract word boundaries from the Accessibility node and use that
* instead.
* @type {RegExp}
*/
const WORD_END_REGEXP = /\S\s/;
Expand Down Expand Up @@ -447,6 +443,7 @@ SelectToSpeak.prototype = {
if (!findAllMatching(root, rect, nodes) && focusedNode)
findAllMatching(focusedNode.root, rect, nodes);
this.startSpeechQueue_(nodes);
this.recordStartEvent_();
}.bind(this));
},

Expand Down Expand Up @@ -487,7 +484,7 @@ SelectToSpeak.prototype = {
this.keysPressedTogether_.has(evt.keyCode) &&
this.keysPressedTogether_.size == 1) {
this.trackingMouse_ = false;
this.stopAll_();
chrome.tts.isSpeaking(this.cancelIfSpeaking_.bind(this));
}

this.keysCurrentlyDown_.delete(evt.keyCode);
Expand Down Expand Up @@ -663,6 +660,34 @@ SelectToSpeak.prototype = {
}
},

/**
* Cancels the current speech queue if speech is in progress.
*/
cancelIfSpeaking_: function(speaking) {
if (speaking) {
this.stopAll_();
this.recordCancelEvent_();
}
},

/**
* Records an event that Select-to-Speak has begun speaking.
*/
recordStartEvent_: function() {
// TODO(katie): Add tracking for speech rate, how STS was activated,
// whether word highlighting is on or off (as histograms?).
chrome.metricsPrivate.recordUserAction(
'Accessibility.CrosSelectToSpeak.StartSpeech');
},

/**
* Records an event that Select-to-Speak speech has been canceled.
*/
recordCancelEvent_: function() {
chrome.metricsPrivate.recordUserAction(
'Accessibility.CrosSelectToSpeak.CancelSpeech');
},

/**
* Loads preferences from chrome.storage, sets default values if
* necessary, and registers a listener to update prefs when they
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ SelectToSpeakOptionsPage.prototype = {
this.syncSelectControlToPref_('rate', 'rate');
this.syncCheckboxControlToPref_('wordHighlight', 'wordHighlight');
this.setUpHighlightListener_();
chrome.metricsPrivate.recordUserAction(
'Accessibility.CrosSelectToSpeak.LoadSettings');
},

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ chrome.automation.RoleType = {
INLINE_TEXT_BOX: 'inlineTextBox',
PARAGRAPH: 'paragraph'
};

chrome.automation.StateType = {
INVISIBLE: 'invisible'
};

chrome.metricsPrivate = {
recordUserAction: function() {}
};
19 changes: 19 additions & 0 deletions tools/metrics/actions/actions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1125,6 +1125,25 @@ should be able to be added at any place in this file.
</description>
</action>

<action name="Accessibility.CrosSelectToSpeak.CancelSpeech">
<owner>katie@chromium.org</owner>
<description>
A Chrome OS user manually cancels Select To Speak while it is speaking.
</description>
</action>

<action name="Accessibility.CrosSelectToSpeak.LoadSettings">
<owner>katie@chromium.org</owner>
<description>
A Chrome OS user loads the Select To Speak settings page.
</description>
</action>

<action name="Accessibility.CrosSelectToSpeak.StartSpeech">
<owner>katie@chromium.org</owner>
<description>A Chrome OS user manually starts Select To Speak.</description>
</action>

<action name="Accessibility.TwoFingersHeldGeneratedSpokenFeedbackCountdown">
<owner>dmazzoni@chromium.org</owner>
<description>
Expand Down

0 comments on commit 0f2b9d8

Please sign in to comment.