Bug 455443 - cache the parent for the accessibilityAttributeValue(NSAccessibilityParentAttribute). r=surkov

This commit is contained in:
Hub Figuiere 2011-12-08 16:19:31 -05:00
parent 7d67f1d492
commit 3377f0b9bf
2 changed files with 42 additions and 11 deletions

View File

@ -46,16 +46,32 @@
@interface mozAccessible : NSObject <mozAccessible>
{
nsAccessibleWrap *mGeckoAccessible; // weak reference; it owns us.
NSMutableArray *mChildren; // strong ref to array of children
/**
* Weak reference; it owns us.
*/
nsAccessibleWrap* mGeckoAccessible;
// we can be marked as 'expired' if Shutdown() is called on our geckoAccessible.
// since we might still be retained by some third-party, we need to do cleanup
// in |expire|, and prevent any potential harm that could come from someone using us
// after this point.
/**
* Strong ref to array of children
*/
NSMutableArray* mChildren;
/**
* Weak reference to the parent
*/
mozAccessible* mParent;
/**
* We can be marked as 'expired' if Shutdown() is called on our geckoAccessible.
* since we might still be retained by some third-party, we need to do cleanup
* in |expire|, and prevent any potential harm that could come from someone using us
* after this point.
*/
BOOL mIsExpired;
// the nsIAccessible role of our gecko accessible.
/**
* The nsIAccessible role of our gecko accessible.
*/
PRUint32 mRole;
}
@ -114,6 +130,9 @@
// invalidates and removes all our children from our cached array.
- (void)invalidateChildren;
// invalidates the cached parent, used by invalidateChildren.
- (void)invalidateParent;
// makes ourselves "expired". after this point, we might be around if someone
// has retained us (e.g., a third-party), but we really contain no information.
- (void)expire;
@ -124,7 +143,7 @@
- (void)printHierarchyWithLevel:(unsigned)numSpaces;
- (void)sanityCheckChildren;
- (void)sanityCheckChildren:(NSArray *)theChildren;
- (void)sanityCheckChildren:(NSArray*)theChildren;
#endif
// ---- NSAccessibility methods ---- //

View File

@ -355,11 +355,15 @@ GetNativeFromGeckoAccessible(nsIAccessible *anAccessible)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
if (mParent)
return mParent;
nsCOMPtr<nsIAccessible> accessibleParent(mGeckoAccessible->GetUnignoredParent());
if (accessibleParent) {
id nativeParent = GetNativeFromGeckoAccessible(accessibleParent);
if (nativeParent)
return GetClosestInterestingAccessible(nativeParent);
if (nativeParent) {
return mParent = GetClosestInterestingAccessible(nativeParent);
}
}
// GetUnignoredParent() returns null when there is no unignored accessible all the way up to
@ -371,7 +375,8 @@ GetNativeFromGeckoAccessible(nsIAccessible *anAccessible)
id nativeParent = GetNativeFromGeckoAccessible(static_cast<nsIAccessible*>(root));
NSAssert1 (nativeParent, @"!!! we can't find a parent for %@", self);
return GetClosestInterestingAccessible(nativeParent);
mParent = GetClosestInterestingAccessible(nativeParent);
return mParent;
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
}
@ -610,6 +615,8 @@ GetNativeFromGeckoAccessible(nsIAccessible *anAccessible)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
[mChildren makeObjectsPerformSelector:@selector(invalidateParent)];
// make room for new children
[mChildren release];
mChildren = nil;
@ -617,6 +624,11 @@ GetNativeFromGeckoAccessible(nsIAccessible *anAccessible)
NS_OBJC_END_TRY_ABORT_BLOCK;
}
- (void)invalidateParent
{
mParent = nil;
}
- (void)expire
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;