Bug 251264 - AddGetIndexInParent to nsIAccessible.

r=aaronleventhal@moonset.net, sr=darin@meer.net
This commit is contained in:
pkw%us.ibm.com 2004-07-15 20:45:59 +00:00
Родитель f84bdb6eef
Коммит 5046699d71
3 изменённых файлов: 38 добавлений и 26 удалений

Просмотреть файл

@ -54,7 +54,7 @@
*
* @status UNDER_REVIEW
*/
[scriptable, uuid(B26FBE47-9A5F-42a1-822B-082461AE4D6D)]
[scriptable, uuid(A84FCE8C-B127-4528-84F1-A022F5B040DA)]
interface nsIAccessible : nsISupports
{
/**
@ -87,6 +87,12 @@ interface nsIAccessible : nsISupports
*/
readonly attribute long childCount;
/**
* The 0-based index of this accessible in its parent's list of children,
* or -1 if this accessible does not have a parent.
*/
readonly attribute long indexInParent;
/**
* Accessible name -- the main text equivalent for this node
*/

Просмотреть файл

@ -858,32 +858,8 @@ getIndexInParentCB(AtkObject *aAtkObj)
nsAccessibleWrap *accWrap =
NS_REINTERPRET_CAST(MaiAtkObject*, aAtkObj)->accWrap;
// we use accId to decide two accessible objects are the same.
void *accId = nsnull;
NS_ENSURE_SUCCESS(accWrap->GetUniqueID(&accId), -1);
nsCOMPtr<nsIAccessible> accParent;
nsresult rv = accWrap->GetParent(getter_AddRefs(accParent));
if (NS_FAILED(rv) || !accParent)
return -1;
nsCOMPtr<nsIAccessible> accChild;
nsCOMPtr<nsIAccessible> accTmpChild;
accParent->GetFirstChild(getter_AddRefs(accChild));
PRInt32 currentIndex = -1;
void *currentAccId = nsnull;
while (accChild) {
++currentIndex;
nsCOMPtr<nsIAccessNode> accNode(do_QueryInterface(accChild));
if (accNode) {
accNode->GetUniqueID(&currentAccId);
if (currentAccId == accId)
break;
}
accChild->GetNextSibling(getter_AddRefs(accTmpChild));
accChild = accTmpChild;
}
accWrap->GetIndexInParent(&currentIndex);
return currentIndex;
}

Просмотреть файл

@ -428,6 +428,36 @@ NS_IMETHODIMP nsAccessible::GetChildCount(PRInt32 *aAccChildCount)
return NS_OK;
}
/* readonly attribute long indexInParent; */
NS_IMETHODIMP nsAccessible::GetIndexInParent(PRInt32 *aIndexInParent)
{
*aIndexInParent = -1;
if (!mParent || !mWeakShell) {
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIAccessible> sibling;
mParent->GetFirstChild(getter_AddRefs(sibling));
if (!sibling) {
return NS_ERROR_FAILURE;
}
*aIndexInParent = 0;
while (sibling != this) {
NS_ASSERTION(sibling, "Never ran into the same child that we started from");
if (!sibling)
return NS_ERROR_FAILURE;
++*aIndexInParent;
nsCOMPtr<nsIAccessible> tempAccessible;
sibling->GetNextSibling(getter_AddRefs(tempAccessible));
sibling = tempAccessible;
}
return NS_OK;
}
nsresult nsAccessible::GetTranslatedString(const nsAString& aKey, nsAString& aStringOut)
{
nsXPIDLString xsValue;