Bug 1665662 - Ensure that at the end of a paragraph, after a line break, we return empty line offsets, r=Jamie

If in a textarea, a blank line is inserted, we need to return the offsets of just that new inner paragraph, or the braille display of a screen reader will show the previous line and not a blank one.

Differential Revision: https://phabricator.services.mozilla.com/D90655
This commit is contained in:
Marco Zehe 2020-09-18 06:58:33 +00:00
Родитель 0fef58f699
Коммит 0c2fda970a
2 изменённых файлов: 16 добавлений и 0 удалений

Просмотреть файл

@ -789,6 +789,14 @@ void HyperTextAccessible::TextAtOffset(int32_t aOffset,
adjustedOffset = AdjustCaretOffset(adjustedOffset);
}
if (IsEmptyLastLineOffset(adjustedOffset)) {
// We are on the last line of a paragraph where there is no text.
// For example, in a textarea where a new line has just been inserted.
// In this case, return offsets for an empty line without text content.
*aStartOffset = *aEndOffset = adjustedOffset;
break;
}
if (IsLineEndCharAt(adjustedOffset)) {
// Layout gives us different results for a paragraph with line breaks.
// For the text, we get the text, for the line break, we get the text

Просмотреть файл

@ -52,6 +52,12 @@
testTextAtOffset("li1", BOUNDARY_PARAGRAPH,
[[0, 3, "• a", 0, 3]]);
// Test that a textarea has a blank paragraph at the end if it contains
// a line break as its last character.
testTextAtOffset("textarea_with_br", BOUNDARY_PARAGRAPH,
[[0, 15, "This is a test.\n", 0, 16],
[16, 16, "", 16, 16]]);
SimpleTest.finish();
}
@ -81,5 +87,7 @@
<p id="br_at_beginning"><br>a<br>b</p>
<p id="pWithLink">a<a id="link" href="https://example.com/">bc</a>d</p>
<ul id="ul"><li id="li1">a</li><li>b</li></ul>
<textarea id="textarea_with_br">This is a test.
</textarea> <!-- This must be outdented for a correct test case -->
</body>
</html>