aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomáš Znamenáček2015-03-04 11:08:47 +0100
committerTomáš Znamenáček2015-03-04 11:08:47 +0100
commit00dd421e208bedbe85182ef3961f1172389cc0e1 (patch)
tree98d95353e4d92890d13f15bc316941857141970d
parent3ea350cec127d7118ef64f0e84a9ad84fa249a11 (diff)
parente2b2d5b9e15cd5c8341202e48f2d63c39963b591 (diff)
downloadMASShortcut-00dd421e208bedbe85182ef3961f1172389cc0e1.tar.bz2
Merge pull request #66 from starkos/issue-47-accessibility
Add basic accessibility support.
-rw-r--r--Framework/MASShortcutView.h2
-rw-r--r--Framework/MASShortcutView.m99
2 files changed, 92 insertions, 9 deletions
diff --git a/Framework/MASShortcutView.h b/Framework/MASShortcutView.h
index 166be44..656f4e4 100644
--- a/Framework/MASShortcutView.h
+++ b/Framework/MASShortcutView.h
@@ -21,4 +21,6 @@ typedef enum {
/// Returns custom class for drawing control.
+ (Class)shortcutCellClass;
+- (void)setAcceptsFirstResponder:(BOOL)value;
+
@end
diff --git a/Framework/MASShortcutView.m b/Framework/MASShortcutView.m
index cb6f3d9..d96989c 100644
--- a/Framework/MASShortcutView.m
+++ b/Framework/MASShortcutView.m
@@ -24,6 +24,7 @@ NSString *const MASShortcutBinding = @"shortcutValue";
NSInteger _shortcutToolTipTag;
NSInteger _hintToolTipTag;
NSTrackingArea *_hintArea;
+ BOOL _acceptsFirstResponder;
}
#pragma mark -
@@ -59,6 +60,7 @@ NSString *const MASShortcutBinding = @"shortcutValue";
_shortcutValidator = [MASShortcutValidator sharedValidator];
_enabled = YES;
_showsDeleteButton = YES;
+ _acceptsFirstResponder = NO;
[self resetShortcutCellStyle];
}
@@ -124,14 +126,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 +484,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 +528,73 @@ 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 _acceptsFirstResponder;
+}
+
+- (void)setAcceptsFirstResponder:(BOOL)value
+{
+ _acceptsFirstResponder = value;
+}
+
+- (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