Skip to content

Commit

Permalink
fleshed out the accessibility for TUIControl and TUIButton
Browse files Browse the repository at this point in the history
  • Loading branch information
joshaber committed Aug 2, 2011
1 parent f44ca0f commit a1d2711
Show file tree
Hide file tree
Showing 13 changed files with 208 additions and 97 deletions.
32 changes: 32 additions & 0 deletions TwUI.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@
886EBA8313D64393006DE018 /* TUIControl+Private.m in Sources */ = {isa = PBXBuildFile; fileRef = 886EBA7E13D64393006DE018 /* TUIControl+Private.m */; };
886EBA8413D64393006DE018 /* TUIControl+Private.m in Sources */ = {isa = PBXBuildFile; fileRef = 886EBA7E13D64393006DE018 /* TUIControl+Private.m */; };
886EBA8513D64393006DE018 /* TUIControl+Private.m in Sources */ = {isa = PBXBuildFile; fileRef = 886EBA7E13D64393006DE018 /* TUIControl+Private.m */; };
88CC1F2F13E365B600827793 /* TUIControl+Accessibility.h in Headers */ = {isa = PBXBuildFile; fileRef = 88CC1F2D13E365B500827793 /* TUIControl+Accessibility.h */; };
88CC1F3013E365B600827793 /* TUIControl+Accessibility.h in Headers */ = {isa = PBXBuildFile; fileRef = 88CC1F2D13E365B500827793 /* TUIControl+Accessibility.h */; };
88CC1F3113E365B600827793 /* TUIControl+Accessibility.h in Headers */ = {isa = PBXBuildFile; fileRef = 88CC1F2D13E365B500827793 /* TUIControl+Accessibility.h */; };
88CC1F3213E365B600827793 /* TUIControl+Accessibility.m in Sources */ = {isa = PBXBuildFile; fileRef = 88CC1F2E13E365B500827793 /* TUIControl+Accessibility.m */; };
88CC1F3313E365B600827793 /* TUIControl+Accessibility.m in Sources */ = {isa = PBXBuildFile; fileRef = 88CC1F2E13E365B500827793 /* TUIControl+Accessibility.m */; };
88CC1F3413E365B600827793 /* TUIControl+Accessibility.m in Sources */ = {isa = PBXBuildFile; fileRef = 88CC1F2E13E365B500827793 /* TUIControl+Accessibility.m */; };
88CC1F3713E3684700827793 /* TUIButton+Accessibility.h in Headers */ = {isa = PBXBuildFile; fileRef = 88CC1F3513E3684400827793 /* TUIButton+Accessibility.h */; };
88CC1F3813E3684700827793 /* TUIButton+Accessibility.h in Headers */ = {isa = PBXBuildFile; fileRef = 88CC1F3513E3684400827793 /* TUIButton+Accessibility.h */; };
88CC1F3913E3684700827793 /* TUIButton+Accessibility.h in Headers */ = {isa = PBXBuildFile; fileRef = 88CC1F3513E3684400827793 /* TUIButton+Accessibility.h */; };
88CC1F3A13E3684700827793 /* TUIButton+Accessibility.m in Sources */ = {isa = PBXBuildFile; fileRef = 88CC1F3613E3684600827793 /* TUIButton+Accessibility.m */; };
88CC1F3B13E3684700827793 /* TUIButton+Accessibility.m in Sources */ = {isa = PBXBuildFile; fileRef = 88CC1F3613E3684600827793 /* TUIButton+Accessibility.m */; };
88CC1F3C13E3684700827793 /* TUIButton+Accessibility.m in Sources */ = {isa = PBXBuildFile; fileRef = 88CC1F3613E3684600827793 /* TUIButton+Accessibility.m */; };
CB5B265A13BE6DA200579B1E /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = CB5B265813BE6DA200579B1E /* InfoPlist.strings */; };
CB5B266313BE6DA300579B1E /* SenTestingKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CB5B266213BE6DA300579B1E /* SenTestingKit.framework */; };
CB5B266413BE6DA300579B1E /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CB5B264F13BE6DA200579B1E /* Cocoa.framework */; };
Expand Down Expand Up @@ -242,6 +254,10 @@
8819794B13E26E5800AA39EB /* TUINSView+Accessibility.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "TUINSView+Accessibility.m"; sourceTree = "<group>"; };
886EBA7D13D64393006DE018 /* TUIControl+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "TUIControl+Private.h"; sourceTree = "<group>"; };
886EBA7E13D64393006DE018 /* TUIControl+Private.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "TUIControl+Private.m"; sourceTree = "<group>"; };
88CC1F2D13E365B500827793 /* TUIControl+Accessibility.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "TUIControl+Accessibility.h"; sourceTree = "<group>"; };
88CC1F2E13E365B500827793 /* TUIControl+Accessibility.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "TUIControl+Accessibility.m"; sourceTree = "<group>"; };
88CC1F3513E3684400827793 /* TUIButton+Accessibility.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "TUIButton+Accessibility.h"; sourceTree = "<group>"; };
88CC1F3613E3684600827793 /* TUIButton+Accessibility.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "TUIButton+Accessibility.m"; sourceTree = "<group>"; };
CB5B264C13BE6DA200579B1E /* TwUI.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = TwUI.framework; sourceTree = BUILT_PRODUCTS_DIR; };
CB5B264F13BE6DA200579B1E /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; };
CB5B265213BE6DA200579B1E /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -504,6 +520,8 @@
CBB74C4113BE6E1900C85CB5 /* TUIActivityIndicatorView.m */,
CBB74C4213BE6E1900C85CB5 /* TUIAttributedString.h */,
CBB74C4313BE6E1900C85CB5 /* TUIAttributedString.m */,
88CC1F3513E3684400827793 /* TUIButton+Accessibility.h */,
88CC1F3613E3684600827793 /* TUIButton+Accessibility.m */,
CBB74C4413BE6E1900C85CB5 /* TUIButton+Content.m */,
CBB74C4513BE6E1900C85CB5 /* TUIButton.h */,
CBB74C4613BE6E1900C85CB5 /* TUIButton.m */,
Expand All @@ -512,6 +530,8 @@
CBB74C4913BE6E1900C85CB5 /* TUIColor.h */,
CBB74C4A13BE6E1900C85CB5 /* TUIColor.m */,
CBB74C4B13BE6E1900C85CB5 /* TUIControl+TargetAction.m */,
88CC1F2D13E365B500827793 /* TUIControl+Accessibility.h */,
88CC1F2E13E365B500827793 /* TUIControl+Accessibility.m */,
886EBA7D13D64393006DE018 /* TUIControl+Private.h */,
886EBA7E13D64393006DE018 /* TUIControl+Private.m */,
CBB74C4C13BE6E1900C85CB5 /* TUIControl.h */,
Expand Down Expand Up @@ -600,6 +620,8 @@
886EBA8113D64393006DE018 /* TUIControl+Private.h in Headers */,
8819794613E26E0200AA39EB /* TUIView+Accessibility.h in Headers */,
8819794E13E26E5800AA39EB /* TUINSView+Accessibility.h in Headers */,
88CC1F3113E365B600827793 /* TUIControl+Accessibility.h in Headers */,
88CC1F3913E3684700827793 /* TUIButton+Accessibility.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -651,6 +673,8 @@
886EBA7F13D64393006DE018 /* TUIControl+Private.h in Headers */,
8819794413E26E0200AA39EB /* TUIView+Accessibility.h in Headers */,
8819794C13E26E5800AA39EB /* TUINSView+Accessibility.h in Headers */,
88CC1F2F13E365B600827793 /* TUIControl+Accessibility.h in Headers */,
88CC1F3713E3684700827793 /* TUIButton+Accessibility.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -661,6 +685,8 @@
886EBA8013D64393006DE018 /* TUIControl+Private.h in Headers */,
8819794513E26E0200AA39EB /* TUIView+Accessibility.h in Headers */,
8819794D13E26E5800AA39EB /* TUINSView+Accessibility.h in Headers */,
88CC1F3013E365B600827793 /* TUIControl+Accessibility.h in Headers */,
88CC1F3813E3684700827793 /* TUIButton+Accessibility.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -856,6 +882,8 @@
886EBA8413D64393006DE018 /* TUIControl+Private.m in Sources */,
8819794913E26E0200AA39EB /* TUIView+Accessibility.m in Sources */,
8819795113E26E5800AA39EB /* TUINSView+Accessibility.m in Sources */,
88CC1F3413E365B600827793 /* TUIControl+Accessibility.m in Sources */,
88CC1F3C13E3684700827793 /* TUIButton+Accessibility.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -912,6 +940,8 @@
886EBA8213D64393006DE018 /* TUIControl+Private.m in Sources */,
8819794713E26E0200AA39EB /* TUIView+Accessibility.m in Sources */,
8819794F13E26E5800AA39EB /* TUINSView+Accessibility.m in Sources */,
88CC1F3213E365B600827793 /* TUIControl+Accessibility.m in Sources */,
88CC1F3A13E3684700827793 /* TUIButton+Accessibility.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -977,6 +1007,8 @@
886EBA8313D64393006DE018 /* TUIControl+Private.m in Sources */,
8819794813E26E0200AA39EB /* TUIView+Accessibility.m in Sources */,
8819795013E26E5800AA39EB /* TUINSView+Accessibility.m in Sources */,
88CC1F3313E365B600827793 /* TUIControl+Accessibility.m in Sources */,
88CC1F3B13E3684700827793 /* TUIButton+Accessibility.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
1 change: 0 additions & 1 deletion lib/UIKit/TUIAccessibility.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ extern TUIAccessibilityTraits TUIAccessibilityTraitSearchField;
extern TUIAccessibilityTraits TUIAccessibilityTraitImage;
extern TUIAccessibilityTraits TUIAccessibilityTraitSelected;
extern TUIAccessibilityTraits TUIAccessibilityTraitPlaysSound;
extern TUIAccessibilityTraits TUIAccessibilityTraitKeyboardKey;
extern TUIAccessibilityTraits TUIAccessibilityTraitStaticText;
extern TUIAccessibilityTraits TUIAccessibilityTraitSummaryElement;
extern TUIAccessibilityTraits TUIAccessibilityTraitNotEnabled;
Expand Down
9 changes: 4 additions & 5 deletions lib/UIKit/TUIAccessibility.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@
TUIAccessibilityTraits TUIAccessibilityTraitImage = 1 << 4;
TUIAccessibilityTraits TUIAccessibilityTraitSelected = 1 << 5;
TUIAccessibilityTraits TUIAccessibilityTraitPlaysSound = 1 << 6;
TUIAccessibilityTraits TUIAccessibilityTraitKeyboardKey = 1 << 7;
TUIAccessibilityTraits TUIAccessibilityTraitStaticText = 1 << 8;
TUIAccessibilityTraits TUIAccessibilityTraitSummaryElement = 1 << 9;
TUIAccessibilityTraits TUIAccessibilityTraitNotEnabled = 1 << 10;
TUIAccessibilityTraits TUIAccessibilityTraitUpdatesFrequently = 1 << 11;
TUIAccessibilityTraits TUIAccessibilityTraitStaticText = 1 << 7;
TUIAccessibilityTraits TUIAccessibilityTraitSummaryElement = 1 << 8;
TUIAccessibilityTraits TUIAccessibilityTraitNotEnabled = 1 << 9;
TUIAccessibilityTraits TUIAccessibilityTraitUpdatesFrequently = 1 << 10;

@implementation NSObject (TUIAccessibility)

Expand Down
14 changes: 14 additions & 0 deletions lib/UIKit/TUIButton+Accessibility.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// TUIButton+Accessibility.h
// TwUI
//
// Created by Josh Abernathy on 7/29/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "TUIButton.h"


@interface TUIButton (Accessibility)

@end
23 changes: 23 additions & 0 deletions lib/UIKit/TUIButton+Accessibility.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// TUIButton+Accessibility.m
// TwUI
//
// Created by Josh Abernathy on 7/29/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "TUIButton+Accessibility.h"


@implementation TUIButton (Accessibility)

- (NSString *)accessibilityLabel
{
if(accessibilityLabel == nil) {
return [self currentTitle];
}

return accessibilityLabel;
}

@end
14 changes: 14 additions & 0 deletions lib/UIKit/TUIControl+Accessibility.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// TUIControl+Accessibility.h
// TwUI
//
// Created by Josh Abernathy on 7/29/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "TUIControl.h"


@interface TUIControl (Accessibility)

@end
38 changes: 38 additions & 0 deletions lib/UIKit/TUIControl+Accessibility.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// TUIControl+Accessibility.m
// TwUI
//
// Created by Josh Abernathy on 7/29/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "TUIControl+Accessibility.h"


@implementation TUIControl (Accessibility)


#pragma mark NSAccessibility

- (NSArray *)accessibilityActionNames
{
return [self allControlEvents] != 0 ? [NSArray arrayWithObject:NSAccessibilityPressAction] : [super accessibilityActionNames];
}

- (NSString *)accessibilityActionDescription:(NSString *)action
{
if([action isEqualToString:NSAccessibilityPressAction]) {
return NSLocalizedString(@"press", @"");
} else {
return nil;
}
}

- (void)accessibilityPerformAction:(NSString *)action
{
if([action isEqualToString:NSAccessibilityPressAction]) {
[self sendActionsForControlEvents:TUIControlEventAllTouchEvents];
}
}

@end
15 changes: 15 additions & 0 deletions lib/UIKit/TUIControl.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,24 @@

#import "TUIControl.h"
#import "TUIControl+Private.h"
#import "TUIView+Accessibility.h"
#import "TUIAccessibility.h"

@implementation TUIControl

- (id)initWithFrame:(CGRect)rect
{
self = [super initWithFrame:rect];
if(self == nil) {
[self release];
return nil;
}

self.accessibilityTraits |= TUIAccessibilityTraitButton;

return self;
}

- (void)dealloc
{
[_targetActions release];
Expand Down
55 changes: 7 additions & 48 deletions lib/UIKit/TUINSView+Accessibility.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,42 +21,24 @@ - (id)accessibilityHitTest:(NSPoint)point

- (BOOL)accessibilityIsIgnored
{
return NO;
return YES;
}
//
//- (id)accessibilityAttributeValue:(NSString *)attribute
//{
// if([attribute isEqualToString:NSAccessibilityRoleAttribute]) {
// return NSAccessibilityGroupRole;
// } else if([attribute isEqualToString:NSAccessibilityRoleDescriptionAttribute]) {
// return NSAccessibilityRoleDescriptionForUIElement(self);
// } else if([attribute isEqualToString:NSAccessibilityChildrenAttribute]) {
// return [self.rootView accessibleSubviews];
// } else {
// return [super accessibilityAttributeValue:attribute];
// }
//}

- (NSArray *)accessibilityAttributeNames
{
static NSArray *attributes = nil;
if(attributes == nil) {
attributes = [[NSArray alloc] initWithObjects:NSAccessibilityRoleAttribute, NSAccessibilityRoleDescriptionAttribute, NSAccessibilityFocusedAttribute, NSAccessibilityChildrenAttribute, NSAccessibilityParentAttribute, NSAccessibilityWindowAttribute, NSAccessibilityTopLevelUIElementAttribute, NSAccessibilityPositionAttribute, NSAccessibilitySizeAttribute, nil];
attributes = [[NSArray alloc] initWithObjects:NSAccessibilityChildrenAttribute, NSAccessibilityParentAttribute, NSAccessibilityWindowAttribute, NSAccessibilityTopLevelUIElementAttribute, NSAccessibilityPositionAttribute, NSAccessibilitySizeAttribute, nil];
}

return attributes;
}

- (id)accessibilityAttributeValue:(NSString *)attribute
{
if([attribute isEqualToString:NSAccessibilityRoleAttribute]) {
return NSAccessibilityGroupRole;
} else if([attribute isEqualToString:NSAccessibilityRoleDescriptionAttribute]) {
return NSAccessibilityRoleDescriptionForUIElement(self);
} else if([attribute isEqualToString:NSAccessibilityFocusedAttribute]) {
id focusedElement = [NSApp accessibilityAttributeValue:NSAccessibilityFocusedUIElementAttribute];
return [NSNumber numberWithBool:[focusedElement isEqual:self]];
} else if([attribute isEqualToString:NSAccessibilityParentAttribute]) {
if([attribute isEqualToString:NSAccessibilityChildrenAttribute]) {
return [NSArray arrayWithObject:self.rootView];
} else if([attribute isEqualToString:NSAccessibilityParentAttribute]) {
return NSAccessibilityUnignoredAncestor(self.superview);
} else if([attribute isEqualToString:NSAccessibilityWindowAttribute]) {
return [self.superview accessibilityAttributeValue:NSAccessibilityWindowAttribute];
Expand All @@ -66,44 +48,21 @@ - (id)accessibilityAttributeValue:(NSString *)attribute
return [NSValue valueWithPoint:[[self window] convertBaseToScreen:[self convertPoint:self.bounds.origin toView:nil]]];
} else if([attribute isEqualToString:NSAccessibilitySizeAttribute]) {
return [NSValue valueWithSize:self.bounds.size];
} else if([attribute isEqualToString:NSAccessibilityChildrenAttribute]) {
return [NSArray arrayWithObject:self.rootView];
} else {
} else {
return nil;
}
}

- (BOOL)accessibilityIsAttributeSettable:(NSString *)attribute
{
if([attribute isEqualToString:NSAccessibilityFocusedAttribute]) {
return NO; // TODO: should this be settable?
} else {
return NO;
}
}

- (void)accessibilitySetValue:(id)value forAttribute:(NSString *)attribute
{
if([attribute isEqualToString:NSAccessibilityFocusedAttribute]) {
// TODO: should we set this?
}
return NO;
}

- (NSArray *)accessibilityActionNames
{
return [NSArray array];
}

- (NSString *)accessibilityActionDescription:(NSString *)action
{
return nil;
}

- (void)accessibilityPerformAction:(NSString *)action
{

}

- (id)accessibilityFocusedUIElement
{
return NSAccessibilityUnignoredAncestor(self);
Expand Down
2 changes: 1 addition & 1 deletion lib/UIKit/TUIView+Accessibility.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
@property (nonatomic, copy) NSString *accessibilityHint;
@property (nonatomic, copy) NSString *accessibilityValue;
@property (nonatomic, assign) TUIAccessibilityTraits accessibilityTraits;
@property (nonatomic, assign) CGRect accessibilityFrame;
@property (nonatomic, assign) CGRect accessibilityFrame; // accessibilityFrame should be in screen coordinates

- (NSArray *)accessibleSubviews;

Expand Down
Loading

0 comments on commit a1d2711

Please sign in to comment.