Bug 691267 - Remove nsHTMLButtonAccessible duplication, r=surkov
authorAndrew Quartey <andrew.quartey@gmail.com>
Wed, 22 Feb 2012 20:33:37 +0900
changeset 88949 6f1953bd8f4623eba7c14ee9cc1e8385d7dfcabe
parent 88948 75bb9debefe9692c336748355dfd215f1856a2f1
child 88950 23fef78981b5fdedd45e9c6c35cb1376e3b6184f
push idunknown
push userunknown
push dateunknown
reviewerssurkov
bugs691267
milestone13.0a1
Bug 691267 - Remove nsHTMLButtonAccessible duplication, r=surkov
accessible/public/nsIAccessibilityService.h
accessible/src/base/nsAccessibilityService.cpp
accessible/src/base/nsAccessibilityService.h
accessible/src/html/nsHTMLFormControlAccessible.cpp
accessible/src/html/nsHTMLFormControlAccessible.h
accessible/tests/mochitest/actions/Makefile.in
accessible/tests/mochitest/actions/test_controls.html
accessible/tests/mochitest/actions/test_inputs.html
accessible/tests/mochitest/states/test_buttons.html
layout/forms/nsHTMLButtonControlFrame.cpp
layout/forms/nsImageControlFrame.cpp
--- a/accessible/public/nsIAccessibilityService.h
+++ b/accessible/public/nsIAccessibilityService.h
@@ -86,20 +86,16 @@ public:
                                                   bool aCanCreate) = 0;
 
   /**
    * Creates accessible for the given DOM node or frame.
    */
   virtual already_AddRefed<nsAccessible>
     CreateHTMLBRAccessible(nsIContent* aContent, nsIPresShell* aPresShell) = 0;
   virtual already_AddRefed<nsAccessible>
-    CreateHTML4ButtonAccessible(nsIContent* aContent, nsIPresShell* aPresShell) = 0;
-  virtual already_AddRefed<nsAccessible>
-    CreateHTMLButtonAccessible(nsIContent* aContent, nsIPresShell* aPresShell) = 0;
-  virtual already_AddRefed<nsAccessible>
     CreateHTMLCaptionAccessible(nsIContent* aContent, nsIPresShell* aPresShell) = 0;
   virtual already_AddRefed<nsAccessible>
     CreateHTMLCheckboxAccessible(nsIContent* aContent, nsIPresShell* aPresShell) = 0;
   virtual already_AddRefed<nsAccessible>
     CreateHTMLComboboxAccessible(nsIContent* aContent, nsIPresShell* aPresShell) = 0;
   virtual already_AddRefed<nsAccessible>
     CreateHTMLGroupboxAccessible(nsIContent* aContent, nsIPresShell* aPresShell) = 0;
   virtual already_AddRefed<nsAccessible>
--- a/accessible/src/base/nsAccessibilityService.cpp
+++ b/accessible/src/base/nsAccessibilityService.cpp
@@ -213,27 +213,16 @@ nsAccessibilityService::CreateOuterDocAc
   nsAccessible* accessible = 
     new nsOuterDocAccessible(aContent, 
                              nsAccUtils::GetDocAccessibleFor(aPresShell));
   NS_ADDREF(accessible);
   return accessible;
 }
 
 already_AddRefed<nsAccessible>
-nsAccessibilityService::CreateHTML4ButtonAccessible(nsIContent* aContent,
-                                                    nsIPresShell* aPresShell)
-{
-  nsAccessible* accessible = 
-    new nsHTML4ButtonAccessible(aContent, 
-                                nsAccUtils::GetDocAccessibleFor(aPresShell));
-  NS_ADDREF(accessible);
-  return accessible;
-}
-
-already_AddRefed<nsAccessible>
 nsAccessibilityService::CreateHTMLButtonAccessible(nsIContent* aContent,
                                                    nsIPresShell* aPresShell)
 {
   nsAccessible* accessible = 
     new nsHTMLButtonAccessible(aContent, 
                                nsAccUtils::GetDocAccessibleFor(aPresShell));
   NS_ADDREF(accessible);
   return accessible;
--- a/accessible/src/base/nsAccessibilityService.h
+++ b/accessible/src/base/nsAccessibilityService.h
@@ -84,23 +84,20 @@ public:
 
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIACCESSIBLERETRIEVAL
   NS_DECL_NSIOBSERVER
 
   // nsIAccessibilityService
   virtual nsAccessible* GetRootDocumentAccessible(nsIPresShell* aPresShell,
                                                   bool aCanCreate);
-
+  already_AddRefed<nsAccessible>
+    CreateHTMLButtonAccessible(nsIContent* aContent, nsIPresShell* aPresShell);
   virtual already_AddRefed<nsAccessible>
     CreateHTMLBRAccessible(nsIContent* aContent, nsIPresShell* aPresShell);
-  virtual already_AddRefed<nsAccessible>
-    CreateHTML4ButtonAccessible(nsIContent* aContent, nsIPresShell* aPresShell);
-  virtual already_AddRefed<nsAccessible>
-    CreateHTMLButtonAccessible(nsIContent* aContent, nsIPresShell* aPresShell);
   already_AddRefed<nsAccessible>
     CreateHTMLCanvasAccessible(nsIContent* aContent, nsIPresShell* aPresShell);
   virtual already_AddRefed<nsAccessible>
     CreateHTMLCaptionAccessible(nsIContent* aContent, nsIPresShell* aPresShell);
   virtual already_AddRefed<nsAccessible>
     CreateHTMLCheckboxAccessible(nsIContent* aContent, nsIPresShell* aPresShell);
   virtual already_AddRefed<nsAccessible>
     CreateHTMLComboboxAccessible(nsIContent* aContent, nsIPresShell* aPresShell);
--- a/accessible/src/html/nsHTMLFormControlAccessible.cpp
+++ b/accessible/src/html/nsHTMLFormControlAccessible.cpp
@@ -309,17 +309,17 @@ nsHTMLButtonAccessible::NativeRole()
 {
   return roles::PUSHBUTTON;
 }
 
 nsresult
 nsHTMLButtonAccessible::GetNameInternal(nsAString& aName)
 {
   nsAccessible::GetNameInternal(aName);
-  if (!aName.IsEmpty())
+  if (!aName.IsEmpty() || mContent->Tag() != nsGkAtoms::input)
     return NS_OK;
 
   // No name from HTML or ARIA
   nsAutoString name;
   if (!mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::value,
                          name) &&
       !mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::alt,
                          name)) {
@@ -349,81 +349,16 @@ nsHTMLButtonAccessible::GetNameInternal(
 bool
 nsHTMLButtonAccessible::IsWidget() const
 {
   return true;
 }
 
 
 ////////////////////////////////////////////////////////////////////////////////
-// nsHTML4ButtonAccessible
-////////////////////////////////////////////////////////////////////////////////
-
-nsHTML4ButtonAccessible::
-  nsHTML4ButtonAccessible(nsIContent* aContent, nsDocAccessible* aDoc) :
-  nsHyperTextAccessibleWrap(aContent, aDoc)
-{
-}
-
-PRUint8
-nsHTML4ButtonAccessible::ActionCount()
-{
-  return 1;
-}
-
-NS_IMETHODIMP nsHTML4ButtonAccessible::GetActionName(PRUint8 aIndex, nsAString& aName)
-{
-  if (aIndex == eAction_Click) {
-    aName.AssignLiteral("press"); 
-    return NS_OK;
-  }
-  return NS_ERROR_INVALID_ARG;
-}
-
-NS_IMETHODIMP
-nsHTML4ButtonAccessible::DoAction(PRUint8 aIndex)
-{
-  if (aIndex != 0)
-    return NS_ERROR_INVALID_ARG;
-
-  DoCommand();
-  return NS_OK;
-}
-
-role
-nsHTML4ButtonAccessible::NativeRole()
-{
-  return roles::PUSHBUTTON;
-}
-
-PRUint64
-nsHTML4ButtonAccessible::NativeState()
-{
-  PRUint64 state = nsHyperTextAccessibleWrap::NativeState();
-
-  state |= states::FOCUSABLE;
-
-  nsEventStates elmState = mContent->AsElement()->State();
-  if (elmState.HasState(NS_EVENT_STATE_DEFAULT))
-    state |= states::DEFAULT;
-
-  return state;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// nsHTML4ButtonAccessible: Widgets
-
-bool
-nsHTML4ButtonAccessible::IsWidget() const
-{
-  return true;
-}
-
-
-////////////////////////////////////////////////////////////////////////////////
 // nsHTMLTextFieldAccessible
 ////////////////////////////////////////////////////////////////////////////////
 
 nsHTMLTextFieldAccessible::
   nsHTMLTextFieldAccessible(nsIContent* aContent, nsDocAccessible* aDoc) :
   nsHyperTextAccessibleWrap(aContent, aDoc)
 {
 }
--- a/accessible/src/html/nsHTMLFormControlAccessible.h
+++ b/accessible/src/html/nsHTMLFormControlAccessible.h
@@ -87,17 +87,17 @@ public:
   virtual PRUint64 NativeState();
   virtual void GetPositionAndSizeInternal(PRInt32 *aPosInSet,
                                           PRInt32 *aSetSize);
 };
 
 
 /**
  * Accessible for HTML input@type="button", @type="submit", @type="image"
- * elements.
+ * and HTML button elements.
  */
 class nsHTMLButtonAccessible : public nsHyperTextAccessibleWrap
 {
 
 public:
   enum { eAction_Click = 0 };
 
   nsHTMLButtonAccessible(nsIContent* aContent, nsDocAccessible* aDoc);
@@ -116,43 +116,16 @@ public:
   virtual PRUint8 ActionCount();
 
   // Widgets
   virtual bool IsWidget() const;
 };
 
 
 /**
- * Accessible for HTML button element.
- */
-class nsHTML4ButtonAccessible : public nsHyperTextAccessibleWrap
-{
-
-public:
-  enum { eAction_Click = 0 };
-
-  nsHTML4ButtonAccessible(nsIContent* aContent, nsDocAccessible* aDoc);
-
-  // nsIAccessible
-  NS_IMETHOD GetActionName(PRUint8 aIndex, nsAString& aName);
-  NS_IMETHOD DoAction(PRUint8 index);
-
-  // nsAccessible
-  virtual mozilla::a11y::role NativeRole();
-  virtual PRUint64 NativeState();
-
-  // ActionAccessible
-  virtual PRUint8 ActionCount();
-
-  // Widgets
-  virtual bool IsWidget() const;
-};
-
-
-/**
  * Accessible for HTML input@type="text" element.
  */
 class nsHTMLTextFieldAccessible : public nsHyperTextAccessibleWrap
 {
 
 public:
   enum { eAction_Click = 0 };
 
--- a/accessible/tests/mochitest/actions/Makefile.in
+++ b/accessible/tests/mochitest/actions/Makefile.in
@@ -45,17 +45,17 @@ relativesrcdir  = accessible/actions
 include $(DEPTH)/config/autoconf.mk
 include $(topsrcdir)/config/rules.mk
 
 _TEST_FILES =\
 		test_anchors.html \
 		test_aria.html \
 		test_general.html \
 		test_general.xul \
-		test_inputs.html \
+		test_controls.html \
 		test_keys_menu.xul \
 		test_keys.html \
 		test_link.html \
 		test_media.html \
 		test_select.html \
 		test_tree.xul \
 		test_treegrid.xul \
 		$(NULL)
rename from accessible/tests/mochitest/actions/test_inputs.html
rename to accessible/tests/mochitest/actions/test_controls.html
--- a/accessible/tests/mochitest/actions/test_inputs.html
+++ b/accessible/tests/mochitest/actions/test_controls.html
@@ -21,16 +21,21 @@
     {
       var actionsArray = [
         {
           ID: "button",
           actionName: "press",
           events: CLICK_EVENTS
         },
         {
+          ID: "input_button",
+          actionName: "press",
+          events: CLICK_EVENTS
+        },
+        {
           ID: "checkbox_unchecked",
           actionName: "check",
           events: CLICK_EVENTS
         },
         {
           ID: "checkbox_checked",
           actionName: "uncheck",
           events: CLICK_EVENTS
@@ -63,17 +68,19 @@
      title="nsIAccessible actions testing">
     Mozilla Bug 477975
   </a>
   <p id="display"></p>
   <div id="content" style="display: none"></div>
   <pre id="test">
   </pre>
 
-  <button id="button" value="button">Button</button>
+  <button id="button">Button</button>
+
+  <input id="input_button" type="button" value="normal">
 
   <input id="checkbox_unchecked" type="checkbox">Checkbox</input>
 
   <input id="checkbox_checked" type="checkbox" checked="true">Checkbox</input>
 
   <input id="checkbox_mixed" type="checkbox">Checkbox</input>
 
   <fieldset>
--- a/accessible/tests/mochitest/states/test_buttons.html
+++ b/accessible/tests/mochitest/states/test_buttons.html
@@ -12,24 +12,26 @@
           src="../common.js"></script>
   <script type="application/javascript"
           src="../states.js"></script>
 
   <script type="application/javascript">
   function doTest()
   {
     // Default state.
-    testStates("f1_image", STATE_DEFAULT);
-    testStates("f2_submit", STATE_DEFAULT);
-    testStates("f3_submitbutton", STATE_DEFAULT);
-    testStates("f4_button", 0, 0, STATE_DEFAULT);
-    testStates("f4_image1", STATE_DEFAULT);
-    testStates("f4_image2", 0, 0, STATE_DEFAULT);
-    testStates("f4_submit", 0, 0, STATE_DEFAULT);
-    testStates("f4_submitbutton", 0, 0, STATE_DEFAULT);
+    testStates("f1_image", STATE_DEFAULT | STATE_FOCUSABLE);
+    testStates("f2_submit", STATE_DEFAULT | STATE_FOCUSABLE);
+    testStates("f3_submitbutton", STATE_DEFAULT | STATE_FOCUSABLE);
+    testStates("f3_disabled_reset", STATE_UNAVAILABLE, 0, STATE_FOCUSABLE, 0);
+    testStates("f4_button", STATE_FOCUSABLE, 0, STATE_DEFAULT);
+    testStates("f4_disabled_button", STATE_UNAVAILABLE, 0, STATE_FOCUSABLE, 0);
+    testStates("f4_image1", STATE_DEFAULT | STATE_FOCUSABLE);
+    testStates("f4_image2", STATE_FOCUSABLE, 0, STATE_DEFAULT);
+    testStates("f4_submit", STATE_FOCUSABLE, 0, STATE_DEFAULT);
+    testStates("f4_submitbutton", STATE_FOCUSABLE, 0, STATE_DEFAULT);
 
     SimpleTest.finish();
   }
 
   SimpleTest.waitForExplicitFinish();
   addA11yLoadEvent(doTest);
   </script>
 </head>
@@ -57,23 +59,25 @@
     <input type="text" name="hi">
     <input id="f2_submit" type="submit">
   </form>
 
   <p>A form with a HTML4 submit button:</p>
   <form name="form3" method="get">
     <input type="text" name="hi">
     <button id="f3_submitbutton" type="submit">submit</button>
+    <button id="f3_disabled_reset" type="reset" disabled>reset</button>
   </form>
 
   <p>A form with normal button, two image buttons, submit button,
     HTML4 submit button:</p>
   <form name="form4" method="get">
     <input type="text" name="hi">
     <input id="f4_button" type="button" value="normal" name="normal-button">
+    <input id="f4_disabled_button" type="button" value="disabled" name="disabled-button" disabled>
     <input id="f4_image1" type="image" value="image-button1" name="image-button1">
     <input id="f4_image2" type="image" value="image-button2" name="image-button2">
     <input id="f4_submit" type="submit" value="real-submit" name="real-submit">
     <button id="f4_submitbutton" type="submit">submit</button>
   </form>
 
   </body>
 </html>
--- a/layout/forms/nsHTMLButtonControlFrame.cpp
+++ b/layout/forms/nsHTMLButtonControlFrame.cpp
@@ -110,19 +110,18 @@ NS_QUERYFRAME_HEAD(nsHTMLButtonControlFr
 NS_QUERYFRAME_TAIL_INHERITING(nsContainerFrame)
 
 #ifdef ACCESSIBILITY
 already_AddRefed<nsAccessible>
 nsHTMLButtonControlFrame::CreateAccessible()
 {
   nsAccessibilityService* accService = nsIPresShell::AccService();
   if (accService) {
-    return IsInput() ?
-      accService->CreateHTMLButtonAccessible(mContent, PresContext()->PresShell()) :
-      accService->CreateHTML4ButtonAccessible(mContent, PresContext()->PresShell());
+    return accService->CreateHTMLButtonAccessible(mContent,
+                                                  PresContext()->PresShell()); 
   }
 
   return nsnull;
 }
 #endif
 
 nsIAtom*
 nsHTMLButtonControlFrame::GetType() const
--- a/layout/forms/nsImageControlFrame.cpp
+++ b/layout/forms/nsImageControlFrame.cpp
@@ -161,21 +161,20 @@ NS_QUERYFRAME_HEAD(nsImageControlFrame)
 NS_QUERYFRAME_TAIL_INHERITING(nsImageControlFrameSuper)
 
 #ifdef ACCESSIBILITY
 already_AddRefed<nsAccessible>
 nsImageControlFrame::CreateAccessible()
 {
   nsAccessibilityService* accService = nsIPresShell::AccService();
   if (accService) {
-    if (mContent->Tag() == nsGkAtoms::button) {
-      return accService->CreateHTML4ButtonAccessible(mContent, PresContext()->PresShell());
-    }
-    else if (mContent->Tag() == nsGkAtoms::input) {
-      return accService->CreateHTMLButtonAccessible(mContent, PresContext()->PresShell());
+    if (mContent->Tag() == nsGkAtoms::button || 
+        mContent->Tag() == nsGkAtoms::input) {
+      return accService->CreateHTMLButtonAccessible(mContent, 
+                                                    PresContext()->PresShell());
     }
   }
 
   return nsnull;
 }
 #endif
 
 nsIAtom*