Skip to content

Commit

Permalink
Internal Sync for 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
j-sid committed Aug 10, 2018
1 parent 2d2bf14 commit 61eb982
Show file tree
Hide file tree
Showing 30 changed files with 1,138 additions and 139 deletions.
6 changes: 5 additions & 1 deletion Classes/GTXAccessibilityTree.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* UITextEffectsWindow which reports 9223372036854775807 possibly due to internal type conversions
* with -1, we use this bounds value to detect that case..
*/
const NSInteger kAccessibilityChildrenUpperBound = 50000;
static const NSInteger kAccessibilityChildrenUpperBound = 50000;

@implementation GTXAccessibilityTree {
// A queue of elements to be visited.
Expand Down Expand Up @@ -89,6 +89,10 @@ - (id)nextObject {
accessibilityElementsSet,
@([nextInQueue accessibilityElementCount]),
accessibilityElementsFromIndicesSet);

// Ensure accessibilityElements* are marked as used even if NSAssert is removed.
(void)accessibilityElementsSet;
(void)accessibilityElementsFromIndicesSet;
} else {
// Set accessibilityElements to whichever is non nil or leave it as is.
axElements = axElementsFromIndices ? axElementsFromIndices : axElements;
Expand Down
51 changes: 51 additions & 0 deletions Classes/GTXBlacklistBlock.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//
// Copyright 2018 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#import <UIKit/UIKit.h>

#import "GTXBlacklisting.h"

NS_ASSUME_NONNULL_BEGIN

/**
A matcher block that determines if the given element must be ignored for the given check.
@param element Element to be looked up if it needs to be ignored.
@param checkName Name of the check for which element must be looked up.
@return @c YES if element needs to be ignored for the given check @c NO other wise.
*/
typedef BOOL(^GTXIgnoreElementMatcher)(id element, NSString *checkName);

@interface GTXBlacklistBlock: NSObject<GTXBlacklisting>

/**
* GTXBlacklistBlock::init is disabled, instead use GTXBlacklistBlock::blacklistWithBlock:
* method to create GTXBlacklists.
*/
- (instancetype)init __attribute__((unavailable("Use blacklistWithBlock: instead.")));

/**
* Creates an GTXBlacklist with the given @c block that determines if an element should be ignored.
*
* @param block A block that determines if an element should be ignored.
*
* @return A GTXBlacklist object.
*/
+ (id<GTXBlacklisting>)blacklistWithBlock:(GTXIgnoreElementMatcher)block;

@end

NS_ASSUME_NONNULL_END
47 changes: 47 additions & 0 deletions Classes/GTXBlacklistBlock.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//
// Copyright 2018 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#import "GTXBlacklistBlock.h"

NS_ASSUME_NONNULL_BEGIN

@implementation GTXBlacklistBlock {
GTXIgnoreElementMatcher _block;
}

+ (id<GTXBlacklisting>)blacklistWithBlock:(GTXIgnoreElementMatcher)block {
return [[GTXBlacklistBlock alloc] initWithBlock:block];
}

- (instancetype)initWithBlock:(GTXIgnoreElementMatcher)block {
NSParameterAssert(block);

self = [super init];
if (self) {
_block = block;
}
return self;
}

#pragma mark - GTXBlacklisting

- (BOOL)shouldIgnoreElement:(id)element forCheckNamed:(NSString *)check {
return _block(element, check);
}

@end

NS_ASSUME_NONNULL_END
61 changes: 61 additions & 0 deletions Classes/GTXBlacklistFactory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//
// Copyright 2018 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#import <UIKit/UIKit.h>

#import "GTXBlacklisting.h"

NS_ASSUME_NONNULL_BEGIN

/**
* Factory for GTXBlacklisting objects for blacklisting elements.
*/
@interface GTXBlacklistFactory : NSObject

- (instancetype)init NS_UNAVAILABLE;
/**
* Returns a GTXBlacklisting object that ignores all elements that are instances of
* a given @c elementClassName.
*
* @param elementClassName The name of the class that should be blacklisted.
* @return A GTXBlacklisting object that ignores all elements of the given class.
*/
+ (id<GTXBlacklisting>)blacklistWithClassName:(NSString *)elementClassName;
/**
* Returns a GTXBlacklisting object that ignores all elements that are instances of
* a given @c elementClassName, but only for GTXChecking objects with a given @c checkName.
*
* @param elementClassName The name of the class that should be blacklisted.
* @param skipCheckName The name of the check that should ignore elements of the given class.
* @return A GTXBlacklisting object that ignores all elements of the given class when running the
* given check.
*/
+ (id<GTXBlacklisting>)blacklistWithClassName:(NSString *)elementClassName
checkName:(NSString *)skipCheckName;
/**
* Returns a GTXBlacklisting object that ignores all elements with a given accessibility
* identifier, but only for GTXChecking objects with a given @c checkName.
*
* @param accessibilityId The accessibility identifier of the element that should be blacklisted.
* @param skipCheckName The name of the check that should ignore elements with the given
* accessibility identifier.
*/
+ (id<GTXBlacklisting>)blacklistWithAccessibilityIdentifier:(NSString *)accessibilityId
checkName:(NSString *)skipCheckName;

@end

NS_ASSUME_NONNULL_END
58 changes: 58 additions & 0 deletions Classes/GTXBlacklistFactory.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//
// Copyright 2018 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#import "GTXBlacklistFactory.h"

#import "GTXBlacklistBlock.h"

NS_ASSUME_NONNULL_BEGIN

@implementation GTXBlacklistFactory

+ (id<GTXBlacklisting>)blacklistWithClassName:(NSString *)elementClassName {
Class classObject = NSClassFromString(elementClassName);
NSAssert(classObject, @"Class named %@ does not exist!", elementClassName);
GTXIgnoreElementMatcher matcher = ^BOOL(id element, NSString *checkName) {
return [element isKindOfClass:classObject];
};
return [GTXBlacklistBlock blacklistWithBlock:matcher];
}

+ (id<GTXBlacklisting>)blacklistWithClassName:(NSString *)elementClassName
checkName:(NSString *)skipCheckName {
NSParameterAssert(elementClassName);
Class classObject = NSClassFromString(elementClassName);
NSAssert(classObject, @"Class named %@ does not exist!", elementClassName);
GTXIgnoreElementMatcher matcher = ^BOOL(id element, NSString *checkName) {
return [element isKindOfClass:classObject] && [checkName isEqualToString:skipCheckName];
};
return [GTXBlacklistBlock blacklistWithBlock:matcher];
}

+ (id<GTXBlacklisting>)blacklistWithAccessibilityIdentifier:(NSString *)accessibilityId
checkName:(NSString *)skipCheckName {
NSParameterAssert(accessibilityId);
NSParameterAssert(skipCheckName);
GTXIgnoreElementMatcher matcher = ^BOOL(id element, NSString *checkName) {
return [[element accessibilityIdentifier] isEqualToString:accessibilityId] &&
[checkName isEqualToString:skipCheckName];
};
return [GTXBlacklistBlock blacklistWithBlock:matcher];
}

@end

NS_ASSUME_NONNULL_END
38 changes: 38 additions & 0 deletions Classes/GTXBlacklisting.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// Copyright 2018 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

/**
* Protocol for blacklisting certain types of UI elements in accessibility checks.
*/
@protocol GTXBlacklisting<NSObject>

/**
* Determines if the given @c check should not be run on the given @c element.
*
* @param element The target element on which the GTX check is to be performed.
* @param[out] checkName The name of the check being run.
*
* @return @c YES if the check should NOT be performed on the given element, NO otherwise.
*/
- (BOOL)shouldIgnoreElement:(id)element forCheckNamed:(NSString *)checkName;

@end

NS_ASSUME_NONNULL_END
13 changes: 10 additions & 3 deletions Classes/GTXChecksCollection.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,21 @@ typedef NS_ENUM(NSUInteger, GTXVersion) {
* Organizes all checks provided by GTX, developers can use these as a starting point
* for implementing their own checks. These checks are based on recommendations found in
* "Accessibility Programming Guide for iOS"
@link https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/iPhoneAccessibility/Introduction/Introduction.html
@link
https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/iPhoneAccessibility/Introduction/Introduction.html // NOLINT
* and on WCAG.
*/
@interface GTXChecksCollection : NSObject

/**
* @return An array of all supported GTXChecks for the given @c version.
*/
+ (NSArray<GTXChecking> *)allChecksForVersion:(GTXVersion)version;
+ (NSArray<id<GTXChecking>> *)allChecksForVersion:(GTXVersion)version;

/**
* @return An array of all supported GTXChecks.
*/
+ (NSArray<GTXChecking> *)allGTXChecks;
+ (NSArray<id<GTXChecking>> *)allGTXChecks;

/**
* @return a check that verifies that accessibility label is present on all accessibility elements.
Expand All @@ -68,6 +69,12 @@ typedef NS_ENUM(NSUInteger, GTXVersion) {
*/
+ (id<GTXChecking>)checkForAXLabelNotPunctuated;

/**
* @return a check that verifies that accessibility labels do not end in strings that VoiceOver
* announces via the element's accessibility traits.
*/
+ (id<GTXChecking>)checkForAXLabelNotRedundantWithTraits;

/**
* @return a check that verifies that accessibility traits dont conflict with each other as
* recommended by "Accessibility Programming Guide for iOS" (see class docs).
Expand Down
Loading

0 comments on commit 61eb982

Please sign in to comment.