2012-03-23 11:54:55 -07:00
|
|
|
/* -*- Mode: Objective-C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2012-12-20 19:16:44 -08:00
|
|
|
#include "Accessible-inl.h"
|
2013-11-18 05:19:33 -08:00
|
|
|
#include "HyperTextAccessible-inl.h"
|
2012-06-29 14:12:16 -07:00
|
|
|
#include "TextLeafAccessible.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;
|
|
|
|
|
2012-04-02 10:15:00 -07:00
|
|
|
inline bool
|
|
|
|
ToNSRange(id aValue, NSRange* aRange)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aRange, "aRange is nil");
|
|
|
|
|
|
|
|
if ([aValue isKindOfClass:[NSValue class]] &&
|
|
|
|
strcmp([(NSValue*)aValue objCType], @encode(NSRange)) == 0) {
|
|
|
|
*aRange = [aValue rangeValue];
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline NSString*
|
|
|
|
ToNSString(id aValue)
|
|
|
|
{
|
|
|
|
if ([aValue isKindOfClass:[NSString class]]) {
|
|
|
|
return aValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
@interface mozTextAccessible ()
|
2007-03-22 10:30:00 -07:00
|
|
|
- (NSString*)subrole;
|
|
|
|
- (NSString*)selectedText;
|
|
|
|
- (NSValue*)selectedTextRange;
|
2012-04-02 10:15:00 -07:00
|
|
|
- (NSValue*)visibleCharacterRange;
|
2007-03-22 10:30:00 -07:00
|
|
|
- (long)textLength;
|
|
|
|
- (BOOL)isReadOnly;
|
2012-04-02 10:15:00 -07:00
|
|
|
- (NSNumber*)caretLineNumber;
|
2007-03-22 10:30:00 -07:00
|
|
|
- (void)setText:(NSString*)newText;
|
2012-01-24 13:00:24 -08:00
|
|
|
- (NSString*)text;
|
2012-04-02 10:15:00 -07:00
|
|
|
- (NSString*)stringFromRange:(NSRange*)range;
|
2007-03-22 10:30:00 -07:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation mozTextAccessible
|
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
- (id)initWithAccessible:(AccessibleWrap*)accessible
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
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])) {
|
2012-06-19 16:01:10 -07:00
|
|
|
mGeckoTextAccessible = accessible->AsHyperText();
|
2007-03-22 10:30:00 -07:00
|
|
|
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
|
|
|
|
{
|
2012-06-29 14:12:02 -07:00
|
|
|
return !mGeckoAccessible;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray*)accessibilityAttributeNames
|
|
|
|
{
|
2008-02-22 12:13:17 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
|
|
|
|
|
2012-04-02 10:15:00 -07:00
|
|
|
static NSMutableArray* supportedAttributes = nil;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!supportedAttributes) {
|
2012-04-02 10:15:00 -07:00
|
|
|
// text-specific attributes to supplement the standard one
|
|
|
|
supportedAttributes = [[NSMutableArray alloc] initWithObjects:
|
|
|
|
NSAccessibilitySelectedTextAttribute, // required
|
|
|
|
NSAccessibilitySelectedTextRangeAttribute, // required
|
|
|
|
NSAccessibilityNumberOfCharactersAttribute, // required
|
|
|
|
NSAccessibilityVisibleCharacterRangeAttribute, // required
|
|
|
|
NSAccessibilityInsertionPointLineNumberAttribute,
|
2012-04-24 13:07:17 -07:00
|
|
|
@"AXRequired",
|
|
|
|
@"AXInvalid",
|
2012-04-02 10:15:00 -07:00
|
|
|
nil
|
|
|
|
];
|
|
|
|
[supportedAttributes addObjectsFromArray:[super accessibilityAttributeNames]];
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
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]];
|
2012-04-02 10:15:00 -07:00
|
|
|
|
|
|
|
if ([attribute isEqualToString:NSAccessibilityInsertionPointLineNumberAttribute])
|
|
|
|
return [self caretLineNumber];
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if ([attribute isEqualToString:NSAccessibilitySelectedTextRangeAttribute])
|
|
|
|
return [self selectedTextRange];
|
2012-04-02 10:15:00 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if ([attribute isEqualToString:NSAccessibilitySelectedTextAttribute])
|
|
|
|
return [self selectedText];
|
2012-04-02 10:15:00 -07:00
|
|
|
|
2012-06-29 14:12:16 -07:00
|
|
|
if ([attribute isEqualToString:NSAccessibilityTitleAttribute])
|
|
|
|
return @"";
|
|
|
|
|
2012-04-02 10:15:00 -07:00
|
|
|
if ([attribute isEqualToString:NSAccessibilityValueAttribute]) {
|
|
|
|
// Apple's SpeechSynthesisServer expects AXValue to return an AXStaticText
|
|
|
|
// object's AXSelectedText attribute. See bug 674612 for details.
|
|
|
|
// Also if there is no selected text, we return the full text.
|
|
|
|
// See bug 369710 for details.
|
2012-06-29 14:12:16 -07:00
|
|
|
if ([[self role] isEqualToString:NSAccessibilityStaticTextRole]) {
|
|
|
|
NSString* selectedText = [self selectedText];
|
|
|
|
return (selectedText && [selectedText length]) ? selectedText : [self text];
|
|
|
|
}
|
2012-04-02 10:15:00 -07:00
|
|
|
|
|
|
|
return [self text];
|
|
|
|
}
|
|
|
|
|
2012-04-24 13:07:17 -07:00
|
|
|
if ([attribute isEqualToString:@"AXRequired"])
|
|
|
|
return [NSNumber numberWithBool:!!(mGeckoAccessible->State() & states::REQUIRED)];
|
|
|
|
|
|
|
|
if ([attribute isEqualToString:@"AXInvalid"])
|
|
|
|
return [NSNumber numberWithBool:!!(mGeckoAccessible->State() & states::INVALID)];
|
|
|
|
|
2012-04-02 10:15:00 -07:00
|
|
|
if ([attribute isEqualToString:NSAccessibilityVisibleCharacterRangeAttribute])
|
|
|
|
return [self visibleCharacterRange];
|
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
|
|
|
}
|
|
|
|
|
2012-04-02 10:15:00 -07:00
|
|
|
- (NSArray*)accessibilityParameterizedAttributeNames
|
|
|
|
{
|
|
|
|
static NSArray* supportedParametrizedAttributes = nil;
|
|
|
|
// text specific parametrized attributes
|
|
|
|
if (!supportedParametrizedAttributes) {
|
|
|
|
supportedParametrizedAttributes = [[NSArray alloc] initWithObjects:
|
|
|
|
NSAccessibilityStringForRangeParameterizedAttribute,
|
|
|
|
NSAccessibilityLineForIndexParameterizedAttribute,
|
|
|
|
NSAccessibilityRangeForLineParameterizedAttribute,
|
|
|
|
NSAccessibilityAttributedStringForRangeParameterizedAttribute,
|
|
|
|
NSAccessibilityBoundsForRangeParameterizedAttribute,
|
|
|
|
#if DEBUG
|
|
|
|
NSAccessibilityRangeForPositionParameterizedAttribute,
|
|
|
|
NSAccessibilityRangeForIndexParameterizedAttribute,
|
|
|
|
NSAccessibilityRTFForRangeParameterizedAttribute,
|
|
|
|
NSAccessibilityStyleRangeForIndexParameterizedAttribute,
|
|
|
|
#endif
|
|
|
|
nil
|
|
|
|
];
|
|
|
|
}
|
|
|
|
return supportedParametrizedAttributes;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id)accessibilityAttributeValue:(NSString*)attribute forParameter:(id)parameter
|
|
|
|
{
|
|
|
|
if (!mGeckoTextAccessible)
|
|
|
|
return nil;
|
|
|
|
|
|
|
|
if ([attribute isEqualToString:NSAccessibilityStringForRangeParameterizedAttribute]) {
|
|
|
|
NSRange range;
|
|
|
|
if (!ToNSRange(parameter, &range)) {
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"%@: range not set", attribute);
|
|
|
|
#endif
|
|
|
|
return @"";
|
|
|
|
}
|
|
|
|
|
|
|
|
return [self stringFromRange:&range];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ([attribute isEqualToString:NSAccessibilityRangeForLineParameterizedAttribute]) {
|
|
|
|
// XXX: actually get the integer value for the line #
|
|
|
|
return [NSValue valueWithRange:NSMakeRange(0, [self textLength])];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ([attribute isEqualToString:NSAccessibilityAttributedStringForRangeParameterizedAttribute]) {
|
|
|
|
NSRange range;
|
|
|
|
if (!ToNSRange(parameter, &range)) {
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"%@: range not set", attribute);
|
|
|
|
#endif
|
|
|
|
return @"";
|
|
|
|
}
|
|
|
|
|
|
|
|
return [[[NSAttributedString alloc] initWithString:[self stringFromRange:&range]] autorelease];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ([attribute isEqualToString:NSAccessibilityLineForIndexParameterizedAttribute]) {
|
|
|
|
// XXX: actually return the line #
|
|
|
|
return [NSNumber numberWithInt:0];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ([attribute isEqualToString:NSAccessibilityBoundsForRangeParameterizedAttribute]) {
|
|
|
|
NSRange range;
|
|
|
|
if (!ToNSRange(parameter, &range)) {
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"%@:no range", attribute);
|
|
|
|
#endif
|
|
|
|
return nil;
|
|
|
|
}
|
2013-11-18 05:19:33 -08:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t start = range.location;
|
|
|
|
int32_t end = start + range.length;
|
2013-11-18 05:19:33 -08:00
|
|
|
nsIntRect bounds = mGeckoTextAccessible->TextBounds(start, end);
|
2012-04-02 10:15:00 -07:00
|
|
|
|
|
|
|
return [NSValue valueWithRect:nsCocoaUtils::GeckoRectToCocoaRect(bounds)];
|
|
|
|
}
|
|
|
|
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"unhandled attribute:%@ forParameter:%@", attribute, parameter);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return 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])
|
2012-06-29 14:12:16 -07:00
|
|
|
return ![self isReadOnly];
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-04-02 10:15:00 -07:00
|
|
|
if ([attribute isEqualToString:NSAccessibilitySelectedTextAttribute] ||
|
|
|
|
[attribute isEqualToString:NSAccessibilitySelectedTextRangeAttribute] ||
|
|
|
|
[attribute isEqualToString:NSAccessibilityVisibleCharacterRangeAttribute])
|
|
|
|
return YES;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
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;
|
|
|
|
|
2012-04-02 10:15:00 -07:00
|
|
|
if (!mGeckoTextAccessible)
|
|
|
|
return;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if ([attribute isEqualToString:NSAccessibilityValueAttribute]) {
|
2012-04-02 10:15:00 -07:00
|
|
|
[self setText:ToNSString(value)];
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ([attribute isEqualToString:NSAccessibilitySelectedTextAttribute]) {
|
2012-04-02 10:16:12 -07:00
|
|
|
NSString* stringValue = ToNSString(value);
|
|
|
|
if (!stringValue)
|
|
|
|
return;
|
|
|
|
|
2013-11-18 05:19:33 -08:00
|
|
|
int32_t start = 0, end = 0;
|
|
|
|
mGeckoTextAccessible->SelectionBoundsAt(0, &start, &end);
|
|
|
|
mGeckoTextAccessible->DeleteText(start, end - start);
|
2012-04-02 10:16:12 -07:00
|
|
|
|
|
|
|
nsString text;
|
|
|
|
nsCocoaUtils::GetStringForNSString(stringValue, text);
|
2013-11-18 05:19:33 -08:00
|
|
|
mGeckoTextAccessible->InsertText(text, start);
|
2012-04-02 10:15:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if ([attribute isEqualToString:NSAccessibilitySelectedTextRangeAttribute]) {
|
|
|
|
NSRange range;
|
|
|
|
if (!ToNSRange(value, &range))
|
|
|
|
return;
|
|
|
|
|
2013-11-18 05:19:33 -08:00
|
|
|
mGeckoTextAccessible->SetSelectionBoundsAt(0, range.location,
|
|
|
|
range.location + range.length);
|
2012-04-02 10:15:00 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ([attribute isEqualToString:NSAccessibilityVisibleCharacterRangeAttribute]) {
|
|
|
|
NSRange range;
|
|
|
|
if (!ToNSRange(value, &range))
|
|
|
|
return;
|
|
|
|
|
|
|
|
mGeckoTextAccessible->ScrollSubstringTo(range.location, range.location + range.length,
|
|
|
|
nsIAccessibleScrollType::SCROLL_TYPE_TOP_EDGE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
[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
|
|
|
|
{
|
2012-04-12 11:02:25 -07:00
|
|
|
if(mRole == roles::PASSWORD_TEXT)
|
|
|
|
return NSAccessibilitySecureTextFieldSubrole;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)expire
|
|
|
|
{
|
2008-02-22 12:13:17 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
mGeckoTextAccessible = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-04-02 10:15:00 -07:00
|
|
|
- (NSNumber*)caretLineNumber
|
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t lineNumber = mGeckoTextAccessible ?
|
2012-04-02 10:15:00 -07:00
|
|
|
mGeckoTextAccessible->CaretLineNumber() - 1 : -1;
|
|
|
|
|
|
|
|
return (lineNumber >= 0) ? [NSNumber numberWithInt:lineNumber] : nil;
|
|
|
|
}
|
|
|
|
|
2012-04-03 12:39:38 -07:00
|
|
|
- (void)setText:(NSString*)aNewString
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-02-22 12:13:17 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mGeckoEditableTextAccessible) {
|
2012-04-03 12:39:38 -07:00
|
|
|
nsString text;
|
|
|
|
nsCocoaUtils::GetStringForNSString(aNewString, text);
|
|
|
|
mGeckoEditableTextAccessible->SetTextContents(text);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
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
|
|
|
|
{
|
2012-06-29 14:12:16 -07:00
|
|
|
if (!mGeckoAccessible || !mGeckoTextAccessible)
|
2012-01-24 13:00:24 -08:00
|
|
|
return nil;
|
2012-04-12 11:02:25 -07:00
|
|
|
|
|
|
|
// A password text field returns an empty value
|
|
|
|
if (mRole == roles::PASSWORD_TEXT)
|
|
|
|
return @"";
|
|
|
|
|
2012-01-24 13:00:24 -08:00
|
|
|
nsAutoString text;
|
2013-11-18 05:19:33 -08:00
|
|
|
mGeckoTextAccessible->TextSubstring(0,
|
|
|
|
nsIAccessibleText::TEXT_OFFSET_END_OF_TEXT,
|
|
|
|
text);
|
2012-04-03 12:39:38 -07:00
|
|
|
return nsCocoaUtils::ToNSString(text);
|
2012-01-24 13:00:24 -08:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2012-06-29 14:12:16 -07:00
|
|
|
if (!mGeckoAccessible || !mGeckoTextAccessible)
|
|
|
|
return 0;
|
|
|
|
|
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) {
|
2013-11-18 05:19:33 -08:00
|
|
|
int32_t start = 0, end = 0;
|
|
|
|
mGeckoTextAccessible->SelectionBoundsAt(0, &start, &end);
|
2007-03-22 10:30:00 -07:00
|
|
|
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) {
|
2013-11-18 05:19:33 -08:00
|
|
|
int32_t start = 0, end = 0;
|
|
|
|
mGeckoTextAccessible->SelectionBoundsAt(0, &start, &end);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (start != end) {
|
|
|
|
nsAutoString selText;
|
2013-11-18 05:19:33 -08:00
|
|
|
mGeckoTextAccessible->TextSubstring(start, end, selText);
|
2012-04-03 12:39:38 -07:00
|
|
|
return nsCocoaUtils::ToNSString(selText);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
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) {
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t start = 0;
|
|
|
|
int32_t end = 0;
|
2013-11-18 05:19:33 -08:00
|
|
|
int32_t count = mGeckoTextAccessible->SelectionCount();
|
2012-04-02 10:15:00 -07:00
|
|
|
|
|
|
|
if (count) {
|
2013-11-18 05:19:33 -08:00
|
|
|
mGeckoTextAccessible->SelectionBoundsAt(0, &start, &end);
|
2012-04-02 10:15:00 -07:00
|
|
|
return [NSValue valueWithRange:NSMakeRange(start, end - start)];
|
|
|
|
}
|
|
|
|
|
2013-11-18 05:19:33 -08:00
|
|
|
start = mGeckoTextAccessible->CaretOffset();
|
2012-04-02 10:15:00 -07:00
|
|
|
return [NSValue valueWithRange:NSMakeRange(start != -1 ? start : 0, 0)];
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-04-02 10:15:00 -07:00
|
|
|
return [NSValue valueWithRange:NSMakeRange(0, 0)];
|
2008-02-22 12:13:17 -08:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-04-02 10:15:00 -07:00
|
|
|
- (NSValue*)visibleCharacterRange
|
|
|
|
{
|
|
|
|
// XXX this won't work with Textarea and such as we actually don't give
|
|
|
|
// the visible character range.
|
|
|
|
return [NSValue valueWithRange:
|
|
|
|
NSMakeRange(0, mGeckoTextAccessible ?
|
|
|
|
mGeckoTextAccessible->CharacterCount() : 0)];
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
- (void)valueDidChange
|
|
|
|
{
|
2008-02-22 12:13:17 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2012-03-23 11:54:55 -07:00
|
|
|
NSAccessibilityPostNotification(GetObjectOrRepresentedView(self),
|
2007-03-22 10:30:00 -07:00
|
|
|
NSAccessibilityValueChangedNotification);
|
2008-02-22 12:13:17 -08:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-04-02 10:15:00 -07:00
|
|
|
- (void)selectedTextDidChange
|
|
|
|
{
|
|
|
|
NSAccessibilityPostNotification(GetObjectOrRepresentedView(self),
|
|
|
|
NSAccessibilitySelectedTextChangedNotification);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString*)stringFromRange:(NSRange*)range
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(mGeckoTextAccessible && range, "no Gecko text accessible or range");
|
|
|
|
|
|
|
|
nsAutoString text;
|
2013-11-18 05:19:33 -08:00
|
|
|
mGeckoTextAccessible->TextSubstring(range->location,
|
|
|
|
range->location + range->length, text);
|
2012-04-02 10:15:00 -07:00
|
|
|
return nsCocoaUtils::ToNSString(text);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
@end
|
2012-06-29 14:12:16 -07:00
|
|
|
|
|
|
|
@implementation mozTextLeafAccessible
|
|
|
|
|
|
|
|
- (NSArray*)accessibilityAttributeNames
|
|
|
|
{
|
|
|
|
static NSMutableArray* supportedAttributes = nil;
|
|
|
|
if (!supportedAttributes) {
|
|
|
|
supportedAttributes = [[super accessibilityAttributeNames] mutableCopy];
|
|
|
|
[supportedAttributes removeObject:NSAccessibilityChildrenAttribute];
|
|
|
|
}
|
|
|
|
|
|
|
|
return supportedAttributes;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id)accessibilityAttributeValue:(NSString*)attribute
|
|
|
|
{
|
|
|
|
if ([attribute isEqualToString:NSAccessibilityTitleAttribute])
|
|
|
|
return @"";
|
|
|
|
|
|
|
|
if ([attribute isEqualToString:NSAccessibilityValueAttribute])
|
|
|
|
return [self text];
|
|
|
|
|
|
|
|
return [super accessibilityAttributeValue:attribute];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString*)text
|
|
|
|
{
|
|
|
|
if (!mGeckoAccessible)
|
|
|
|
return nil;
|
|
|
|
|
|
|
|
return nsCocoaUtils::ToNSString(mGeckoAccessible->AsTextLeaf()->Text());
|
|
|
|
}
|
|
|
|
|
|
|
|
- (long)textLength
|
|
|
|
{
|
|
|
|
if (!mGeckoAccessible)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return mGeckoAccessible->AsTextLeaf()->Text().Length();
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|