From 1e470443eaa713e8669f05db3d32df16511d1bb8 Mon Sep 17 00:00:00 2001 From: Eitan Isaacson Date: Tue, 29 Sep 2020 20:49:29 +0000 Subject: [PATCH] Bug 1668100 - Make target root for AXUIElementsForSearchPredicate. r=morgan Instead of having the web area be the implicit root, the search results should exclusively be descendants of the target element that the search is called on. Differential Revision: https://phabricator.services.mozilla.com/D91826 --- accessible/mac/MOXSearchInfo.h | 5 ++--- accessible/mac/MOXSearchInfo.mm | 20 +++++++++++++---- accessible/mac/mozAccessible.mm | 5 +---- accessible/tests/browser/mac/browser_rotor.js | 22 +++++++++++++++++++ 4 files changed, 41 insertions(+), 11 deletions(-) diff --git a/accessible/mac/MOXSearchInfo.h b/accessible/mac/MOXSearchInfo.h index ecd00494057b..e2469d0bd7d5 100644 --- a/accessible/mac/MOXSearchInfo.h +++ b/accessible/mac/MOXSearchInfo.h @@ -13,7 +13,7 @@ using namespace mozilla::a11y; @interface MOXSearchInfo : NSObject { // The MOX accessible of the web area, we need a reference // to set the pivot's root. This is a weak ref. - MOXWebAreaAccessible* mWebArea; + MOXAccessibleBase* mRoot; // The MOX accessible we should start searching from. // This is a weak ref. @@ -32,8 +32,7 @@ using namespace mozilla::a11y; BOOL mImmediateDescendantsOnly; } -- (id)initWithParameters:(NSDictionary*)params - andRoot:(MOXWebAreaAccessible*)root; +- (id)initWithParameters:(NSDictionary*)params andRoot:(MOXAccessibleBase*)root; - (NSArray*)performSearch; diff --git a/accessible/mac/MOXSearchInfo.mm b/accessible/mac/MOXSearchInfo.mm index 8267b6b8cd87..84a238ec3349 100644 --- a/accessible/mac/MOXSearchInfo.mm +++ b/accessible/mac/MOXSearchInfo.mm @@ -17,13 +17,15 @@ using namespace mozilla::a11y; @interface MOXSearchInfo () - (NSMutableArray*)getMatchesForRule:(PivotRule&)rule; +- (AccessibleOrProxy)rootGeckoAccessible; + - (AccessibleOrProxy)startGeckoAccessible; @end @implementation MOXSearchInfo - (id)initWithParameters:(NSDictionary*)params - andRoot:(MOXWebAreaAccessible*)root { + andRoot:(MOXAccessibleBase*)root { if (id searchKeyParam = [params objectForKey:@"AXSearchKey"]) { mSearchKeys = [searchKeyParam isKindOfClass:[NSString class]] ? @[ searchKeyParam ] @@ -36,7 +38,7 @@ using namespace mozilla::a11y; mStartElem = root; } - mWebArea = root; + mRoot = root; mResultLimit = [[params objectForKey:@"AXResultsLimit"] intValue]; @@ -49,6 +51,15 @@ using namespace mozilla::a11y; return [super init]; } +- (AccessibleOrProxy)rootGeckoAccessible { + id root = + [mRoot isKindOfClass:[mozAccessible class]] ? mRoot : [mRoot moxParent]; + + MOZ_ASSERT([mRoot isKindOfClass:[mozAccessible class]]); + + return [static_cast(root) geckoAccessible]; +} + - (AccessibleOrProxy)startGeckoAccessible { if ([mStartElem isKindOfClass:[mozAccessible class]]) { return [static_cast(mStartElem) geckoAccessible]; @@ -57,14 +68,15 @@ using namespace mozilla::a11y; // If it isn't a mozAccessible, it doesn't have a gecko accessible // this is most likely the root group. Use the gecko doc as the start // accessible. - return [mWebArea geckoAccessible]; + return [self rootGeckoAccessible]; } - (NSMutableArray*)getMatchesForRule:(PivotRule&)rule { int resultLimit = mResultLimit; NSMutableArray* matches = [[NSMutableArray alloc] init]; - Pivot p = Pivot([mWebArea geckoAccessible]); + AccessibleOrProxy geckoRootAcc = [self rootGeckoAccessible]; AccessibleOrProxy geckoStartAcc = [self startGeckoAccessible]; + Pivot p = Pivot(geckoRootAcc); AccessibleOrProxy match = mSearchForward ? p.Next(geckoStartAcc, rule) : p.Prev(geckoStartAcc, rule); while (!match.IsNull() && resultLimit != 0) { diff --git a/accessible/mac/mozAccessible.mm b/accessible/mac/mozAccessible.mm index 0bb4b1dde5f4..a71d33ac19a2 100644 --- a/accessible/mac/mozAccessible.mm +++ b/accessible/mac/mozAccessible.mm @@ -751,11 +751,8 @@ struct RoleDescrComparator { // params. The init function does additional parsing. We pass a // reference to the web area to use as a start element if one is not // specified. - MOXWebAreaAccessible* webArea = static_cast( - GetNativeFromGeckoAccessible([self geckoDocument])); MOXSearchInfo* search = - [[MOXSearchInfo alloc] initWithParameters:searchPredicate - andRoot:webArea]; + [[MOXSearchInfo alloc] initWithParameters:searchPredicate andRoot:self]; return [search performSearch]; } diff --git a/accessible/tests/browser/mac/browser_rotor.js b/accessible/tests/browser/mac/browser_rotor.js index 4452cda973c5..013683a811b1 100644 --- a/accessible/tests/browser/mac/browser_rotor.js +++ b/accessible/tests/browser/mac/browser_rotor.js @@ -1343,3 +1343,25 @@ addAccessibleTask( // ); } ); + +/** + * Test search with non-webarea root + */ +addAccessibleTask( + `

hello

world

goodybe

`, + async (browser, accDoc) => { + let searchPred = { + AXSearchKey: "AXAnyTypeSearchKey", + AXImmediateDescendantsOnly: 1, + AXResultsLimit: -1, + AXDirection: "AXDirectionNext", + }; + + const searchRoot = getNativeInterface(accDoc, "searchroot"); + const resultCount = searchRoot.getParameterizedAttributeValue( + "AXUIElementCountForSearchPredicate", + NSDictionary(searchPred) + ); + is(resultCount, 2, "Found 2 items"); + } +);