Bug 320388 AT-SPI getLinkIndex doesn't work

r=aaronleventhal sr=roc a=aaronleventhal


git-svn-id: svn://10.0.0.236/branches/MOZILLA_1_8_BRANCH@193319 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
ginn.chen%sun.com
2006-03-31 10:14:01 +00:00
parent f08fd5a3dd
commit c2d0996f31
3 changed files with 49 additions and 46 deletions

View File

@@ -194,6 +194,9 @@ NS_IMETHODIMP nsAccessibleHyperText::GetCaretOffset(PRInt32 *aCaretOffset)
if (NS_SUCCEEDED(accText.GetCaretOffset(&caretOffset))) {
*aCaretOffset += caretOffset;
return NS_OK;
} else if (GetLinkNode(domNode) == nsAccessNode::gLastFocusedNode) {
//Focus is here
return NS_OK;
}
if (NS_SUCCEEDED(accText.GetCharacterCount(&charCount))) {
*aCaretOffset += charCount;
@@ -392,28 +395,11 @@ NS_IMETHODIMP nsAccessibleHyperText::RemoveSelection(PRInt32 aSelectionNum)
*aLinks = 0;
PRUint32 index, count;
PRInt32 caretOffset;
mTextChildren->GetLength(&count);
for (index = 0; index < count; index++) {
nsCOMPtr<nsIDOMNode> domNode(do_QueryElementAt(mTextChildren, index));
nsCOMPtr<nsIDOMNode> parentNode;
nsCOMPtr<nsILink> link = nsnull;
domNode->GetParentNode(getter_AddRefs(parentNode));
while (parentNode) {
link = do_QueryInterface(parentNode);
if (link)
break;
nsCOMPtr<nsIDOMNode> temp = parentNode;
temp->GetParentNode(getter_AddRefs(parentNode));
}
if (link)
if (GetLinkNode(domNode)) {
(*aLinks)++;
else {
nsAccessibleText accText(domNode);
if (NS_SUCCEEDED(accText.GetCaretOffset(&caretOffset))) {
*aLinks = 0;
return NS_OK;
}
}
}
@@ -427,20 +413,8 @@ NS_IMETHODIMP nsAccessibleHyperText::GetLink(PRInt32 aIndex, nsIAccessibleHyperL
mTextChildren->GetLength(&count);
for (index = 0; index < count; index++) {
nsCOMPtr<nsIDOMNode> domNode(do_QueryElementAt(mTextChildren, index));
nsCOMPtr<nsIDOMNode> parentNode;
// text node maybe a child (or grandchild, ...) of a link node
nsCOMPtr<nsILink> link;
domNode->GetParentNode(getter_AddRefs(parentNode));
while (parentNode) {
link = do_QueryInterface(parentNode);
if (link)
break;
nsCOMPtr<nsIDOMNode> temp = parentNode;
temp->GetParentNode(getter_AddRefs(parentNode));
}
if (link) {
nsIDOMNode* parentNode = GetLinkNode(domNode);
if (parentNode) {
if (linkCount++ == NS_STATIC_CAST(PRUint32, aIndex)) {
nsCOMPtr<nsIWeakReference> weakShell;
nsAccessibilityService::GetShellFromNode(parentNode, getter_AddRefs(weakShell));
@@ -482,7 +456,21 @@ NS_IMETHODIMP nsAccessibleHyperText::GetLink(PRInt32 aIndex, nsIAccessibleHyperL
/* long getLinkIndex (in long charIndex); */
NS_IMETHODIMP nsAccessibleHyperText::GetLinkIndex(PRInt32 aCharIndex, PRInt32 *aLinkIndex)
{
return NS_ERROR_NOT_IMPLEMENTED;
*aLinkIndex = -1;
PRInt32 beforeLength_unused;
PRUint32 nodeIndex;
nsIDOMNode* domNode = FindTextNodeByOffset(aCharIndex, beforeLength_unused);
if (GetLinkNode(domNode)
&& NS_SUCCEEDED(mTextChildren->IndexOf(0, domNode, &nodeIndex))) {
(*aLinkIndex)++;
for (PRUint32 index = 0; index < nodeIndex; index++) {
nsCOMPtr<nsIDOMNode> childNode(do_QueryElementAt(mTextChildren, index));
if (GetLinkNode(childNode)) {
(*aLinkIndex)++;
}
}
}
return NS_OK;
}
/* long getSelectedLinkIndex (); */
@@ -500,17 +488,9 @@ NS_IMETHODIMP nsAccessibleHyperText::GetSelectedLinkIndex(PRInt32 *aSelectedLink
PRUint32 index, linkCount = 0;
for (index = 0; index < count; index++) {
nsCOMPtr<nsIDOMNode> domNode(do_QueryElementAt(mTextChildren, index));
nsCOMPtr<nsIDOMNode> parentNode;
nsCOMPtr<nsILink> link;
do {
// text node maybe a child of a link node
domNode->GetParentNode(getter_AddRefs(parentNode));
domNode = parentNode;
link = do_QueryInterface(parentNode);
} while (domNode && link == nsnull);
if (link) {
if (parentNode == nsAccessNode::gLastFocusedNode) {
nsIDOMNode* linkNode = GetLinkNode(domNode);
if (linkNode) {
if (linkNode == nsAccessNode::gLastFocusedNode) {
*aSelectedLinkIndex = linkCount;
return NS_OK;
}
@@ -547,3 +527,18 @@ nsresult nsAccessibleHyperText::GetBounds(nsIWeakReference *aWeakShell, PRInt32
return NS_OK;
}
nsIDOMNode* nsAccessibleHyperText::GetLinkNode(nsIDOMNode* aNode)
{
nsCOMPtr<nsIDOMNode> parentNode;
nsCOMPtr<nsILink> link;
while (aNode && link == nsnull) {
// text node maybe a child (or grandchild, ...) of a link node
aNode->GetParentNode(getter_AddRefs(parentNode));
aNode = parentNode;
link = do_QueryInterface(parentNode);
}
return parentNode;
}

View File

@@ -67,8 +67,11 @@ protected:
PRBool GetAllTextChildren(nsPresContext *aPresContext, nsIFrame *aCurFrame, nsIDOMNode* aNode, PRBool &bSave);
nsIDOMNode* FindTextNodeByOffset(PRInt32 aOffset, PRInt32& aBeforeLength);
nsresult GetTextHelper(EGetTextType aType, nsAccessibleTextBoundary aBoundaryType,
PRInt32 aOffset, PRInt32 *aStartOffset, PRInt32 *aEndOffset, nsAString & aText);
nsresult GetTextHelper(EGetTextType aType,
nsAccessibleTextBoundary aBoundaryType,
PRInt32 aOffset, PRInt32 *aStartOffset,
PRInt32 *aEndOffset, nsAString & aText);
nsIDOMNode* GetLinkNode(nsIDOMNode* aNode);
};
#endif

View File

@@ -814,6 +814,11 @@ NS_IMETHODIMP nsRootAccessible::HandleEvent(nsIDOMEvent* aEvent)
else if (anchorElement) {
nsCOMPtr<nsIAccessibleHyperText> hyperText(do_QueryInterface(accessible));
if (hyperText) {
nsCOMPtr<nsIDOMNode> focusedNode(do_QueryInterface(anchorElement));
NS_IF_RELEASE(gLastFocusedNode);
gLastFocusedNode = focusedNode;
NS_IF_ADDREF(gLastFocusedNode);
PRInt32 selectedLink;
hyperText->GetSelectedLinkIndex(&selectedLink);
privAcc->FireToolkitEvent(nsIAccessibleEvent::EVENT_ATK_LINK_SELECTED, accessible, &selectedLink);