зеркало из https://github.com/mozilla/gecko-dev.git
Bug 824901 - HyperTextAccessible::DOMPointToHypertextOffset fails for node and offset equal to node child count, r=tbsaunde
This commit is contained in:
Родитель
cbdc494f2c
Коммит
f798dfcd2a
|
@ -529,22 +529,32 @@ HyperTextAccessible::DOMPointToHypertextOffset(nsINode* aNode,
|
|||
} else {
|
||||
// findNode could be null if aNodeOffset == # of child nodes, which means
|
||||
// one of two things:
|
||||
// 1) we're at the end of the children, keep findNode = null, so that we get
|
||||
// the last possible offset
|
||||
// 2) there are no children and the passed-in node is mContent, which means
|
||||
// we're an aempty nsIAccessibleText
|
||||
// 3) there are no children, and the passed-in node is not mContent -- use
|
||||
// 1) there are no children, and the passed-in node is not mContent -- use
|
||||
// parentContent for the node to find
|
||||
// 2) there are no children and the passed-in node is mContent, which means
|
||||
// we're an empty nsIAccessibleText
|
||||
// 3) there are children and we're at the end of the children
|
||||
|
||||
findNode = aNode->GetChildAt(aNodeOffset);
|
||||
if (!findNode && !aNodeOffset) {
|
||||
if (!findNode) {
|
||||
if (aNodeOffset == 0) {
|
||||
if (aNode == GetNode()) {
|
||||
// There are no children, which means this is an empty nsIAccessibleText, in which
|
||||
// case we can only be at hypertext offset 0
|
||||
// Case #1: this accessible has no children and thus has empty text,
|
||||
// we can only be at hypertext offset 0.
|
||||
*aHyperTextOffset = 0;
|
||||
return nullptr;
|
||||
}
|
||||
findNode = aNode; // Case #2: there are no children
|
||||
|
||||
// Case #2: there are no children, we're at this node.
|
||||
findNode = aNode;
|
||||
} else if (aNodeOffset == aNode->GetChildCount()) {
|
||||
// Case #3: we're after the last child, get next node to this one.
|
||||
for (nsINode* tmpNode = aNode;
|
||||
!findNode && tmpNode && tmpNode != mContent;
|
||||
tmpNode = tmpNode->GetParent()) {
|
||||
findNode = tmpNode->GetNextSibling();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1266,6 +1266,38 @@ function synthSelectAll(aNodeOrID, aCheckerOrEventSeq)
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the caret in text accessible.
|
||||
*/
|
||||
function moveCaretToDOMPoint(aID, aNode, aOffset, aExpectedOffset,
|
||||
aFocusTargetID)
|
||||
{
|
||||
this.target = getAccessible(aID, [nsIAccessibleText]);
|
||||
this.focus = aFocusTargetID ? getAccessible(aFocusTargetID) : null;
|
||||
this.focusNode = this.focus ? this.focus.DOMNode : null;
|
||||
|
||||
this.invoke = function moveCaretToDOMPoint_invoke()
|
||||
{
|
||||
if (this.focusNode)
|
||||
this.focusNode.focus();
|
||||
|
||||
window.getSelection().getRangeAt(0).setStart(aNode, aOffset);
|
||||
}
|
||||
|
||||
this.getID = function moveCaretToDOMPoint_getID()
|
||||
{
|
||||
return "Set caret on " + prettyName(aID) + " at point: " +
|
||||
prettyName(aNode) + " node with offset " + aOffset;
|
||||
}
|
||||
|
||||
this.eventSeq = [
|
||||
new caretMoveChecker(aExpectedOffset, this.target)
|
||||
];
|
||||
|
||||
if (this.focus)
|
||||
this.eventSeq.push(new asyncInvokerChecker(EVENT_FOCUS, this.focus));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set caret offset in text accessible.
|
||||
*/
|
||||
|
|
|
@ -77,6 +77,18 @@
|
|||
id = "p";
|
||||
gQueue.push(new synthTab(id, new caretMoveChecker(0, id)));
|
||||
|
||||
// Set caret after a child of span element, i.e. after 'text' text.
|
||||
gQueue.push(new moveCaretToDOMPoint("test1", getNode("test1_span"), 1,
|
||||
4, "test1"));
|
||||
gQueue.push(new moveCaretToDOMPoint("test2", getNode("test2_span"), 1,
|
||||
4, "test2"));
|
||||
|
||||
// empty text element
|
||||
gQueue.push(new moveCaretToDOMPoint("test3", getNode("test3"), 0,
|
||||
0, "test3"));
|
||||
gQueue.push(new moveCaretToDOMPoint("test4", getNode("test4_span"), 0,
|
||||
0, "test4"));
|
||||
|
||||
gQueue.invoke(); // Will call SimpleTest.finish();
|
||||
}
|
||||
|
||||
|
@ -90,7 +102,12 @@
|
|||
<a target="_blank"
|
||||
href="https://bugzilla.mozilla.org/show_bug.cgi?id=454377"
|
||||
title="Accessible caret move events testing">
|
||||
Mozilla Bug 454377
|
||||
Bug 454377
|
||||
</a>
|
||||
<a target="_blank"
|
||||
href="https://bugzilla.mozilla.org/show_bug.cgi?id=824901"
|
||||
title="HyperTextAccessible::DOMPointToHypertextOffset fails for node and offset equal to node child count">
|
||||
Bug 824901
|
||||
</a>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none"></div>
|
||||
|
@ -102,6 +119,11 @@
|
|||
<p id="p" contentEditable="true"><span>text</span><br/>text</p>
|
||||
<div id="div" contentEditable="true"><p id="p1_in_div">text</p><p id="p2_in_div">text</p></div>
|
||||
|
||||
<p contentEditable="true" id="test1"><span id="test1_span">text</span>ohoho</p>
|
||||
<p contentEditable="true" id="test2"><span><span id="test2_span">text</span></span>ohoho</p>
|
||||
<p contentEditable="true" id="test3"></p>
|
||||
<p contentEditable="true" id="test4"><span id="test4_span"></span></p>
|
||||
|
||||
<div id="eventdump"></div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
Загрузка…
Ссылка в новой задаче