Bug 1730088 part 8: Move ToTextLeafPoint to HyperTextAccessibleBase. r=eeejay

Differential Revision: https://phabricator.services.mozilla.com/D127213
This commit is contained in:
James Teh 2021-10-07 04:22:46 +00:00
Родитель eb660a098e
Коммит ddbabe9849
4 изменённых файлов: 29 добавлений и 26 удалений

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

@ -8,6 +8,7 @@
#include "mozilla/a11y/Accessible.h" #include "mozilla/a11y/Accessible.h"
#include "nsAccUtils.h" #include "nsAccUtils.h"
#include "nsIAccessibleText.h" #include "nsIAccessibleText.h"
#include "TextLeafRange.h"
namespace mozilla::a11y { namespace mozilla::a11y {
@ -160,4 +161,23 @@ bool HyperTextAccessibleBase::CharAt(int32_t aOffset, nsAString& aChar,
return true; return true;
} }
TextLeafPoint HyperTextAccessibleBase::ToTextLeafPoint(int32_t aOffset,
bool aDescendToEnd) {
Accessible* thisAcc = Acc();
if (!thisAcc->HasChildren()) {
return TextLeafPoint(thisAcc, 0);
}
Accessible* child = GetChildAtOffset(aOffset);
if (!child) {
return TextLeafPoint();
}
if (HyperTextAccessibleBase* childHt = child->AsHyperTextBase()) {
return childHt->ToTextLeafPoint(
aDescendToEnd ? static_cast<int32_t>(childHt->CharacterCount()) : 0,
aDescendToEnd);
}
int32_t offset = aOffset - GetChildOffset(child);
return TextLeafPoint(child, offset);
}
} // namespace mozilla::a11y } // namespace mozilla::a11y

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

@ -8,6 +8,7 @@
namespace mozilla::a11y { namespace mozilla::a11y {
class Accessible; class Accessible;
class TextLeafPoint;
// This character marks where in the text returned via Text interface, // This character marks where in the text returned via Text interface,
// that embedded object characters exist // that embedded object characters exist
@ -93,6 +94,14 @@ class HyperTextAccessibleBase {
bool CharAt(int32_t aOffset, nsAString& aChar, bool CharAt(int32_t aOffset, nsAString& aChar,
int32_t* aStartOffset = nullptr, int32_t* aEndOffset = nullptr); int32_t* aStartOffset = nullptr, int32_t* aEndOffset = nullptr);
/**
* Get a TextLeafPoint for a given offset in this HyperTextAccessible.
* If the offset points to an embedded object and aDescendToEnd is true,
* the point right at the end of this subtree will be returned instead of the
* start.
*/
TextLeafPoint ToTextLeafPoint(int32_t aOffset, bool aDescendToEnd = false);
protected: protected:
virtual const Accessible* Acc() const = 0; virtual const Accessible* Acc() const = 0;
Accessible* Acc() { Accessible* Acc() {

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

@ -2087,24 +2087,6 @@ void HyperTextAccessible::RangeAtPoint(int32_t aX, int32_t aY,
} }
} }
TextLeafPoint HyperTextAccessible::ToTextLeafPoint(int32_t aOffset,
bool aDescendToEnd) {
if (!HasChildren()) {
return TextLeafPoint(this, 0);
}
LocalAccessible* child = GetChildAtOffset(aOffset);
if (!child) {
return TextLeafPoint();
}
if (HyperTextAccessible* childHt = child->AsHyperText()) {
return childHt->ToTextLeafPoint(
aDescendToEnd ? static_cast<int32_t>(childHt->CharacterCount()) : 0,
aDescendToEnd);
}
int32_t offset = aOffset - GetChildOffset(child);
return TextLeafPoint(child, offset);
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// LocalAccessible public // LocalAccessible public

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

@ -326,14 +326,6 @@ class HyperTextAccessible : public AccessibleWrap,
*/ */
void RangeAtPoint(int32_t aX, int32_t aY, TextRange& aRange) const; void RangeAtPoint(int32_t aX, int32_t aY, TextRange& aRange) const;
/**
* Get a TextLeafPoint for a given offset in this HyperTextAccessible.
* If the offset points to an embedded object and aDescendToEnd is true,
* the point right at the end of this subtree will be returned instead of the
* start.
*/
TextLeafPoint ToTextLeafPoint(int32_t aOffset, bool aDescendToEnd = false);
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
// EditableTextAccessible // EditableTextAccessible