2007-03-22 10:30:00 -07:00
|
|
|
#include "nsAccessibleWrap.h"
|
2012-01-24 13:00:24 -08:00
|
|
|
|
|
|
|
#include "nsCocoaUtils.h"
|
2008-02-22 12:13:17 -08:00
|
|
|
#include "nsObjCExceptions.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#import "mozTextAccessible.h"
|
|
|
|
|
2011-07-27 05:43:01 -07:00
|
|
|
using namespace mozilla::a11y;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
@interface mozTextAccessible (Private)
|
|
|
|
- (NSString*)subrole;
|
|
|
|
- (NSString*)selectedText;
|
|
|
|
- (NSValue*)selectedTextRange;
|
|
|
|
- (long)textLength;
|
|
|
|
- (BOOL)isReadOnly;
|
|
|
|
- (void)setText:(NSString*)newText;
|
2012-01-24 13:00:24 -08:00
|
|
|
- (NSString*)text;
|
2007-03-22 10:30:00 -07:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation mozTextAccessible
|
|
|
|
|
|
|
|
- (id)initWithAccessible:(nsAccessibleWrap*)accessible
|
|
|
|
{
|
2008-02-22 12:13:17 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if ((self = [super initWithAccessible:accessible])) {
|
|
|
|
CallQueryInterface(accessible, &mGeckoTextAccessible);
|
|
|
|
CallQueryInterface(accessible, &mGeckoEditableTextAccessible);
|
|
|
|
}
|
|
|
|
return self;
|
2008-02-22 12:13:17 -08:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)accessibilityIsIgnored
|
|
|
|
{
|
|
|
|
return mIsExpired;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray*)accessibilityAttributeNames
|
|
|
|
{
|
2008-02-22 12:13:17 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
static NSArray *supportedAttributes = nil;
|
|
|
|
if (!supportedAttributes) {
|
|
|
|
// standard attributes that are shared and supported by all generic elements.
|
|
|
|
supportedAttributes = [[NSArray alloc] initWithObjects:NSAccessibilityParentAttribute, // required
|
|
|
|
NSAccessibilityRoleAttribute, // required
|
|
|
|
NSAccessibilityTitleAttribute,
|
|
|
|
NSAccessibilityValueAttribute, // required
|
|
|
|
NSAccessibilitySubroleAttribute,
|
|
|
|
NSAccessibilityRoleDescriptionAttribute,
|
|
|
|
NSAccessibilityPositionAttribute, // required
|
|
|
|
NSAccessibilitySizeAttribute, // required
|
|
|
|
NSAccessibilityWindowAttribute, // required
|
|
|
|
NSAccessibilityFocusedAttribute, // required
|
|
|
|
NSAccessibilityEnabledAttribute, // required
|
2011-12-08 23:25:25 -08:00
|
|
|
NSAccessibilityTopLevelUIElementAttribute, // required
|
|
|
|
NSAccessibilityDescriptionAttribute, // required
|
2007-03-22 10:30:00 -07:00
|
|
|
/* text-specific attributes */
|
|
|
|
NSAccessibilitySelectedTextAttribute, // required
|
|
|
|
NSAccessibilitySelectedTextRangeAttribute, // required
|
|
|
|
NSAccessibilityNumberOfCharactersAttribute, // required
|
|
|
|
// TODO: NSAccessibilityVisibleCharacterRangeAttribute, // required
|
|
|
|
// TODO: NSAccessibilityInsertionPointLineNumberAttribute
|
2012-01-27 07:50:04 -08:00
|
|
|
#if DEBUG
|
|
|
|
@"AXMozDescription",
|
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
nil];
|
|
|
|
}
|
|
|
|
return supportedAttributes;
|
2008-02-22 12:13:17 -08:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (id)accessibilityAttributeValue:(NSString*)attribute
|
|
|
|
{
|
2008-02-22 12:13:17 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if ([attribute isEqualToString:NSAccessibilityNumberOfCharactersAttribute])
|
|
|
|
return [NSNumber numberWithInt:[self textLength]];
|
|
|
|
if ([attribute isEqualToString:NSAccessibilitySelectedTextRangeAttribute])
|
|
|
|
return [self selectedTextRange];
|
|
|
|
if ([attribute isEqualToString:NSAccessibilitySelectedTextAttribute])
|
|
|
|
return [self selectedText];
|
2011-09-27 08:38:44 -07:00
|
|
|
// Apple's SpeechSynthesisServer expects AXValue to return an AXStaticText
|
|
|
|
// object's AXSelectedText attribute. See bug 674612.
|
2012-01-24 13:00:24 -08:00
|
|
|
// Also if there is no selected text, we return the full text.See bug 369710
|
2011-09-27 08:38:44 -07:00
|
|
|
if ([attribute isEqualToString:NSAccessibilityValueAttribute])
|
2012-01-24 13:00:24 -08:00
|
|
|
return [self selectedText] ? : [self text];
|
2011-09-27 08:38:44 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// let mozAccessible handle all other attributes
|
|
|
|
return [super accessibilityAttributeValue:attribute];
|
2008-02-22 12:13:17 -08:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)accessibilityIsAttributeSettable:(NSString*)attribute
|
|
|
|
{
|
2008-02-22 12:13:17 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if ([attribute isEqualToString:NSAccessibilityValueAttribute])
|
|
|
|
return [self isReadOnly];
|
|
|
|
|
|
|
|
return [super accessibilityIsAttributeSettable:attribute];
|
2008-02-22 12:13:17 -08:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(NO);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)accessibilitySetValue:(id)value forAttribute:(NSString *)attribute
|
|
|
|
{
|
2008-02-22 12:13:17 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if ([attribute isEqualToString:NSAccessibilityValueAttribute]) {
|
|
|
|
if ([value isKindOfClass:[NSString class]])
|
|
|
|
[self setText:(NSString*)value];
|
|
|
|
} else
|
|
|
|
[super accessibilitySetValue:value forAttribute:attribute];
|
2008-02-22 12:13:17 -08:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString*)subrole
|
|
|
|
{
|
|
|
|
// TODO: text accessibles have two different subroles in Cocoa: secure textfield (passwords) and search field
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)expire
|
|
|
|
{
|
2008-02-22 12:13:17 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IF_RELEASE(mGeckoTextAccessible);
|
|
|
|
NS_IF_RELEASE(mGeckoEditableTextAccessible);
|
|
|
|
[super expire];
|
2008-02-22 12:13:17 -08:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
|
|
|
- (BOOL)isReadOnly
|
|
|
|
{
|
2008-02-22 12:13:17 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if ([[self role] isEqualToString:NSAccessibilityStaticTextRole])
|
|
|
|
return YES;
|
|
|
|
|
2011-04-09 16:38:06 -07:00
|
|
|
if (mGeckoEditableTextAccessible)
|
2011-04-11 08:50:15 -07:00
|
|
|
return (mGeckoAccessible->State() & states::READONLY) == 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NO;
|
2008-02-22 12:13:17 -08:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(NO);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setText:(NSString*)newString
|
|
|
|
{
|
2008-02-22 12:13:17 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mGeckoEditableTextAccessible) {
|
|
|
|
mGeckoEditableTextAccessible->SetTextContents(NS_ConvertUTF8toUTF16([newString UTF8String]));
|
|
|
|
}
|
2008-02-22 12:13:17 -08:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-01-24 13:00:24 -08:00
|
|
|
- (NSString*)text
|
|
|
|
{
|
|
|
|
if (!mGeckoTextAccessible)
|
|
|
|
return nil;
|
|
|
|
|
|
|
|
nsAutoString text;
|
|
|
|
nsresult rv =
|
|
|
|
mGeckoTextAccessible->GetText(0, nsIAccessibleText::TEXT_OFFSET_END_OF_TEXT,
|
|
|
|
text);
|
|
|
|
NS_ENSURE_SUCCESS(rv, nil);
|
|
|
|
|
|
|
|
return text.IsEmpty() ? nil : nsCocoaUtils::ToNSString(text);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
- (long)textLength
|
|
|
|
{
|
2008-02-22 12:13:17 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
|
|
|
|
|
2011-01-24 19:33:47 -08:00
|
|
|
return mGeckoTextAccessible ? mGeckoTextAccessible->CharacterCount() : 0;
|
2008-02-22 12:13:17 -08:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(0);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (long)selectedTextLength
|
|
|
|
{
|
2008-02-22 12:13:17 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mGeckoTextAccessible) {
|
|
|
|
PRInt32 start, end;
|
|
|
|
start = end = 0;
|
|
|
|
mGeckoTextAccessible->GetSelectionBounds(0, &start, &end);
|
|
|
|
return (end - start);
|
|
|
|
}
|
|
|
|
return 0;
|
2008-02-22 12:13:17 -08:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(0);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString*)selectedText
|
|
|
|
{
|
2008-02-22 12:13:17 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mGeckoTextAccessible) {
|
|
|
|
PRInt32 start, end;
|
|
|
|
start = end = 0;
|
|
|
|
mGeckoTextAccessible->GetSelectionBounds(0, &start, &end);
|
|
|
|
if (start != end) {
|
|
|
|
nsAutoString selText;
|
|
|
|
mGeckoTextAccessible->GetText(start, end, selText);
|
|
|
|
return selText.IsEmpty() ? nil : [NSString stringWithCharacters:selText.BeginReading() length:selText.Length()];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil;
|
2008-02-22 12:13:17 -08:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSValue*)selectedTextRange
|
|
|
|
{
|
2008-02-22 12:13:17 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mGeckoTextAccessible) {
|
|
|
|
PRInt32 start, end;
|
|
|
|
start = end = 0;
|
|
|
|
mGeckoTextAccessible->GetSelectionBounds(0, &start, &end);
|
|
|
|
return [NSValue valueWithRange:NSMakeRange(start, start-end)];
|
|
|
|
}
|
|
|
|
return nil;
|
2008-02-22 12:13:17 -08:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
|
|
|
- (void)valueDidChange
|
|
|
|
{
|
2008-02-22 12:13:17 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NSAccessibilityPostNotification([self hasRepresentedView] ? [self representedView] : self,
|
|
|
|
NSAccessibilityValueChangedNotification);
|
2008-02-22 12:13:17 -08:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation mozComboboxAccessible
|
|
|
|
|
|
|
|
- (NSArray*)accessibilityAttributeNames
|
|
|
|
{
|
2008-02-22 12:13:17 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
static NSArray *supportedAttributes = nil;
|
|
|
|
if (!supportedAttributes) {
|
|
|
|
// standard attributes that are shared and supported by all generic elements.
|
|
|
|
supportedAttributes = [[NSArray alloc] initWithObjects:NSAccessibilityParentAttribute, // required
|
|
|
|
NSAccessibilityRoleAttribute, // required
|
|
|
|
NSAccessibilityTitleAttribute,
|
|
|
|
NSAccessibilityValueAttribute, // required
|
|
|
|
NSAccessibilityHelpAttribute,
|
|
|
|
NSAccessibilityRoleDescriptionAttribute,
|
|
|
|
NSAccessibilityPositionAttribute, // required
|
|
|
|
NSAccessibilitySizeAttribute, // required
|
|
|
|
NSAccessibilityWindowAttribute, // required
|
|
|
|
NSAccessibilityFocusedAttribute, // required
|
|
|
|
NSAccessibilityEnabledAttribute, // required
|
|
|
|
NSAccessibilityChildrenAttribute, // required
|
|
|
|
NSAccessibilityHelpAttribute,
|
|
|
|
// NSAccessibilityExpandedAttribute, // required
|
2011-12-08 23:25:25 -08:00
|
|
|
NSAccessibilityTopLevelUIElementAttribute, // required
|
|
|
|
NSAccessibilityDescriptionAttribute, // required
|
2007-03-22 10:30:00 -07:00
|
|
|
/* text-specific attributes */
|
|
|
|
NSAccessibilitySelectedTextAttribute, // required
|
|
|
|
NSAccessibilitySelectedTextRangeAttribute, // required
|
|
|
|
NSAccessibilityNumberOfCharactersAttribute, // required
|
|
|
|
// TODO: NSAccessibilityVisibleCharacterRangeAttribute, // required
|
|
|
|
// TODO: NSAccessibilityInsertionPointLineNumberAttribute
|
2012-01-27 07:50:04 -08:00
|
|
|
#if DEBUG
|
|
|
|
@"AXMozDescription",
|
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
nil];
|
|
|
|
}
|
|
|
|
return supportedAttributes;
|
2008-02-22 12:13:17 -08:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *)accessibilityActionNames
|
|
|
|
{
|
2008-02-22 12:13:17 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if ([self isEnabled]) {
|
2007-03-27 07:07:09 -07:00
|
|
|
return [NSArray arrayWithObjects:NSAccessibilityConfirmAction,
|
|
|
|
NSAccessibilityShowMenuAction,
|
2007-03-22 10:30:00 -07:00
|
|
|
nil];
|
|
|
|
}
|
|
|
|
return nil;
|
2008-02-22 12:13:17 -08:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *)accessibilityActionDescription:(NSString *)action
|
|
|
|
{
|
2008-02-22 12:13:17 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if ([action isEqualToString:NSAccessibilityShowMenuAction])
|
|
|
|
return @"show menu";
|
|
|
|
if ([action isEqualToString:NSAccessibilityConfirmAction])
|
|
|
|
return @"confirm";
|
|
|
|
|
|
|
|
return [super accessibilityActionDescription:action];
|
2008-02-22 12:13:17 -08:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)accessibilityPerformAction:(NSString *)action
|
|
|
|
{
|
2008-02-22 12:13:17 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// both the ShowMenu and Click action do the same thing.
|
|
|
|
if ([self isEnabled]) {
|
|
|
|
if ([action isEqualToString:NSAccessibilityShowMenuAction])
|
|
|
|
[self showMenu];
|
|
|
|
if ([action isEqualToString:NSAccessibilityConfirmAction])
|
|
|
|
[self confirm];
|
|
|
|
}
|
2008-02-22 12:13:17 -08:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)showMenu
|
|
|
|
{
|
|
|
|
// currently unimplemented. waiting for support in bug 363697
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)confirm
|
|
|
|
{
|
|
|
|
// should be the same as pressing enter/return in this textfield.
|
|
|
|
// not yet implemented
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|