diff options
| -rw-r--r-- | Framework/MASShortcutView.m | 92 |
1 files changed, 83 insertions, 9 deletions
diff --git a/Framework/MASShortcutView.m b/Framework/MASShortcutView.m index cb6f3d9..4132ce2 100644 --- a/Framework/MASShortcutView.m +++ b/Framework/MASShortcutView.m @@ -124,14 +124,24 @@ NSString *const MASShortcutBinding = @"shortcutValue"; // Only enabled view supports recording if (flag && !self.enabled) return; - - if (_recording != flag) { - _recording = flag; - self.shortcutPlaceholder = nil; - [self resetToolTips]; - [self activateEventMonitoring:_recording]; - [self activateResignObserver:_recording]; - [self setNeedsDisplay:YES]; + + // Only care about changes in state + if (flag == _recording) return; + + _recording = flag; + self.shortcutPlaceholder = nil; + [self resetToolTips]; + [self activateEventMonitoring:_recording]; + [self activateResignObserver:_recording]; + [self setNeedsDisplay:YES]; + + // Give VO users feedback on the result + if (_recording == NO) { + NSString* msg = (_shortcutValue.description) ? + NSLocalizedString(@"Shortcut set", @"VoiceOver shortcut recording feedback") : + NSLocalizedString(@"Shortcut cleared", @"VoiceOver shortcut recording feedback"); + NSDictionary *announcementInfo = [[NSDictionary alloc] initWithObjectsAndKeys:msg, NSAccessibilityAnnouncementKey, @"High", NSAccessibilityPriorityKey, nil]; + NSAccessibilityPostNotificationWithUserInfo(self, NSAccessibilityAnnouncementRequestedNotification, announcementInfo); } } @@ -472,7 +482,7 @@ void *kUserDataHint = &kUserDataHint; #pragma mark Bindings // http://tomdalling.com/blog/cocoa/implementing-your-own-cocoa-bindings/ --(void) propagateValue:(id)value forBinding:(NSString*)binding; +-(void) propagateValue:(id)value forBinding:(NSString*)binding { NSParameterAssert(binding != nil); @@ -516,4 +526,68 @@ void *kUserDataHint = &kUserDataHint; [boundObject setValue:value forKeyPath:boundKeyPath]; } +#pragma mark - Accessibility + +- (BOOL)accessibilityIsIgnored +{ + return NO; +} + +- (NSString *)accessibilityHelp +{ + return NSLocalizedString(@"To record a new shortcut, click this button, and then type the" + @" new shortcut, or press delete to clear an existing shortcut.", + @"VoiceOver shortcut help"); +} + +- (NSString *)accessibilityLabel +{ + NSString* title = _shortcutValue.description ? _shortcutValue.description : @"Empty"; + title = [title stringByAppendingFormat:@" %@", NSLocalizedString(@"keyboard shortcut", @"VoiceOver title")]; + return title; +} + +- (BOOL)accessibilityPerformPress +{ + if (self.isRecording == NO) { + self.recording = YES; + return YES; + } + else { + return NO; + } +} + +- (NSString *)accessibilityRole +{ + return NSAccessibilityButtonRole; +} + +- (BOOL)acceptsFirstResponder +{ + return YES; +} + +- (BOOL)becomeFirstResponder +{ + [self setNeedsDisplay:YES]; + return [super becomeFirstResponder]; +} + +- (BOOL)resignFirstResponder +{ + [self setNeedsDisplay:YES]; + return [super resignFirstResponder]; +} + +- (void)drawFocusRingMask +{ + [_shortcutCell drawFocusRingMaskWithFrame:[self bounds] inView:self]; +} + +- (NSRect)focusRingMaskBounds +{ + return [self bounds]; +} + @end |
