Bug 718624 - Handle press action on links, expose the URL. r=surkov
authorHub Figuière <hfiguiere@mozilla.com>
Fri, 27 Jan 2012 07:50:04 -0800
changeset 85547 b07da7be62c2a89c8af4a839a27500744c350020
parent 85546 7a0a7c36def8a15fce297af412bf1e57a4aaaee1
child 85548 7b3a4af0e68a1dd62d178d32cefeea3165ac071f
push id5384
push userhfiguiere@mozilla.com
push dateFri, 27 Jan 2012 16:26:52 +0000
treeherdermozilla-inbound@b07da7be62c2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssurkov
bugs718624
milestone12.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 718624 - Handle press action on links, expose the URL. r=surkov
accessible/src/mac/mozAccessible.mm
accessible/src/mac/mozActionElements.mm
accessible/src/mac/mozHTMLAccessible.h
accessible/src/mac/mozHTMLAccessible.mm
accessible/src/mac/mozTextAccessible.mm
accessible/src/mac/nsAccessibleWrap.mm
--- a/accessible/src/mac/mozAccessible.mm
+++ b/accessible/src/mac/mozAccessible.mm
@@ -216,17 +216,17 @@ GetNativeFromGeckoAccessible(nsIAccessib
 {  
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
 
   if (mIsExpired)
     return nil;
 
 #if DEBUG
   if ([attribute isEqualToString:@"AXMozDescription"])
-    return [NSString stringWithFormat:@"role = %u", mRole];
+    return [NSString stringWithFormat:@"role = %u native = %@", mRole, [self class]];
 #endif
   
   if ([attribute isEqualToString:NSAccessibilityChildrenAttribute])
     return [self children];
   if ([attribute isEqualToString:NSAccessibilityParentAttribute]) 
     return [self parent];
   
 #ifdef DEBUG_hakan
@@ -333,17 +333,19 @@ GetNativeFromGeckoAccessible(nsIAccessib
 
 - (NSArray*)accessibilityActionNames 
 {
   return nil;
 }
 
 - (NSString*)accessibilityActionDescription:(NSString*)action 
 {
-  return nil;
+  // by default we return whatever the MacOS API know about.
+  // if you have custom actions, override.
+  return NSAccessibilityActionDescription(action);
 }
 
 - (void)accessibilityPerformAction:(NSString*)action 
 {
 }
 
 - (id)accessibilityFocusedUIElement
 {
--- a/accessible/src/mac/mozActionElements.mm
+++ b/accessible/src/mac/mozActionElements.mm
@@ -70,16 +70,19 @@ enum CheckboxValue {
                                                   NSAccessibilityWindowAttribute, // required
                                                   NSAccessibilityPositionAttribute, // required
                                                   NSAccessibilityTopLevelUIElementAttribute, // required
                                                   NSAccessibilityHelpAttribute,
                                                   NSAccessibilityEnabledAttribute, // required
                                                   NSAccessibilityFocusedAttribute, // required
                                                   NSAccessibilityTitleAttribute, // required
                                                   NSAccessibilityDescriptionAttribute,
+#if DEBUG
+                                                  @"AXMozDescription",
+#endif
                                                   nil];
   }
   return attributes;
 
   NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
 }
 
 - (id)accessibilityAttributeValue:(NSString *)attribute
@@ -214,16 +217,19 @@ enum CheckboxValue {
                                                   NSAccessibilityWindowAttribute, // required
                                                   NSAccessibilityTopLevelUIElementAttribute, // required
                                                   NSAccessibilityHelpAttribute,
                                                   NSAccessibilityEnabledAttribute, // required
                                                   NSAccessibilityFocusedAttribute, // required
                                                   NSAccessibilityTitleAttribute, // required for popupmenus, and for menubuttons with a title
                                                   NSAccessibilityChildrenAttribute, // required
                                                   NSAccessibilityDescriptionAttribute, // required if it has no title attr
+#if DEBUG
+                                                  @"AXMozDescription",
+#endif
                                                   nil];
   }
   return attributes;
 
   NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
 }
 
 - (id)accessibilityAttributeValue:(NSString *)attribute
--- a/accessible/src/mac/mozHTMLAccessible.h
+++ b/accessible/src/mac/mozHTMLAccessible.h
@@ -38,8 +38,12 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 #import "mozAccessible.h"
 
 @interface mozHeadingAccessible : mozAccessible
 
 @end
+
+@interface mozLinkAccessible : mozAccessible
+
+@end
--- a/accessible/src/mac/mozHTMLAccessible.mm
+++ b/accessible/src/mac/mozHTMLAccessible.mm
@@ -37,20 +37,97 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #import "mozHTMLAccessible.h"
 
 #import "nsHyperTextAccessible.h"
 
+#import "nsCocoaUtils.h"
+
 @implementation mozHeadingAccessible
 
 - (id)value
 {
   if (!mGeckoAccessible || !mGeckoAccessible->IsHyperText())
     return nil;
 
   PRUint32 level = mGeckoAccessible->AsHyperText()->GetLevelInternal();
   return [NSNumber numberWithInt:level];
 }
 
 @end
+
+@interface mozLinkAccessible ()
+-(NSURL*)url;
+@end
+
+@implementation mozLinkAccessible
+
+- (NSArray*)accessibilityAttributeNames
+{
+  // if we're expired, we don't support any attributes.
+  if (mIsExpired)
+    return [NSArray array];
+  
+  static NSMutableArray* attributes = nil;
+  
+  if (!attributes) {
+    attributes = [[super accessibilityAttributeNames] mutableCopy];
+    [attributes addObject:NSAccessibilityURLAttribute];
+  }
+
+  return attributes;
+}
+
+- (id)accessibilityAttributeValue:(NSString *)attribute
+{
+  if ([attribute isEqualToString:NSAccessibilityURLAttribute])
+    return [self url];
+
+  return [super accessibilityAttributeValue:attribute];
+}
+
+- (NSArray*)accessibilityActionNames 
+{
+    // if we're expired, we don't support any attributes.
+  if (mIsExpired)
+    return [NSArray array];
+
+  static NSArray* actionNames = nil;
+
+  if (!actionNames) {
+    actionNames = [[NSArray alloc] initWithObjects:NSAccessibilityPressAction,
+                                   nil];
+  }
+
+  return actionNames;
+}
+
+- (void)accessibilityPerformAction:(NSString*)action 
+{
+  if (!mGeckoAccessible)
+    return;
+
+  if ([action isEqualToString:NSAccessibilityPressAction])
+    mGeckoAccessible->DoAction(0);
+  else
+    [super accessibilityPerformAction:action];
+}
+
+- (NSURL*)url
+{
+  if (!mGeckoAccessible)
+    return nil;
+
+  nsAutoString value;
+  nsresult rv = mGeckoAccessible->GetValue(value);
+  NS_ENSURE_SUCCESS(rv, nil);
+
+  NSString* urlString = value.IsEmpty() ? nil : nsCocoaUtils::ToNSString(value);
+  if (!urlString)
+    return nil;
+
+  return [NSURL URLWithString:urlString];
+}
+
+@end
--- a/accessible/src/mac/mozTextAccessible.mm
+++ b/accessible/src/mac/mozTextAccessible.mm
@@ -58,16 +58,19 @@ using namespace mozilla::a11y;
                                                            NSAccessibilityTopLevelUIElementAttribute, // required
                                                            NSAccessibilityDescriptionAttribute, // required
                                                            /* text-specific attributes */
                                                            NSAccessibilitySelectedTextAttribute, // required
                                                            NSAccessibilitySelectedTextRangeAttribute, // required
                                                            NSAccessibilityNumberOfCharactersAttribute, // required
                                                            // TODO: NSAccessibilityVisibleCharacterRangeAttribute, // required
                                                            // TODO: NSAccessibilityInsertionPointLineNumberAttribute
+#if DEBUG
+                                                           @"AXMozDescription",
+#endif
                                                            nil];
   }
   return supportedAttributes;
 
   NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
 }
 
 - (id)accessibilityAttributeValue:(NSString*)attribute
@@ -274,16 +277,19 @@ using namespace mozilla::a11y;
                                                            NSAccessibilityTopLevelUIElementAttribute, // required
                                                            NSAccessibilityDescriptionAttribute, // required
                                                            /* text-specific attributes */
                                                            NSAccessibilitySelectedTextAttribute, // required
                                                            NSAccessibilitySelectedTextRangeAttribute, // required
                                                            NSAccessibilityNumberOfCharactersAttribute, // required
                                                            // TODO: NSAccessibilityVisibleCharacterRangeAttribute, // required
                                                            // TODO: NSAccessibilityInsertionPointLineNumberAttribute
+#if DEBUG
+                                                           @"AXMozDescription",
+#endif
                                                            nil];
   }
   return supportedAttributes;
 
   NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
 }
 
 - (NSArray *)accessibilityActionNames
--- a/accessible/src/mac/nsAccessibleWrap.mm
+++ b/accessible/src/mac/nsAccessibleWrap.mm
@@ -122,17 +122,20 @@ nsAccessibleWrap::GetNativeType ()
     case roles::ENTRY:
     case roles::STATICTEXT:
     case roles::LABEL:
     case roles::CAPTION:
     case roles::ACCEL_LABEL:
     case roles::TEXT_LEAF:
       // normal textfield (static or editable)
       return [mozTextAccessible class]; 
-      
+
+    case roles::LINK:
+      return [mozLinkAccessible class];
+
     case roles::COMBOBOX:
       return [mozPopupButtonAccessible class];
       
     default:
       return [mozAccessible class];
   }
   
   return nil;