Bug 1520779 Part 2: Implement nsIAccessibleText::BOUNDARY_PARAGRAPH in HyperTextAccessible::GetTextAtOffset, r=Jamie,eeejay

For TextBeforeOffset and TextAfterOffset, bail out with an empty text and 0-initialized out integers if the boundary type is nsIAccessibleText::BOUNDARY_PARAGRAPH.

Differential Revision: https://phabricator.services.mozilla.com/D90115
This commit is contained in:
Marco Zehe 2020-09-16 03:52:47 +00:00
Родитель 55045fb9a9
Коммит b1af3b9011
1 изменённых файлов: 22 добавлений и 0 удалений

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

@ -649,6 +649,11 @@ void HyperTextAccessible::TextBeforeOffset(int32_t aOffset,
*aStartOffset = *aEndOffset = 0;
aText.Truncate();
if (aBoundaryType == nsIAccessibleText::BOUNDARY_PARAGRAPH) {
// Not supported, bail out with empty text.
return;
}
index_t convertedOffset = ConvertMagicOffset(aOffset);
if (!convertedOffset.IsValid() || convertedOffset > CharacterCount()) {
NS_ERROR("Wrong in offset!");
@ -774,6 +779,18 @@ void HyperTextAccessible::TextAtOffset(int32_t aOffset,
*aEndOffset = FindLineBoundary(adjustedOffset, eThisLineEnd);
TextSubstring(*aStartOffset, *aEndOffset, aText);
break;
case nsIAccessibleText::BOUNDARY_PARAGRAPH: {
if (aOffset == nsIAccessibleText::TEXT_OFFSET_CARET) {
adjustedOffset = AdjustCaretOffset(adjustedOffset);
}
*aStartOffset =
FindOffset(adjustedOffset, eDirPrevious, eSelectParagraph);
*aEndOffset = FindOffset(adjustedOffset, eDirNext, eSelectParagraph);
TextSubstring(*aStartOffset, *aEndOffset, aText);
break;
}
}
}
@ -785,6 +802,11 @@ void HyperTextAccessible::TextAfterOffset(int32_t aOffset,
*aStartOffset = *aEndOffset = 0;
aText.Truncate();
if (aBoundaryType == nsIAccessibleText::BOUNDARY_PARAGRAPH) {
// Not supported, bail out with empty text.
return;
}
index_t convertedOffset = ConvertMagicOffset(aOffset);
if (!convertedOffset.IsValid() || convertedOffset > CharacterCount()) {
NS_ERROR("Wrong in offset!");