Bug 718700 - Implement subroles for WAI-ARIA Landmarks. f=marcoz r=dbolter
authorHub Figuière <hfiguiere@mozilla.com>
Fri, 29 Jun 2012 14:12:18 -0700
changeset 98456 163d51da4349e8d7cf48a8b5d5a1f203f78536f5
parent 98455 fbc2677b146dcb48f01d7fce2e8532be8e30908e
child 98457 709db7ae0dbc4396bdb8f79b4531c3a47a10e3ba
push id11488
push userhfiguiere@mozilla.com
push dateThu, 05 Jul 2012 22:52:09 +0000
treeherdermozilla-inbound@163d51da4349 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdbolter
bugs718700
milestone16.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 718700 - Implement subroles for WAI-ARIA Landmarks. f=marcoz r=dbolter
accessible/src/mac/mozAccessible.mm
dom/locales/en-US/chrome/accessibility/mac/accessible.properties
--- a/accessible/src/mac/mozAccessible.mm
+++ b/accessible/src/mac/mozAccessible.mm
@@ -4,28 +4,30 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  
 #import "mozAccessible.h"
 
 #import "MacUtils.h"
 #import "mozView.h"
 
 #include "Accessible-inl.h"
+#include "nsAccUtils.h"
 #include "nsIAccessibleRelation.h"
 #include "nsIAccessibleText.h"
 #include "nsIAccessibleEditableText.h"
 #include "Relation.h"
 #include "Role.h"
 #include "RootAccessible.h"
 
 #include "mozilla/Services.h"
 #include "nsRect.h"
 #include "nsCocoaUtils.h"
 #include "nsCoord.h"
 #include "nsObjCExceptions.h"
+#include "nsWhitespaceTokenizer.h"
 
 using namespace mozilla;
 using namespace mozilla::a11y;
 
 // converts a screen-global point in the cocoa coordinate system (with origo in the bottom-left corner
 // of the screen), into a top-left screen point, that gecko can use.
 static inline void
 ConvertCocoaToGeckoPoint(NSPoint &aInPoint, nsPoint &aOutPoint)
@@ -426,16 +428,52 @@ GetClosestInterestingAccessible(id anObj
       return NSAccessibilityUnknownRole;
   }
 
 #undef ROLE
 }
 
 - (NSString*)subrole
 {
+  if (!mGeckoAccessible)
+    return nil;
+
+  // XXX maybe we should cache the subrole.
+  nsAutoString xmlRoles;
+  nsCOMPtr<nsIPersistentProperties> attributes;
+
+  // XXX we don't need all the attributes (see bug 771113)
+  nsresult rv = mGeckoAccessible->GetAttributes(getter_AddRefs(attributes));
+  if (NS_SUCCEEDED(rv) && attributes)
+    nsAccUtils::GetAccAttr(attributes, nsGkAtoms::xmlroles, xmlRoles);
+
+  nsWhitespaceTokenizer tokenizer(xmlRoles);
+
+  while (tokenizer.hasMoreTokens()) {
+    const nsDependentSubstring token(tokenizer.nextToken());
+
+    if (token.EqualsLiteral("banner"))
+      return @"AXLandmarkBanner";
+
+    if (token.EqualsLiteral("complementary"))
+      return @"AXLandmarkComplementary";
+
+    if (token.EqualsLiteral("contentinfo"))
+      return @"AXLandmarkContentInfo";
+
+    if (token.EqualsLiteral("main"))
+      return @"AXLandmarkMain";
+
+    if (token.EqualsLiteral("navigation"))
+      return @"AXLandmarkNavigation";
+
+    if (token.EqualsLiteral("search"))
+      return @"AXLandmarkSearch";
+  }
+
   switch (mRole) {
     case roles::LIST:
       return @"AXContentList"; // 10.6+ NSAccessibilityContentListSubrole;
 
     case roles::DEFINITION_LIST:
       return @"AXDefinitionList"; // 10.6+ NSAccessibilityDefinitionListSubrole;
 
     case roles::TERM:
@@ -450,25 +488,43 @@ GetClosestInterestingAccessible(id anObj
 
   return nil;
 }
 
 - (NSString*)roleDescription
 {
   if (mRole == roles::DOCUMENT)
     return utils::LocalizedString(NS_LITERAL_STRING("htmlContent"));
-  
+
   NSString* subrole = [self subrole];
-  
+
   if ((mRole == roles::LISTITEM) && [subrole isEqualToString:@"AXTerm"])
     return utils::LocalizedString(NS_LITERAL_STRING("term"));
   if ((mRole == roles::PARAGRAPH) && [subrole isEqualToString:@"AXDefinition"])
     return utils::LocalizedString(NS_LITERAL_STRING("definition"));
-  
-  return NSAccessibilityRoleDescription([self role], subrole);
+
+  NSString* role = [self role];
+
+  // the WAI-ARIA Landmarks
+  if ([role isEqualToString:NSAccessibilityGroupRole]) {
+    if ([subrole isEqualToString:@"AXLandmarkBanner"])
+      return utils::LocalizedString(NS_LITERAL_STRING("banner"));
+    if ([subrole isEqualToString:@"AXLandmarkComplementary"])
+      return utils::LocalizedString(NS_LITERAL_STRING("complementary"));
+    if ([subrole isEqualToString:@"AXLandmarkContentInfo"])
+      return utils::LocalizedString(NS_LITERAL_STRING("content"));
+    if ([subrole isEqualToString:@"AXLandmarkMain"])
+      return utils::LocalizedString(NS_LITERAL_STRING("main"));
+    if ([subrole isEqualToString:@"AXLandmarkNavigation"])
+      return utils::LocalizedString(NS_LITERAL_STRING("navigation"));
+    if ([subrole isEqualToString:@"AXLandmarkSearch"])
+      return utils::LocalizedString(NS_LITERAL_STRING("search"));
+  }
+
+  return NSAccessibilityRoleDescription(role, subrole);
 }
 
 - (NSString*)title
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
 
   nsAutoString title;
   mGeckoAccessible->Name(title);
--- a/dom/locales/en-US/chrome/accessibility/mac/accessible.properties
+++ b/dom/locales/en-US/chrome/accessibility/mac/accessible.properties
@@ -20,8 +20,15 @@ cycle   =       Cycle
 # (Mac Only)
 # The Role Description for AXWebArea (the web widget). Like in Safari.
 htmlContent = HTML Content
 # The Role Description for the Tab button.
 tab     =       tab
 # The Role Description for definition list dl, dt and dd
 term    =       term
 definition =    definition
+# The Role Description for WAI-ARIA Landmarks
+search  =       search
+banner  =       banner
+navigation =    navigation
+complementary = complementary
+content =       content
+main    =       main