Bug 348037. GetIndexInParent impl for ATK counting too many children. r=ginn.chen

This commit is contained in:
aaronleventhal%moonset.net 2006-08-15 14:37:30 +00:00
parent 06d750b78a
commit 0985d3c59c

View File

@ -902,12 +902,41 @@ refChildCB(AtkObject *aAtkObj, gint aChildIndex)
gint
getIndexInParentCB(AtkObject *aAtkObj)
{
// We don't use nsIAccessible::GetIndexInParent() because
// for ATK we don't want to include text leaf nodes as children
NS_ENSURE_SUCCESS(CheckMaiAtkObject(aAtkObj), -1);
nsAccessibleWrap *accWrap =
NS_REINTERPRET_CAST(MaiAtkObject*, aAtkObj)->accWrap;
PRInt32 currentIndex = -1;
accWrap->GetIndexInParent(&currentIndex);
nsCOMPtr<nsIAccessible> parent;
accWrap->GetParent(getter_AddRefs(parent));
if (!parent) {
return -1; // No parent
}
nsCOMPtr<nsIAccessible> sibling;
parent->GetFirstChild(getter_AddRefs(sibling));
if (!sibling) {
return -1; // Error, parent has no children
}
PRInt32 currentIndex = 0;
while (sibling != NS_STATIC_CAST(nsIAccessible*, accWrap)) {
NS_ASSERTION(sibling, "Never ran into the same child that we started from");
if (!sibling) {
return -1;
}
if (nsAccessible::IsEmbeddedObject(sibling)) {
++ currentIndex;
}
nsCOMPtr<nsIAccessible> tempAccessible;
sibling->GetNextSibling(getter_AddRefs(tempAccessible));
sibling.swap(tempAccessible);
}
return currentIndex;
}