On May 10, 2010, at 2:57 PM, Mickey Roberson wrote:
I have implemented custom table cells (subclass of NSTextFieldCell) in my application (a Twitter client). Each cell represents a tweet including things like name, date, tweet text, etc. Within my cell subclass I have the following code:
- (NSArray *)accessibilityAttributeNames {
if(validAXAttributes == nil) {
validAXAttributes = [[NSArray alloc] initWithObjects:NSAccessibilityRoleAttribute,
NSAccessibilityRoleDescriptionAttribute,
NSAccessibilityHelpAttribute,
NSAccessibilityFocusedAttribute,
NSAccessibilityParentAttribute,
NSAccessibilityChildrenAttribute,
NSAccessibilityWindowAttribute,
NSAccessibilityPositionAttribute,
NSAccessibilitySizeAttribute,
NSAccessibilityEnabledAttribute,
NSAccessibilityValueAttribute, nil];
}
return validAXAttributes;
}
- (id)accessibilityAttributeValue:(NSString *)attribute
{
if([attribute isEqualToString:NSAccessibilityRoleAttribute]) //AXRole
return NSAccessibilityStaticTextRole;
if([attribute isEqualToString:NSAccessibilityRoleDescriptionAttribute]) //AXRoleDescription
return @"Timeline Tweet";
if([attribute isEqualToString:NSAccessibilityHelpAttribute]) //AXHelp
return @"Timeline Tweet";
if([attribute isEqualToString:NSAccessibilityValueAttribute]) { //AXValue
SRXTweetObject* tweet = (SRXTweetObject*)[self objectValue];
NSMutableString* readableString = [NSMutableString stringWithFormat:@"%@: %@", [tweet.user displayName], tweet.text];
//Removed for brevity...
return readableString;
}
return [super accessibilityAttributeValue:attribute];
}
Mickey - it's great that you are working towards making your app accessible! That's great!
You should always ignore NSAccessibilityException exceptions - and if you have special exception-handling code, you should always re-raise NSAccessibilityExceptions. They are expected to occur even if there is no problem in your application.
Why? For historic reasons, AppKit uses exceptions internally to deal with situations where an application needs to send an error back to the accessibility client.
So, you can and should safely ignore those exceptions.
Some other things to point out, scanning through the code you provided:
1. When subclassing a text field cell, it is best to let the NSAccessibilityValueAttribute keep its inherited behavior (which reports the string value of the text field). This is because there are a number of other attributes and parameterized attributes, such as AXNumberOfCharacters, AXBoundsForRange, AXAttributedStringForRange, AXStringForRange, etc, which all are based on the value of the text field.
If you return something else as the AXValue, it will confuse accessibility clients like VoiceOver.
Instead, add an NSAccessibilityDescriptionAttribute. This string can contain all of the extra information.
2. If the cell is not editable, it should already report its role as static text, and its role description should be provided automatically as well.
3. In this case, you should not provide a custom role description - the role is static text, and the element should describe its role accordingly.
4. You might want to consider getting the attributes from your superclass, and adding the additional attributes. Otherwise, if an attribute is added to text fields in the future (For instance we added AXPlaceholderValue in a recent release), then your subclass will not support it automatically.
-James
For the most part this behaves correctly except that it occasionally reads the Accessibility Content twice. While looking into this in gdb I noticed that multiple NSAccessibilityExceptions are being thrown when I turn VO on with a tweet as main focus.
2010-05-10 17:39:43.954 Syrinx[85907:a0f] NSExceptionHandler has recorded the following exception:
NSAccessibilityException -- Attempt to observe "AXTextInputMarkingSessionBegan" on non-observable element: <NSTableViewCellProxy: 0x11d4ebbf0> col:0 row:33 real element:<SRXTableCell: 0x11d51e5a0>
Stack trace: 0x7fff81c18a2c 0x7fff827510f3 0x7fff82ed19b9 0x7fff86485c45 0x7fff864839f5 0x7fff8618900b 0x7fff86192f6c 0x7fff8616f541 0x7fff82e16201 0x7fff82e148df 0x7fff85349ada 0x7fff853498df 0x7fff85349798 0x7fff86235a2a 0x7fff86235379 0x7fff861fb05b 0x7fff861f3d7c 0x100001365 0x100001314 0x1
(gdb) continue
(gdb) continue
2010-05-10 17:39:44.641 Syrinx[85907:a0f] NSExceptionHandler has recorded the following exception:
NSAccessibilityException -- Attempt to observe "AXCreated" on non-observable element: <NSTableViewCellProxy: 0x11e673ac0> col:0 row:33 real element:<SRXTableCell: 0x11d51e5a0>
Stack trace: 0x7fff81c18a2c 0x7fff827510f3 0x7fff82ed19b9 0x7fff86485c45 0x7fff864839f5 0x7fff8618900b 0x7fff86192f6c 0x7fff8616f541 0x7fff82e16201 0x7fff82e148df 0x7fff85349ada 0x7fff853498df 0x7fff85349798 0x7fff86235a2a 0x7fff86235379 0x7fff861fb05b 0x7fff861f3d7c 0x100001365 0x100001314 0x1
What am I doing wrong that is causing these exceptions, and how do I fix them?
_______________________
Mickey Roberson
MRR Software
Do not post admin requests to the list. They will be ignored.
Accessibility-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden