Bug 417564 - "protect against Obj-C exceptions in 'accessible' top-level directory". r=josh, sr=roc, a=blocking1.9+.

This commit is contained in:
bent.mozilla@gmail.com 2008-02-22 12:13:17 -08:00
parent 12f713ce65
commit 84b66071ff
7 changed files with 273 additions and 0 deletions

View File

@ -44,6 +44,7 @@
#include "nsRect.h"
#include "nsCoord.h"
#include "nsObjCExceptions.h"
#include "nsIAccessible.h"
#include "nsIAccessibleText.h"
@ -73,9 +74,13 @@ ConvertCocoaToGeckoPoint(NSPoint &aInPoint, nsPoint &aOutPoint)
static inline id <mozAccessible>
GetObjectOrRepresentedView(id <mozAccessible> anObject)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
if ([anObject hasRepresentedView])
return [anObject representedView];
return anObject;
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
}
// returns the passed in object if it is not ignored. if it's ignored, will return
@ -83,6 +88,8 @@ GetObjectOrRepresentedView(id <mozAccessible> anObject)
static inline id
GetClosestInterestingAccessible(id anObject)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
// this object is not ignored, so let's return it.
if (![anObject accessibilityIsIgnored])
return GetObjectOrRepresentedView(anObject);
@ -101,14 +108,20 @@ GetClosestInterestingAccessible(id anObject)
return GetObjectOrRepresentedView(unignoredObject);
return unignoredObject;
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
}
static inline mozAccessible*
GetNativeFromGeckoAccessible(nsIAccessible *anAccessible)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSNULL;
mozAccessible *native = nil;
anAccessible->GetNativeInterface ((void**)&native);
return native;
NS_OBJC_END_TRY_ABORT_BLOCK_NSNULL;
}
#pragma mark -
@ -117,6 +130,8 @@ GetNativeFromGeckoAccessible(nsIAccessible *anAccessible)
- (id)initWithAccessible:(nsAccessibleWrap*)geckoAccessible
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
if ((self = [super init])) {
mGeckoAccessible = geckoAccessible;
mIsExpired = NO;
@ -128,25 +143,37 @@ GetNativeFromGeckoAccessible(nsIAccessible *anAccessible)
}
return self;
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
}
- (void)dealloc
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
[mChildren release];
[super dealloc];
NS_OBJC_END_TRY_ABORT_BLOCK;
}
#pragma mark -
- (BOOL)accessibilityIsIgnored
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
// unknown (either unimplemented, or irrelevant) elements are marked as ignored
// as well as expired elements.
return mIsExpired || [[self role] isEqualToString:NSAccessibilityUnknownRole];
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(NO);
}
- (NSArray*)accessibilityAttributeNames
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
// if we're expired, we don't support any attributes.
if (mIsExpired)
return [NSArray array];
@ -177,10 +204,14 @@ GetNativeFromGeckoAccessible(nsIAccessible *anAccessible)
}
return generalAttributes;
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
}
- (id)accessibilityAttributeValue:(NSString*)attribute
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
if (mIsExpired)
return nil;
@ -227,18 +258,26 @@ GetNativeFromGeckoAccessible(nsIAccessible *anAccessible)
NSLog (@"!!! %@ can't respond to attribute %@", self, attribute);
#endif
return nil; // be nice and return empty string instead?
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
}
- (BOOL)accessibilityIsAttributeSettable:(NSString*)attribute
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
if ([attribute isEqualToString:NSAccessibilityFocusedAttribute])
return [self canBeFocused];
return NO;
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(NO);
}
- (void)accessibilitySetValue:(id)value forAttribute:(NSString*)attribute
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
#ifdef DEBUG_hakan
NSLog (@"[%@] %@='%@'", self, attribute, value);
#endif
@ -246,6 +285,8 @@ GetNativeFromGeckoAccessible(nsIAccessible *anAccessible)
// we only support focusing elements so far.
if ([attribute isEqualToString:NSAccessibilityFocusedAttribute] && [value boolValue])
[self focus];
NS_OBJC_END_TRY_ABORT_BLOCK;
}
- (id)accessibilityHitTest:(NSPoint)point
@ -315,6 +356,8 @@ GetNativeFromGeckoAccessible(nsIAccessible *anAccessible)
- (id <mozAccessible>)parent
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
nsCOMPtr<nsIAccessible> accessibleParent(mGeckoAccessible->GetUnignoredParent());
if (accessibleParent) {
id nativeParent = GetNativeFromGeckoAccessible(accessibleParent);
@ -332,6 +375,8 @@ GetNativeFromGeckoAccessible(nsIAccessible *anAccessible)
NSAssert1 (nativeParent, @"!!! we can't find a parent for %@", self);
return GetClosestInterestingAccessible(nativeParent);
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
}
- (BOOL)hasRepresentedView
@ -353,6 +398,8 @@ GetNativeFromGeckoAccessible(nsIAccessible *anAccessible)
// returns nil when there are no children.
- (NSArray*)children
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
if (mChildren)
return mChildren;
@ -385,10 +432,14 @@ GetNativeFromGeckoAccessible(nsIAccessible *anAccessible)
#endif
return mChildren;
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
}
- (NSValue*)position
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
PRInt32 x, y, width, height;
mGeckoAccessible->GetBounds (&x, &y, &width, &height);
NSPoint p = NSMakePoint (x, y);
@ -404,13 +455,19 @@ GetNativeFromGeckoAccessible(nsIAccessible *anAccessible)
p.y = mainScreenHeight - p.y - height;
return [NSValue valueWithPoint:p];
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
}
- (NSValue*)size
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
PRInt32 x, y, width, height;
mGeckoAccessible->GetBounds (&x, &y, &width, &height);
return [NSValue valueWithSize:NSMakeSize (width, height)];
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
}
- (NSString*)role
@ -428,45 +485,69 @@ GetNativeFromGeckoAccessible(nsIAccessible *anAccessible)
- (NSString*)title
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
nsAutoString title;
mGeckoAccessible->GetName (title);
return title.IsEmpty() ? nil : [NSString stringWithCharacters:title.BeginReading() length:title.Length()];
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
}
- (id)value
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
nsAutoString value;
mGeckoAccessible->GetValue (value);
return value.IsEmpty() ? nil : [NSString stringWithCharacters:value.BeginReading() length:value.Length()];
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
}
- (void)valueDidChange
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
#ifdef DEBUG_hakan
NSLog(@"%@'s value changed!", self);
#endif
// sending out a notification is expensive, so we don't do it other than for really important objects,
// like mozTextAccessible.
NS_OBJC_END_TRY_ABORT_BLOCK;
}
- (NSString*)customDescription
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
nsAutoString desc;
mGeckoAccessible->GetDescription (desc);
return desc.IsEmpty() ? nil : [NSString stringWithCharacters:desc.BeginReading() length:desc.Length()];
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
}
- (NSString*)help
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
nsAutoString helpText;
mGeckoAccessible->GetHelp (helpText);
return helpText.IsEmpty() ? nil : [NSString stringWithCharacters:helpText.BeginReading() length:helpText.Length()];
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
}
// objc-style description (from NSObject); not to be confused with the accessible description above.
- (NSString*)description
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
return [NSString stringWithFormat:@"(%p) %@", self, [self role]];
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
}
- (BOOL)isFocused
@ -500,35 +581,51 @@ GetNativeFromGeckoAccessible(nsIAccessible *anAccessible)
// changed to us.
- (void)didReceiveFocus
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
#ifdef DEBUG_hakan
NSLog (@"%@ received focus!", self);
#endif
NSAssert1(![self accessibilityIsIgnored], @"trying to set focus to ignored element! (%@)", self);
NSAccessibilityPostNotification(GetObjectOrRepresentedView(self),
NSAccessibilityFocusedUIElementChangedNotification);
NS_OBJC_END_TRY_ABORT_BLOCK;
}
- (NSWindow*)window
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
nsAccessibleWrap *accWrap = static_cast<nsAccessibleWrap*>(mGeckoAccessible);
NSWindow *nativeWindow = nil;
accWrap->GetNativeWindow ((void**)&nativeWindow);
NSAssert1(nativeWindow, @"Could not get native window for %@", self);
return nativeWindow;
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
}
- (void)invalidateChildren
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
// make room for new children
[mChildren release];
mChildren = nil;
NS_OBJC_END_TRY_ABORT_BLOCK;
}
- (void)expire
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
[self invalidateChildren];
mIsExpired = YES;
NS_OBJC_END_TRY_ABORT_BLOCK;
}
- (BOOL)isExpired
@ -546,6 +643,8 @@ GetNativeFromGeckoAccessible(nsIAccessible *anAccessible)
// parent.
- (void)sanityCheckChildren:(NSArray *)children
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
NSAssert(![self accessibilityIsIgnored], @"can't sanity check children of an ignored accessible!");
NSEnumerator *iter = [children objectEnumerator];
mozAccessible *curObj = nil;
@ -558,20 +657,32 @@ GetNativeFromGeckoAccessible(nsIAccessible *anAccessible)
NSAssert2([curObj parent] == realSelf,
@"!!! %@ not returning %@ as AXParent, even though it is a AXChild of it!", curObj, realSelf);
}
NS_OBJC_END_TRY_ABORT_BLOCK;
}
- (void)sanityCheckChildren
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
[self sanityCheckChildren:[self children]];
NS_OBJC_END_TRY_ABORT_BLOCK;
}
- (void)printHierarchy
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
[self printHierarchyWithLevel:0];
NS_OBJC_END_TRY_ABORT_BLOCK;
}
- (void)printHierarchyWithLevel:(unsigned)level
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
NSAssert(![self isExpired], @"!!! trying to print hierarchy of expired object!");
// print this node
@ -597,6 +708,8 @@ GetNativeFromGeckoAccessible(nsIAccessible *anAccessible)
// print every child node's subtree, increasing the indenting
// by two for every level.
[object printHierarchyWithLevel:(level+1)];
NS_OBJC_END_TRY_ABORT_BLOCK;
}
#endif /* DEBUG */

View File

@ -38,6 +38,8 @@
#include "nsAccessibleWrap.h"
#include "nsObjCExceptions.h"
#import "mozAccessible.h"
/* Wrapper class.
@ -56,15 +58,23 @@
struct AccessibleWrapper {
mozAccessible *object;
AccessibleWrapper (nsAccessibleWrap *parent, Class classType) {
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
object = (mozAccessible*)[[classType alloc] initWithAccessible:parent];
NS_OBJC_END_TRY_ABORT_BLOCK;
}
~AccessibleWrapper () {
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
// if some third-party still holds on to the object, it's important that it is marked
// as expired, so it can't do any harm (e.g., walk into an expired hierarchy of nodes).
[object expire];
[object release];
NS_OBJC_END_TRY_ABORT_BLOCK;
}
mozAccessible* getNativeObject () {
@ -72,6 +82,10 @@ struct AccessibleWrapper {
}
PRBool isIgnored () {
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
return (PRBool)[object accessibilityIsIgnored];
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(PR_FALSE);
}
};

View File

@ -39,6 +39,8 @@
#import "mozActionElements.h"
#import "nsIAccessible.h"
#include "nsObjCExceptions.h"
extern const NSString *kInstanceDescriptionAttribute; // NSAccessibilityDescriptionAttribute
extern const NSString *kTopLevelUIElementAttribute; // NSAccessibilityTopLevelUIElementAttribute
@ -53,6 +55,8 @@ enum CheckboxValue {
- (NSArray*)accessibilityAttributeNames
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
static NSArray *attributes = nil;
if (!attributes) {
attributes = [[NSArray alloc] initWithObjects:NSAccessibilityParentAttribute, // required
@ -70,13 +74,19 @@ enum CheckboxValue {
nil];
}
return attributes;
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
}
- (id)accessibilityAttributeValue:(NSString *)attribute
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
if ([attribute isEqualToString:NSAccessibilityChildrenAttribute])
return nil;
return [super accessibilityAttributeValue:attribute];
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
}
- (BOOL)accessibilityIsIgnored
@ -86,24 +96,36 @@ enum CheckboxValue {
- (NSArray*)accessibilityActionNames
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
if ([self isEnabled])
return [NSArray arrayWithObject:NSAccessibilityPressAction];
return nil;
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
}
- (NSString*)accessibilityActionDescription:(NSString*)action
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
if ([action isEqualToString:NSAccessibilityPressAction])
return @"press button"; // XXX: localize this later?
return nil;
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
}
- (void)accessibilityPerformAction:(NSString*)action
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
if ([action isEqualToString:NSAccessibilityPressAction])
[self click];
NS_OBJC_END_TRY_ABORT_BLOCK;
}
- (void)click
@ -119,6 +141,8 @@ enum CheckboxValue {
- (NSString*)accessibilityActionDescription:(NSString*)action
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
if ([action isEqualToString:NSAccessibilityPressAction]) {
if ([self isChecked] != kUnchecked)
return @"uncheck checkbox"; // XXX: localize this later?
@ -127,6 +151,8 @@ enum CheckboxValue {
}
return nil;
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
}
- (int)isChecked
@ -144,7 +170,11 @@ enum CheckboxValue {
- (id)value
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
return [NSNumber numberWithInt:[self isChecked]];
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
}
@end
@ -153,6 +183,8 @@ enum CheckboxValue {
- (NSArray *)accessibilityAttributeNames
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
static NSArray *attributes = nil;
if (!attributes) {
@ -171,18 +203,26 @@ enum CheckboxValue {
nil];
}
return attributes;
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
}
- (id)accessibilityAttributeValue:(NSString *)attribute
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
if ([attribute isEqualToString:NSAccessibilityChildrenAttribute]) {
return [super children];
}
return [super accessibilityAttributeValue:attribute];
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
}
- (NSArray *)accessibilityActionNames
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
if ([self isEnabled]) {
return [NSArray arrayWithObjects:NSAccessibilityPressAction,
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
@ -191,19 +231,27 @@ enum CheckboxValue {
nil];
}
return nil;
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
}
- (NSString *)accessibilityActionDescription:(NSString *)action
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
if ([action isEqualToString:NSAccessibilityShowMenuAction])
return @"show menu";
#endif
return [super accessibilityActionDescription:action];
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
}
- (void)accessibilityPerformAction:(NSString *)action
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
// both the ShowMenu and Click action do the same thing.
if ([self isEnabled]) {
// TODO: this should bring up the menu, but currently doesn't.
@ -211,6 +259,8 @@ enum CheckboxValue {
// the action needed to show the menu.
[super click];
}
NS_OBJC_END_TRY_ABORT_BLOCK;
}
@end

View File

@ -37,6 +37,7 @@
* ***** END LICENSE BLOCK ***** */
#include "nsRootAccessibleWrap.h"
#include "nsObjCExceptions.h"
#import "mozDocAccessible.h"
@ -57,6 +58,8 @@ static id <mozAccessible, mozView> getNativeViewFromRootAccessible (nsAccessible
// return the AXParent that our parallell NSView tells us about.
- (id)parent
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
if (!mParallelView)
mParallelView = (id<mozView, mozAccessible>)[self representedView];
@ -65,6 +68,8 @@ static id <mozAccessible, mozView> getNativeViewFromRootAccessible (nsAccessible
NSAssert(mParallelView, @"we're a root accessible w/o native view?");
return [super parent];
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
}
- (BOOL)hasRepresentedView
@ -75,6 +80,8 @@ static id <mozAccessible, mozView> getNativeViewFromRootAccessible (nsAccessible
// this will return our parallell NSView. see mozDocAccessible.h
- (id)representedView
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
if (mParallelView)
return (id)mParallelView;
@ -82,6 +89,8 @@ static id <mozAccessible, mozView> getNativeViewFromRootAccessible (nsAccessible
NSAssert(mParallelView, @"can't return root accessible's native parallel view.");
return mParallelView;
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
}
- (BOOL)isRoot

View File

@ -1,4 +1,5 @@
#include "nsAccessibleWrap.h"
#include "nsObjCExceptions.h"
#import "mozTextAccessible.h"
@ -18,11 +19,15 @@ extern const NSString *kTopLevelUIElementAttribute; // NSAccessibilityTopLevel
- (id)initWithAccessible:(nsAccessibleWrap*)accessible
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
if ((self = [super initWithAccessible:accessible])) {
CallQueryInterface(accessible, &mGeckoTextAccessible);
CallQueryInterface(accessible, &mGeckoEditableTextAccessible);
}
return self;
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
}
- (BOOL)accessibilityIsIgnored
@ -32,6 +37,8 @@ extern const NSString *kTopLevelUIElementAttribute; // NSAccessibilityTopLevel
- (NSArray*)accessibilityAttributeNames
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
static NSArray *supportedAttributes = nil;
if (!supportedAttributes) {
// standard attributes that are shared and supported by all generic elements.
@ -59,10 +66,14 @@ extern const NSString *kTopLevelUIElementAttribute; // NSAccessibilityTopLevel
nil];
}
return supportedAttributes;
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
}
- (id)accessibilityAttributeValue:(NSString*)attribute
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
if ([attribute isEqualToString:NSAccessibilityNumberOfCharactersAttribute])
return [NSNumber numberWithInt:[self textLength]];
if ([attribute isEqualToString:NSAccessibilitySelectedTextRangeAttribute])
@ -72,23 +83,33 @@ extern const NSString *kTopLevelUIElementAttribute; // NSAccessibilityTopLevel
// let mozAccessible handle all other attributes
return [super accessibilityAttributeValue:attribute];
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
}
- (BOOL)accessibilityIsAttributeSettable:(NSString*)attribute
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
if ([attribute isEqualToString:NSAccessibilityValueAttribute])
return [self isReadOnly];
return [super accessibilityIsAttributeSettable:attribute];
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(NO);
}
- (void)accessibilitySetValue:(id)value forAttribute:(NSString *)attribute
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
if ([attribute isEqualToString:NSAccessibilityValueAttribute]) {
if ([value isKindOfClass:[NSString class]])
[self setText:(NSString*)value];
} else
[super accessibilitySetValue:value forAttribute:attribute];
NS_OBJC_END_TRY_ABORT_BLOCK;
}
- (NSString*)subrole
@ -99,15 +120,21 @@ extern const NSString *kTopLevelUIElementAttribute; // NSAccessibilityTopLevel
- (void)expire
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
NS_IF_RELEASE(mGeckoTextAccessible);
NS_IF_RELEASE(mGeckoEditableTextAccessible);
[super expire];
NS_OBJC_END_TRY_ABORT_BLOCK;
}
#pragma mark -
- (BOOL)isReadOnly
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
if ([[self role] isEqualToString:NSAccessibilityStaticTextRole])
return YES;
@ -118,27 +145,39 @@ extern const NSString *kTopLevelUIElementAttribute; // NSAccessibilityTopLevel
}
return NO;
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(NO);
}
- (void)setText:(NSString*)newString
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
if (mGeckoEditableTextAccessible) {
mGeckoEditableTextAccessible->SetTextContents(NS_ConvertUTF8toUTF16([newString UTF8String]));
}
NS_OBJC_END_TRY_ABORT_BLOCK;
}
- (long)textLength
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
if (mGeckoTextAccessible) {
PRInt32 charCount = 0;
mGeckoTextAccessible->GetCharacterCount(&charCount);
return charCount;
}
return 0;
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(0);
}
- (long)selectedTextLength
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
if (mGeckoTextAccessible) {
PRInt32 start, end;
start = end = 0;
@ -146,10 +185,14 @@ extern const NSString *kTopLevelUIElementAttribute; // NSAccessibilityTopLevel
return (end - start);
}
return 0;
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(0);
}
- (NSString*)selectedText
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
if (mGeckoTextAccessible) {
PRInt32 start, end;
start = end = 0;
@ -161,10 +204,14 @@ extern const NSString *kTopLevelUIElementAttribute; // NSAccessibilityTopLevel
}
}
return nil;
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
}
- (NSValue*)selectedTextRange
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
if (mGeckoTextAccessible) {
PRInt32 start, end;
start = end = 0;
@ -172,14 +219,20 @@ extern const NSString *kTopLevelUIElementAttribute; // NSAccessibilityTopLevel
return [NSValue valueWithRange:NSMakeRange(start, start-end)];
}
return nil;
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
}
#pragma mark -
- (void)valueDidChange
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
NSAccessibilityPostNotification([self hasRepresentedView] ? [self representedView] : self,
NSAccessibilityValueChangedNotification);
NS_OBJC_END_TRY_ABORT_BLOCK;
}
@end
@ -188,6 +241,8 @@ extern const NSString *kTopLevelUIElementAttribute; // NSAccessibilityTopLevel
- (NSArray*)accessibilityAttributeNames
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
static NSArray *supportedAttributes = nil;
if (!supportedAttributes) {
// standard attributes that are shared and supported by all generic elements.
@ -218,10 +273,14 @@ extern const NSString *kTopLevelUIElementAttribute; // NSAccessibilityTopLevel
nil];
}
return supportedAttributes;
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
}
- (NSArray *)accessibilityActionNames
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
if ([self isEnabled]) {
return [NSArray arrayWithObjects:NSAccessibilityConfirmAction,
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
@ -230,10 +289,14 @@ extern const NSString *kTopLevelUIElementAttribute; // NSAccessibilityTopLevel
nil];
}
return nil;
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
}
- (NSString *)accessibilityActionDescription:(NSString *)action
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
if ([action isEqualToString:NSAccessibilityShowMenuAction])
return @"show menu";
@ -242,10 +305,14 @@ extern const NSString *kTopLevelUIElementAttribute; // NSAccessibilityTopLevel
return @"confirm";
return [super accessibilityActionDescription:action];
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
}
- (void)accessibilityPerformAction:(NSString *)action
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
// both the ShowMenu and Click action do the same thing.
if ([self isEnabled]) {
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
@ -255,6 +322,8 @@ extern const NSString *kTopLevelUIElementAttribute; // NSAccessibilityTopLevel
if ([action isEqualToString:NSAccessibilityConfirmAction])
[self confirm];
}
NS_OBJC_END_TRY_ABORT_BLOCK;
}
- (void)showMenu

View File

@ -39,6 +39,7 @@
#include "nsAccessibleWrap.h"
#include "nsIAccessibleDocument.h"
#include "nsIAccessibleText.h"
#include "nsObjCExceptions.h"
#import "nsRoleMap.h"
@ -100,6 +101,8 @@ nsAccessibleWrap::GetNativeWindow (void **aOutNativeWindow)
objc_class*
nsAccessibleWrap::GetNativeType ()
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
PRUint32 role = Role(this);
switch (role) {
case nsIAccessibleRole::ROLE_PUSHBUTTON:
@ -138,6 +141,8 @@ nsAccessibleWrap::GetNativeType ()
}
return nil;
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
}
// this method is very important. it is fired when an accessible object "dies". after this point
@ -157,6 +162,8 @@ nsAccessibleWrap::Shutdown ()
NS_IMETHODIMP
nsAccessibleWrap::FireAccessibleEvent(nsIAccessibleEvent *aEvent)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
NS_ENSURE_ARG_POINTER(aEvent);
nsresult rv = nsAccessible::FireAccessibleEvent(aEvent);
@ -190,16 +197,22 @@ nsAccessibleWrap::FireAccessibleEvent(nsIAccessibleEvent *aEvent)
}
return NS_OK;
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
}
nsresult
nsAccessibleWrap::InvalidateChildren ()
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
if (mNativeWrapper) {
mozAccessible *object = mNativeWrapper->getNativeObject();
[object invalidateChildren];
}
return nsAccessible::InvalidateChildren();
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
}
PRInt32

View File

@ -41,6 +41,7 @@
#include "mozDocAccessible.h"
#include "nsCOMPtr.h"
#include "nsObjCExceptions.h"
#include "nsIWidget.h"
#include "nsIViewManager.h"
@ -59,7 +60,11 @@ nsRootAccessibleWrap::~nsRootAccessibleWrap()
objc_class*
nsRootAccessibleWrap::GetNativeType ()
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
return [mozRootAccessible class];
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
}
void