зеркало из https://github.com/mozilla/gecko-dev.git
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
This commit is contained in:
Родитель
7a98582567
Коммит
1e470443ea
|
@ -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;
|
||||
|
||||
|
|
|
@ -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<mozAccessible*>(root) geckoAccessible];
|
||||
}
|
||||
|
||||
- (AccessibleOrProxy)startGeckoAccessible {
|
||||
if ([mStartElem isKindOfClass:[mozAccessible class]]) {
|
||||
return [static_cast<mozAccessible*>(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) {
|
||||
|
|
|
@ -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<MOXWebAreaAccessible*>(
|
||||
GetNativeFromGeckoAccessible([self geckoDocument]));
|
||||
MOXSearchInfo* search =
|
||||
[[MOXSearchInfo alloc] initWithParameters:searchPredicate
|
||||
andRoot:webArea];
|
||||
[[MOXSearchInfo alloc] initWithParameters:searchPredicate andRoot:self];
|
||||
|
||||
return [search performSearch];
|
||||
}
|
||||
|
|
|
@ -1343,3 +1343,25 @@ addAccessibleTask(
|
|||
// );
|
||||
}
|
||||
);
|
||||
|
||||
/**
|
||||
* Test search with non-webarea root
|
||||
*/
|
||||
addAccessibleTask(
|
||||
`<div id="searchroot"><p>hello</p><p>world</p></div><div><p>goodybe</p></div>`,
|
||||
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");
|
||||
}
|
||||
);
|
||||
|
|
Загрузка…
Ссылка в новой задаче