2012-03-23 22:54:55 +04:00
|
|
|
/* -*- Mode: Objective-C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04: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-21 07:16:44 +04:00
|
|
|
#include "Accessible-inl.h"
|
2013-11-18 17:19:33 +04:00
|
|
|
#include "HyperTextAccessible-inl.h"
|
2012-06-30 01:12:16 +04:00
|
|
|
#include "TextLeafAccessible.h"
|
2012-01-25 01:00:24 +04:00
|
|
|
|
|
|
|
#include "nsCocoaUtils.h"
|
2008-02-22 23:13:17 +03:00
|
|
|
#include "nsObjCExceptions.h"
|
2006-11-15 14:08:14 +03:00
|
|
|
|
|
|
|
#import "mozTextAccessible.h"
|
|
|
|
|
2011-07-27 16:43:01 +04:00
|
|
|
using namespace mozilla::a11y;
|
|
|
|
|
2012-04-02 21:15:00 +04:00
|
|
|
inline bool
|
|
|
|
ToNSRange(id aValue, NSRange* aRange)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aRange, "aRange is nil");
|
|
|
|
|
2015-06-08 17:59:19 +03:00
|
|
|
if ([aValue isKindOfClass:[NSValue class]] &&
|
2012-04-02 21:15:00 +04:00
|
|
|
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 ()
|
2006-11-15 14:08:14 +03:00
|
|
|
- (NSString*)subrole;
|
|
|
|
- (NSString*)selectedText;
|
|
|
|
- (NSValue*)selectedTextRange;
|
2012-04-02 21:15:00 +04:00
|
|
|
- (NSValue*)visibleCharacterRange;
|
2006-11-15 14:08:14 +03:00
|
|
|
- (long)textLength;
|
|
|
|
- (BOOL)isReadOnly;
|
2012-04-02 21:15:00 +04:00
|
|
|
- (NSNumber*)caretLineNumber;
|
2006-11-15 14:08:14 +03:00
|
|
|
- (void)setText:(NSString*)newText;
|
2012-01-25 01:00:24 +04:00
|
|
|
- (NSString*)text;
|
2012-04-02 21:15:00 +04:00
|
|
|
- (NSString*)stringFromRange:(NSRange*)range;
|
2006-11-15 14:08:14 +03:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation mozTextAccessible
|
|
|
|
|
|
|
|
- (BOOL)accessibilityIsIgnored
|
|
|
|
{
|
2015-07-17 00:35:29 +03:00
|
|
|
return ![self getGeckoAccessible] && ![self getProxyAccessible];
|
2006-11-15 14:08:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray*)accessibilityAttributeNames
|
|
|
|
{
|
2008-02-22 23:13:17 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
|
|
|
|
|
2012-04-02 21:15:00 +04:00
|
|
|
static NSMutableArray* supportedAttributes = nil;
|
2006-11-15 14:08:14 +03:00
|
|
|
if (!supportedAttributes) {
|
2012-04-02 21:15:00 +04:00
|
|
|
// text-specific attributes to supplement the standard one
|
|
|
|
supportedAttributes = [[NSMutableArray alloc] initWithObjects:
|
|
|
|
NSAccessibilitySelectedTextAttribute, // required
|
|
|
|
NSAccessibilitySelectedTextRangeAttribute, // required
|
|
|
|
NSAccessibilityNumberOfCharactersAttribute, // required
|
|
|
|
NSAccessibilityVisibleCharacterRangeAttribute, // required
|
|
|
|
NSAccessibilityInsertionPointLineNumberAttribute,
|
2012-04-25 00:07:17 +04:00
|
|
|
@"AXRequired",
|
|
|
|
@"AXInvalid",
|
2012-04-02 21:15:00 +04:00
|
|
|
nil
|
|
|
|
];
|
|
|
|
[supportedAttributes addObjectsFromArray:[super accessibilityAttributeNames]];
|
2006-11-15 14:08:14 +03:00
|
|
|
}
|
|
|
|
return supportedAttributes;
|
2008-02-22 23:13:17 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
|
2006-11-15 14:08:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
- (id)accessibilityAttributeValue:(NSString*)attribute
|
|
|
|
{
|
2008-02-22 23:13:17 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
|
|
|
|
|
2006-11-15 14:08:14 +03:00
|
|
|
if ([attribute isEqualToString:NSAccessibilityNumberOfCharactersAttribute])
|
|
|
|
return [NSNumber numberWithInt:[self textLength]];
|
2012-04-02 21:15:00 +04:00
|
|
|
|
|
|
|
if ([attribute isEqualToString:NSAccessibilityInsertionPointLineNumberAttribute])
|
|
|
|
return [self caretLineNumber];
|
|
|
|
|
2006-11-15 14:08:14 +03:00
|
|
|
if ([attribute isEqualToString:NSAccessibilitySelectedTextRangeAttribute])
|
|
|
|
return [self selectedTextRange];
|
2012-04-02 21:15:00 +04:00
|
|
|
|
2006-11-15 14:08:14 +03:00
|
|
|
if ([attribute isEqualToString:NSAccessibilitySelectedTextAttribute])
|
|
|
|
return [self selectedText];
|
2012-04-02 21:15:00 +04:00
|
|
|
|
2012-06-30 01:12:16 +04:00
|
|
|
if ([attribute isEqualToString:NSAccessibilityTitleAttribute])
|
|
|
|
return @"";
|
|
|
|
|
2012-04-02 21:15:00 +04:00
|
|
|
if ([attribute isEqualToString:NSAccessibilityValueAttribute]) {
|
|
|
|
// Apple's SpeechSynthesisServer expects AXValue to return an AXStaticText
|
|
|
|
// object's AXSelectedText attribute. See bug 674612 for details.
|
2015-06-08 17:59:19 +03:00
|
|
|
// Also if there is no selected text, we return the full text.
|
2012-04-02 21:15:00 +04:00
|
|
|
// See bug 369710 for details.
|
2012-06-30 01:12:16 +04:00
|
|
|
if ([[self role] isEqualToString:NSAccessibilityStaticTextRole]) {
|
|
|
|
NSString* selectedText = [self selectedText];
|
|
|
|
return (selectedText && [selectedText length]) ? selectedText : [self text];
|
|
|
|
}
|
2012-04-02 21:15:00 +04:00
|
|
|
|
|
|
|
return [self text];
|
|
|
|
}
|
|
|
|
|
2015-05-22 17:59:26 +03:00
|
|
|
AccessibleWrap* accWrap = [self getGeckoAccessible];
|
|
|
|
|
2012-04-25 00:07:17 +04:00
|
|
|
if ([attribute isEqualToString:@"AXRequired"])
|
2015-05-22 17:59:26 +03:00
|
|
|
return [NSNumber numberWithBool:!!(accWrap->State() & states::REQUIRED)];
|
2012-04-25 00:07:17 +04:00
|
|
|
|
|
|
|
if ([attribute isEqualToString:@"AXInvalid"])
|
2015-05-22 17:59:26 +03:00
|
|
|
return [NSNumber numberWithBool:!!(accWrap->State() & states::INVALID)];
|
2012-04-25 00:07:17 +04:00
|
|
|
|
2012-04-02 21:15:00 +04:00
|
|
|
if ([attribute isEqualToString:NSAccessibilityVisibleCharacterRangeAttribute])
|
|
|
|
return [self visibleCharacterRange];
|
2011-09-27 19:38:44 +04:00
|
|
|
|
2006-11-15 14:08:14 +03:00
|
|
|
// let mozAccessible handle all other attributes
|
|
|
|
return [super accessibilityAttributeValue:attribute];
|
2008-02-22 23:13:17 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
|
2006-11-15 14:08:14 +03:00
|
|
|
}
|
|
|
|
|
2012-04-02 21:15:00 +04: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
|
|
|
|
{
|
2015-05-22 18:07:13 +03:00
|
|
|
AccessibleWrap* accWrap = [self getGeckoAccessible];
|
|
|
|
HyperTextAccessible* textAcc = accWrap? accWrap->AsHyperText() : nullptr;
|
|
|
|
if (!textAcc)
|
2012-04-02 21:15:00 +04:00
|
|
|
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 17:19:33 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t start = range.location;
|
|
|
|
int32_t end = start + range.length;
|
2015-05-22 18:07:13 +03:00
|
|
|
nsIntRect bounds = textAcc->TextBounds(start, end);
|
2012-04-02 21:15:00 +04:00
|
|
|
|
|
|
|
return [NSValue valueWithRect:nsCocoaUtils::GeckoRectToCocoaRect(bounds)];
|
|
|
|
}
|
|
|
|
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"unhandled attribute:%@ forParameter:%@", attribute, parameter);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2006-11-15 14:08:14 +03:00
|
|
|
- (BOOL)accessibilityIsAttributeSettable:(NSString*)attribute
|
|
|
|
{
|
2008-02-22 23:13:17 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
|
|
|
|
|
2006-11-15 14:08:14 +03:00
|
|
|
if ([attribute isEqualToString:NSAccessibilityValueAttribute])
|
2012-06-30 01:12:16 +04:00
|
|
|
return ![self isReadOnly];
|
2015-06-08 17:59:19 +03:00
|
|
|
|
2012-04-02 21:15:00 +04:00
|
|
|
if ([attribute isEqualToString:NSAccessibilitySelectedTextAttribute] ||
|
|
|
|
[attribute isEqualToString:NSAccessibilitySelectedTextRangeAttribute] ||
|
|
|
|
[attribute isEqualToString:NSAccessibilityVisibleCharacterRangeAttribute])
|
|
|
|
return YES;
|
|
|
|
|
2006-11-15 14:08:14 +03:00
|
|
|
return [super accessibilityIsAttributeSettable:attribute];
|
2008-02-22 23:13:17 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(NO);
|
2006-11-15 14:08:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)accessibilitySetValue:(id)value forAttribute:(NSString *)attribute
|
|
|
|
{
|
2008-02-22 23:13:17 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2015-05-22 18:07:13 +03:00
|
|
|
AccessibleWrap* accWrap = [self getGeckoAccessible];
|
|
|
|
HyperTextAccessible* textAcc = accWrap? accWrap->AsHyperText() : nullptr;
|
|
|
|
if (!textAcc)
|
2012-04-02 21:15:00 +04:00
|
|
|
return;
|
|
|
|
|
2006-11-15 14:08:14 +03:00
|
|
|
if ([attribute isEqualToString:NSAccessibilityValueAttribute]) {
|
2012-04-02 21:15:00 +04:00
|
|
|
[self setText:ToNSString(value)];
|
2015-06-08 17:59:19 +03:00
|
|
|
|
2012-04-02 21:15:00 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ([attribute isEqualToString:NSAccessibilitySelectedTextAttribute]) {
|
2012-04-02 21:16:12 +04:00
|
|
|
NSString* stringValue = ToNSString(value);
|
|
|
|
if (!stringValue)
|
|
|
|
return;
|
|
|
|
|
2013-11-18 17:19:33 +04:00
|
|
|
int32_t start = 0, end = 0;
|
2015-05-22 18:07:13 +03:00
|
|
|
textAcc->SelectionBoundsAt(0, &start, &end);
|
|
|
|
textAcc->DeleteText(start, end - start);
|
2012-04-02 21:16:12 +04:00
|
|
|
|
|
|
|
nsString text;
|
|
|
|
nsCocoaUtils::GetStringForNSString(stringValue, text);
|
2015-05-22 18:07:13 +03:00
|
|
|
textAcc->InsertText(text, start);
|
2012-04-02 21:15:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if ([attribute isEqualToString:NSAccessibilitySelectedTextRangeAttribute]) {
|
|
|
|
NSRange range;
|
|
|
|
if (!ToNSRange(value, &range))
|
|
|
|
return;
|
|
|
|
|
2015-05-22 18:07:13 +03:00
|
|
|
textAcc->SetSelectionBoundsAt(0, range.location,
|
|
|
|
range.location + range.length);
|
2012-04-02 21:15:00 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ([attribute isEqualToString:NSAccessibilityVisibleCharacterRangeAttribute]) {
|
|
|
|
NSRange range;
|
|
|
|
if (!ToNSRange(value, &range))
|
|
|
|
return;
|
|
|
|
|
2015-05-22 18:07:13 +03:00
|
|
|
textAcc->ScrollSubstringTo(range.location, range.location + range.length,
|
|
|
|
nsIAccessibleScrollType::SCROLL_TYPE_TOP_EDGE);
|
2012-04-02 21:15:00 +04:00
|
|
|
return;
|
2015-06-08 17:59:19 +03:00
|
|
|
}
|
2012-04-02 21:15:00 +04:00
|
|
|
|
|
|
|
[super accessibilitySetValue:value forAttribute:attribute];
|
2008-02-22 23:13:17 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2006-11-15 14:08:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString*)subrole
|
|
|
|
{
|
2012-04-12 22:02:25 +04:00
|
|
|
if(mRole == roles::PASSWORD_TEXT)
|
|
|
|
return NSAccessibilitySecureTextFieldSubrole;
|
|
|
|
|
2006-11-15 14:08:14 +03:00
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
|
|
|
- (BOOL)isReadOnly
|
|
|
|
{
|
2008-02-22 23:13:17 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
|
|
|
|
|
2006-11-15 14:08:14 +03:00
|
|
|
if ([[self role] isEqualToString:NSAccessibilityStaticTextRole])
|
|
|
|
return YES;
|
2014-10-22 04:49:28 +04:00
|
|
|
|
2015-05-22 18:07:13 +03:00
|
|
|
AccessibleWrap* accWrap = [self getGeckoAccessible];
|
|
|
|
HyperTextAccessible* textAcc = accWrap? accWrap->AsHyperText() : nullptr;
|
|
|
|
if (textAcc)
|
|
|
|
return (accWrap->State() & states::READONLY) == 0;
|
2006-11-15 14:08:14 +03:00
|
|
|
|
|
|
|
return NO;
|
2008-02-22 23:13:17 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(NO);
|
2006-11-15 14:08:14 +03:00
|
|
|
}
|
|
|
|
|
2012-04-02 21:15:00 +04:00
|
|
|
- (NSNumber*)caretLineNumber
|
|
|
|
{
|
2015-05-22 18:07:13 +03:00
|
|
|
AccessibleWrap* accWrap = [self getGeckoAccessible];
|
|
|
|
HyperTextAccessible* textAcc = accWrap? accWrap->AsHyperText() : nullptr;
|
|
|
|
int32_t lineNumber = textAcc ?
|
|
|
|
textAcc->CaretLineNumber() - 1 : -1;
|
2012-04-02 21:15:00 +04:00
|
|
|
|
|
|
|
return (lineNumber >= 0) ? [NSNumber numberWithInt:lineNumber] : nil;
|
|
|
|
}
|
|
|
|
|
2012-04-03 23:39:38 +04:00
|
|
|
- (void)setText:(NSString*)aNewString
|
2006-11-15 14:08:14 +03:00
|
|
|
{
|
2008-02-22 23:13:17 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2015-05-22 18:07:13 +03:00
|
|
|
AccessibleWrap* accWrap = [self getGeckoAccessible];
|
|
|
|
HyperTextAccessible* textAcc = accWrap? accWrap->AsHyperText() : nullptr;
|
|
|
|
if (textAcc) {
|
2012-04-03 23:39:38 +04:00
|
|
|
nsString text;
|
|
|
|
nsCocoaUtils::GetStringForNSString(aNewString, text);
|
2015-05-22 18:07:13 +03:00
|
|
|
textAcc->ReplaceText(text);
|
2006-11-15 14:08:14 +03:00
|
|
|
}
|
2008-02-22 23:13:17 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2006-11-15 14:08:14 +03:00
|
|
|
}
|
|
|
|
|
2012-01-25 01:00:24 +04:00
|
|
|
- (NSString*)text
|
|
|
|
{
|
2015-05-22 18:07:13 +03:00
|
|
|
AccessibleWrap* accWrap = [self getGeckoAccessible];
|
|
|
|
HyperTextAccessible* textAcc = accWrap? accWrap->AsHyperText() : nullptr;
|
|
|
|
if (!accWrap || !textAcc)
|
2012-01-25 01:00:24 +04:00
|
|
|
return nil;
|
2012-04-12 22:02:25 +04:00
|
|
|
|
|
|
|
// A password text field returns an empty value
|
|
|
|
if (mRole == roles::PASSWORD_TEXT)
|
|
|
|
return @"";
|
|
|
|
|
2012-01-25 01:00:24 +04:00
|
|
|
nsAutoString text;
|
2015-05-22 18:07:13 +03:00
|
|
|
textAcc->TextSubstring(0, nsIAccessibleText::TEXT_OFFSET_END_OF_TEXT, text);
|
2012-04-03 23:39:38 +04:00
|
|
|
return nsCocoaUtils::ToNSString(text);
|
2012-01-25 01:00:24 +04:00
|
|
|
}
|
|
|
|
|
2006-11-15 14:08:14 +03:00
|
|
|
- (long)textLength
|
|
|
|
{
|
2008-02-22 23:13:17 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
|
|
|
|
|
2015-05-22 18:07:13 +03:00
|
|
|
AccessibleWrap* accWrap = [self getGeckoAccessible];
|
|
|
|
HyperTextAccessible* textAcc = accWrap? accWrap->AsHyperText() : nullptr;
|
|
|
|
if (!accWrap || !textAcc)
|
2012-06-30 01:12:16 +04:00
|
|
|
return 0;
|
|
|
|
|
2015-05-22 18:07:13 +03:00
|
|
|
return textAcc ? textAcc->CharacterCount() : 0;
|
2008-02-22 23:13:17 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(0);
|
2006-11-15 14:08:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
- (long)selectedTextLength
|
|
|
|
{
|
2008-02-22 23:13:17 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
|
|
|
|
|
2015-05-22 18:07:13 +03:00
|
|
|
AccessibleWrap* accWrap = [self getGeckoAccessible];
|
|
|
|
HyperTextAccessible* textAcc = accWrap? accWrap->AsHyperText() : nullptr;
|
|
|
|
if (textAcc) {
|
2013-11-18 17:19:33 +04:00
|
|
|
int32_t start = 0, end = 0;
|
2015-05-22 18:07:13 +03:00
|
|
|
textAcc->SelectionBoundsAt(0, &start, &end);
|
2006-11-15 14:08:14 +03:00
|
|
|
return (end - start);
|
|
|
|
}
|
|
|
|
return 0;
|
2008-02-22 23:13:17 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(0);
|
2006-11-15 14:08:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString*)selectedText
|
|
|
|
{
|
2008-02-22 23:13:17 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
|
|
|
|
|
2015-05-22 18:07:13 +03:00
|
|
|
AccessibleWrap* accWrap = [self getGeckoAccessible];
|
|
|
|
HyperTextAccessible* textAcc = accWrap? accWrap->AsHyperText() : nullptr;
|
|
|
|
if (textAcc) {
|
2013-11-18 17:19:33 +04:00
|
|
|
int32_t start = 0, end = 0;
|
2015-05-22 18:07:13 +03:00
|
|
|
textAcc->SelectionBoundsAt(0, &start, &end);
|
2006-11-15 14:08:14 +03:00
|
|
|
if (start != end) {
|
|
|
|
nsAutoString selText;
|
2015-05-22 18:07:13 +03:00
|
|
|
textAcc->TextSubstring(start, end, selText);
|
2012-04-03 23:39:38 +04:00
|
|
|
return nsCocoaUtils::ToNSString(selText);
|
2006-11-15 14:08:14 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil;
|
2008-02-22 23:13:17 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
|
2006-11-15 14:08:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSValue*)selectedTextRange
|
|
|
|
{
|
2008-02-22 23:13:17 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
|
|
|
|
|
2015-05-22 18:07:13 +03:00
|
|
|
AccessibleWrap* accWrap = [self getGeckoAccessible];
|
|
|
|
HyperTextAccessible* textAcc = accWrap? accWrap->AsHyperText() : nullptr;
|
|
|
|
if (textAcc) {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t start = 0;
|
|
|
|
int32_t end = 0;
|
2015-05-22 18:07:13 +03:00
|
|
|
int32_t count = textAcc->SelectionCount();
|
2012-04-02 21:15:00 +04:00
|
|
|
|
|
|
|
if (count) {
|
2015-05-22 18:07:13 +03:00
|
|
|
textAcc->SelectionBoundsAt(0, &start, &end);
|
2012-04-02 21:15:00 +04:00
|
|
|
return [NSValue valueWithRange:NSMakeRange(start, end - start)];
|
|
|
|
}
|
|
|
|
|
2015-05-22 18:07:13 +03:00
|
|
|
start = textAcc->CaretOffset();
|
2012-04-02 21:15:00 +04:00
|
|
|
return [NSValue valueWithRange:NSMakeRange(start != -1 ? start : 0, 0)];
|
2006-11-15 14:08:14 +03:00
|
|
|
}
|
2012-04-02 21:15:00 +04:00
|
|
|
return [NSValue valueWithRange:NSMakeRange(0, 0)];
|
2008-02-22 23:13:17 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
|
2006-11-15 14:08:14 +03:00
|
|
|
}
|
|
|
|
|
2012-04-02 21:15:00 +04:00
|
|
|
- (NSValue*)visibleCharacterRange
|
|
|
|
{
|
|
|
|
// XXX this won't work with Textarea and such as we actually don't give
|
|
|
|
// the visible character range.
|
2015-05-22 18:07:13 +03:00
|
|
|
AccessibleWrap* accWrap = [self getGeckoAccessible];
|
|
|
|
HyperTextAccessible* textAcc = accWrap? accWrap->AsHyperText() : nullptr;
|
2012-04-02 21:15:00 +04:00
|
|
|
return [NSValue valueWithRange:
|
2015-05-22 18:07:13 +03:00
|
|
|
NSMakeRange(0, textAcc ?
|
|
|
|
textAcc->CharacterCount() : 0)];
|
2012-04-02 21:15:00 +04:00
|
|
|
}
|
2006-11-15 14:08:14 +03:00
|
|
|
|
|
|
|
- (void)valueDidChange
|
|
|
|
{
|
2008-02-22 23:13:17 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2012-03-23 22:54:55 +04:00
|
|
|
NSAccessibilityPostNotification(GetObjectOrRepresentedView(self),
|
2006-11-15 14:08:14 +03:00
|
|
|
NSAccessibilityValueChangedNotification);
|
2008-02-22 23:13:17 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2006-11-15 14:08:14 +03:00
|
|
|
}
|
|
|
|
|
2012-04-02 21:15:00 +04:00
|
|
|
- (void)selectedTextDidChange
|
|
|
|
{
|
|
|
|
NSAccessibilityPostNotification(GetObjectOrRepresentedView(self),
|
|
|
|
NSAccessibilitySelectedTextChangedNotification);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString*)stringFromRange:(NSRange*)range
|
|
|
|
{
|
2015-05-22 18:07:13 +03:00
|
|
|
NS_PRECONDITION(range, "no range");
|
|
|
|
|
|
|
|
AccessibleWrap* accWrap = [self getGeckoAccessible];
|
|
|
|
HyperTextAccessible* textAcc = accWrap? accWrap->AsHyperText() : nullptr;
|
|
|
|
if (!textAcc)
|
|
|
|
return nil;
|
2012-04-02 21:15:00 +04:00
|
|
|
|
|
|
|
nsAutoString text;
|
2015-05-22 18:07:13 +03:00
|
|
|
textAcc->TextSubstring(range->location,
|
|
|
|
range->location + range->length, text);
|
2012-04-02 21:15:00 +04:00
|
|
|
return nsCocoaUtils::ToNSString(text);
|
|
|
|
}
|
|
|
|
|
2006-11-15 14:08:14 +03:00
|
|
|
@end
|
2012-06-30 01:12:16 +04: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
|
|
|
|
{
|
2015-05-22 17:59:26 +03:00
|
|
|
AccessibleWrap* accWrap = [self getGeckoAccessible];
|
|
|
|
if (!accWrap)
|
2012-06-30 01:12:16 +04:00
|
|
|
return nil;
|
|
|
|
|
2015-05-22 17:59:26 +03:00
|
|
|
return nsCocoaUtils::ToNSString(accWrap->AsTextLeaf()->Text());
|
2012-06-30 01:12:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
- (long)textLength
|
|
|
|
{
|
2015-05-22 17:59:26 +03:00
|
|
|
AccessibleWrap* accWrap = [self getGeckoAccessible];
|
|
|
|
if (!accWrap)
|
2012-06-30 01:12:16 +04:00
|
|
|
return 0;
|
|
|
|
|
2015-05-22 17:59:26 +03:00
|
|
|
return accWrap->AsTextLeaf()->Text().Length();
|
2012-06-30 01:12:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|