From a49527ed08685fe39d678984f89d066930082e1b Mon Sep 17 00:00:00 2001 From: Alexander Surkov Date: Thu, 7 Apr 2011 14:17:54 +0900 Subject: [PATCH] Bug 646368 - don't check whether children are cached while tree is traversed, r=davidb --- accessible/src/base/nsAccessible.cpp | 32 ++++++++++--------- accessible/src/base/nsDocAccessible.cpp | 13 +++++--- accessible/src/html/nsHyperTextAccessible.cpp | 1 - 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/accessible/src/base/nsAccessible.cpp b/accessible/src/base/nsAccessible.cpp index 21bf3d49663b..a164269d1679 100644 --- a/accessible/src/base/nsAccessible.cpp +++ b/accessible/src/base/nsAccessible.cpp @@ -474,6 +474,9 @@ nsAccessible::GetFirstChild(nsIAccessible **aFirstChild) NS_ENSURE_ARG_POINTER(aFirstChild); *aFirstChild = nsnull; + if (IsDefunct()) + return NS_ERROR_FAILURE; + PRInt32 childCount = GetChildCount(); NS_ENSURE_TRUE(childCount != -1, NS_ERROR_FAILURE); @@ -490,6 +493,9 @@ nsAccessible::GetLastChild(nsIAccessible **aLastChild) NS_ENSURE_ARG_POINTER(aLastChild); *aLastChild = nsnull; + if (IsDefunct()) + return NS_ERROR_FAILURE; + PRInt32 childCount = GetChildCount(); NS_ENSURE_TRUE(childCount != -1, NS_ERROR_FAILURE); @@ -503,6 +509,9 @@ nsAccessible::GetChildAt(PRInt32 aChildIndex, nsIAccessible **aChild) NS_ENSURE_ARG_POINTER(aChild); *aChild = nsnull; + if (IsDefunct()) + return NS_ERROR_FAILURE; + PRInt32 childCount = GetChildCount(); NS_ENSURE_TRUE(childCount != -1, NS_ERROR_FAILURE); @@ -526,6 +535,9 @@ nsAccessible::GetChildren(nsIArray **aOutChildren) NS_ENSURE_ARG_POINTER(aOutChildren); *aOutChildren = nsnull; + if (IsDefunct()) + return NS_ERROR_FAILURE; + PRInt32 childCount = GetChildCount(); NS_ENSURE_TRUE(childCount != -1, NS_ERROR_FAILURE); @@ -555,6 +567,9 @@ nsAccessible::GetChildCount(PRInt32 *aChildCount) { NS_ENSURE_ARG_POINTER(aChildCount); + if (IsDefunct()) + return NS_ERROR_FAILURE; + *aChildCount = GetChildCount(); return *aChildCount != -1 ? NS_OK : NS_ERROR_FAILURE; } @@ -2812,9 +2827,6 @@ nsAccessible::RemoveChild(nsAccessible* aChild) nsAccessible* nsAccessible::GetChildAt(PRUint32 aIndex) { - if (EnsureChildren()) - return nsnull; - nsAccessible *child = mChildren.SafeElementAt(aIndex, nsnull); if (!child) return nsnull; @@ -2831,14 +2843,13 @@ nsAccessible::GetChildAt(PRUint32 aIndex) PRInt32 nsAccessible::GetChildCount() { - return EnsureChildren() ? -1 : mChildren.Length(); + return mChildren.Length(); } PRInt32 nsAccessible::GetIndexOf(nsAccessible* aChild) { - return EnsureChildren() || (aChild->mParent != this) ? - -1 : aChild->GetIndexInParent(); + return (aChild->mParent != this) ? -1 : aChild->GetIndexInParent(); } PRInt32 @@ -2850,9 +2861,6 @@ nsAccessible::GetIndexInParent() const PRInt32 nsAccessible::GetEmbeddedChildCount() { - if (EnsureChildren()) - return -1; - if (IsChildrenFlag(eMixedChildren)) { if (!mEmbeddedObjCollector) mEmbeddedObjCollector = new EmbeddedObjCollector(this); @@ -2865,9 +2873,6 @@ nsAccessible::GetEmbeddedChildCount() nsAccessible* nsAccessible::GetEmbeddedChildAt(PRUint32 aIndex) { - if (EnsureChildren()) - return nsnull; - if (IsChildrenFlag(eMixedChildren)) { if (!mEmbeddedObjCollector) mEmbeddedObjCollector = new EmbeddedObjCollector(this); @@ -2881,9 +2886,6 @@ nsAccessible::GetEmbeddedChildAt(PRUint32 aIndex) PRInt32 nsAccessible::GetIndexOfEmbeddedChild(nsAccessible* aChild) { - if (EnsureChildren()) - return -1; - if (IsChildrenFlag(eMixedChildren)) { if (!mEmbeddedObjCollector) mEmbeddedObjCollector = new EmbeddedObjCollector(this); diff --git a/accessible/src/base/nsDocAccessible.cpp b/accessible/src/base/nsDocAccessible.cpp index 17f7991eca83..cbd805b142aa 100644 --- a/accessible/src/base/nsDocAccessible.cpp +++ b/accessible/src/base/nsDocAccessible.cpp @@ -1468,15 +1468,20 @@ nsDocAccessible::NotifyOfCachingEnd(nsAccessible* aAccessible) // invalidation list. for (PRUint32 idx = 0; idx < mInvalidationList.Length(); idx++) { nsIContent* content = mInvalidationList[idx]; - if (!HasAccessible(content)) { - // Make sure we keep children updated. While we're inside of caching - // loop then we must exist it with cached children. + nsAccessible* accessible = GetAccessible(content); + if (!accessible) { nsAccessible* container = GetContainerAccessible(content); NS_ASSERTION(container, "Got a referenced element that is not in document!"); - if (container) + if (container) { container->UpdateChildren(); + accessible = GetAccessible(content); + } } + + // Make sure the subtree is created. + if (accessible) + CacheChildrenInSubtree(accessible); } mInvalidationList.Clear(); diff --git a/accessible/src/html/nsHyperTextAccessible.cpp b/accessible/src/html/nsHyperTextAccessible.cpp index 7f494e561993..b5bbb2fa62ab 100644 --- a/accessible/src/html/nsHyperTextAccessible.cpp +++ b/accessible/src/html/nsHyperTextAccessible.cpp @@ -2212,7 +2212,6 @@ nsHyperTextAccessible::GetChildOffset(PRUint32 aChildIndex, PRUint32 lastOffset = mOffsets.IsEmpty() ? 0 : mOffsets[mOffsets.Length() - 1]; - EnsureChildren(); while (mOffsets.Length() < aChildIndex) { nsAccessible* child = mChildren[mOffsets.Length()]; lastOffset += nsAccUtils::TextLength(child);