Bug 1509222 - XUL toolbarbutton with checked="true' but not type="checkbox" doesn't get the pressed state, r=Jamie
authorMarco Zehe <mzehe@mozilla.com>
Thu, 22 Nov 2018 22:39:51 +0000
changeset 504223 ad6143ff142da2f47fe8fcbfd025174a791707bf
parent 504222 b188f2d1917b840fc6327246444afbbb141964de
child 504228 c2593a3058afdfeaac5c990e18794ee8257afe99
child 504229 0f57247530fd990832fd1e3a50d11c25c21b86ac
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
bugs1509222
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 1509222 - XUL toolbarbutton with checked="true' but not type="checkbox" doesn't get the pressed state, r=Jamie Simply decouple the check for the checked attribute from the one for the type attribute. Differential Revision: https://phabricator.services.mozilla.com/D12632
accessible/tests/mochitest/states/test_controls.xul
accessible/xul/XULFormControlAccessible.cpp
--- a/accessible/tests/mochitest/states/test_controls.xul
+++ b/accessible/tests/mochitest/states/test_controls.xul
@@ -27,16 +27,20 @@
       testStates("checkbox2", STATE_UNAVAILABLE, 0 , STATE_FOCUSABLE);
       testStates("radiogroup", 0, 0, STATE_FOCUSABLE | STATE_UNAVAILABLE);
       testStates("radio", STATE_FOCUSABLE, 0, STATE_UNAVAILABLE);
       testStates("radio-disabled", STATE_UNAVAILABLE, 0 , STATE_FOCUSABLE);
       testStates("radiogroup-disabled", STATE_UNAVAILABLE, 0 , STATE_FOCUSABLE);
       testStates("radio-disabledradiogroup", STATE_UNAVAILABLE, 0 , STATE_FOCUSABLE);
       testStates("button", STATE_FOCUSABLE, 0, STATE_UNAVAILABLE);
       testStates("button-disabled", STATE_UNAVAILABLE, 0 , STATE_FOCUSABLE);
+      testStates("checkbutton",
+                 STATE_FOCUSABLE | STATE_CHECKABLE | STATE_PRESSED);
+      testStates("fakecheckbutton", STATE_FOCUSABLE | STATE_PRESSED, 0, 
+                 STATE_CHECKABLE);
       testStates("combobox", STATE_FOCUSABLE | STATE_HASPOPUP, 0, STATE_UNAVAILABLE);
       testStates("combobox-disabled", STATE_UNAVAILABLE | STATE_HASPOPUP, 0, STATE_FOCUSABLE);
       testStates("listbox", STATE_FOCUSABLE, 0, STATE_UNAVAILABLE);
       testStates("listitem", STATE_FOCUSABLE | STATE_SELECTABLE | STATE_SELECTED, 0, STATE_UNAVAILABLE);
       testStates("listbox-disabled", STATE_UNAVAILABLE, 0, STATE_FOCUSABLE | STATE_SELECTABLE);
       testStates("listitem-disabledlistbox", STATE_UNAVAILABLE | STATE_SELECTED, 0, STATE_FOCUSABLE | STATE_SELECTABLE);
       testStates("menubar", 0, 0, STATE_FOCUSABLE);
       testStates("menu", STATE_FOCUSABLE, 0, STATE_UNAVAILABLE);
@@ -84,16 +88,19 @@
 
     <radiogroup id="radiogroup-disabled" disabled="true">
       <radio id="radio-disabledradiogroup" label="Orange"/>
       <radio id="violet2" selected="true" label="Violet"/>
     </radiogroup>
 
     <button id="button" value="button"/>
     <button id="button-disabled" disabled="true" value="button"/>
+    <button id="checkbutton" type="checkbox" checked="true" 
+            value="checkbutton" />
+    <button id="fakecheckbutton" checked="true" value="fakecheckbutton" />
 
     <menulist id="combobox">
       <menupopup>
         <menuitem label="item1"/>
       </menupopup>
     </menulist>
 
     <menulist id="combobox-disabled" disabled="true">
--- a/accessible/xul/XULFormControlAccessible.cpp
+++ b/accessible/xul/XULFormControlAccessible.cpp
@@ -95,21 +95,23 @@ XULButtonAccessible::NativeState() const
 
   // Buttons can be checked -- they simply appear pressed in rather than checked
   nsCOMPtr<nsIDOMXULButtonElement> xulButtonElement(do_QueryInterface(mContent));
   if (xulButtonElement) {
     nsAutoString type;
     xulButtonElement->GetType(type);
     if (type.EqualsLiteral("checkbox") || type.EqualsLiteral("radio")) {
       state |= states::CHECKABLE;
-      bool checked = false;
-      xulButtonElement->GetChecked(&checked);
-      if (checked) {
-        state |= states::PRESSED;
-      }
+    }
+    // Some buttons can have their checked state set without being of type
+    // checkbox or radio. Expose the pressed state unconditionally.
+    bool checked = false;
+    xulButtonElement->GetChecked(&checked);
+    if (checked) {
+      state |= states::PRESSED;
     }
   }
 
   if (ContainsMenu())
     state |= states::HASPOPUP;
 
   if (mContent->AsElement()->HasAttr(kNameSpaceID_None, nsGkAtoms::_default))
     state |= states::DEFAULT;