Bug 1620324 - Part 2: Make rotor API work with generated root group. r=morgan

Differential Revision: https://phabricator.services.mozilla.com/D90175
This commit is contained in:
Eitan Isaacson 2020-09-16 20:20:10 +00:00
Родитель e039e76c8f
Коммит b9f75d2671
2 изменённых файлов: 64 добавлений и 20 удалений

Просмотреть файл

@ -46,13 +46,13 @@ using namespace mozilla::a11y;
@end
@interface MOXSearchInfo : NSObject {
// The gecko accessible of the web area, we need a reference
// The MOX accessible of the web area, we need a reference
// to set the pivot's root. This is a weak ref.
AccessibleOrProxy mWebArea;
MOXWebAreaAccessible* mWebArea;
// The gecko accessible we should start searching from.
// The MOX accessible we should start searching from.
// This is a weak ref.
AccessibleOrProxy mStartElem;
MOXAccessibleBase* mStartElem;
// The amount of matches we should return
int mResultLimit;
@ -68,7 +68,9 @@ using namespace mozilla::a11y;
}
- (id)initWithParameters:(NSDictionary*)params
andRoot:(mozilla::a11y::AccessibleOrProxy)root;
andRoot:(MOXWebAreaAccessible*)root;
- (AccessibleOrProxy)startGeckoAccessible;
- (NSMutableArray*)getMatchesForRule:(PivotRule&)rule;

Просмотреть файл

@ -176,8 +176,8 @@ using namespace mozilla::a11y;
// reference to the web area (mGeckoAccessible) to use as
// a start element if one is not specified.
MOXSearchInfo* search =
[[MOXSearchInfo alloc] initWithParameters:searchPredicate
andRoot:mGeckoAccessible];
[[MOXSearchInfo alloc] initWithParameters:searchPredicate andRoot:self];
return [search performSearch];
}
@ -262,7 +262,8 @@ using namespace mozilla::a11y;
@implementation MOXSearchInfo
- (id)initWithParameters:(NSDictionary*)params andRoot:(AccessibleOrProxy)root {
- (id)initWithParameters:(NSDictionary*)params
andRoot:(MOXWebAreaAccessible*)root {
if (id searchKeyParam = [params objectForKey:@"AXSearchKey"]) {
mSearchKeys = [searchKeyParam isKindOfClass:[NSString class]]
? @[ searchKeyParam ]
@ -270,7 +271,7 @@ using namespace mozilla::a11y;
}
if (id startElemParam = [params objectForKey:@"AXStartElement"]) {
mStartElem = [startElemParam geckoAccessible];
mStartElem = startElemParam;
} else {
mStartElem = root;
}
@ -290,12 +291,24 @@ using namespace mozilla::a11y;
return [super init];
}
- (AccessibleOrProxy)startGeckoAccessible {
if ([mStartElem isKindOfClass:[mozAccessible class]]) {
return [static_cast<mozAccessible*>(mStartElem) geckoAccessible];
}
// 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];
}
- (NSMutableArray*)getMatchesForRule:(PivotRule&)rule {
int resultLimit = mResultLimit;
NSMutableArray* matches = [[NSMutableArray alloc] init];
Pivot p = Pivot(mWebArea);
AccessibleOrProxy match =
mSearchForward ? p.Next(mStartElem, rule) : p.Prev(mStartElem, rule);
Pivot p = Pivot([mWebArea geckoAccessible]);
AccessibleOrProxy geckoStartAcc = [self startGeckoAccessible];
AccessibleOrProxy match = mSearchForward ? p.Next(geckoStartAcc, rule)
: p.Prev(geckoStartAcc, rule);
while (!match.IsNull() && resultLimit != 0) {
// we use mResultLimit != 0 to capture the case where mResultLimit is -1
// when it is set from the params dictionary. If that's true, we want
@ -315,52 +328,81 @@ using namespace mozilla::a11y;
}
- (NSArray*)performSearch {
AccessibleOrProxy geckoStartAcc = [self startGeckoAccessible];
NSMutableArray* matches = [[NSMutableArray alloc] init];
for (id key in mSearchKeys) {
if ([key isEqualToString:@"AXAnyTypeSearchKey"]) {
RotorAllRule rule =
mImmediateDescendantsOnly ? RotorAllRule(mStartElem) : RotorAllRule();
RotorAllRule rule = mImmediateDescendantsOnly
? RotorAllRule(geckoStartAcc)
: RotorAllRule();
if (mSearchForward) {
if ([mStartElem isKindOfClass:[MOXWebAreaAccessible class]]) {
if (id rootGroup =
[static_cast<MOXWebAreaAccessible*>(mStartElem) rootGroup]) {
// Moving forward from web area, rootgroup; if it exists, is next.
[matches addObject:rootGroup];
if (mResultLimit == 1) {
// Found one match, continue in search keys for block.
continue;
}
}
} else if (mImmediateDescendantsOnly &&
[mStartElem isKindOfClass:[MOXRootGroup class]]) {
// Moving forward from root group. If we don't match descendants,
// there is no match. Continue.
continue;
}
} else if (!mSearchForward &&
[mStartElem isKindOfClass:[MOXRootGroup class]]) {
// Moving backward from root group. Web area is next.
[matches addObject:[mStartElem moxParent]];
if (mResultLimit == 1) {
// Found one match, continue in search keys for block.
continue;
}
}
[matches addObjectsFromArray:[self getMatchesForRule:rule]];
}
if ([key isEqualToString:@"AXHeadingSearchKey"]) {
RotorHeadingRule rule = mImmediateDescendantsOnly
? RotorHeadingRule(mStartElem)
? RotorHeadingRule(geckoStartAcc)
: RotorHeadingRule();
[matches addObjectsFromArray:[self getMatchesForRule:rule]];
}
if ([key isEqualToString:@"AXArticleSearchKey"]) {
RotorArticleRule rule = mImmediateDescendantsOnly
? RotorArticleRule(mStartElem)
? RotorArticleRule(geckoStartAcc)
: RotorArticleRule();
[matches addObjectsFromArray:[self getMatchesForRule:rule]];
}
if ([key isEqualToString:@"AXTableSearchKey"]) {
RotorTableRule rule = mImmediateDescendantsOnly
? RotorTableRule(mStartElem)
? RotorTableRule(geckoStartAcc)
: RotorTableRule();
[matches addObjectsFromArray:[self getMatchesForRule:rule]];
}
if ([key isEqualToString:@"AXLandmarkSearchKey"]) {
RotorLandmarkRule rule = mImmediateDescendantsOnly
? RotorLandmarkRule(mStartElem)
? RotorLandmarkRule(geckoStartAcc)
: RotorLandmarkRule();
[matches addObjectsFromArray:[self getMatchesForRule:rule]];
}
if ([key isEqualToString:@"AXButtonSearchKey"]) {
RotorButtonRule rule = mImmediateDescendantsOnly
? RotorButtonRule(mStartElem)
? RotorButtonRule(geckoStartAcc)
: RotorButtonRule();
[matches addObjectsFromArray:[self getMatchesForRule:rule]];
}
if ([key isEqualToString:@"AXControlSearchKey"]) {
RotorControlRule rule = mImmediateDescendantsOnly
? RotorControlRule(mStartElem)
? RotorControlRule(geckoStartAcc)
: RotorControlRule();
[matches addObjectsFromArray:[self getMatchesForRule:rule]];
}