bug 1109891 - part 1 - use an accessor method to get mGeckoAccessible r=tbsaunde

This commit is contained in:
Lorien Hu 2015-05-22 10:59:26 -04:00 committed by Trevor Saunders
parent 9b8bcf5bf0
commit 639c18002e
6 changed files with 107 additions and 67 deletions

View File

@ -54,6 +54,9 @@ GetNativeFromGeckoAccessible(mozilla::a11y::Accessible* aAccessible)
mozilla::a11y::role mRole;
}
// return the Accessible for this mozAccessible.
- (mozilla::a11y::AccessibleWrap*) getGeckoAccessible;
// inits with the gecko owner.
- (id)initWithAccessible:(mozilla::a11y::AccessibleWrap*)geckoParent;

View File

@ -83,6 +83,11 @@ GetClosestInterestingAccessible(id anObject)
NS_OBJC_END_TRY_ABORT_BLOCK;
}
- (mozilla::a11y::AccessibleWrap*)getGeckoAccessible
{
return mGeckoAccessible;
}
#pragma mark -
@ -92,8 +97,10 @@ GetClosestInterestingAccessible(id anObject)
// unknown (either unimplemented, or irrelevant) elements are marked as ignored
// as well as expired elements.
return !mGeckoAccessible || ([[self role] isEqualToString:NSAccessibilityUnknownRole] &&
!(mGeckoAccessible->InteractiveState() & states::FOCUSABLE));
AccessibleWrap* accWrap = [self getGeckoAccessible];
return !accWrap || ([[self role] isEqualToString:NSAccessibilityUnknownRole] &&
!(accWrap->InteractiveState() & states::FOCUSABLE));
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(NO);
}
@ -103,7 +110,7 @@ GetClosestInterestingAccessible(id anObject)
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
// if we're expired, we don't support any attributes.
if (!mGeckoAccessible)
if (![self getGeckoAccessible])
return [NSArray array];
static NSArray *generalAttributes = nil;
@ -141,7 +148,7 @@ GetClosestInterestingAccessible(id anObject)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
if (!mGeckoAccessible)
if (![self getGeckoAccessible])
return nil;
#if DEBUG
@ -183,7 +190,8 @@ GetClosestInterestingAccessible(id anObject)
if ([attribute isEqualToString:NSAccessibilityTitleAttribute])
return [self title];
if ([attribute isEqualToString:NSAccessibilityTitleUIElementAttribute]) {
Relation rel = mGeckoAccessible->RelationByType(RelationType::LABELLED_BY);
Relation rel =
[self getGeckoAccessible]->RelationByType(RelationType::LABELLED_BY);
Accessible* tempAcc = rel.Next();
return tempAcc ? GetNativeFromGeckoAccessible(tempAcc) : nil;
}
@ -227,7 +235,9 @@ GetClosestInterestingAccessible(id anObject)
- (id)accessibilityHitTest:(NSPoint)point
{
if (!mGeckoAccessible)
AccessibleWrap* accWrap = [self getGeckoAccessible];
if (!accWrap)
return nil;
// Convert the given screen-global point in the cocoa coordinate system (with
@ -239,8 +249,9 @@ GetClosestInterestingAccessible(id anObject)
nsIntPoint geckoPoint = nsCocoaUtils::
CocoaPointsToDevPixels(tmpPoint, nsCocoaUtils::GetBackingScaleFactor(mainView));
Accessible* child = mGeckoAccessible->ChildAtPoint(geckoPoint.x, geckoPoint.y,
Accessible::eDeepestChild);
Accessible* child =
accWrap->ChildAtPoint(geckoPoint.x, geckoPoint.y,
Accessible::eDeepestChild);
if (child) {
mozAccessible* nativeChild = GetNativeFromGeckoAccessible(child);
@ -270,10 +281,12 @@ GetClosestInterestingAccessible(id anObject)
- (id)accessibilityFocusedUIElement
{
if (!mGeckoAccessible)
AccessibleWrap* accWrap = [self getGeckoAccessible];
if (!accWrap)
return nil;
Accessible* focusedGeckoChild = mGeckoAccessible->FocusedChild();
Accessible* focusedGeckoChild = accWrap->FocusedChild();
if (focusedGeckoChild) {
mozAccessible *focusedChild = GetNativeFromGeckoAccessible(focusedGeckoChild);
if (focusedChild)
@ -290,7 +303,9 @@ GetClosestInterestingAccessible(id anObject)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
Accessible* accessibleParent = mGeckoAccessible->GetUnignoredParent();
AccessibleWrap* accWrap = [self getGeckoAccessible];
Accessible* accessibleParent = accWrap->GetUnignoredParent();
if (accessibleParent) {
id nativeParent = GetNativeFromGeckoAccessible(accessibleParent);
if (nativeParent)
@ -303,7 +318,7 @@ GetClosestInterestingAccessible(id anObject)
//
// get the native root accessible, and tell it to return its first parent unignored accessible.
id nativeParent =
GetNativeFromGeckoAccessible(mGeckoAccessible->RootAccessible());
GetNativeFromGeckoAccessible(accWrap->RootAccessible());
NSAssert1 (nativeParent, @"!!! we can't find a parent for %@", self);
return GetClosestInterestingAccessible(nativeParent);
@ -332,14 +347,16 @@ GetClosestInterestingAccessible(id anObject)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
if (mChildren || !mGeckoAccessible->AreChildrenCached())
AccessibleWrap* accWrap = [self getGeckoAccessible];
if (mChildren || !accWrap->AreChildrenCached())
return mChildren;
mChildren = [[NSMutableArray alloc] init];
// get the array of children.
nsAutoTArray<Accessible*, 10> childrenArray;
mGeckoAccessible->GetUnignoredChildren(&childrenArray);
accWrap->GetUnignoredChildren(&childrenArray);
// now iterate through the children array, and get each native accessible.
uint32_t totalCount = childrenArray.Length();
@ -370,10 +387,11 @@ GetClosestInterestingAccessible(id anObject)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
if (!mGeckoAccessible)
AccessibleWrap* accWrap = [self getGeckoAccessible];
if (!accWrap)
return nil;
nsIntRect rect = mGeckoAccessible->Bounds();
nsIntRect rect = accWrap->Bounds();
NSScreen* mainView = [[NSScreen screens] objectAtIndex:0];
CGFloat scaleFactor = nsCocoaUtils::GetBackingScaleFactor(mainView);
@ -389,10 +407,12 @@ GetClosestInterestingAccessible(id anObject)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
if (!mGeckoAccessible)
AccessibleWrap* accWrap = [self getGeckoAccessible];
if (!accWrap)
return nil;
nsIntRect rect = mGeckoAccessible->Bounds();
nsIntRect rect = accWrap->Bounds();
CGFloat scaleFactor =
nsCocoaUtils::GetBackingScaleFactor([[NSScreen screens] objectAtIndex:0]);
return [NSValue valueWithSize:NSMakeSize(static_cast<CGFloat>(rect.width) / scaleFactor,
@ -403,11 +423,12 @@ GetClosestInterestingAccessible(id anObject)
- (NSString*)role
{
if (!mGeckoAccessible)
AccessibleWrap* accWrap = [self getGeckoAccessible];
if (!accWrap)
return nil;
#ifdef DEBUG_A11Y
NS_ASSERTION(nsAccUtils::IsTextInterfaceSupportCorrect(mGeckoAccessible),
NS_ASSERTION(nsAccUtils::IsTextInterfaceSupportCorrect(accWrap),
"Does not support Text when it should");
#endif
@ -427,10 +448,11 @@ GetClosestInterestingAccessible(id anObject)
- (NSString*)subrole
{
if (!mGeckoAccessible)
AccessibleWrap* accWrap = [self getGeckoAccessible];
if (!accWrap)
return nil;
nsIAtom* landmark = mGeckoAccessible->LandmarkRole();
nsIAtom* landmark = accWrap->LandmarkRole();
if (landmark) {
if (landmark == nsGkAtoms::application)
return @"AXLandmarkApplication";
@ -457,7 +479,7 @@ GetClosestInterestingAccessible(id anObject)
return @"AXContentList"; // 10.6+ NSAccessibilityContentListSubrole;
case roles::ENTRY:
if (mGeckoAccessible->IsSearchbox())
if (accWrap->IsSearchbox())
return @"AXSearchField";
break;
@ -528,7 +550,7 @@ struct RoleDescrComparator
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
nsAutoString title;
mGeckoAccessible->Name(title);
[self getGeckoAccessible]->Name(title);
return nsCocoaUtils::ToNSString(title);
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
@ -539,7 +561,7 @@ struct RoleDescrComparator
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
nsAutoString value;
mGeckoAccessible->Value(value);
[self getGeckoAccessible]->Value(value);
return nsCocoaUtils::ToNSString(value);
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
@ -567,11 +589,12 @@ struct RoleDescrComparator
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
if (mGeckoAccessible->IsDefunct())
AccessibleWrap* accWrap = [self getGeckoAccessible];
if (accWrap->IsDefunct())
return nil;
nsAutoString desc;
mGeckoAccessible->Description(desc);
accWrap->Description(desc);
return nsCocoaUtils::ToNSString(desc);
@ -583,7 +606,7 @@ struct RoleDescrComparator
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
nsAutoString helpText;
mGeckoAccessible->Help(helpText);
[self getGeckoAccessible]->Help(helpText);
return nsCocoaUtils::ToNSString(helpText);
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
@ -601,26 +624,29 @@ struct RoleDescrComparator
- (BOOL)isFocused
{
return FocusMgr()->IsFocused(mGeckoAccessible);
return FocusMgr()->IsFocused([self getGeckoAccessible]);
}
- (BOOL)canBeFocused
{
return mGeckoAccessible && (mGeckoAccessible->InteractiveState() & states::FOCUSABLE);
AccessibleWrap* accWrap = [self getGeckoAccessible];
return accWrap && (accWrap->InteractiveState() & states::FOCUSABLE);
}
- (BOOL)focus
{
if (!mGeckoAccessible)
AccessibleWrap* accWrap = [self getGeckoAccessible];
if (!accWrap)
return NO;
mGeckoAccessible->TakeFocus();
accWrap->TakeFocus();
return YES;
}
- (BOOL)isEnabled
{
return mGeckoAccessible && ((mGeckoAccessible->InteractiveState() & states::UNAVAILABLE) == 0);
AccessibleWrap* accWrap = [self getGeckoAccessible];
return accWrap && ((accWrap->InteractiveState() & states::UNAVAILABLE) == 0);
}
// The root accessible calls this when the focused node was
@ -643,7 +669,7 @@ struct RoleDescrComparator
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
AccessibleWrap* accWrap = static_cast<AccessibleWrap*>(mGeckoAccessible);
AccessibleWrap* accWrap = static_cast<AccessibleWrap*>([self getGeckoAccessible]);
// Get a pointer to the native window (NSWindow) we reside in.
NSWindow *nativeWindow = nil;
@ -692,7 +718,7 @@ struct RoleDescrComparator
- (BOOL)isExpired
{
return !mGeckoAccessible;
return ![self getGeckoAccessible];
}
#pragma mark -

View File

@ -73,7 +73,7 @@ enum CheckboxValue {
- (BOOL)accessibilityIsIgnored
{
return !mGeckoAccessible;
return ![self getGeckoAccessible];
}
- (NSArray*)accessibilityActionNames
@ -118,12 +118,13 @@ enum CheckboxValue {
{
// both buttons and checkboxes have only one action. we should really stop using arbitrary
// arrays with actions, and define constants for these actions.
mGeckoAccessible->DoAction(0);
[self getGeckoAccessible]->DoAction(0);
}
- (BOOL)isTab
{
return (mGeckoAccessible && (mGeckoAccessible->Role() == roles::PAGETAB));
AccessibleWrap* accWrap = [self getGeckoAccessible];
return (accWrap && (accWrap->Role() == roles::PAGETAB));
}
@end
@ -148,7 +149,7 @@ enum CheckboxValue {
- (int)isChecked
{
uint64_t state = mGeckoAccessible->NativeState();
uint64_t state = [self getGeckoAccessible]->NativeState();
// check if we're checked or in a mixed state
if (state & states::CHECKED) {
@ -292,10 +293,10 @@ enum CheckboxValue {
*/
- (id)value
{
if (!mGeckoAccessible)
if (![self getGeckoAccessible])
return nil;
Accessible* accessible = mGeckoAccessible->GetSelectedItem(0);
Accessible* accessible = [self getGeckoAccessible]->GetSelectedItem(0);
if (!accessible)
return nil;
@ -339,29 +340,29 @@ enum CheckboxValue {
- (NSUInteger)accessibilityArrayAttributeCount:(NSString*)attribute
{
if (!mGeckoAccessible)
if (![self getGeckoAccessible])
return 0;
// By default this calls -[[mozAccessible children] count].
// Since we don't cache mChildren. This is faster.
if ([attribute isEqualToString:NSAccessibilityChildrenAttribute])
return mGeckoAccessible->ChildCount() ? 1 : 0;
return [self getGeckoAccessible]->ChildCount() ? 1 : 0;
return [super accessibilityArrayAttributeCount:attribute];
}
- (NSArray*)children
{
if (!mGeckoAccessible)
if (![self getGeckoAccessible])
return nil;
nsDeckFrame* deckFrame = do_QueryFrame(mGeckoAccessible->GetFrame());
nsDeckFrame* deckFrame = do_QueryFrame([self getGeckoAccessible]->GetFrame());
nsIFrame* selectedFrame = deckFrame ? deckFrame->GetSelectedBox() : nullptr;
Accessible* selectedAcc = nullptr;
if (selectedFrame) {
nsINode* node = selectedFrame->GetContent();
selectedAcc = mGeckoAccessible->Document()->GetAccessible(node);
selectedAcc = [self getGeckoAccessible]->Document()->GetAccessible(node);
}
if (selectedAcc) {

View File

@ -33,7 +33,7 @@ getNativeViewFromRootAccessible(Accessible* aAccessible)
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
// if we're expired, we don't support any attributes.
if (!mGeckoAccessible)
if (![self getGeckoAccessible])
return [NSArray array];
// standard attributes that are shared and supported by root accessible (AXMain) elements.
@ -95,7 +95,7 @@ getNativeViewFromRootAccessible(Accessible* aAccessible)
if (mParallelView)
return (id)mParallelView;
mParallelView = getNativeViewFromRootAccessible (mGeckoAccessible);
mParallelView = getNativeViewFromRootAccessible ([self getGeckoAccessible]);
NSAssert(mParallelView, @"can't return root accessible's native parallel view.");
return mParallelView;

View File

@ -20,17 +20,19 @@
mozilla::ErrorResult rv;
// XXX use the flattening API when there are available
// see bug 768298
mGeckoAccessible->GetContent()->GetTextContent(title, rv);
[self getGeckoAccessible]->GetContent()->GetTextContent(title, rv);
return nsCocoaUtils::ToNSString(title);
}
- (id)value
{
if (!mGeckoAccessible || !mGeckoAccessible->IsHyperText())
AccessibleWrap* accWrap = [self getGeckoAccessible];
if (!accWrap || !accWrap->IsHyperText())
return nil;
uint32_t level = mGeckoAccessible->AsHyperText()->GetLevelInternal();
uint32_t level = accWrap->AsHyperText()->GetLevelInternal();
return [NSNumber numberWithInt:level];
}
@ -45,7 +47,7 @@
- (NSArray*)accessibilityAttributeNames
{
// if we're expired, we don't support any attributes.
if (!mGeckoAccessible)
if (![self getGeckoAccessible])
return [NSArray array];
static NSMutableArray* attributes = nil;
@ -69,7 +71,7 @@
- (NSArray*)accessibilityActionNames
{
// if we're expired, we don't support any attributes.
if (!mGeckoAccessible)
if (![self getGeckoAccessible])
return [NSArray array];
static NSArray* actionNames = nil;
@ -84,11 +86,13 @@
- (void)accessibilityPerformAction:(NSString*)action
{
if (!mGeckoAccessible)
AccessibleWrap* accWrap = [self getGeckoAccessible];
if (!accWrap)
return;
if ([action isEqualToString:NSAccessibilityPressAction])
mGeckoAccessible->DoAction(0);
accWrap->DoAction(0);
else
[super accessibilityPerformAction:action];
}
@ -105,11 +109,11 @@
- (NSURL*)url
{
if (!mGeckoAccessible || mGeckoAccessible->IsDefunct())
if (![self getGeckoAccessible] || [self getGeckoAccessible]->IsDefunct())
return nil;
nsAutoString value;
mGeckoAccessible->Value(value);
[self getGeckoAccessible]->Value(value);
NSString* urlString = value.IsEmpty() ? nil : nsCocoaUtils::ToNSString(value);
if (!urlString)

View File

@ -67,7 +67,7 @@ ToNSString(id aValue)
- (BOOL)accessibilityIsIgnored
{
return !mGeckoAccessible;
return ![self getGeckoAccessible];
}
- (NSArray*)accessibilityAttributeNames
@ -126,11 +126,13 @@ ToNSString(id aValue)
return [self text];
}
AccessibleWrap* accWrap = [self getGeckoAccessible];
if ([attribute isEqualToString:@"AXRequired"])
return [NSNumber numberWithBool:!!(mGeckoAccessible->State() & states::REQUIRED)];
return [NSNumber numberWithBool:!!(accWrap->State() & states::REQUIRED)];
if ([attribute isEqualToString:@"AXInvalid"])
return [NSNumber numberWithBool:!!(mGeckoAccessible->State() & states::INVALID)];
return [NSNumber numberWithBool:!!(accWrap->State() & states::INVALID)];
if ([attribute isEqualToString:NSAccessibilityVisibleCharacterRangeAttribute])
return [self visibleCharacterRange];
@ -323,7 +325,7 @@ ToNSString(id aValue)
return YES;
if (mGeckoTextAccessible)
return (mGeckoAccessible->State() & states::READONLY) == 0;
return ([self getGeckoAccessible]->State() & states::READONLY) == 0;
return NO;
@ -353,7 +355,7 @@ ToNSString(id aValue)
- (NSString*)text
{
if (!mGeckoAccessible || !mGeckoTextAccessible)
if (![self getGeckoAccessible] || !mGeckoTextAccessible)
return nil;
// A password text field returns an empty value
@ -371,7 +373,7 @@ ToNSString(id aValue)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
if (!mGeckoAccessible || !mGeckoTextAccessible)
if (![self getGeckoAccessible] || !mGeckoTextAccessible)
return 0;
return mGeckoTextAccessible ? mGeckoTextAccessible->CharacterCount() : 0;
@ -496,18 +498,22 @@ ToNSString(id aValue)
- (NSString*)text
{
if (!mGeckoAccessible)
AccessibleWrap* accWrap = [self getGeckoAccessible];
if (!accWrap)
return nil;
return nsCocoaUtils::ToNSString(mGeckoAccessible->AsTextLeaf()->Text());
return nsCocoaUtils::ToNSString(accWrap->AsTextLeaf()->Text());
}
- (long)textLength
{
if (!mGeckoAccessible)
AccessibleWrap* accWrap = [self getGeckoAccessible];
if (!accWrap)
return 0;
return mGeckoAccessible->AsTextLeaf()->Text().Length();
return accWrap->AsTextLeaf()->Text().Length();
}
@end