Bug 1837332: Remove unused HyperTextAccessible::EnclosingRange/VisibleRanges/RangeByChild/RangeAtPoint, TextRange::EmbeddedChildren/Text and xpcAccessibleTextRange::ScrollIntoView. r=eeejay

Differential Revision: https://phabricator.services.mozilla.com/D180301
This commit is contained in:
James Teh
2023-06-14 00:43:11 +00:00
parent 284731180e
commit a385baf40d
10 changed files with 17 additions and 411 deletions

View File

@@ -108,80 +108,6 @@ TextRange::TextRange(Accessible* aRoot, Accessible* aStartContainer,
mStartOffset(aStartOffset),
mEndOffset(aEndOffset) {}
void TextRange::EmbeddedChildren(nsTArray<Accessible*>* aChildren) const {
HyperTextAccessibleBase* startHyper = mStartContainer->AsHyperTextBase();
if (mStartContainer == mEndContainer) {
int32_t startIdx = startHyper->GetChildIndexAtOffset(mStartOffset);
int32_t endIdx = startHyper->GetChildIndexAtOffset(mEndOffset);
for (int32_t idx = startIdx; idx <= endIdx; idx++) {
Accessible* child = mStartContainer->ChildAt(idx);
if (!child->IsText()) {
aChildren->AppendElement(child);
}
}
return;
}
Accessible* p1 = startHyper->GetChildAtOffset(mStartOffset);
HyperTextAccessibleBase* endHyper = mEndContainer->AsHyperTextBase();
Accessible* p2 = endHyper->GetChildAtOffset(mEndOffset);
uint32_t pos1 = 0, pos2 = 0;
AutoTArray<Accessible*, 30> parents1, parents2;
Accessible* container =
CommonParent(p1, p2, &parents1, &pos1, &parents2, &pos2);
// Traverse the tree up to the container and collect embedded objects.
for (uint32_t idx = 0; idx < pos1 - 1; idx++) {
Accessible* parent = parents1[idx + 1];
Accessible* child = parents1[idx];
uint32_t childCount = parent->ChildCount();
for (uint32_t childIdx = child->IndexInParent(); childIdx < childCount;
childIdx++) {
Accessible* next = parent->ChildAt(childIdx);
if (!next->IsText()) {
aChildren->AppendElement(next);
}
}
}
// Traverse through direct children in the container.
int32_t endIdx = parents2[pos2 - 1]->IndexInParent();
int32_t childIdx = parents1[pos1 - 1]->IndexInParent() + 1;
for (; childIdx < endIdx; childIdx++) {
Accessible* next = container->ChildAt(childIdx);
if (!next->IsText()) {
aChildren->AppendElement(next);
}
}
// Traverse down from the container to end point.
for (int32_t idx = pos2 - 2; idx > 0; idx--) {
Accessible* parent = parents2[idx];
Accessible* child = parents2[idx - 1];
int32_t endIdx = child->IndexInParent();
for (int32_t childIdx = 0; childIdx < endIdx; childIdx++) {
Accessible* next = parent->ChildAt(childIdx);
if (!next->IsText()) {
aChildren->AppendElement(next);
}
}
}
}
void TextRange::Text(nsAString& aText) const {
HyperTextAccessibleBase* startHyper = mStartContainer->AsHyperTextBase();
Accessible* current = startHyper->GetChildAtOffset(mStartOffset);
uint32_t startIntlOffset = mStartOffset - startHyper->GetChildOffset(current);
while (current && TextInternal(aText, current, startIntlOffset)) {
current = current->Parent();
if (!current) break;
current = current->NextSibling();
}
}
bool TextRange::Crop(Accessible* aContainer) {
uint32_t boundaryPos = 0, containerPos = 0;
AutoTArray<Accessible*, 30> boundaryParents, containerParents;
@@ -406,39 +332,6 @@ void TextRange::Set(Accessible* aRoot, Accessible* aStartContainer,
mEndOffset = aEndOffset;
}
bool TextRange::TextInternal(nsAString& aText, Accessible* aCurrent,
uint32_t aStartIntlOffset) const {
bool moveNext = true;
int32_t endIntlOffset = -1;
HyperTextAccessibleBase* endHyper = mEndContainer->AsHyperTextBase();
if (aCurrent->Parent() == mEndContainer &&
endHyper->GetChildAtOffset(mEndOffset) == aCurrent) {
uint32_t currentStartOffset = endHyper->GetChildOffset(aCurrent);
endIntlOffset = mEndOffset - currentStartOffset;
if (endIntlOffset == 0) return false;
moveNext = false;
}
if (aCurrent->IsTextLeaf()) {
aCurrent->AppendTextTo(aText, aStartIntlOffset,
endIntlOffset - aStartIntlOffset);
if (!moveNext) return false;
}
Accessible* next = aCurrent->FirstChild();
if (next) {
if (!TextInternal(aText, next, 0)) return false;
}
next = aCurrent->NextSibling();
if (next) {
if (!TextInternal(aText, next, 0)) return false;
}
return moveNext;
}
Accessible* TextRange::CommonParent(Accessible* aAcc1, Accessible* aAcc2,
nsTArray<Accessible*>* aParents1,
uint32_t* aPos1,

View File

@@ -94,17 +94,6 @@ class TextRange final {
*/
Accessible* Container() const;
/**
* Return a list of embedded objects enclosed by the text range (includes
* partially overlapped objects).
*/
void EmbeddedChildren(nsTArray<Accessible*>* aChildren) const;
/**
* Return text enclosed by the range.
*/
void Text(nsAString& aText) const;
/**
* Crops the range if it overlaps the given accessible element boundaries,
* returns true if the range was cropped successfully.
@@ -153,16 +142,6 @@ class TextRange final {
void Set(Accessible* aRoot, Accessible* aStartContainer, int32_t aStartOffset,
Accessible* aEndContainer, int32_t aEndOffset);
/**
* Text() method helper.
* @param aText [in,out] calculated text
* @param aCurrent [in] currently traversed node
* @param aStartIntlOffset [in] start offset if current node is a text node
* @return true if calculation is not finished yet
*/
bool TextInternal(nsAString& aText, Accessible* aCurrent,
uint32_t aStartIntlOffset) const;
/**
* A helper method returning a common parent for two given accessible
* elements.

View File

@@ -939,15 +939,6 @@ void HyperTextAccessible::ScrollSubstringToPoint(int32_t aStartOffset,
}
}
void HyperTextAccessible::EnclosingRange(a11y::TextRange& aRange) const {
if (IsTextField()) {
aRange.Set(mDoc, const_cast<HyperTextAccessible*>(this), 0,
const_cast<HyperTextAccessible*>(this), CharacterCount());
} else {
aRange.Set(mDoc, mDoc, 0, mDoc, mDoc->CharacterCount());
}
}
void HyperTextAccessible::SelectionRanges(
nsTArray<a11y::TextRange>* aRanges) const {
dom::Selection* sel = DOMSelection();
@@ -958,53 +949,6 @@ void HyperTextAccessible::SelectionRanges(
TextRange::TextRangesFromSelection(sel, aRanges);
}
void HyperTextAccessible::VisibleRanges(
nsTArray<a11y::TextRange>* aRanges) const {}
void HyperTextAccessible::RangeByChild(LocalAccessible* aChild,
a11y::TextRange& aRange) const {
HyperTextAccessible* ht = aChild->AsHyperText();
if (ht) {
aRange.Set(mDoc, ht, 0, ht, ht->CharacterCount());
return;
}
LocalAccessible* child = aChild;
LocalAccessible* parent = nullptr;
while ((parent = child->LocalParent()) && !(ht = parent->AsHyperText())) {
child = parent;
}
// If no text then return collapsed text range, otherwise return a range
// containing the text enclosed by the given child.
if (ht) {
int32_t childIdx = child->IndexInParent();
int32_t startOffset = ht->GetChildOffset(childIdx);
int32_t endOffset =
child->IsTextLeaf() ? ht->GetChildOffset(childIdx + 1) : startOffset;
aRange.Set(mDoc, ht, startOffset, ht, endOffset);
}
}
void HyperTextAccessible::RangeAtPoint(int32_t aX, int32_t aY,
a11y::TextRange& aRange) const {
LocalAccessible* child =
mDoc->LocalChildAtPoint(aX, aY, EWhichChildAtPoint::DeepestChild);
if (!child) return;
LocalAccessible* parent = nullptr;
while ((parent = child->LocalParent()) && !parent->IsHyperText()) {
child = parent;
}
// Return collapsed text range for the point.
if (parent) {
HyperTextAccessible* ht = parent->AsHyperText();
int32_t offset = ht->GetChildOffset(child);
aRange.Set(mDoc, ht, offset, ht, offset);
}
}
void HyperTextAccessible::ReplaceText(const nsAString& aText) {
if (aText.Length() == 0) {
DeleteText(0, CharacterCount());

View File

@@ -173,30 +173,8 @@ class HyperTextAccessible : public AccessibleWrap,
void ScrollSubstringToPoint(int32_t aStartOffset, int32_t aEndOffset,
uint32_t aCoordinateType, int32_t aX, int32_t aY);
/**
* Return a range that encloses the text control or the document this
* accessible belongs to.
*/
void EnclosingRange(TextRange& aRange) const;
virtual void SelectionRanges(nsTArray<TextRange>* aRanges) const override;
/**
* Return an array of disjoint ranges of visible text within the text control
* or the document this accessible belongs to.
*/
void VisibleRanges(nsTArray<TextRange>* aRanges) const;
/**
* Return a range containing the given accessible.
*/
void RangeByChild(LocalAccessible* aChild, TextRange& aRange) const;
/**
* Return a range containing an accessible at the given point.
*/
void RangeAtPoint(int32_t aX, int32_t aY, TextRange& aRange) const;
//////////////////////////////////////////////////////////////////////////////
// EditableTextAccessible

View File

@@ -194,33 +194,11 @@ interface nsIAccessibleText : nsISupports
in unsigned long coordinateType,
in long x, in long y);
/**
* Return a range that encloses this text control or otherwise the document
* this text accessible belongs to.
*/
readonly attribute nsIAccessibleTextRange enclosingRange;
/**
* Return an array of disjoint ranges for selected text within the text control
* or otherwise the document this accessible belongs to.
*/
readonly attribute nsIArray selectionRanges;
/**
* Return an array of disjoint ranges of visible text within the text control
* or otherwise the document this accessible belongs to.
*/
readonly attribute nsIArray visibleRanges;
/**
* Return a range containing the given accessible.
*/
nsIAccessibleTextRange getRangeByChild(in nsIAccessible child);
/**
* Return a range containing an accessible at the given point.
*/
nsIAccessibleTextRange getRangeAtPoint(in long x, in long y);
};
/*

View File

@@ -26,11 +26,6 @@ interface nsIAccessibleTextRange : nsISupports
*/
readonly attribute nsIAccessible container;
/**
* Return embedded children within the range.
*/
readonly attribute nsIArray embeddedChildren;
/**
* Return true if this range has the same end points of the given range.
*/
@@ -52,11 +47,6 @@ interface nsIAccessibleTextRange : nsISupports
in nsIAccessibleTextRange aOtherRange,
in unsigned long aOtherRangeEndPoint);
/**
* Return text within the range.
*/
readonly attribute AString text;
/**
* Crops the range by the given accessible element.
*/
@@ -64,9 +54,4 @@ interface nsIAccessibleTextRange : nsISupports
const unsigned long AlignToTop = 0;
const unsigned long AlignToBottom = 1;
/**
* Scroll the range into view.
*/
void scrollIntoView(in unsigned long aHow);
};

View File

@@ -15,59 +15,25 @@
<script type="application/javascript">
function doTest() {
// enclosingRange
var input = getAccessible("input", [ nsIAccessibleText ]);
testTextRange(input.enclosingRange, "enclosing range for 'input'",
input, 0, input, 5, "hello", input);
var ta = getAccessible("textarea", [ nsIAccessibleText ]);
testTextRange(ta.enclosingRange, "enclosing range for 'textarea'",
ta, 0, ta, 5, "hello", ta);
var iframeDocNode = getNode("iframe").contentDocument;
var iframeDoc = getAccessible(iframeDocNode, [ nsIAccessibleText ]);
testTextRange(iframeDoc.enclosingRange, "enclosing range for iframe doc",
iframeDoc, 0, iframeDoc, 1, "hello",
iframeDoc, [ getNode("p", iframeDocNode) ]);
// getRangeByChild
var docacc = getAccessible(document, [ nsIAccessibleText ]);
var p1 = getAccessible("p1");
var p1Range = docacc.getRangeByChild(p1);
testTextRange(p1Range, "range by 'p1' child",
p1, 0, "p1", 11, "text text",
p1, ["p1_img"]);
testTextRange(docacc.getRangeByChild(getAccessible("p1_img")),
"range by 'p1_img' child",
"p1", 5, "p1", 5, "",
"p1", ["p1_img"]);
var p2 = getAccessible("p2");
var p2Range = docacc.getRangeByChild(p2);
testTextRange(p2Range, "range by 'p2' child",
p2, 0, "p2", 11, "text link text",
p2, ["p2_a"]);
testTextRange(docacc.getRangeByChild(getAccessible("p2_a")),
"range by 'p2_a' child",
"p2_a", 0, "p2_a", 5, "link",
"p2_a", ["p2_img"]);
// getRangeAtPoint
getNode("p2_a").scrollIntoView(true);
var [x, y] = getPos("p2_a");
testTextRange(docacc.getRangeAtPoint(x + 1, y + 1),
"range at 'p2_a' top-left edge",
"p2_a", 0, "p2_a", 0, "",
"p2_a");
const sel = window.getSelection();
const r1 = document.createRange();
r1.selectNode(getNode("p1"));
sel.addRange(r1);
const r2 = document.createRange();
r2.selectNode(getNode("p2"));
sel.addRange(r2);
const docAcc = getAccessible(document, [nsIAccessibleText]);
const accRanges = docAcc.selectionRanges;
const p1Range = accRanges.queryElementAt(0, nsIAccessibleTextRange);
const p1RangeCopy = docAcc.selectionRanges.queryElementAt(0, nsIAccessibleTextRange);
const p2Range = accRanges.queryElementAt(1, nsIAccessibleTextRange);
// TextRange::compare
ok(input.enclosingRange.compare(input.enclosingRange),
"input enclosing ranges should be equal");
ok(p1Range.compare(p1RangeCopy),
"p1 ranges should be equal");
ok(!input.enclosingRange.compare(ta.enclosingRange),
"input and textarea enclosing ranges can't be equal");
ok(!p1Range.compare(p2Range),
"p1 and p2 ranges can't be equal");
// TextRange::compareEndPoints
var res = p1Range.compareEndPoints(EndPoint_End, p2Range, EndPoint_Start);
@@ -96,10 +62,8 @@
<pre id="test">
</pre>
<input id="input" value="hello">
<textarea id="textarea">hello</textarea>
<iframe id="iframe" src="data:text/html,<html><body><p id='p'>hello</p></body></html>"></iframe>
<p id="p1">text <img id="p1_img", src="../moz.png"> text</p>
<p>between</p>
<p id="p2">text <a id="p2_a" href="www">link<img id="p2_img", src="../moz.png"></a> text</p>
</body>

View File

@@ -358,23 +358,6 @@ xpcAccessibleHyperText::ScrollSubstringToPoint(int32_t aStartOffset,
return NS_OK;
}
NS_IMETHODIMP
xpcAccessibleHyperText::GetEnclosingRange(nsIAccessibleTextRange** aRange) {
NS_ENSURE_ARG_POINTER(aRange);
*aRange = nullptr;
if (!IntlLocal()) return NS_ERROR_FAILURE;
TextRange range;
IntlLocal()->EnclosingRange(range);
NS_ASSERTION(range.IsValid(), "Should always have an enclosing range!");
RefPtr<xpcAccessibleTextRange> xpcRange = new xpcAccessibleTextRange(range);
xpcRange.forget(aRange);
return NS_OK;
}
NS_IMETHODIMP
xpcAccessibleHyperText::GetSelectionRanges(nsIArray** aRanges) {
NS_ENSURE_ARG_POINTER(aRanges);
@@ -396,69 +379,6 @@ xpcAccessibleHyperText::GetSelectionRanges(nsIArray** aRanges) {
return NS_OK;
}
NS_IMETHODIMP
xpcAccessibleHyperText::GetVisibleRanges(nsIArray** aRanges) {
NS_ENSURE_ARG_POINTER(aRanges);
*aRanges = nullptr;
if (!IntlLocal()) return NS_ERROR_FAILURE;
nsresult rv = NS_OK;
nsCOMPtr<nsIMutableArray> xpcRanges =
do_CreateInstance(NS_ARRAY_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsTArray<TextRange> ranges;
IntlLocal()->VisibleRanges(&ranges);
uint32_t len = ranges.Length();
for (uint32_t idx = 0; idx < len; idx++) {
xpcRanges->AppendElement(new xpcAccessibleTextRange(ranges[idx]));
}
xpcRanges.forget(aRanges);
return NS_OK;
}
NS_IMETHODIMP
xpcAccessibleHyperText::GetRangeByChild(nsIAccessible* aChild,
nsIAccessibleTextRange** aRange) {
NS_ENSURE_ARG_POINTER(aRange);
*aRange = nullptr;
if (!IntlLocal()) return NS_ERROR_FAILURE;
LocalAccessible* child = aChild->ToInternalAccessible();
if (child) {
TextRange range;
IntlLocal()->RangeByChild(child, range);
if (range.IsValid()) {
RefPtr<xpcAccessibleTextRange> xpcRange =
new xpcAccessibleTextRange(range);
xpcRange.forget(aRange);
}
}
return NS_OK;
}
NS_IMETHODIMP
xpcAccessibleHyperText::GetRangeAtPoint(int32_t aX, int32_t aY,
nsIAccessibleTextRange** aRange) {
NS_ENSURE_ARG_POINTER(aRange);
*aRange = nullptr;
if (!IntlLocal()) return NS_ERROR_FAILURE;
TextRange range;
IntlLocal()->RangeAtPoint(aX, aY, range);
if (range.IsValid()) {
RefPtr<xpcAccessibleTextRange> xpcRange = new xpcAccessibleTextRange(range);
xpcRange.forget(aRange);
}
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////
// nsIAccessibleEditableText

View File

@@ -78,26 +78,6 @@ xpcAccessibleTextRange::GetContainer(nsIAccessible** aContainer) {
return NS_OK;
}
NS_IMETHODIMP
xpcAccessibleTextRange::GetEmbeddedChildren(nsIArray** aList) {
nsresult rv = NS_OK;
nsCOMPtr<nsIMutableArray> xpcList =
do_CreateInstance(NS_ARRAY_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsTArray<Accessible*> objects;
Range().EmbeddedChildren(&objects);
uint32_t len = objects.Length();
for (uint32_t idx = 0; idx < len; idx++) {
xpcList->AppendElement(static_cast<nsIAccessible*>(ToXPC(objects[idx])));
}
xpcList.forget(aList);
return NS_OK;
}
NS_IMETHODIMP
xpcAccessibleTextRange::Compare(nsIAccessibleTextRange* aOtherRange,
bool* aResult) {
@@ -133,15 +113,6 @@ xpcAccessibleTextRange::CompareEndPoints(uint32_t aEndPoint,
return NS_OK;
}
NS_IMETHODIMP
xpcAccessibleTextRange::GetText(nsAString& aText) {
nsAutoString text;
Range().Text(text);
aText.Assign(text);
return NS_OK;
}
NS_IMETHODIMP
xpcAccessibleTextRange::Crop(nsIAccessible* aContainer, bool* aSuccess) {
Accessible* container = aContainer->ToInternalGeneric();
@@ -154,6 +125,3 @@ xpcAccessibleTextRange::Crop(nsIAccessible* aContainer, bool* aSuccess) {
}
return NS_OK;
}
NS_IMETHODIMP
xpcAccessibleTextRange::ScrollIntoView(uint32_t aHow) { return NS_OK; }

View File

@@ -36,15 +36,12 @@ class xpcAccessibleTextRange final : public nsIAccessibleTextRange {
NS_IMETHOD GetEndContainer(nsIAccessibleText** aAnchor) final;
NS_IMETHOD GetEndOffset(int32_t* aOffset) final;
NS_IMETHOD GetContainer(nsIAccessible** aContainer) final;
NS_IMETHOD GetEmbeddedChildren(nsIArray** aList) final;
NS_IMETHOD Compare(nsIAccessibleTextRange* aOtherRange, bool* aResult) final;
NS_IMETHOD CompareEndPoints(uint32_t aEndPoint,
nsIAccessibleTextRange* aOtherRange,
uint32_t aOtherRangeEndPoint,
int32_t* aResult) final;
NS_IMETHOD GetText(nsAString& aText) final;
NS_IMETHOD Crop(nsIAccessible* aContainer, bool* aSuccess) final;
NS_IMETHOD ScrollIntoView(uint32_t aHow) final;
NS_DECLARE_STATIC_IID_ACCESSOR(NS_ACCESSIBLETEXTRANGE_IMPL_IID)