зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1730088 part 6: Move TextSubstring to HyperTextAccessibleBase. r=eeejay
Differential Revision: https://phabricator.services.mozilla.com/D127211
This commit is contained in:
Родитель
3c9b8a17dd
Коммит
2dbf269a3f
|
@ -81,4 +81,63 @@ index_t HyperTextAccessibleBase::ConvertMagicOffset(int32_t aOffset) const {
|
|||
return aOffset;
|
||||
}
|
||||
|
||||
void HyperTextAccessibleBase::TextSubstring(int32_t aStartOffset,
|
||||
int32_t aEndOffset,
|
||||
nsAString& aText) const {
|
||||
aText.Truncate();
|
||||
|
||||
index_t startOffset = ConvertMagicOffset(aStartOffset);
|
||||
index_t endOffset = ConvertMagicOffset(aEndOffset);
|
||||
if (!startOffset.IsValid() || !endOffset.IsValid() ||
|
||||
startOffset > endOffset || endOffset > CharacterCount()) {
|
||||
NS_ERROR("Wrong in offset");
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t startChildIdx = GetChildIndexAtOffset(startOffset);
|
||||
if (startChildIdx == -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t endChildIdx = GetChildIndexAtOffset(endOffset);
|
||||
if (endChildIdx == -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
const Accessible* thisAcc = Acc();
|
||||
if (startChildIdx == endChildIdx) {
|
||||
int32_t childOffset = GetChildOffset(startChildIdx);
|
||||
if (childOffset == -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
Accessible* child = thisAcc->ChildAt(startChildIdx);
|
||||
child->AppendTextTo(aText, startOffset - childOffset,
|
||||
endOffset - startOffset);
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t startChildOffset = GetChildOffset(startChildIdx);
|
||||
if (startChildOffset == -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
Accessible* startChild = thisAcc->ChildAt(startChildIdx);
|
||||
startChild->AppendTextTo(aText, startOffset - startChildOffset);
|
||||
|
||||
for (int32_t childIdx = startChildIdx + 1; childIdx < endChildIdx;
|
||||
childIdx++) {
|
||||
Accessible* child = thisAcc->ChildAt(childIdx);
|
||||
child->AppendTextTo(aText);
|
||||
}
|
||||
|
||||
int32_t endChildOffset = GetChildOffset(endChildIdx);
|
||||
if (endChildOffset == -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
Accessible* endChild = thisAcc->ChildAt(endChildIdx);
|
||||
endChild->AppendTextTo(aText, 0, endOffset - endChildOffset);
|
||||
}
|
||||
|
||||
} // namespace mozilla::a11y
|
||||
|
|
|
@ -81,6 +81,12 @@ class HyperTextAccessibleBase {
|
|||
*/
|
||||
index_t ConvertMagicOffset(int32_t aOffset) const;
|
||||
|
||||
/**
|
||||
* Return text between given offsets.
|
||||
*/
|
||||
virtual void TextSubstring(int32_t aStartOffset, int32_t aEndOffset,
|
||||
nsAString& aText) const;
|
||||
|
||||
protected:
|
||||
virtual const Accessible* Acc() const = 0;
|
||||
Accessible* Acc() {
|
||||
|
|
|
@ -271,53 +271,6 @@ nsIntRect HyperTextAccessible::GetBoundsInFrame(nsIFrame* aFrame,
|
|||
return screenRect.ToNearestPixels(presContext->AppUnitsPerDevPixel());
|
||||
}
|
||||
|
||||
void HyperTextAccessible::TextSubstring(int32_t aStartOffset,
|
||||
int32_t aEndOffset, nsAString& aText) {
|
||||
aText.Truncate();
|
||||
|
||||
index_t startOffset = ConvertMagicOffset(aStartOffset);
|
||||
index_t endOffset = ConvertMagicOffset(aEndOffset);
|
||||
if (!startOffset.IsValid() || !endOffset.IsValid() ||
|
||||
startOffset > endOffset || endOffset > CharacterCount()) {
|
||||
NS_ERROR("Wrong in offset");
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t startChildIdx = GetChildIndexAtOffset(startOffset);
|
||||
if (startChildIdx == -1) return;
|
||||
|
||||
int32_t endChildIdx = GetChildIndexAtOffset(endOffset);
|
||||
if (endChildIdx == -1) return;
|
||||
|
||||
if (startChildIdx == endChildIdx) {
|
||||
int32_t childOffset = GetChildOffset(startChildIdx);
|
||||
if (childOffset == -1) return;
|
||||
|
||||
LocalAccessible* child = LocalChildAt(startChildIdx);
|
||||
child->AppendTextTo(aText, startOffset - childOffset,
|
||||
endOffset - startOffset);
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t startChildOffset = GetChildOffset(startChildIdx);
|
||||
if (startChildOffset == -1) return;
|
||||
|
||||
LocalAccessible* startChild = LocalChildAt(startChildIdx);
|
||||
startChild->AppendTextTo(aText, startOffset - startChildOffset);
|
||||
|
||||
for (int32_t childIdx = startChildIdx + 1; childIdx < endChildIdx;
|
||||
childIdx++) {
|
||||
LocalAccessible* child = LocalChildAt(childIdx);
|
||||
child->AppendTextTo(aText);
|
||||
}
|
||||
|
||||
int32_t endChildOffset = GetChildOffset(endChildIdx);
|
||||
if (endChildOffset == -1) return;
|
||||
|
||||
LocalAccessible* endChild = LocalChildAt(endChildIdx);
|
||||
endChild->AppendTextTo(aText, 0, endOffset - endChildOffset);
|
||||
}
|
||||
|
||||
uint32_t HyperTextAccessible::DOMPointToOffset(nsINode* aNode,
|
||||
int32_t aNodeOffset,
|
||||
bool aIsEndOffset) const {
|
||||
|
|
|
@ -183,12 +183,6 @@ class HyperTextAccessible : public AccessibleWrap,
|
|||
*/
|
||||
bool IsLineEndCharAt(int32_t aOffset) { return IsCharAt(aOffset, '\n'); }
|
||||
|
||||
/**
|
||||
* Return text between given offsets.
|
||||
*/
|
||||
void TextSubstring(int32_t aStartOffset, int32_t aEndOffset,
|
||||
nsAString& aText);
|
||||
|
||||
/**
|
||||
* Return text before/at/after the given offset corresponding to
|
||||
* the boundary type.
|
||||
|
|
|
@ -78,11 +78,8 @@ void SetCaretOffset(int32_t aOffset);
|
|||
int32_t CharacterCount();
|
||||
int32_t SelectionCount();
|
||||
|
||||
/**
|
||||
* Get the text between the given offsets.
|
||||
*/
|
||||
bool TextSubstring(int32_t aStartOffset, int32_t aEndOfset,
|
||||
nsString& aText) const;
|
||||
virtual void TextSubstring(int32_t aStartOffset, int32_t aEndOfset,
|
||||
nsAString& aText) const override;
|
||||
|
||||
void GetTextAfterOffset(int32_t aOffset, AccessibleTextBoundary aBoundaryType,
|
||||
nsString& aText, int32_t* aStartOffset,
|
||||
|
|
|
@ -176,12 +176,13 @@ int32_t RemoteAccessible::SelectionCount() {
|
|||
return count;
|
||||
}
|
||||
|
||||
bool RemoteAccessible::TextSubstring(int32_t aStartOffset, int32_t aEndOfset,
|
||||
nsString& aText) const {
|
||||
void RemoteAccessible::TextSubstring(int32_t aStartOffset, int32_t aEndOfset,
|
||||
nsAString& aText) const {
|
||||
bool valid;
|
||||
Unused << mDoc->SendTextSubstring(mID, aStartOffset, aEndOfset, &aText,
|
||||
nsString text;
|
||||
Unused << mDoc->SendTextSubstring(mID, aStartOffset, aEndOfset, &text,
|
||||
&valid);
|
||||
return valid;
|
||||
aText = std::move(text);
|
||||
}
|
||||
|
||||
void RemoteAccessible::GetTextAfterOffset(int32_t aOffset,
|
||||
|
|
|
@ -526,24 +526,27 @@ int32_t RemoteAccessible::OffsetAtPoint(int32_t aX, int32_t aY,
|
|||
return static_cast<int32_t>(offset);
|
||||
}
|
||||
|
||||
bool RemoteAccessible::TextSubstring(int32_t aStartOffset, int32_t aEndOffset,
|
||||
nsString& aText) const {
|
||||
void RemoteAccessible::TextSubstring(int32_t aStartOffset, int32_t aEndOffset,
|
||||
nsAString& aText) const {
|
||||
if (StaticPrefs::accessibility_cache_enabled_AtStartup()) {
|
||||
return RemoteAccessibleBase<RemoteAccessible>::TextSubstring(
|
||||
aStartOffset, aEndOffset, aText);
|
||||
}
|
||||
|
||||
RefPtr<IAccessibleText> acc = QueryInterface<IAccessibleText>(this);
|
||||
if (!acc) {
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
BSTR result;
|
||||
HRESULT hr = acc->get_text(static_cast<long>(aStartOffset),
|
||||
static_cast<long>(aEndOffset), &result);
|
||||
if (FAILED(hr)) {
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
_bstr_t resultWrap(result, false);
|
||||
aText = (wchar_t*)result;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void RemoteAccessible::GetTextBeforeOffset(int32_t aOffset,
|
||||
|
|
Загрузка…
Ссылка в новой задаче