зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1652809: Add heading attributes to rotor r=eeejay
Differential Revision: https://phabricator.services.mozilla.com/D83673
This commit is contained in:
Родитель
ae15a943ed
Коммит
4148549840
|
@ -562,7 +562,12 @@ AccessibleOrProxy Pivot::AtPoint(int32_t aX, int32_t aY, PivotRule& aRule) {
|
|||
|
||||
// Role Rule
|
||||
|
||||
PivotRoleRule::PivotRoleRule(mozilla::a11y::role aRole) : mRole(aRole) {}
|
||||
PivotRoleRule::PivotRoleRule(mozilla::a11y::role aRole)
|
||||
: mRole(aRole), mDirectDescendantsFrom(nullptr) {}
|
||||
|
||||
PivotRoleRule::PivotRoleRule(mozilla::a11y::role aRole,
|
||||
AccessibleOrProxy& aDirectDescendantsFrom)
|
||||
: mRole(aRole), mDirectDescendantsFrom(aDirectDescendantsFrom) {}
|
||||
|
||||
uint16_t PivotRoleRule::Match(const AccessibleOrProxy& aAccOrProxy) {
|
||||
uint16_t result = nsIAccessibleTraversalRule::FILTER_IGNORE;
|
||||
|
@ -571,6 +576,18 @@ uint16_t PivotRoleRule::Match(const AccessibleOrProxy& aAccOrProxy) {
|
|||
result |= nsIAccessibleTraversalRule::FILTER_IGNORE_SUBTREE;
|
||||
}
|
||||
|
||||
if (!mDirectDescendantsFrom.IsNull() &&
|
||||
(aAccOrProxy != mDirectDescendantsFrom)) {
|
||||
// If we've specified mDirectDescendantsFrom, we should ignore
|
||||
// non-direct descendants of from the specified AoP. Because
|
||||
// pivot performs a preorder traversal, the first aAccOrProxy
|
||||
// object(s) that don't equal mDirectDescendantsFrom will be
|
||||
// mDirectDescendantsFrom's children. We'll process them, but ignore
|
||||
// their subtrees thereby processing direct descendants of
|
||||
// mDirectDescendantsFrom only.
|
||||
result |= nsIAccessibleTraversalRule::FILTER_IGNORE_SUBTREE;
|
||||
}
|
||||
|
||||
if (aAccOrProxy.Role() == mRole) {
|
||||
result |= nsIAccessibleTraversalRule::FILTER_MATCH;
|
||||
}
|
||||
|
@ -580,11 +597,20 @@ uint16_t PivotRoleRule::Match(const AccessibleOrProxy& aAccOrProxy) {
|
|||
|
||||
// Match All Rule
|
||||
|
||||
PivotMatchAllRule::PivotMatchAllRule(AccessibleOrProxy& aDirectDescendantsFrom)
|
||||
: mDirectDescendantsFrom(aDirectDescendantsFrom) {}
|
||||
|
||||
PivotMatchAllRule::PivotMatchAllRule() : mDirectDescendantsFrom(nullptr) {}
|
||||
|
||||
uint16_t PivotMatchAllRule::Match(const AccessibleOrProxy& aAccOrProxy) {
|
||||
uint16_t result = nsIAccessibleTraversalRule::FILTER_IGNORE;
|
||||
|
||||
if (nsAccUtils::MustPrune(aAccOrProxy)) {
|
||||
result |= nsIAccessibleTraversalRule::FILTER_IGNORE_SUBTREE;
|
||||
} else if (!mDirectDescendantsFrom.IsNull() &&
|
||||
(aAccOrProxy != mDirectDescendantsFrom)) {
|
||||
result |= nsIAccessibleTraversalRule::FILTER_MATCH |
|
||||
nsIAccessibleTraversalRule::FILTER_IGNORE_SUBTREE;
|
||||
} else {
|
||||
result |= nsIAccessibleTraversalRule::FILTER_MATCH;
|
||||
}
|
||||
|
|
|
@ -87,24 +87,34 @@ class Pivot final {
|
|||
};
|
||||
|
||||
/**
|
||||
* This rule matches accessibles on a given role.
|
||||
* This rule matches accessibles on a given role, filtering out non-direct
|
||||
* descendants if necessary.
|
||||
*/
|
||||
class PivotRoleRule final : public PivotRule {
|
||||
public:
|
||||
explicit PivotRoleRule(role aRole);
|
||||
explicit PivotRoleRule(role aRole, AccessibleOrProxy& aDirectDescendantsFrom);
|
||||
|
||||
virtual uint16_t Match(const AccessibleOrProxy& aAccOrProxy) override;
|
||||
|
||||
private:
|
||||
role mRole;
|
||||
AccessibleOrProxy mDirectDescendantsFrom;
|
||||
};
|
||||
|
||||
/**
|
||||
* This rule matches all accessibles.
|
||||
* This rule matches all accessibles, filtering out non-direct
|
||||
* descendants if necessary.
|
||||
*/
|
||||
class PivotMatchAllRule final : public PivotRule {
|
||||
public:
|
||||
explicit PivotMatchAllRule(AccessibleOrProxy& aDirectDescendantsFrom);
|
||||
explicit PivotMatchAllRule();
|
||||
|
||||
virtual uint16_t Match(const AccessibleOrProxy& aAccOrProxy) override;
|
||||
|
||||
private:
|
||||
AccessibleOrProxy mDirectDescendantsFrom;
|
||||
};
|
||||
|
||||
} // namespace a11y
|
||||
|
|
|
@ -321,6 +321,12 @@
|
|||
// AttributedStringForRange
|
||||
- (NSAttributedString* _Nullable)moxAttributedStringForRange:(NSValue* _Nonnull)range;
|
||||
|
||||
// AXUIElementsForSearchPredicate
|
||||
- (NSArray* _Nullable)moxUIElementsForSearchPredicate:(NSDictionary* _Nonnull)searchPredicate;
|
||||
|
||||
// AXUIElementCountForSearchPredicate
|
||||
- (NSUInteger)moxUIElementCountForSearchPredicate:(NSDictionary* _Nonnull)searchPredicate;
|
||||
|
||||
// AXCellForColumnAndRow
|
||||
- (id _Nullable)moxCellForColumnAndRow:(NSArray* _Nonnull)columnAndRow;
|
||||
|
||||
|
|
|
@ -7,6 +7,15 @@
|
|||
|
||||
#import "mozAccessible.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace a11y {
|
||||
|
||||
class Pivot;
|
||||
class PivotRule;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@interface MOXWebAreaAccessible : mozAccessible
|
||||
// overrides
|
||||
- (NSURL*)moxURL;
|
||||
|
@ -17,6 +26,12 @@
|
|||
// overrides
|
||||
- (NSNumber*)moxLoadingProgress;
|
||||
|
||||
// override
|
||||
- (NSArray*)moxUIElementsForSearchPredicate:(NSDictionary*)searchPredicate;
|
||||
|
||||
// override
|
||||
- (NSUInteger)moxUIElementCountForSearchPredicate:(NSDictionary*)searchPredicate;
|
||||
|
||||
// overrides
|
||||
- (void)handleAccessibleEvent:(uint32_t)eventType;
|
||||
|
||||
|
@ -32,7 +47,7 @@
|
|||
mozilla::a11y::AccessibleOrProxy mStartElem;
|
||||
|
||||
// The amount of matches we should return
|
||||
unsigned mResultLimit;
|
||||
int mResultLimit;
|
||||
|
||||
// The array of search keys to use during this search
|
||||
NSMutableArray* mSearchKeys;
|
||||
|
@ -46,6 +61,10 @@
|
|||
|
||||
- (id)initWithParameters:(NSDictionary*)params andRoot:(mozilla::a11y::AccessibleOrProxy)root;
|
||||
|
||||
- (NSMutableArray*)getMatchesForRule:(mozilla::a11y::PivotRule&)rule;
|
||||
|
||||
- (NSArray*)performSearch;
|
||||
|
||||
- (void)dealloc;
|
||||
|
||||
@end
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
#include "nsCocoaUtils.h"
|
||||
#include "DocAccessibleParent.h"
|
||||
#include "Pivot.h"
|
||||
|
||||
using namespace mozilla::a11y;
|
||||
|
||||
|
@ -64,6 +65,21 @@ using namespace mozilla::a11y;
|
|||
return @1.0;
|
||||
}
|
||||
|
||||
- (NSArray*)moxUIElementsForSearchPredicate:(NSDictionary*)searchPredicate {
|
||||
// Create our search object and set it up with the searchPredicate
|
||||
// params. The init function does additional parsing. We pass a
|
||||
// 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];
|
||||
|
||||
return [search performSearch];
|
||||
}
|
||||
|
||||
- (NSUInteger)moxUIElementCountForSearchPredicate:(NSDictionary*)searchPredicate {
|
||||
return [[self moxUIElementsForSearchPredicate:searchPredicate] count];
|
||||
}
|
||||
|
||||
- (void)handleAccessibleEvent:(uint32_t)eventType {
|
||||
switch (eventType) {
|
||||
case nsIAccessibleEvent::EVENT_DOCUMENT_LOAD_COMPLETE:
|
||||
|
@ -113,6 +129,43 @@ using namespace mozilla::a11y;
|
|||
return [super init];
|
||||
}
|
||||
|
||||
- (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);
|
||||
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
|
||||
// to return all matches (ie. have no limit)
|
||||
[matches addObject:GetNativeFromGeckoAccessible(match)];
|
||||
resultLimit -= 1;
|
||||
match = mSearchForward ? p.Next(match, rule) : p.Prev(match, rule);
|
||||
}
|
||||
|
||||
return matches;
|
||||
}
|
||||
|
||||
- (NSArray*)performSearch {
|
||||
NSMutableArray* matches = [[NSMutableArray alloc] init];
|
||||
|
||||
for (id key in mSearchKeys) {
|
||||
if ([key isEqualToString:@"AXAnyTypeSearchKey"]) {
|
||||
PivotMatchAllRule rule =
|
||||
mImmediateDescendantsOnly ? PivotMatchAllRule(mStartElem) : PivotMatchAllRule();
|
||||
[matches addObjectsFromArray:[self getMatchesForRule:rule]];
|
||||
}
|
||||
|
||||
if ([key isEqualToString:@"AXHeadingSearchKey"]) {
|
||||
PivotRoleRule rule = mImmediateDescendantsOnly ? PivotRoleRule(roles::HEADING, mStartElem)
|
||||
: PivotRoleRule(roles::HEADING);
|
||||
[matches addObjectsFromArray:[self getMatchesForRule:rule]];
|
||||
}
|
||||
}
|
||||
|
||||
return matches;
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[mSearchKeys release];
|
||||
[super dealloc];
|
||||
|
|
Загрузка…
Ссылка в новой задаче