Bug 1255261 - Read current paragraph after pressing stop. r=jaws

We always had to make sure we were one paragraph back from where we wanted
to start. That seems broken. I made it so that we start from the current
paragraph.

MozReview-Commit-ID: 4HMTdXcF644
This commit is contained in:
Eitan Isaacson 2016-08-03 10:34:06 -07:00
parent 757d82e0ba
commit 5123fa44ad
2 changed files with 19 additions and 9 deletions

View File

@ -143,7 +143,7 @@ Narrator.prototype = {
_speakInner: function() { _speakInner: function() {
this._win.speechSynthesis.cancel(); this._win.speechSynthesis.cancel();
let tw = this._treeWalker; let tw = this._treeWalker;
let paragraph = tw.nextNode(); let paragraph = tw.currentNode;
if (!paragraph) { if (!paragraph) {
tw.currentNode = tw.root; tw.currentNode = tw.root;
return Promise.resolve(); return Promise.resolve();
@ -193,6 +193,7 @@ Narrator.prototype = {
// User pressed stopped. // User pressed stopped.
resolve(); resolve();
} else { } else {
tw.nextNode();
this._speakInner().then(resolve, reject); this._speakInner().then(resolve, reject);
} }
}); });
@ -216,14 +217,10 @@ Narrator.prototype = {
let tw = this._treeWalker; let tw = this._treeWalker;
if (!this._isParagraphInView(tw.currentNode)) { if (!this._isParagraphInView(tw.currentNode)) {
tw.currentNode = tw.root; tw.currentNode = tw.root;
while (tw.nextNode()) { while (tw.nextNode() && !this._isParagraphInView(tw.currentNode)) {}
if (this._isParagraphInView(tw.currentNode)) { }
break; if (tw.currentNode == tw.root) {
} tw.nextNode();
}
// _speakInner will advance to the next node for us, so we need
// to have it one paragraph back from the first visible one.
tw.previousNode();
} }
return this._speakInner(); return this._speakInner();

View File

@ -64,6 +64,19 @@ add_task(function* testNarrate() {
NarrateTestUtils.isStartedState(content, ok); NarrateTestUtils.isStartedState(content, ok);
paragraph = speechinfo.paragraph;
$(NarrateTestUtils.STOP).click();
yield ContentTaskUtils.waitForCondition(
() => !$(NarrateTestUtils.STOP), "transitioned to stopped state");
NarrateTestUtils.isStoppedState(content, ok);
promiseEvent = ContentTaskUtils.waitForEvent(content, "paragraphstart");
$(NarrateTestUtils.START).click();
speechinfo = (yield promiseEvent).detail;
is(speechinfo.paragraph, paragraph, "read same paragraph again");
NarrateTestUtils.isStartedState(content, ok);
let eventUtils = NarrateTestUtils.getEventUtils(content); let eventUtils = NarrateTestUtils.getEventUtils(content);
promiseEvent = ContentTaskUtils.waitForEvent(content, "paragraphstart"); promiseEvent = ContentTaskUtils.waitForEvent(content, "paragraphstart");