forked from mirrors/gecko-dev
Bug 1827557 part 1: When constructing a CachedTextMarker from a HyperText, allow an offset equal to the character count. r=morgan
CachedTextMarker uses TextLeafPoint. Because caret and selection events currently use HyperText offsets, we construct text markers using a HyperTextAccessible. The constructor detects that it was provided with a HyperText and converts to a TextLeafPoint appropriately. However, this was previously conditional on the provided offset being less than the character count. When the caret is at the insertion point at the end of a text box, the caret offset will be the character count itself. This meant that we didn't convert to TextLeafPoint in this case, resulting in an incorrect text marker. This was causing VoiceOver to report the first character, word, etc. when cursoring through text boxes instead of the last. Differential Revision: https://phabricator.services.mozilla.com/D176522
This commit is contained in:
parent
67b18f1427
commit
a431ef8f27
2 changed files with 72 additions and 1 deletions
|
|
@ -23,7 +23,7 @@ namespace a11y {
|
|||
CachedTextMarker::CachedTextMarker(Accessible* aAcc, int32_t aOffset) {
|
||||
HyperTextAccessibleBase* ht = aAcc->AsHyperTextBase();
|
||||
if (ht && aOffset != nsIAccessibleText::TEXT_OFFSET_END_OF_TEXT &&
|
||||
aOffset < static_cast<int32_t>(ht->CharacterCount())) {
|
||||
aOffset <= static_cast<int32_t>(ht->CharacterCount())) {
|
||||
mPoint = aAcc->AsHyperTextBase()->ToTextLeafPoint(aOffset);
|
||||
} else {
|
||||
mPoint = TextLeafPoint(aAcc, aOffset);
|
||||
|
|
|
|||
|
|
@ -153,6 +153,28 @@ async function synthKeyAndTestSelectionChanged(
|
|||
expectedSelectionString,
|
||||
`selection has correct value (${expectedSelectionString}) via top document`
|
||||
);
|
||||
|
||||
return inputEvent;
|
||||
}
|
||||
|
||||
function testSelectionEventLeftChar(event, expectedChar) {
|
||||
const selStart = event.macIface.getParameterizedAttributeValue(
|
||||
"AXStartTextMarkerForTextMarkerRange",
|
||||
event.data.AXSelectedTextMarkerRange
|
||||
);
|
||||
const selLeft = event.macIface.getParameterizedAttributeValue(
|
||||
"AXPreviousTextMarkerForTextMarker",
|
||||
selStart
|
||||
);
|
||||
const leftCharRange = event.macIface.getParameterizedAttributeValue(
|
||||
"AXTextMarkerRangeForUnorderedTextMarkers",
|
||||
[selLeft, selStart]
|
||||
);
|
||||
const leftCharString = event.macIface.getParameterizedAttributeValue(
|
||||
"AXStringForTextMarkerRange",
|
||||
leftCharRange
|
||||
);
|
||||
is(leftCharString, expectedChar, "Left character is correct");
|
||||
}
|
||||
|
||||
async function synthKeyAndTestValueChanged(
|
||||
|
|
@ -452,3 +474,52 @@ addAccessibleTask(
|
|||
},
|
||||
{ topLevel: true, iframe: true, remoteIframe: true }
|
||||
);
|
||||
|
||||
/**
|
||||
* Test that the caret returns the correct marker when it is positioned after
|
||||
* the last character (to facilitate appending text).
|
||||
*/
|
||||
addAccessibleTask(
|
||||
`<input id="input" value="abc">`,
|
||||
async function(browser, docAcc) {
|
||||
await focusIntoInput(docAcc, "input");
|
||||
|
||||
let event = await synthKeyAndTestSelectionChanged(
|
||||
"KEY_ArrowRight",
|
||||
null,
|
||||
"input",
|
||||
"",
|
||||
{
|
||||
AXTextStateChangeType: AXTextStateChangeTypeSelectionMove,
|
||||
AXTextSelectionDirection: AXTextSelectionDirectionNext,
|
||||
AXTextSelectionGranularity: AXTextSelectionGranularityCharacter,
|
||||
}
|
||||
);
|
||||
testSelectionEventLeftChar(event, "a");
|
||||
event = await synthKeyAndTestSelectionChanged(
|
||||
"KEY_ArrowRight",
|
||||
null,
|
||||
"input",
|
||||
"",
|
||||
{
|
||||
AXTextStateChangeType: AXTextStateChangeTypeSelectionMove,
|
||||
AXTextSelectionDirection: AXTextSelectionDirectionNext,
|
||||
AXTextSelectionGranularity: AXTextSelectionGranularityCharacter,
|
||||
}
|
||||
);
|
||||
testSelectionEventLeftChar(event, "b");
|
||||
event = await synthKeyAndTestSelectionChanged(
|
||||
"KEY_ArrowRight",
|
||||
null,
|
||||
"input",
|
||||
"",
|
||||
{
|
||||
AXTextStateChangeType: AXTextStateChangeTypeSelectionMove,
|
||||
AXTextSelectionDirection: AXTextSelectionDirectionNext,
|
||||
AXTextSelectionGranularity: AXTextSelectionGranularityCharacter,
|
||||
}
|
||||
);
|
||||
testSelectionEventLeftChar(event, "c");
|
||||
},
|
||||
{ chrome: true, topLevel: true }
|
||||
);
|
||||
|
|
|
|||
Loading…
Reference in a new issue