Bug 1479678: Fix incorrect start offset when retrieving accessible text attributes if the last spelling error is not within this accessible. r=surkov

When dealing with an editor which contains multiple accessibles, the previous spelling error range might be in a previous accessible, not the accessible currently being queried.
In this case, DOMPointToOffset will return the length of this accessible.
Previously, we weren't checking for this and were overriding the start offset of the returned range regardless, resulting in broken offsets.
Now, we leave the start offset alone in this case.

Differential Revision: https://phabricator.services.mozilla.com/D3960

--HG--
extra : moz-landing-system : lando
This commit is contained in:
James Teh 2018-08-24 03:08:28 +00:00
parent 768f7a15c5
commit 2a8cad4bfc
3 changed files with 62 additions and 2 deletions

View file

@ -2206,7 +2206,10 @@ HyperTextAccessible::GetSpellTextAttr(nsINode* aNode,
prevRange->EndOffset());
}
if (startOffset > *aStartOffset)
// The previous range might not be within this accessible. In that case,
// DOMPointToOffset returns length as a fallback. We don't want to use
// that offset if so, hence the startOffset < *aEndOffset check.
if (startOffset > *aStartOffset && startOffset < *aEndOffset)
*aStartOffset = startOffset;
if (endOffset < *aEndOffset)
@ -2223,7 +2226,10 @@ HyperTextAccessible::GetSpellTextAttr(nsINode* aNode,
startOffset = DOMPointToOffset(prevRange->GetEndContainer(),
prevRange->EndOffset());
if (startOffset > *aStartOffset)
// The previous range might not be within this accessible. In that case,
// DOMPointToOffset returns length as a fallback. We don't want to use
// that offset if so, hence the startOffset < *aEndOffset check.
if (startOffset > *aStartOffset && startOffset < *aEndOffset)
*aStartOffset = startOffset;
}

View file

@ -5,3 +5,4 @@ support-files =
[test_general.html]
[test_invalid.html]
[test_spelling.html]

View file

@ -0,0 +1,53 @@
<html>
<head>
<title>Spell check text attribute tests</title>
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript"
src="../common.js"></script>
<script type="application/javascript"
src="../attributes.js"></script>
<script type="application/javascript"
src="../events.js"></script>
<script type="application/javascript">
async function doTest() {
const misspelledAttrs = {"invalid": "spelling"};
let editable = document.getElementById("div_after_misspelling");
// The attr change event gets fired on the last accessible containing a
// spelling error.
let spellDone = waitForEventPromise(EVENT_TEXT_ATTRIBUTE_CHANGED, "div_after_misspelling_div2");
editable.focus();
await spellDone;
testTextAttrs("div_after_misspelling_div1", 0, {}, {}, 0, 5, true);
testTextAttrs("div_after_misspelling_div1", 5, misspelledAttrs, {}, 5, 9, true);
testTextAttrs("div_after_misspelling_div2", 0, {}, {}, 0, 5, true);
testTextAttrs("div_after_misspelling_div2", 5, misspelledAttrs, {}, 5, 9, true);
SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
addA11yLoadEvent(doTest);
</script>
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none"></div>
<pre id="test">
</pre>
<!-- Text attribute offsets for accessibles after first spelling error (bug 1479678) -->
<div id="div_after_misspelling" contenteditable="true" spellcheck="true" lang="en-US">
<div id="div_after_misspelling_div1">Test tset</div>
<div id="div_after_misspelling_div2">test tset</div>
</div>
</body>
</html>