зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1755420 part 2: Remove unnecessary case/if statements now that all boundaries (except CHAR) are implemented by TextLeafPoint. r=morgan
This also causes HyperTextAccessible to use HyperTextAccessibleBase for BOUNDARY_CHAR when the cache is enabled. The fact that we weren't doing this already was an oversight. Differential Revision: https://phabricator.services.mozilla.com/D138753
This commit is contained in:
Родитель
759cd2a4f0
Коммит
03c7ccd06d
|
@ -262,48 +262,48 @@ void HyperTextAccessibleBase::TextBeforeOffset(
|
|||
*aStartOffset = *aEndOffset = 0;
|
||||
aText.Truncate();
|
||||
|
||||
if (aBoundaryType == nsIAccessibleText::BOUNDARY_SENTENCE_START ||
|
||||
aBoundaryType == nsIAccessibleText::BOUNDARY_SENTENCE_END) {
|
||||
return; // Not implemented.
|
||||
}
|
||||
|
||||
uint32_t adjustedOffset = ConvertMagicOffset(aOffset);
|
||||
if (adjustedOffset == std::numeric_limits<uint32_t>::max()) {
|
||||
NS_ERROR("Wrong given offset!");
|
||||
return;
|
||||
}
|
||||
|
||||
switch (aBoundaryType) {
|
||||
case nsIAccessibleText::BOUNDARY_CHAR:
|
||||
if (adjustedOffset > 0) {
|
||||
CharAt(static_cast<int32_t>(adjustedOffset) - 1, aText, aStartOffset,
|
||||
aEndOffset);
|
||||
}
|
||||
break;
|
||||
case nsIAccessibleText::BOUNDARY_WORD_START:
|
||||
case nsIAccessibleText::BOUNDARY_WORD_END:
|
||||
case nsIAccessibleText::BOUNDARY_LINE_START:
|
||||
case nsIAccessibleText::BOUNDARY_LINE_END:
|
||||
TextLeafPoint orig;
|
||||
if (aOffset == nsIAccessibleText::TEXT_OFFSET_CARET) {
|
||||
orig = TextLeafPoint::GetCaret(Acc());
|
||||
} else {
|
||||
orig = ToTextLeafPoint(static_cast<int32_t>(adjustedOffset));
|
||||
}
|
||||
AdjustOriginIfEndBoundary(orig, aBoundaryType);
|
||||
TextLeafPoint end = orig.FindBoundary(aBoundaryType, eDirPrevious,
|
||||
/* aIncludeOrigin */ true);
|
||||
bool ok;
|
||||
std::tie(ok, *aEndOffset) = TransformOffset(end.mAcc, end.mOffset,
|
||||
/* aIsEndOffset */ true);
|
||||
if (!ok) {
|
||||
// There is no previous boundary inside this HyperText.
|
||||
*aStartOffset = *aEndOffset = 0;
|
||||
return;
|
||||
}
|
||||
TextLeafPoint start = end.FindBoundary(aBoundaryType, eDirPrevious);
|
||||
// If TransformOffset fails because start is outside this HyperText,
|
||||
// *aStartOffset will be 0, which is what we want.
|
||||
std::tie(ok, *aStartOffset) = TransformOffset(start.mAcc, start.mOffset,
|
||||
/* aIsEndOffset */ false);
|
||||
TextSubstring(*aStartOffset, *aEndOffset, aText);
|
||||
return;
|
||||
if (aBoundaryType == nsIAccessibleText::BOUNDARY_CHAR) {
|
||||
if (adjustedOffset > 0) {
|
||||
CharAt(static_cast<int32_t>(adjustedOffset) - 1, aText, aStartOffset,
|
||||
aEndOffset);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
TextLeafPoint orig;
|
||||
if (aOffset == nsIAccessibleText::TEXT_OFFSET_CARET) {
|
||||
orig = TextLeafPoint::GetCaret(Acc());
|
||||
} else {
|
||||
orig = ToTextLeafPoint(static_cast<int32_t>(adjustedOffset));
|
||||
}
|
||||
AdjustOriginIfEndBoundary(orig, aBoundaryType);
|
||||
TextLeafPoint end = orig.FindBoundary(aBoundaryType, eDirPrevious,
|
||||
/* aIncludeOrigin */ true);
|
||||
bool ok;
|
||||
std::tie(ok, *aEndOffset) = TransformOffset(end.mAcc, end.mOffset,
|
||||
/* aIsEndOffset */ true);
|
||||
if (!ok) {
|
||||
// There is no previous boundary inside this HyperText.
|
||||
*aStartOffset = *aEndOffset = 0;
|
||||
return;
|
||||
}
|
||||
TextLeafPoint start = end.FindBoundary(aBoundaryType, eDirPrevious);
|
||||
// If TransformOffset fails because start is outside this HyperText,
|
||||
// *aStartOffset will be 0, which is what we want.
|
||||
std::tie(ok, *aStartOffset) = TransformOffset(start.mAcc, start.mOffset,
|
||||
/* aIsEndOffset */ false);
|
||||
TextSubstring(*aStartOffset, *aEndOffset, aText);
|
||||
}
|
||||
|
||||
void HyperTextAccessibleBase::TextAtOffset(int32_t aOffset,
|
||||
|
@ -315,64 +315,63 @@ void HyperTextAccessibleBase::TextAtOffset(int32_t aOffset,
|
|||
*aStartOffset = *aEndOffset = 0;
|
||||
aText.Truncate();
|
||||
|
||||
if (aBoundaryType == nsIAccessibleText::BOUNDARY_SENTENCE_START ||
|
||||
aBoundaryType == nsIAccessibleText::BOUNDARY_SENTENCE_END) {
|
||||
return; // Not implemented.
|
||||
}
|
||||
|
||||
uint32_t adjustedOffset = ConvertMagicOffset(aOffset);
|
||||
if (adjustedOffset == std::numeric_limits<uint32_t>::max()) {
|
||||
NS_ERROR("Wrong given offset!");
|
||||
return;
|
||||
}
|
||||
|
||||
switch (aBoundaryType) {
|
||||
case nsIAccessibleText::BOUNDARY_CHAR:
|
||||
if (aOffset == nsIAccessibleText::TEXT_OFFSET_CARET) {
|
||||
TextLeafPoint caret = TextLeafPoint::GetCaret(Acc());
|
||||
if (caret.IsCaretAtEndOfLine()) {
|
||||
// The caret is at the end of the line. Return no character.
|
||||
*aStartOffset = *aEndOffset = static_cast<int32_t>(adjustedOffset);
|
||||
return;
|
||||
}
|
||||
if (aBoundaryType == nsIAccessibleText::BOUNDARY_CHAR) {
|
||||
if (aOffset == nsIAccessibleText::TEXT_OFFSET_CARET) {
|
||||
TextLeafPoint caret = TextLeafPoint::GetCaret(Acc());
|
||||
if (caret.IsCaretAtEndOfLine()) {
|
||||
// The caret is at the end of the line. Return no character.
|
||||
*aStartOffset = *aEndOffset = static_cast<int32_t>(adjustedOffset);
|
||||
return;
|
||||
}
|
||||
CharAt(adjustedOffset, aText, aStartOffset, aEndOffset);
|
||||
break;
|
||||
case nsIAccessibleText::BOUNDARY_WORD_START:
|
||||
case nsIAccessibleText::BOUNDARY_WORD_END:
|
||||
case nsIAccessibleText::BOUNDARY_LINE_START:
|
||||
case nsIAccessibleText::BOUNDARY_LINE_END:
|
||||
case nsIAccessibleText::BOUNDARY_PARAGRAPH:
|
||||
TextLeafPoint start, end;
|
||||
if (aOffset == nsIAccessibleText::TEXT_OFFSET_CARET) {
|
||||
start = TextLeafPoint::GetCaret(Acc());
|
||||
AdjustOriginIfEndBoundary(start, aBoundaryType, /* aAtOffset */ true);
|
||||
end = start;
|
||||
} else {
|
||||
start = ToTextLeafPoint(static_cast<int32_t>(adjustedOffset));
|
||||
Accessible* childAcc = GetChildAtOffset(adjustedOffset);
|
||||
if (childAcc && childAcc->IsHyperText()) {
|
||||
// We're searching for boundaries enclosing an embedded object.
|
||||
// An embedded object might contain several boundaries itself.
|
||||
// Thus, we must ensure we search for the end boundary from the last
|
||||
// text in the subtree, not just the first.
|
||||
// For example, if the embedded object is a link and it contains two
|
||||
// words, but the second word expands beyond the link, we want to
|
||||
// include the part of the second word which is outside of the link.
|
||||
end = ToTextLeafPoint(static_cast<int32_t>(adjustedOffset),
|
||||
/* aDescendToEnd */ true);
|
||||
} else {
|
||||
AdjustOriginIfEndBoundary(start, aBoundaryType,
|
||||
/* aAtOffset */ true);
|
||||
end = start;
|
||||
}
|
||||
}
|
||||
start = start.FindBoundary(aBoundaryType, eDirPrevious,
|
||||
/* aIncludeOrigin */ true);
|
||||
bool ok;
|
||||
std::tie(ok, *aStartOffset) = TransformOffset(start.mAcc, start.mOffset,
|
||||
/* aIsEndOffset */ false);
|
||||
end = end.FindBoundary(aBoundaryType, eDirNext);
|
||||
std::tie(ok, *aEndOffset) = TransformOffset(end.mAcc, end.mOffset,
|
||||
/* aIsEndOffset */ true);
|
||||
TextSubstring(*aStartOffset, *aEndOffset, aText);
|
||||
return;
|
||||
}
|
||||
CharAt(adjustedOffset, aText, aStartOffset, aEndOffset);
|
||||
return;
|
||||
}
|
||||
|
||||
TextLeafPoint start, end;
|
||||
if (aOffset == nsIAccessibleText::TEXT_OFFSET_CARET) {
|
||||
start = TextLeafPoint::GetCaret(Acc());
|
||||
AdjustOriginIfEndBoundary(start, aBoundaryType, /* aAtOffset */ true);
|
||||
end = start;
|
||||
} else {
|
||||
start = ToTextLeafPoint(static_cast<int32_t>(adjustedOffset));
|
||||
Accessible* childAcc = GetChildAtOffset(adjustedOffset);
|
||||
if (childAcc && childAcc->IsHyperText()) {
|
||||
// We're searching for boundaries enclosing an embedded object.
|
||||
// An embedded object might contain several boundaries itself.
|
||||
// Thus, we must ensure we search for the end boundary from the last
|
||||
// text in the subtree, not just the first.
|
||||
// For example, if the embedded object is a link and it contains two
|
||||
// words, but the second word expands beyond the link, we want to
|
||||
// include the part of the second word which is outside of the link.
|
||||
end = ToTextLeafPoint(static_cast<int32_t>(adjustedOffset),
|
||||
/* aDescendToEnd */ true);
|
||||
} else {
|
||||
AdjustOriginIfEndBoundary(start, aBoundaryType,
|
||||
/* aAtOffset */ true);
|
||||
end = start;
|
||||
}
|
||||
}
|
||||
start = start.FindBoundary(aBoundaryType, eDirPrevious,
|
||||
/* aIncludeOrigin */ true);
|
||||
bool ok;
|
||||
std::tie(ok, *aStartOffset) = TransformOffset(start.mAcc, start.mOffset,
|
||||
/* aIsEndOffset */ false);
|
||||
end = end.FindBoundary(aBoundaryType, eDirNext);
|
||||
std::tie(ok, *aEndOffset) = TransformOffset(end.mAcc, end.mOffset,
|
||||
/* aIsEndOffset */ true);
|
||||
TextSubstring(*aStartOffset, *aEndOffset, aText);
|
||||
}
|
||||
|
||||
void HyperTextAccessibleBase::TextAfterOffset(
|
||||
|
@ -382,57 +381,55 @@ void HyperTextAccessibleBase::TextAfterOffset(
|
|||
*aStartOffset = *aEndOffset = 0;
|
||||
aText.Truncate();
|
||||
|
||||
if (aBoundaryType == nsIAccessibleText::BOUNDARY_SENTENCE_START ||
|
||||
aBoundaryType == nsIAccessibleText::BOUNDARY_SENTENCE_END) {
|
||||
return; // Not implemented.
|
||||
}
|
||||
|
||||
uint32_t adjustedOffset = ConvertMagicOffset(aOffset);
|
||||
if (adjustedOffset == std::numeric_limits<uint32_t>::max()) {
|
||||
NS_ERROR("Wrong given offset!");
|
||||
return;
|
||||
}
|
||||
|
||||
switch (aBoundaryType) {
|
||||
case nsIAccessibleText::BOUNDARY_CHAR: {
|
||||
if (aOffset == nsIAccessibleText::TEXT_OFFSET_CARET &&
|
||||
adjustedOffset > 0 &&
|
||||
TextLeafPoint::GetCaret(Acc()).IsCaretAtEndOfLine()) {
|
||||
--adjustedOffset;
|
||||
}
|
||||
uint32_t count = CharacterCount();
|
||||
if (adjustedOffset >= count) {
|
||||
*aStartOffset = *aEndOffset = static_cast<int32_t>(count);
|
||||
} else {
|
||||
CharAt(static_cast<int32_t>(adjustedOffset) + 1, aText, aStartOffset,
|
||||
aEndOffset);
|
||||
}
|
||||
break;
|
||||
if (aBoundaryType == nsIAccessibleText::BOUNDARY_CHAR) {
|
||||
if (aOffset == nsIAccessibleText::TEXT_OFFSET_CARET && adjustedOffset > 0 &&
|
||||
TextLeafPoint::GetCaret(Acc()).IsCaretAtEndOfLine()) {
|
||||
--adjustedOffset;
|
||||
}
|
||||
case nsIAccessibleText::BOUNDARY_WORD_START:
|
||||
case nsIAccessibleText::BOUNDARY_WORD_END:
|
||||
case nsIAccessibleText::BOUNDARY_LINE_START:
|
||||
case nsIAccessibleText::BOUNDARY_LINE_END:
|
||||
TextLeafPoint orig;
|
||||
if (aOffset == nsIAccessibleText::TEXT_OFFSET_CARET) {
|
||||
orig = TextLeafPoint::GetCaret(Acc());
|
||||
} else {
|
||||
orig = ToTextLeafPoint(static_cast<int32_t>(adjustedOffset),
|
||||
/* aDescendToEnd */ true);
|
||||
}
|
||||
AdjustOriginIfEndBoundary(orig, aBoundaryType);
|
||||
TextLeafPoint start = orig.FindBoundary(aBoundaryType, eDirNext);
|
||||
bool ok;
|
||||
std::tie(ok, *aStartOffset) = TransformOffset(start.mAcc, start.mOffset,
|
||||
/* aIsEndOffset */ false);
|
||||
if (!ok) {
|
||||
// There is no next boundary inside this HyperText.
|
||||
*aStartOffset = *aEndOffset = static_cast<int32_t>(CharacterCount());
|
||||
return;
|
||||
}
|
||||
TextLeafPoint end = start.FindBoundary(aBoundaryType, eDirNext);
|
||||
// If TransformOffset fails because end is outside this HyperText,
|
||||
// *aEndOffset will be CharacterCount(), which is what we want.
|
||||
std::tie(ok, *aEndOffset) = TransformOffset(end.mAcc, end.mOffset,
|
||||
/* aIsEndOffset */ true);
|
||||
TextSubstring(*aStartOffset, *aEndOffset, aText);
|
||||
return;
|
||||
uint32_t count = CharacterCount();
|
||||
if (adjustedOffset >= count) {
|
||||
*aStartOffset = *aEndOffset = static_cast<int32_t>(count);
|
||||
} else {
|
||||
CharAt(static_cast<int32_t>(adjustedOffset) + 1, aText, aStartOffset,
|
||||
aEndOffset);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
TextLeafPoint orig;
|
||||
if (aOffset == nsIAccessibleText::TEXT_OFFSET_CARET) {
|
||||
orig = TextLeafPoint::GetCaret(Acc());
|
||||
} else {
|
||||
orig = ToTextLeafPoint(static_cast<int32_t>(adjustedOffset),
|
||||
/* aDescendToEnd */ true);
|
||||
}
|
||||
AdjustOriginIfEndBoundary(orig, aBoundaryType);
|
||||
TextLeafPoint start = orig.FindBoundary(aBoundaryType, eDirNext);
|
||||
bool ok;
|
||||
std::tie(ok, *aStartOffset) = TransformOffset(start.mAcc, start.mOffset,
|
||||
/* aIsEndOffset */ false);
|
||||
if (!ok) {
|
||||
// There is no next boundary inside this HyperText.
|
||||
*aStartOffset = *aEndOffset = static_cast<int32_t>(CharacterCount());
|
||||
return;
|
||||
}
|
||||
TextLeafPoint end = start.FindBoundary(aBoundaryType, eDirNext);
|
||||
// If TransformOffset fails because end is outside this HyperText,
|
||||
// *aEndOffset will be CharacterCount(), which is what we want.
|
||||
std::tie(ok, *aEndOffset) = TransformOffset(end.mAcc, end.mOffset,
|
||||
/* aIsEndOffset */ true);
|
||||
TextSubstring(*aStartOffset, *aEndOffset, aText);
|
||||
}
|
||||
|
||||
int32_t HyperTextAccessibleBase::CaretOffset() const {
|
||||
|
|
|
@ -920,11 +920,7 @@ void HyperTextAccessible::TextBeforeOffset(int32_t aOffset,
|
|||
int32_t* aStartOffset,
|
||||
int32_t* aEndOffset,
|
||||
nsAString& aText) {
|
||||
if (StaticPrefs::accessibility_cache_enabled_AtStartup() &&
|
||||
(aBoundaryType == nsIAccessibleText::BOUNDARY_WORD_START ||
|
||||
aBoundaryType == nsIAccessibleText::BOUNDARY_WORD_END ||
|
||||
aBoundaryType == nsIAccessibleText::BOUNDARY_LINE_START ||
|
||||
aBoundaryType == nsIAccessibleText::BOUNDARY_LINE_END)) {
|
||||
if (StaticPrefs::accessibility_cache_enabled_AtStartup()) {
|
||||
// This isn't strictly related to caching, but this new text implementation
|
||||
// is being developed to make caching feasible. We put it behind this pref
|
||||
// to make it easy to test while it's still under development.
|
||||
|
@ -1011,12 +1007,7 @@ void HyperTextAccessible::TextAtOffset(int32_t aOffset,
|
|||
AccessibleTextBoundary aBoundaryType,
|
||||
int32_t* aStartOffset,
|
||||
int32_t* aEndOffset, nsAString& aText) {
|
||||
if (StaticPrefs::accessibility_cache_enabled_AtStartup() &&
|
||||
(aBoundaryType == nsIAccessibleText::BOUNDARY_WORD_START ||
|
||||
aBoundaryType == nsIAccessibleText::BOUNDARY_WORD_END ||
|
||||
aBoundaryType == nsIAccessibleText::BOUNDARY_LINE_START ||
|
||||
aBoundaryType == nsIAccessibleText::BOUNDARY_LINE_END ||
|
||||
aBoundaryType == nsIAccessibleText::BOUNDARY_PARAGRAPH)) {
|
||||
if (StaticPrefs::accessibility_cache_enabled_AtStartup()) {
|
||||
// This isn't strictly related to caching, but this new text implementation
|
||||
// is being developed to make caching feasible. We put it behind this pref
|
||||
// to make it easy to test while it's still under development.
|
||||
|
@ -1111,11 +1102,7 @@ void HyperTextAccessible::TextAfterOffset(int32_t aOffset,
|
|||
int32_t* aStartOffset,
|
||||
int32_t* aEndOffset,
|
||||
nsAString& aText) {
|
||||
if (StaticPrefs::accessibility_cache_enabled_AtStartup() &&
|
||||
(aBoundaryType == nsIAccessibleText::BOUNDARY_WORD_START ||
|
||||
aBoundaryType == nsIAccessibleText::BOUNDARY_WORD_END ||
|
||||
aBoundaryType == nsIAccessibleText::BOUNDARY_LINE_START ||
|
||||
aBoundaryType == nsIAccessibleText::BOUNDARY_LINE_END)) {
|
||||
if (StaticPrefs::accessibility_cache_enabled_AtStartup()) {
|
||||
// This isn't strictly related to caching, but this new text implementation
|
||||
// is being developed to make caching feasible. We put it behind this pref
|
||||
// to make it easy to test while it's still under development.
|
||||
|
|
Загрузка…
Ссылка в новой задаче