Bug 1730088 part 7: Move CharAt to HyperTextAccessibleBase. r=eeejay

Differential Revision: https://phabricator.services.mozilla.com/D127212
This commit is contained in:
James Teh 2021-10-06 10:13:10 +00:00
Родитель b1c9ba78d4
Коммит 0300ea1e93
3 изменённых файлов: 27 добавлений и 20 удалений

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

@ -140,4 +140,24 @@ void HyperTextAccessibleBase::TextSubstring(int32_t aStartOffset,
endChild->AppendTextTo(aText, 0, endOffset - endChildOffset);
}
bool HyperTextAccessibleBase::CharAt(int32_t aOffset, nsAString& aChar,
int32_t* aStartOffset, int32_t* aEndOffset) {
MOZ_ASSERT(!aStartOffset == !aEndOffset,
"Offsets should be both defined or both undefined!");
int32_t childIdx = GetChildIndexAtOffset(aOffset);
if (childIdx == -1) {
return false;
}
Accessible* child = Acc()->ChildAt(childIdx);
child->AppendTextTo(aChar, aOffset - GetChildOffset(childIdx), 1);
if (aStartOffset && aEndOffset) {
*aStartOffset = aOffset;
*aEndOffset = aOffset + aChar.Length();
}
return true;
}
} // namespace mozilla::a11y

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

@ -87,6 +87,12 @@ class HyperTextAccessibleBase {
virtual void TextSubstring(int32_t aStartOffset, int32_t aEndOffset,
nsAString& aText) const;
/**
* Get a character at the given offset (don't support magic offsets).
*/
bool CharAt(int32_t aOffset, nsAString& aChar,
int32_t* aStartOffset = nullptr, int32_t* aEndOffset = nullptr);
protected:
virtual const Accessible* Acc() const = 0;
Accessible* Acc() {

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

@ -144,26 +144,7 @@ class HyperTextAccessible : public HyperTextAccessibleBase,
//////////////////////////////////////////////////////////////////////////////
// TextAccessible
/**
* Get a character at the given offset (don't support magic offsets).
*/
bool CharAt(int32_t aOffset, nsAString& aChar,
int32_t* aStartOffset = nullptr, int32_t* aEndOffset = nullptr) {
NS_ASSERTION(!aStartOffset == !aEndOffset,
"Offsets should be both defined or both undefined!");
int32_t childIdx = GetChildIndexAtOffset(aOffset);
if (childIdx == -1) return false;
LocalAccessible* child = LocalChildAt(childIdx);
child->AppendTextTo(aChar, aOffset - GetChildOffset(childIdx), 1);
if (aStartOffset && aEndOffset) {
*aStartOffset = aOffset;
*aEndOffset = aOffset + aChar.Length();
}
return true;
}
using HyperTextAccessibleBase::CharAt;
char16_t CharAt(int32_t aOffset) {
nsAutoString charAtOffset;