Bug 718625 - Implement TextLeaf accessibles for Mac. Fix Heading title. r=tbsaunde

--HG--
extra : rebase_source : c5f3044614af18ace16f7a91d3b51effa48c9ff8
This commit is contained in:
Hub Figuière 2012-06-29 14:12:16 -07:00
parent c81599a0c3
commit 79fe9e58b7
5 changed files with 78 additions and 8 deletions

View File

@ -89,10 +89,12 @@ AccessibleWrap::GetNativeType ()
case roles::STATICTEXT:
case roles::CAPTION:
case roles::ACCEL_LABEL:
case roles::TEXT_LEAF:
case roles::PASSWORD_TEXT:
// normal textfield (static or editable)
return [mozTextAccessible class];
return [mozTextAccessible class];
case roles::TEXT_LEAF:
return [mozTextLeafAccessible class];
case roles::LINK:
return [mozLinkAccessible class];

View File

@ -472,7 +472,7 @@ GetClosestInterestingAccessible(id anObject)
nsAutoString title;
mGeckoAccessible->Name(title);
return title.IsEmpty() ? nil : [NSString stringWithCharacters:title.BeginReading() length:title.Length()];
return nsCocoaUtils::ToNSString(title);
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
}
@ -515,7 +515,8 @@ GetClosestInterestingAccessible(id anObject)
nsAutoString desc;
mGeckoAccessible->Description(desc);
return desc.IsEmpty() ? nil : [NSString stringWithCharacters:desc.BeginReading() length:desc.Length()];
return nsCocoaUtils::ToNSString(desc);
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
}

View File

@ -13,6 +13,17 @@
@implementation mozHeadingAccessible
- (NSString*)title
{
nsAutoString title;
// XXX use the flattening API when there are available
// see bug 768298
nsresult rv = mGeckoAccessible->GetContent()->GetTextContent(title);
NS_ENSURE_SUCCESS(rv, nil);
return nsCocoaUtils::ToNSString(title);
}
- (id)value
{
if (!mGeckoAccessible || !mGeckoAccessible->IsHyperText())

View File

@ -14,3 +14,8 @@
nsIAccessibleEditableText *mGeckoEditableTextAccessible; // strong
}
@end
@interface mozTextLeafAccessible : mozAccessible
{
}
@end

View File

@ -5,6 +5,7 @@
#include "AccessibleWrap.h"
#include "TextLeafAccessible.h"
#include "nsCocoaUtils.h"
#include "nsObjCExceptions.h"
@ -110,13 +111,18 @@ ToNSString(id aValue)
if ([attribute isEqualToString:NSAccessibilitySelectedTextAttribute])
return [self selectedText];
if ([attribute isEqualToString:NSAccessibilityTitleAttribute])
return @"";
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];
if ([[self role] isEqualToString:NSAccessibilityStaticTextRole]) {
NSString* selectedText = [self selectedText];
return (selectedText && [selectedText length]) ? selectedText : [self text];
}
return [self text];
}
@ -226,7 +232,7 @@ ToNSString(id aValue)
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
if ([attribute isEqualToString:NSAccessibilityValueAttribute])
return [self isReadOnly];
return ![self isReadOnly];
if ([attribute isEqualToString:NSAccessibilitySelectedTextAttribute] ||
[attribute isEqualToString:NSAccessibilitySelectedTextRangeAttribute] ||
@ -359,7 +365,7 @@ ToNSString(id aValue)
- (NSString*)text
{
if (!mGeckoTextAccessible)
if (!mGeckoAccessible || !mGeckoTextAccessible)
return nil;
// A password text field returns an empty value
@ -378,6 +384,9 @@ ToNSString(id aValue)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
if (!mGeckoAccessible || !mGeckoTextAccessible)
return 0;
return mGeckoTextAccessible ? mGeckoTextAccessible->CharacterCount() : 0;
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(0);
@ -484,3 +493,45 @@ ToNSString(id aValue)
}
@end
@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