Bug 1507365 - Allow labels inside toolbarbuttons to participate in accessible name calculation, r=Jamie
authorMarco Zehe <mzehe@mozilla.com>
Thu, 22 Nov 2018 05:57:48 +0000
changeset 504098 111154a7621cc50da7bed70c93171b96c8ef92f0
parent 504097 5f543ba66e2c74cfb9ece932447a2fded0da9abb
child 504112 785032241b2fe327aa833267416b3eb8d846cb4f
child 504113 af8241e64ecb7096c314c1a174479d11ab18163d
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersJamie
bugs1507365
milestone65.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 1507365 - Allow labels inside toolbarbuttons to participate in accessible name calculation, r=Jamie Toolbar buttons in XUL can now have labels inside them to provide the actual caption for the button. Adjust the accessibility module to allow label elements as acceptable children for the toolbarbutton element so the algorithm can pick up their text for the button's name. Differential Revision: https://phabricator.services.mozilla.com/D12527
accessible/tests/mochitest/name/test_general.xul
accessible/tests/mochitest/tree/test_button.xul
accessible/tests/mochitest/tree/test_formctrl.xul
accessible/tests/mochitest/treeupdate/test_menubutton.xul
accessible/xul/XULFormControlAccessible.cpp
accessible/xul/XULFormControlAccessible.h
--- a/accessible/tests/mochitest/name/test_general.xul
+++ b/accessible/tests/mochitest/name/test_general.xul
@@ -153,16 +153,21 @@
       is(entryAcc.name, "ooospspss",
          "Wrong name for text entry of autocomplete textbox 'toolbaritem_textbox'.");
 
       // Child from subtree of toolbaritem.
       testName("toolbaritem_hboxbutton", "ooospspss");
 
 
       //////////////////////////////////////////////////////////////////////////
+      // name from label inside toolbar button
+      testName("toolbarbuttonwithlabel", "I am the button");
+
+
+      //////////////////////////////////////////////////////////////////////////
       // Name from children
 
       // ARIA role button is presented allowing the name calculation from
       // children.
       testName("box_children", "14");
 
       // ARIA role option is presented allowing the name calculation from
       // the visible children (bug 443081)
@@ -318,27 +323,31 @@
        role="group"/>
 
   <!-- tooltiptext -->
   <box id="box_tooltiptext"
        role="group"
        tooltiptext="tooltiptext label"/>
 
   <!-- the name from @title of toolbaritem -->
+  <!-- and the name from label of a toolbarbutton -->
   <toolbar>
     <toolbaritem title="ooospspss">
       <textbox id="toolbaritem_textbox"
                flex="1"
                type="autocomplete"
                enablehistory="true">
         <hbox role="button" id="toolbaritem_hboxbutton">
            <description value="button"/>
         </hbox>
       </textbox>
     </toolbaritem>
+    <toolbarbutton id="toolbarbuttonwithlabel">
+      <label flex="1">I am the button</label>
+    </toolbarbutton>
   </toolbar>
 
   <!-- name from children -->
   <box id="box_children" role="button">14</box>
 
   <!-- name from children, hidden children -->
   <vbox role="listbox" tabindex="0">
     <hbox id="lb_opt1_children_hidden" role="option" tabindex="0">
--- a/accessible/tests/mochitest/tree/test_button.xul
+++ b/accessible/tests/mochitest/tree/test_button.xul
@@ -32,17 +32,20 @@
       testAccessibleTree("button1", accTree);
 
       //////////////////////////////////////////////////////////////////////////
       // toolbarbutton
 
       var accTree = {
         role: ROLE_PUSHBUTTON,
         name: "hello",
-        children: [ ]
+        children: [ {
+          role: ROLE_LABEL,
+          name: "hello"
+        } ]
       };
       testAccessibleTree("button2", accTree);
 
       SimpleTest.finish()
     }
 
     SimpleTest.waitForExplicitFinish();
     addA11yLoadEvent(doTest);
--- a/accessible/tests/mochitest/tree/test_formctrl.xul
+++ b/accessible/tests/mochitest/tree/test_formctrl.xul
@@ -57,32 +57,42 @@
       // toolbar
       accTree = {
         role: ROLE_TOOLBAR,
         name: "My toolbar",
         children: [
           {
             role: ROLE_PUSHBUTTON,
             name: "hello",
-            children: [ ]
+            children: [
+              {
+                role: ROLE_LABEL,
+                name: "hello"
+              }
+            ]
           }
         ]
       };
 
       testAccessibleTree("toolbar", accTree);
 
       // toolbar
       accTree = {
         role: ROLE_TOOLBAR,
         name: "My second toolbar",
         children: [
           {
             role: ROLE_PUSHBUTTON,
             name: "hello",
-            children: [ ]
+            children: [
+              {
+                role: ROLE_LABEL,
+                name: "hello"
+              }
+            ]
           }
         ]
       };
 
       testAccessibleTree("toolbar2", accTree);
 
       if (!SEAMONKEY)
         testAccessibleTree("tb_customizable", { TOOLBAR: [] });
--- a/accessible/tests/mochitest/treeupdate/test_menubutton.xul
+++ b/accessible/tests/mochitest/treeupdate/test_menubutton.xul
@@ -30,34 +30,59 @@
       this.button = getAccessible(aButtonID);
       this.menupopup = this.button.firstChild;
 
       var checker = new invokerChecker(EVENT_REORDER, this.menupopup);
       this.__proto__ = new synthClick(aButtonID, checker);
 
       this.invoke = function openMenu_invoke()
       {
-        var tree =
-          { PUSHBUTTON: [
-            { MENUPOPUP: [ ] }
-          ] };
+        var tree = {};
+        if (this.button.name === "toolbarbutton") {
+          tree = 
+            { PUSHBUTTON: [
+              { MENUPOPUP: [ ] },
+              { LABEL: [
+                { TEXT_LEAF: [ ] }
+              ] }
+            ] };
+        } else {
+          tree = 
+            { PUSHBUTTON: [
+              { MENUPOPUP: [ ] }
+            ] };     
+        }
         testAccessibleTree(this.button, tree);
 
         this.__proto__.invoke();
       }
 
       this.finalCheck = function openMenu_finalCheck()
       {
-        var tree =
-          { PUSHBUTTON: [
-            { MENUPOPUP: [
-              { role: menuItemRole, children: [ ] },
-              { role: menuItemRole, children: [ ] }
-            ] }
-          ] };
+        var tree = {};
+        if (this.button.name === "toolbarbutton") {
+          tree =
+            { PUSHBUTTON: [
+              { MENUPOPUP: [
+                { role: menuItemRole, children: [ ] },
+                { role: menuItemRole, children: [ ] }
+              ] },
+              { LABEL: [
+                { TEXT_LEAF: [ ] }
+              ] }
+            ] };
+        } else {
+          tree =
+            { PUSHBUTTON: [
+              { MENUPOPUP: [
+                { role: menuItemRole, children: [ ] },
+                { role: menuItemRole, children: [ ] }
+              ] }
+            ] };
+        }
         testAccessibleTree(this.button, tree);
 
         synthesizeKey("KEY_Escape");
       }
 
       this.getID = function openMenu_getID()
       {
         return "open menu of the button " + prettyName(aButtonID);
--- a/accessible/xul/XULFormControlAccessible.cpp
+++ b/accessible/xul/XULFormControlAccessible.cpp
@@ -463,16 +463,30 @@ bool
 XULToolbarButtonAccessible::IsSeparator(Accessible* aAccessible)
 {
   nsIContent* content = aAccessible->GetContent();
   return content && content->IsAnyOfXULElements(nsGkAtoms::toolbarseparator,
                                                 nsGkAtoms::toolbarspacer,
                                                 nsGkAtoms::toolbarspring);
 }
 
+////////////////////////////////////////////////////////////////////////////////
+// XULToolbarButtonAccessible: Widgets
+
+bool
+XULToolbarButtonAccessible::IsAcceptableChild(nsIContent* aEl) const
+{
+  // In general XUL button has not accessible children. Nevertheless menu
+  // buttons can have popup accessibles (@type="menu" or columnpicker).
+  // Also: Toolbar buttons can have labels as children.
+  return aEl->IsXULElement(nsGkAtoms::menupopup) ||
+         aEl->IsXULElement(nsGkAtoms::popup) ||
+         aEl->IsXULElement(nsGkAtoms::label);
+}
+
 
 ////////////////////////////////////////////////////////////////////////////////
 // XULToolbarAccessible
 ////////////////////////////////////////////////////////////////////////////////
 
 XULToolbarAccessible::
   XULToolbarAccessible(nsIContent* aContent, DocAccessible* aDoc) :
   AccessibleWrap(aContent, aDoc)
--- a/accessible/xul/XULFormControlAccessible.h
+++ b/accessible/xul/XULFormControlAccessible.h
@@ -149,16 +149,19 @@ public:
   XULToolbarButtonAccessible(nsIContent* aContent, DocAccessible* aDoc);
 
   // Accessible
   virtual void GetPositionAndSizeInternal(int32_t* aPosInSet,
                                           int32_t* aSetSize) override;
 
   // nsXULToolbarButtonAccessible
   static bool IsSeparator(Accessible* aAccessible);
+
+  // Widgets
+  virtual bool IsAcceptableChild(nsIContent* aEl) const override;
 };
 
 /**
  * Used for XUL toolbar element.
  */
 class XULToolbarAccessible : public AccessibleWrap
 {
 public: