2012-03-23 11:54:55 -07:00
|
|
|
/* -*- Mode: Objective-C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
|
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;
|
|
|
|
|
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
|
|
|
|
|
|
|
|
- (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;
|
|
|
|
|
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,
|
|
|
|
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
|
|
|
|
|
|
|
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.
|
|
|
|
if ([[self role] isEqualToString:NSAccessibilityStaticTextRole])
|
|
|
|
return [self selectedText] ? : [self text];
|
|
|
|
|
|
|
|
return [self text];
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 start = range.location;
|
|
|
|
PRInt32 end = start + range.length;
|
|
|
|
nsIntRect bounds = mGeckoTextAccessible->GetTextBounds(start, end);
|
|
|
|
|
|
|
|
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])
|
|
|
|
return [self isReadOnly];
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
PRInt32 start = 0;
|
|
|
|
PRInt32 end = 0;
|
|
|
|
|
|
|
|
nsresult rv = mGeckoTextAccessible->GetSelectionBounds(0, &start, &end);
|
|
|
|
NS_ENSURE_SUCCESS(rv,);
|
|
|
|
|
|
|
|
rv = mGeckoTextAccessible->DeleteText(start, end - start);
|
|
|
|
NS_ENSURE_SUCCESS(rv,);
|
|
|
|
|
|
|
|
nsString text;
|
|
|
|
nsCocoaUtils::GetStringForNSString(stringValue, text);
|
|
|
|
rv = mGeckoTextAccessible->InsertText(text, start);
|
|
|
|
NS_ENSURE_SUCCESS(rv,);
|
|
|
|
|
2012-04-02 10:15:00 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ([attribute isEqualToString:NSAccessibilitySelectedTextRangeAttribute]) {
|
|
|
|
NSRange range;
|
|
|
|
if (!ToNSRange(value, &range))
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsresult rv = mGeckoTextAccessible->SetSelectionBounds(0, range.location,
|
|
|
|
range.location + range.length);
|
|
|
|
NS_ENSURE_SUCCESS(rv,);
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
// 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
|
|
|
}
|
|
|
|
|
2012-04-02 10:15:00 -07:00
|
|
|
- (NSNumber*)caretLineNumber
|
|
|
|
{
|
|
|
|
PRInt32 lineNumber = mGeckoTextAccessible ?
|
|
|
|
mGeckoTextAccessible->CaretLineNumber() - 1 : -1;
|
|
|
|
|
|
|
|
return (lineNumber >= 0) ? [NSNumber numberWithInt:lineNumber] : nil;
|
|
|
|
}
|
|
|
|
|
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;
|
2012-04-02 10:15:00 -07:00
|
|
|
nsresult rv = mGeckoTextAccessible->GetSelectionBounds(0, &start, &end);
|
|
|
|
NS_ENSURE_SUCCESS(rv, 0);
|
|
|
|
|
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) {
|
|
|
|
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) {
|
2012-04-02 10:15:00 -07:00
|
|
|
PRInt32 start = 0;
|
|
|
|
PRInt32 end = 0;
|
|
|
|
PRInt32 count = 0;
|
|
|
|
|
|
|
|
nsresult rv = mGeckoTextAccessible->GetSelectionCount(&count);
|
|
|
|
NS_ENSURE_SUCCESS(rv, nil);
|
|
|
|
|
|
|
|
if (count) {
|
|
|
|
rv = mGeckoTextAccessible->GetSelectionBounds(0, &start, &end);
|
|
|
|
NS_ENSURE_SUCCESS(rv, nil);
|
|
|
|
|
|
|
|
return [NSValue valueWithRange:NSMakeRange(start, end - start)];
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = mGeckoTextAccessible->GetCaretOffset(&start);
|
|
|
|
NS_ENSURE_SUCCESS(rv, nil);
|
|
|
|
|
|
|
|
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;
|
|
|
|
mGeckoTextAccessible->GetText(range->location,
|
|
|
|
range->location + range->length, text);
|
|
|
|
return nsCocoaUtils::ToNSString(text);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
@end
|