diff --git a/accessible/public/nsIAccessible.idl b/accessible/public/nsIAccessible.idl index 281e85bb2c4..84c3d77f308 100644 --- a/accessible/public/nsIAccessible.idl +++ b/accessible/public/nsIAccessible.idl @@ -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 */ diff --git a/accessible/src/atk/nsAccessibleWrap.cpp b/accessible/src/atk/nsAccessibleWrap.cpp index 8d83579636c..3993732ab2c 100644 --- a/accessible/src/atk/nsAccessibleWrap.cpp +++ b/accessible/src/atk/nsAccessibleWrap.cpp @@ -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 accParent; - nsresult rv = accWrap->GetParent(getter_AddRefs(accParent)); - if (NS_FAILED(rv) || !accParent) - return -1; - - nsCOMPtr accChild; - nsCOMPtr accTmpChild; - accParent->GetFirstChild(getter_AddRefs(accChild)); - PRInt32 currentIndex = -1; - void *currentAccId = nsnull; - while (accChild) { - ++currentIndex; - nsCOMPtr accNode(do_QueryInterface(accChild)); - if (accNode) { - accNode->GetUniqueID(¤tAccId); - if (currentAccId == accId) - break; - } - accChild->GetNextSibling(getter_AddRefs(accTmpChild)); - accChild = accTmpChild; - } + accWrap->GetIndexInParent(¤tIndex); return currentIndex; } diff --git a/accessible/src/base/nsAccessible.cpp b/accessible/src/base/nsAccessible.cpp index 99f1c5b6496..278171ed340 100644 --- a/accessible/src/base/nsAccessible.cpp +++ b/accessible/src/base/nsAccessible.cpp @@ -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 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 tempAccessible; + sibling->GetNextSibling(getter_AddRefs(tempAccessible)); + sibling = tempAccessible; + } + + return NS_OK; +} + nsresult nsAccessible::GetTranslatedString(const nsAString& aKey, nsAString& aStringOut) { nsXPIDLString xsValue;