Bug 1625153 - Implement the WAI-ARIA 1.2 code role, r=Jamie
authorMarco Zehe <mzehe@mozilla.com>
Thu, 26 Mar 2020 21:26:15 +0000
changeset 2725560 51eebe7d6199e974f8d395110cc0cc7eeac369cf
parent 2725559 e608cbaf20d451fe0dd63e778ffa3f9408b8c43d
child 2725561 b2c96c58335b3a1bdab52c01835a0eaa6a8c1a15
push id510263
push usermalexandru@mozilla.com
push dateFri, 27 Mar 2020 09:57:42 +0000
treeherdertry@750dbc575147 [default view] [failures only]
reviewersJamie
bugs1625153
milestone76.0a1
Bug 1625153 - Implement the WAI-ARIA 1.2 code role, r=Jamie Differential Revision: https://phabricator.services.mozilla.com/D68432
accessible/base/ARIAMap.cpp
accessible/base/MarkupMap.h
accessible/base/Role.h
accessible/base/RoleMap.h
accessible/interfaces/nsIAccessibleRole.idl
accessible/mac/mozAccessible.mm
accessible/tests/mochitest/attributes/test_xml-roles.html
accessible/tests/mochitest/role.js
accessible/tests/mochitest/role/test_aria.html
--- a/accessible/base/ARIAMap.cpp
+++ b/accessible/base/ARIAMap.cpp
@@ -134,16 +134,25 @@ static const nsRoleMapEntry sWAIRoleMaps
     eNoValue,
     eCheckUncheckAction,
     eNoLiveAttr,
     kGenericAccType,
     kNoReqStates,
     eARIACheckableMixed,
     eARIAReadonly
   },
+  { // code
+    nsGkAtoms::code,
+    roles::CODE,
+    kUseMapRole,
+    eNoValue,
+    eNoAction,
+    eNoLiveAttr,
+    kGenericAccType,
+  },
   { // columnheader
     nsGkAtoms::columnheader,
     roles::COLUMNHEADER,
     kUseMapRole,
     eNoValue,
     eSortAction,
     eNoLiveAttr,
     eTableCell,
--- a/accessible/base/MarkupMap.h
+++ b/accessible/base/MarkupMap.h
@@ -47,16 +47,19 @@ MARKUPMAP(
             tableEl->GetCaption() == aElement) {
           return new HTMLCaptionAccessible(aElement, aContext->Document());
         }
       }
       return nullptr;
     },
     0)
 
+// XXX: Uncomment this once HTML-aam agrees to map to same as ARIA.
+// MARKUPMAP(code, New_HyperText, roles::CODE)
+
 MARKUPMAP(dd, New_HTMLDtOrDd<HyperTextAccessibleWrap>, roles::DEFINITION)
 
 MARKUPMAP(del, New_HyperText, roles::CONTENT_DELETION)
 
 MARKUPMAP(details, New_HyperText, roles::DETAILS)
 
 MARKUPMAP(
     div,
--- a/accessible/base/Role.h
+++ b/accessible/base/Role.h
@@ -1056,17 +1056,22 @@ enum Role {
    */
   SUGGESTION = 180,
 
   /**
    * The WAI-ARIA comment role.
    */
   COMMENT = 181,
 
-  LAST_ROLE = COMMENT
+  /**
+   * A snippet of program code. ATs might want to treat this differently.
+   */
+  CODE = 182,
+
+  LAST_ROLE = CODE
 };
 
 }  // namespace roles
 
 typedef enum mozilla::a11y::roles::Role role;
 
 }  // namespace a11y
 }  // namespace mozilla
--- a/accessible/base/RoleMap.h
+++ b/accessible/base/RoleMap.h
@@ -1652,9 +1652,18 @@ ROLE(SUGGESTION,
 ROLE(COMMENT,
      "comment",
      ATK_ROLE_COMMENT,
      NSAccessibilityGroupRole,
      USE_ROLE_STRING,
      IA2_ROLE_COMMENT,
      java::SessionAccessibility::CLASSNAME_VIEW,
      eNoNameRule)
+
+ROLE(CODE,
+     "code",
+     ATK_ROLE_STATIC,
+     NSAccessibilityGroupRole,
+     USE_ROLE_STRING,
+     IA2_ROLE_TEXT_FRAME,
+     java::SessionAccessibility::CLASSNAME_VIEW,
+     eNoNameRule)
 // clang-format on
--- a/accessible/interfaces/nsIAccessibleRole.idl
+++ b/accessible/interfaces/nsIAccessibleRole.idl
@@ -1050,9 +1050,14 @@ interface nsIAccessibleRole : nsISupport
    */
   const unsigned long ROLE_SUGGESTION = 180;
 
   /**
    * The WAI-ARIA comment role.
    */
   const unsigned long ROLE_COMMENT = 181;
 
+  /**
+   * A snippet of program code. ATs might want to treat this differently.
+   */
+  const unsigned long ROLE_CODE = 182;
+
 };
--- a/accessible/mac/mozAccessible.mm
+++ b/accessible/mac/mozAccessible.mm
@@ -947,16 +947,19 @@ static inline NSMutableArray* ConvertToN
       break;
 
     case roles::CONTENT_DELETION:
       return @"AXDeleteStyleGroup";
 
     case roles::CONTENT_INSERTION:
       return @"AXInsertStyleGroup";
 
+    case roles::CODE:
+      return @"AXCodeStyleGroup";
+
     case roles::TOGGLE_BUTTON:
       return @"AXToggle";
 
     default:
       break;
   }
 
   return nil;
--- a/accessible/tests/mochitest/attributes/test_xml-roles.html
+++ b/accessible/tests/mochitest/attributes/test_xml-roles.html
@@ -33,16 +33,18 @@
       testAttrs("form", {"xml-roles": "form"}, true);
       testAttrs("feed", {"xml-roles": "feed"}, true);
       testAttrs("article", {"xml-roles": "article"}, true);
       testAttrs("main_element", {"xml-roles": "main"}, true);
       testAttrs("figure", {"xml-roles": "figure"}, true);
 
       testAttrs("search", {"xml-roles": "searchbox"}, true);
 
+      testAttrs("code", {"xml-roles": "code"}, true);
+
       testAttrs("open-1", {"xml-roles": "open-fence"}, true);
       testAttrs("open-2", {"xml-roles": "open-fence"}, true);
       testAttrs("open-3", {"xml-roles": "open-fence"}, true);
       testAttrs("open-4", {"xml-roles": "open-fence"}, true);
       testAttrs("open-5", {"xml-roles": "open-fence"}, true);
       testAttrs("open-6", {"xml-roles": "open-fence"}, true);
       testAttrs("open-7", {"xml-roles": "open-fence"}, true);
 
@@ -173,16 +175,18 @@
   <article id="form" role="form">a form area</article>
   <div id="feed" role="feed">a feed</div>
   <article id="article">article</article>
   <main id="main_element">another main area</main>
   <div id="figure" role="figure">a figure</div>
 
   <input id="search" type="search"/>
 
+  <div id="code" role="code"></div>
+
   <!-- open-fence, separator, close-fence -->
   <math><mo id="open-1">(</mo><mi>x</mi><mo id="sep-1">,</mo><mi>y</mi><mo id="close-1">)</mo></math>
   <math><mrow><mo id="open-2">(</mo><mi>x</mi><mo id="sep-2">,</mo><mi>y</mi><mo id="close-2">)</mo></mrow></math>
   <math><mstyle><mo id="open-3">(</mo><mi>x</mi><mo id="sep-3">,</mo><mi>y</mi><mo id="close-3">)</mo></mstyle></math>
   <math><msqrt><mo id="open-4">(</mo><mi>x</mi><mo id="sep-4">,</mo><mi>y</mi><mo id="close-4">)</mo></msqrt></math>
   <math><menclose><mo id="open-5">(</mo><mi>x</mi><mo id="sep-5">,</mo><mi>y</mi><mo id="close-5">)</mo></menclose></math>
   <math><merror><mo id="open-6">(</mo><mi>x</mi><mo id="sep-6">,</mo><mi>y</mi><mo id="close-6">)</mo></merror></math>
   <math><mtable><mtr><mtd><mo id="open-7">(</mo><mi>x</mi><mo id="sep-7">,</mo><mi>y</mi><mo id="close-7">)</mo></mtd></mtr></mtable></math>
--- a/accessible/tests/mochitest/role.js
+++ b/accessible/tests/mochitest/role.js
@@ -12,16 +12,17 @@ const ROLE_AUTOCOMPLETE = nsIAccessibleR
 const ROLE_BLOCKQUOTE = nsIAccessibleRole.ROLE_BLOCKQUOTE;
 const ROLE_BUTTONDROPDOWNGRID = nsIAccessibleRole.ROLE_BUTTONDROPDOWNGRID;
 const ROLE_CANVAS = nsIAccessibleRole.ROLE_CANVAS;
 const ROLE_CAPTION = nsIAccessibleRole.ROLE_CAPTION;
 const ROLE_CELL = nsIAccessibleRole.ROLE_CELL;
 const ROLE_CHECKBUTTON = nsIAccessibleRole.ROLE_CHECKBUTTON;
 const ROLE_CHECK_MENU_ITEM = nsIAccessibleRole.ROLE_CHECK_MENU_ITEM;
 const ROLE_CHROME_WINDOW = nsIAccessibleRole.ROLE_CHROME_WINDOW;
+const ROLE_CODE = nsIAccessibleRole.ROLE_CODE;
 const ROLE_COLUMNHEADER = nsIAccessibleRole.ROLE_COLUMNHEADER;
 const ROLE_COMBOBOX = nsIAccessibleRole.ROLE_COMBOBOX;
 const ROLE_COMBOBOX_LIST = nsIAccessibleRole.ROLE_COMBOBOX_LIST;
 const ROLE_COMBOBOX_OPTION = nsIAccessibleRole.ROLE_COMBOBOX_OPTION;
 const ROLE_COMMENT = nsIAccessibleRole.ROLE_COMMENT;
 const ROLE_CONTENT_DELETION = nsIAccessibleRole.ROLE_CONTENT_DELETION;
 const ROLE_CONTENT_INSERTION = nsIAccessibleRole.ROLE_CONTENT_INSERTION;
 const ROLE_DATE_EDITOR = nsIAccessibleRole.ROLE_DATE_EDITOR;
--- a/accessible/tests/mochitest/role/test_aria.html
+++ b/accessible/tests/mochitest/role/test_aria.html
@@ -27,16 +27,17 @@
       testRole("aria_alert", ROLE_ALERT);
       testRole("aria_alertdialog", ROLE_DIALOG);
       testRole("aria_application", ROLE_APPLICATION);
       testRole("aria_article", ROLE_ARTICLE);
       testRole("aria_blockquote", ROLE_BLOCKQUOTE);
       testRole("aria_button", ROLE_PUSHBUTTON);
       testRole("aria_caption", ROLE_CAPTION);
       testRole("aria_checkbox", ROLE_CHECKBUTTON);
+      testRole("aria_code", ROLE_CODE);
       testRole("aria_columnheader", ROLE_COLUMNHEADER);
       testRole("aria_combobox", ROLE_EDITCOMBOBOX);
       testRole("aria_comment", ROLE_COMMENT);
       testRole("aria_deletion", ROLE_CONTENT_DELETION);
       testRole("aria_dialog", ROLE_DIALOG);
       testRole("aria_directory", ROLE_LIST);
       testRole("aria_document", ROLE_NON_NATIVE_DOCUMENT);
       testRole("aria_form", ROLE_FORM);
@@ -243,16 +244,17 @@
   <span id="aria_alert" role="alert"></span>
   <span id="aria_alertdialog" role="alertdialog"></span>
   <span id="aria_application" role="application"></span>
   <span id="aria_article" role="article"></span>
   <span id="aria_blockquote" role="blockquote"></span>
   <span id="aria_button" role="button"></span>
   <span id="aria_caption" role="caption"></span>
   <span id="aria_checkbox" role="checkbox"></span>
+  <span id="aria_code" role="code"></span>
   <span id="aria_columnheader" role="columnheader"></span>
   <span id="aria_combobox" role="combobox"></span>
   <span id="aria_comment" role="comment"></span>
   <span id="aria_deletion" role="deletion"></span>
   <span id="aria_dialog" role="dialog"></span>
   <span id="aria_directory" role="directory"></span>
   <span id="aria_document" role="document"></span>
   <span id="aria_form" role="form"></span>