Bug 1321862 - Use charLength for word highlight in Narrate. r=Gijs

MozReview-Commit-ID: 8mdjtRj2ljw

--HG--
extra : rebase_source : 146bd14b4c5974c743746b068488cad5549782f3
This commit is contained in:
Eitan Isaacson 2016-11-17 11:55:12 -08:00
parent a0b75bb470
commit 7c9afce020
3 changed files with 12 additions and 17 deletions

View File

@ -220,18 +220,12 @@ Narrator.prototype = {
return;
}
// Match non-whitespace. This isn't perfect, but the most universal
// solution for now.
let reWordBoundary = /\S+/g;
// Match the first word from the boundary event offset.
reWordBoundary.lastIndex = e.charIndex;
let firstIndex = reWordBoundary.exec(paragraph.textContent);
if (firstIndex) {
highlighter.highlight(firstIndex.index, reWordBoundary.lastIndex);
if (e.charLength) {
highlighter.highlight(e.charIndex, e.charLength);
if (this._inTest) {
this._sendTestEvent("wordhighlight", {
start: firstIndex.index,
end: reWordBoundary.lastIndex
start: e.charIndex,
end: e.charIndex + e.charLength
});
}
}
@ -320,11 +314,11 @@ Highlighter.prototype = {
* Highlight the range within offsets relative to the container.
*
* @param {Number} startOffset the start offset
* @param {Number} endOffset the end offset
* @param {Number} length the length in characters of the range
*/
highlight: function(startOffset, endOffset) {
highlight: function(startOffset, length) {
let containerRect = this.container.getBoundingClientRect();
let range = this._getRange(startOffset, endOffset);
let range = this._getRange(startOffset, startOffset + length);
let rangeRects = range.getClientRects();
let win = this.container.ownerDocument.defaultView;
let computedStyle = win.getComputedStyle(range.endContainer.parentNode);

View File

@ -125,8 +125,8 @@ this.NarrateTestUtils = {
});
},
sendBoundaryEvent: function(window, name, charIndex) {
let detail = { type: "boundary", args: { name, charIndex } };
sendBoundaryEvent: function(window, name, charIndex, charLength) {
let detail = { type: "boundary", args: { name, charIndex, charLength } };
window.dispatchEvent(new window.CustomEvent("testsynthevent",
{ detail: detail }));
},

View File

@ -39,12 +39,13 @@ add_task(function* testNarrate() {
details = (yield promiseEvent).detail;
} while (details.tag != "p");
let boundaryPat = /(\s+)\S/g;
let boundaryPat = /(\S+)/g;
let position = { left: 0, top: 0 };
let text = details.paragraph;
for (let res = boundaryPat.exec(text); res; res = boundaryPat.exec(text)) {
promiseEvent = ContentTaskUtils.waitForEvent(content, "wordhighlight");
NarrateTestUtils.sendBoundaryEvent(content, "word", res.index);
NarrateTestUtils.sendBoundaryEvent(content, "word",
res.index, res[0].length);
let { start, end } = (yield promiseEvent).detail;
let nodes = NarrateTestUtils.getWordHighlights(content);
for (let node of nodes) {