Commit 160e72c5 authored by Katie D's avatar Katie D Committed by Commit Bot

Fix STS reading selected text in Docs with Search+S.

This was introduced in https://chromium-review.googlesource.com/1136842.

Bug: 882868,882923
Change-Id: I507ffe0d35dfe568276971ca1b6775fcc150896b
Reviewed-on: https://chromium-review.googlesource.com/1219930
Commit-Queue: Katie Dektar <katie@chromium.org>
Reviewed-by: default avatarDavid Tseng <dtseng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#590460}
parent cf285d2d
......@@ -59,6 +59,23 @@ let InputHandler = function(callbacks) {
/** @private {{x: number, y: number}} */
this.mouseEnd_ = {x: 0, y: 0};
/**
* The timestamp at which clipboard data read was requested by the user
* doing a "read selection" keystroke on a Google Docs app. If a
* clipboard change event comes in within CLIPBOARD_READ_MAX_DELAY_MS,
* Select-to-Speak will read that text out loud.
* @private {Date}
*/
this.lastReadClipboardDataTime_ = new Date(0);
/**
* The timestamp at which the last clipboard data clear was requested.
* Used to make sure we don't clear the clipboard on a user's request,
* but only after the clipboard was used to read selected text.
* @private {Date}
*/
this.lastClearClipboardDataTime_ = new Date(0);
/**
* Called when the mouse is moved or dragged and the user is in a
* mode where select-to-speak is capturing mouse events (for example
......@@ -82,7 +99,7 @@ let InputHandler = function(callbacks) {
* @private
*/
this.onClipboardDataChanged_ = function() {
if (Date.now() - this.readClipboardDataTimeMs_ <
if (new Date() - this.lastReadClipboardDataTime_ <
InputHandler.CLIPBOARD_READ_MAX_DELAY_MS) {
// The data has changed, and we are ready to read it.
// Get it using a paste.
......@@ -94,13 +111,13 @@ let InputHandler = function(callbacks) {
* @private
*/
this.onClipboardCopy_ = function(evt) {
if (Date.now() - this.clearClipboardDataTimeMs_ <
if (new Date() - this.lastClearClipboardDataTime_ <
InputHandler.CLIPBOARD_CLEAR_MAX_DELAY_MS) {
// onClipboardPaste has just completed reading the clipboard for speech.
// This is used to clear the clipboard.
evt.clipboardData.setData('text/plain', '');
evt.preventDefault();
this.clearClipboardDataTimeMs_ = -1;
this.lastClearClipboardDataTime_ = new Date(0);
}
};
......@@ -108,17 +125,17 @@ let InputHandler = function(callbacks) {
* @private
*/
this.onClipboardPaste_ = function(evt) {
if (Date.now() - this.readClipboardDataTimeMs_ <
if (new Date() - this.lastReadClipboardDataTime_ <
InputHandler.CLIPBOARD_READ_MAX_DELAY_MS) {
// Read the current clipboard data.
evt.preventDefault();
this.callbacks_.onTextReceived(evt.clipboardData.getData('text/plain'));
this.readClipboardDataTimeMs_ = -1;
this.lastReadClipboardDataTime_ = new Date(0);
// Clear the clipboard data by copying nothing (the current document).
// Do this in a timeout to avoid a recursive warning per
// https://crbug.com/363288.
setTimeout(() => {
this.clearClipboardDataTimeMs_ = Date.now();
this.lastClearClipboardDataTime_ = new Date();
document.execCommand('copy');
}, 0);
}
......@@ -165,6 +182,14 @@ InputHandler.prototype = {
this.mouseEnd_.y);
},
/**
* Sets the date at which we last wanted the clipboard data to be read.
* @public
*/
onRequestReadClipboardData: function() {
this.lastReadClipboardDataTime_ = new Date();
},
/**
* Called when the mouse is pressed and the user is in a mode where
* select-to-speak is capturing mouse events (for example holding down
......
......@@ -87,15 +87,6 @@ let SelectToSpeak = function() {
/** @private {boolean} */
this.scrollToSpokenNode_ = false;
/**
* The timestamp at which clipboard data read was requested by the user
* doing a "read selection" keystroke on a Google Docs app. If a
* clipboard change event comes in within CLIPBOARD_READ_MAX_DELAY_MS,
* Select-to-Speak will read that text out loud.
* @private {number}
*/
this.readClipboardDataTimeMs_ = -1;
/**
* The interval ID from a call to setInterval, which is set whenever
* speech is in progress.
......@@ -316,7 +307,7 @@ SelectToSpeak.prototype = {
return;
}
let tab = tabs[0];
this.readClipboardDataTimeMs_ = Date.now();
this.inputHandler_.onRequestReadClipboardData();
this.currentNode_ =
new ParagraphUtils.NodeGroupItem(driveAppRootNode, 0, false);
chrome.tabs.executeScript(tab.id, {
......
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