-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Xcode 14 modernization #3
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,6 +82,8 @@ typedef NS_ENUM(NSUInteger, _SRRecorderControlButtonTag) | |
_SRRecorderControlMainButtonTag = 2 | ||
}; | ||
|
||
@interface SRRecorderControl () <NSAccessibility, NSViewToolTipOwner> | ||
@end | ||
|
||
@implementation SRRecorderControl | ||
{ | ||
|
@@ -146,6 +148,10 @@ - (void)_initInternalState | |
_shapeYRadious = _SRRecorderControlYosemiteShapeYRadius; | ||
} | ||
|
||
[self setAccessibilityElement:YES]; | ||
[self setAccessibilityRole:NSAccessibilityButtonRole]; | ||
[self setAccessibilityEnabled:YES]; | ||
|
||
[self setToolTip:SRLoc(@"Click to record shortcut")]; | ||
[self updateTrackingAreas]; | ||
} | ||
|
@@ -193,6 +199,8 @@ - (void)setEnabled:(BOOL)newEnabled | |
// Focus ring is only drawn when view is enabled | ||
if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6) | ||
[self noteFocusRingMaskChanged]; | ||
|
||
[self setAccessibilityEnabled:_enabled]; | ||
} | ||
|
||
- (void)setObjectValue:(NSDictionary *)newObjectValue | ||
|
@@ -422,6 +430,11 @@ - (NSString *)accessibilityLabel | |
return label; | ||
} | ||
|
||
- (NSString *)accessibilityTitle | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this duplication resolve a specific issue? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (label is intended to be a clean replacement for title, but there have definitely been bugs historically) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That was done in 349fa68 - IIRC VoiceOver reads the title of the button but we were only providing the label. |
||
{ | ||
return [self accessibilityLabel]; | ||
} | ||
|
||
- (NSString *)stringValue | ||
{ | ||
if (![self.objectValue count]) | ||
|
@@ -845,102 +858,47 @@ - (id)value | |
|
||
#pragma mark NSAccessibility | ||
|
||
- (BOOL)accessibilityIsIgnored | ||
- (BOOL)accessibilityPerformPress | ||
{ | ||
return NO; | ||
[self beginRecording]; | ||
|
||
return YES; | ||
} | ||
|
||
- (NSArray *)accessibilityAttributeNames | ||
- (BOOL)accessibilityPerformCancel | ||
{ | ||
static NSArray *AttributeNames = nil; | ||
static dispatch_once_t OnceToken; | ||
dispatch_once(&OnceToken, ^ | ||
{ | ||
AttributeNames = [[super accessibilityAttributeNames] mutableCopy]; | ||
NSArray *newAttributes = @[ | ||
NSAccessibilityRoleAttribute, | ||
NSAccessibilityTitleAttribute, | ||
NSAccessibilityEnabledAttribute | ||
]; | ||
|
||
for (NSString *attributeName in newAttributes) | ||
{ | ||
if (![AttributeNames containsObject:attributeName]) | ||
[(NSMutableArray *)AttributeNames addObject:attributeName]; | ||
} | ||
if (self.isRecording) { | ||
[self endRecording]; | ||
} | ||
|
||
AttributeNames = [AttributeNames copy]; | ||
}); | ||
return AttributeNames; | ||
return self.isRecording; | ||
} | ||
|
||
- (id)accessibilityAttributeValue:(NSString *)anAttributeName | ||
- (BOOL)accessibilityPerformDelete | ||
{ | ||
if ([anAttributeName isEqualToString:NSAccessibilityRoleAttribute]) | ||
return NSAccessibilityButtonRole; | ||
else if ([anAttributeName isEqualToString:NSAccessibilityTitleAttribute]) | ||
return self.accessibilityLabel; | ||
else if ([anAttributeName isEqualToString:NSAccessibilityEnabledAttribute]) | ||
return @(self.enabled); | ||
else | ||
return [super accessibilityAttributeValue:anAttributeName]; | ||
if (self.isRecording) { | ||
[self clearAndEndRecording]; | ||
} | ||
|
||
return self.isRecording; | ||
} | ||
|
||
- (NSArray *)accessibilityActionNames | ||
- (BOOL)isAccessibilitySelectorAllowed:(SEL)selector | ||
{ | ||
static NSArray *AllActions = nil; | ||
static NSArray *ButtonStateActionNames = nil; | ||
static NSArray *RecorderStateActionNames = nil; | ||
// This method asks us which accessibility selector are allowed. We need | ||
// to limit some of these based on whether we're recording. However, all | ||
// other selectors should return the default result (otherwise we might | ||
// block `accessibilityLabel`). | ||
|
||
static dispatch_once_t OnceToken; | ||
dispatch_once(&OnceToken, ^ | ||
{ | ||
AllActions = @[ | ||
NSAccessibilityPressAction, | ||
NSAccessibilityCancelAction, | ||
NSAccessibilityDeleteAction | ||
]; | ||
|
||
ButtonStateActionNames = @[ | ||
NSAccessibilityPressAction | ||
]; | ||
|
||
RecorderStateActionNames = @[ | ||
NSAccessibilityCancelAction, | ||
NSAccessibilityDeleteAction | ||
]; | ||
}); | ||
|
||
// List of supported actions names must be fixed for 10.6, but can vary for 10.7 and above. | ||
if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6) | ||
{ | ||
if (self.enabled) | ||
{ | ||
if (self.isRecording) | ||
return RecorderStateActionNames; | ||
else | ||
return ButtonStateActionNames; | ||
} | ||
else | ||
return @[]; | ||
if (selector == @selector(accessibilityPerformPress)) { | ||
return self.enabled; | ||
} else if (selector == @selector(accessibilityPerformCancel)) { | ||
return self.isRecording; | ||
} else if (selector == @selector(accessibilityPerformDelete)) { | ||
return self.isRecording; | ||
} | ||
else | ||
return AllActions; | ||
} | ||
|
||
- (NSString *)accessibilityActionDescription:(NSString *)anAction | ||
{ | ||
return NSAccessibilityActionDescription(anAction); | ||
} | ||
|
||
- (void)accessibilityPerformAction:(NSString *)anAction | ||
{ | ||
if ([anAction isEqualToString:NSAccessibilityPressAction]) | ||
[self beginRecording]; | ||
else if (self.isRecording && [anAction isEqualToString:NSAccessibilityCancelAction]) | ||
[self endRecording]; | ||
else if (self.isRecording && [anAction isEqualToString:NSAccessibilityDeleteAction]) | ||
[self clearAndEndRecording]; | ||
return YES; | ||
} | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's unusual to add
NSAccessibility
conformance like this. What are you indicating?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might want
NSAccessibilityButton
which will populate the role for you