From bc235e0716e8f6646cff7d8ee98aaf6c074fee0a Mon Sep 17 00:00:00 2001 From: Lorien Hu Date: Wed, 15 Jul 2015 00:51:23 -0400 Subject: [PATCH] Bug 1172946 - (part 3) Add handling for proxies in mozAccessible children r=tbsaunde --- accessible/mac/mozAccessible.h | 3 ++ accessible/mac/mozAccessible.mm | 57 +++++++++++++++++++++++++++++---- 2 files changed, 54 insertions(+), 6 deletions(-) diff --git a/accessible/mac/mozAccessible.h b/accessible/mac/mozAccessible.h index aff523edac6..d908cf41b4d 100644 --- a/accessible/mac/mozAccessible.h +++ b/accessible/mac/mozAccessible.h @@ -44,6 +44,9 @@ GetNativeFromProxy(const ProxyAccessible* aProxy) ProxyAccessible* GetProxyUnignoredParent(const ProxyAccessible* aProxy); +void GetProxyUnignoredChildren(const ProxyAccessible* aProxy, + nsTArray* aChildrenArray); + BOOL IsProxyIgnored(const ProxyAccessible* aProxy); } // a11y diff --git a/accessible/mac/mozAccessible.mm b/accessible/mac/mozAccessible.mm index d778ac85f0d..8ea2d2462f3 100644 --- a/accessible/mac/mozAccessible.mm +++ b/accessible/mac/mozAccessible.mm @@ -86,6 +86,27 @@ a11y::GetProxyUnignoredParent(const ProxyAccessible* aProxy) return parent; } +void +a11y::GetProxyUnignoredChildren(const ProxyAccessible* aProxy, + nsTArray* aChildrenArray) +{ + if (aProxy->MustPruneChildren()) + return; + + uint32_t childCount = aProxy->ChildrenCount(); + for (size_t childIdx = 0; childIdx < childCount; childIdx++) { + ProxyAccessible* childProxy = aProxy->ChildAt(childIdx); + + // If element is ignored, then add its children as substitutes. + if (IsProxyIgnored(childProxy)) { + GetProxyUnignoredChildren(aProxy, aChildrenArray); + continue; + } + + aChildrenArray->AppendElement(childProxy); + } +} + BOOL a11y::IsProxyIgnored(const ProxyAccessible* aProxy) { @@ -103,8 +124,8 @@ ConvertToNSArray(nsTArray& aArray) NSMutableArray* nativeArray = [[NSMutableArray alloc] init]; // iterate through the list, and get each native accessible. - uint32_t totalCount = aArray.Length(); - for (uint32_t i = 0; i < totalCount; i++) { + size_t totalCount = aArray.Length(); + for (size_t i = 0; i < totalCount; i++) { Accessible* curAccessible = aArray.ElementAt(i); mozAccessible* curNative = GetNativeFromGeckoAccessible(curAccessible); if (curNative) @@ -114,6 +135,24 @@ ConvertToNSArray(nsTArray& aArray) return nativeArray; } +// convert an array of Gecko proxy accessibles to an NSArray of native accessibles +static inline NSMutableArray* +ConvertToNSArray(nsTArray& aArray) +{ + NSMutableArray* nativeArray = [[NSMutableArray alloc] init]; + + // iterate through the list, and get each native accessible. + size_t totalCount = aArray.Length(); + for (size_t i = 0; i < totalCount; i++) { + ProxyAccessible* curAccessible = aArray.ElementAt(i); + mozAccessible* curNative = GetNativeFromProxy(curAccessible); + if (curNative) + [nativeArray addObject:GetObjectOrRepresentedView(curNative)]; + } + + return nativeArray; +} + #pragma mark - @implementation mozAccessible @@ -689,13 +728,19 @@ ConvertToNSArray(nsTArray& aArray) NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL; AccessibleWrap* accWrap = [self getGeckoAccessible]; - if (mChildren || !accWrap->AreChildrenCached()) + if (mChildren || (accWrap && !accWrap->AreChildrenCached())) return mChildren; // get the array of children. - nsAutoTArray childrenArray; - accWrap->GetUnignoredChildren(&childrenArray); - mChildren = ConvertToNSArray(childrenArray); + if (accWrap) { + nsAutoTArray childrenArray; + accWrap->GetUnignoredChildren(&childrenArray); + mChildren = ConvertToNSArray(childrenArray); + } else if (ProxyAccessible* proxy = [self getProxyAccessible]) { + nsAutoTArray childrenArray; + GetProxyUnignoredChildren(proxy, &childrenArray); + mChildren = ConvertToNSArray(childrenArray); + } #ifdef DEBUG_hakan // make sure we're not returning any ignored accessibles.