bug 767860 - stop using nsIDOMHTMLInputElement in a11y r=mounir, surkov
authorTrevor Saunders <trev.saunders@gmail.com>
Sun, 03 Jun 2012 07:36:51 -0400
changeset 103804 ca08bbcd7dc496b21d34f7d8f8156289518f2ca2
parent 103803 b3ad8edbd748f0e3ba2a0c081852e6d2ee706f2a
child 103805 42fb32915739f7018879d7bdf45e421d38a6ce2a
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersmounir, surkov
bugs767860
milestone18.0a1
bug 767860 - stop using nsIDOMHTMLInputElement in a11y r=mounir, surkov
accessible/src/base/nsCaretAccessible.cpp
accessible/src/generic/FormControlAccessible.cpp
accessible/src/html/HTMLFormControlAccessible.cpp
accessible/src/html/Makefile.in
accessible/src/xul/XULFormControlAccessible.cpp
content/html/content/src/nsHTMLInputElement.cpp
content/html/content/src/nsHTMLInputElement.h
--- a/accessible/src/base/nsCaretAccessible.cpp
+++ b/accessible/src/base/nsCaretAccessible.cpp
@@ -10,17 +10,16 @@
 #include "nsAccUtils.h"
 #include "nsCoreUtils.h"
 #include "nsIAccessibleEvent.h"
 #include "RootAccessible.h"
 
 #include "nsCaret.h"
 #include "nsIDOMDocument.h"
 #include "nsIDOMHTMLAnchorElement.h"
-#include "nsIDOMHTMLInputElement.h"
 #include "nsIDOMHTMLTextAreaElement.h"
 #include "nsIFrame.h"
 #include "nsIPresShell.h"
 #include "nsISelectionPrivate.h"
 #include "nsServiceManagerUtils.h"
 
 class nsIWidget;
 
--- a/accessible/src/generic/FormControlAccessible.cpp
+++ b/accessible/src/generic/FormControlAccessible.cpp
@@ -4,17 +4,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 // NOTE: alphabetically ordered
 
 #include "FormControlAccessible.h"
 #include "Role.h"
 
 #include "nsIDOMHTMLFormElement.h"
-#include "nsIDOMHTMLInputElement.h"
 #include "nsIDOMXULElement.h"
 #include "nsIDOMXULControlElement.h"
 
 using namespace mozilla::a11y;
 
 ////////////////////////////////////////////////////////////////////////////////
 // ProgressMeterAccessible
 ////////////////////////////////////////////////////////////////////////////////
--- a/accessible/src/html/HTMLFormControlAccessible.cpp
+++ b/accessible/src/html/HTMLFormControlAccessible.cpp
@@ -10,23 +10,20 @@
 #include "nsARIAMap.h"
 #include "nsEventShell.h"
 #include "nsTextEquivUtils.h"
 #include "Relation.h"
 #include "Role.h"
 #include "States.h"
 
 #include "nsContentList.h"
+#include "nsHTMLInputElement.h"
 #include "nsIAccessibleRelation.h"
-#include "nsIDOMHTMLInputElement.h"
 #include "nsIDOMNSEditableElement.h"
-#include "nsIDOMHTMLFormElement.h"
-#include "nsIDOMHTMLLegendElement.h"
 #include "nsIDOMHTMLTextAreaElement.h"
-#include "nsIDOMNodeList.h"
 #include "nsIEditor.h"
 #include "nsIFormControl.h"
 #include "nsIFrame.h"
 #include "nsINameSpaceManager.h"
 #include "nsISelectionController.h"
 #include "jsapi.h"
 #include "nsIJSContextStack.h"
 #include "nsIServiceManager.h"
@@ -89,33 +86,26 @@ HTMLCheckboxAccessible::DoAction(uint8_t
 }
 
 uint64_t
 HTMLCheckboxAccessible::NativeState()
 {
   uint64_t state = LeafAccessible::NativeState();
 
   state |= states::CHECKABLE;
-  bool checkState = false;   // Radio buttons and check boxes can be checked or mixed
-
-  nsCOMPtr<nsIDOMHTMLInputElement> htmlCheckboxElement =
-    do_QueryInterface(mContent);
-           
-  if (htmlCheckboxElement) {
-    htmlCheckboxElement->GetIndeterminate(&checkState);
+  nsHTMLInputElement* input = nsHTMLInputElement::FromContent(mContent);
+  if (!input)
+    return state;
 
-    if (checkState) {
-      state |= states::MIXED;
-    } else {   // indeterminate can't be checked at the same time.
-      htmlCheckboxElement->GetChecked(&checkState);
-    
-      if (checkState)
-        state |= states::CHECKED;
-    }
-  }
+  if (input->Indeterminate())
+    return state | states::MIXED;
+
+  if (input->Checked())
+    return state | states::CHECKED;
+           
   return state;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 // HTMLCheckboxAccessible: Widgets
 
 bool
 HTMLCheckboxAccessible::IsWidget() const
@@ -136,23 +126,18 @@ HTMLRadioButtonAccessible::
 
 uint64_t
 HTMLRadioButtonAccessible::NativeState()
 {
   uint64_t state = AccessibleWrap::NativeState();
 
   state |= states::CHECKABLE;
 
-  bool checked = false;   // Radio buttons and check boxes can be checked
-  nsCOMPtr<nsIDOMHTMLInputElement> htmlRadioElement =
-    do_QueryInterface(mContent);
-  if (htmlRadioElement)
-    htmlRadioElement->GetChecked(&checked);
-
-  if (checked)
+  nsHTMLInputElement* input = nsHTMLInputElement::FromContent(mContent);
+  if (input && input->Checked())
     state |= states::CHECKED;
 
   return state;
 }
 
 void
 HTMLRadioButtonAccessible::GetPositionAndSizeInternal(int32_t* aPosInSet,
                                                       int32_t* aSetSize)
@@ -378,20 +363,19 @@ HTMLTextFieldAccessible::Value(nsString&
     return;
 
   nsCOMPtr<nsIDOMHTMLTextAreaElement> textArea(do_QueryInterface(mContent));
   if (textArea) {
     textArea->GetValue(aValue);
     return;
   }
   
-  nsCOMPtr<nsIDOMHTMLInputElement> inputElement(do_QueryInterface(mContent));
-  if (inputElement) {
-    inputElement->GetValue(aValue);
-  }
+  nsHTMLInputElement* input = nsHTMLInputElement::FromContent(mContent);
+  if (input)
+    input->GetValue(aValue);
 }
 
 void
 HTMLTextFieldAccessible::ApplyARIAState(uint64_t* aState) const
 {
   HyperTextAccessibleWrap::ApplyARIAState(aState);
 
   aria::MapToState(aria::eARIAAutoComplete, mContent->AsElement(), aState);
@@ -427,18 +411,19 @@ HTMLTextFieldAccessible::NativeState()
     state |= states::PROTECTED;
   }
 
   if (mContent->HasAttr(kNameSpaceID_None, nsGkAtoms::readonly)) {
     state |= states::READONLY;
   }
 
   // Is it an <input> or a <textarea> ?
-  nsCOMPtr<nsIDOMHTMLInputElement> htmlInput(do_QueryInterface(mContent));
-  state |= htmlInput ? states::SINGLE_LINE : states::MULTI_LINE;
+  nsHTMLInputElement* input = nsHTMLInputElement::FromContent(mContent);
+  state |= input && input->IsSingleLineTextControl() ?
+    states::SINGLE_LINE : states::MULTI_LINE;
 
   if (!(state & states::EDITABLE) ||
       (state & (states::PROTECTED | states::MULTI_LINE)))
     return state;
 
   // Expose autocomplete states if this input is part of autocomplete widget.
   Accessible* widget = ContainerWidget();
   if (widget && widget-IsAutoComplete()) {
@@ -458,19 +443,17 @@ HTMLTextFieldAccessible::NativeState()
     // for a page if the user asks it to be. However, the kind of autocomplete
     // we're talking here is based on what the user types, where a popup of
     // possible choices comes up.
     nsAutoString autocomplete;
     mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::autocomplete,
                       autocomplete);
 
     if (!autocomplete.LowerCaseEqualsLiteral("off")) {
-      nsCOMPtr<nsIDOMHTMLFormElement> form;
-      htmlInput->GetForm(getter_AddRefs(form));
-      nsCOMPtr<nsIContent> formContent(do_QueryInterface(form));
+      nsIContent* formContent = input->GetFormElement();
       if (formContent) {
         formContent->GetAttr(kNameSpaceID_None,
                              nsGkAtoms::autocomplete, autocomplete);
       }
 
       if (!formContent || !autocomplete.LowerCaseEqualsLiteral("off"))
         state |= states::SUPPORTS_AUTOCOMPLETION;
     }
@@ -494,17 +477,17 @@ HTMLTextFieldAccessible::GetActionName(u
   }
   return NS_ERROR_INVALID_ARG;
 }
 
 NS_IMETHODIMP
 HTMLTextFieldAccessible::DoAction(uint8_t aIndex)
 {
   if (aIndex == 0) {
-    nsCOMPtr<nsIDOMHTMLElement> element(do_QueryInterface(mContent));
+    nsHTMLInputElement* element = nsHTMLInputElement::FromContent(mContent);
     if (element)
       return element->Focus();
 
     return NS_ERROR_FAILURE;
   }
   return NS_ERROR_INVALID_ARG;
 }
 
--- a/accessible/src/html/Makefile.in
+++ b/accessible/src/html/Makefile.in
@@ -31,16 +31,17 @@ CPPSRCS = \
 FORCE_STATIC_LIB = 1
 
 include $(topsrcdir)/config/rules.mk
 
 LOCAL_INCLUDES = \
   -I$(srcdir)/../base \
   -I$(srcdir)/../generic \
   -I$(srcdir)/../xpcom \
+  -I$(srcdir)/../../../content/base/src \
   -I$(srcdir)/../../../content/html/content/src \
   -I$(srcdir)/../../../layout/generic \
   -I$(srcdir)/../../../layout/xul/base/src \
   $(NULL)
 
 ifeq ($(MOZ_WIDGET_TOOLKIT),gtk2)
 LOCAL_INCLUDES += \
   -I$(srcdir)/../atk \
--- a/accessible/src/xul/XULFormControlAccessible.cpp
+++ b/accessible/src/xul/XULFormControlAccessible.cpp
@@ -12,17 +12,16 @@
 #include "nsCoreUtils.h"
 #include "DocAccessible.h"
 #include "nsIAccessibleRelation.h"
 #include "Relation.h"
 #include "Role.h"
 #include "States.h"
 #include "XULMenuAccessible.h"
 
-#include "nsIDOMHTMLInputElement.h"
 #include "nsIDOMNSEditableElement.h"
 #include "nsIDOMXULButtonElement.h"
 #include "nsIDOMXULCheckboxElement.h"
 #include "nsIDOMXULMenuListElement.h"
 #include "nsIDOMXULSelectCntrlItemEl.h"
 #include "nsIDOMXULTextboxElement.h"
 #include "nsIEditor.h"
 #include "nsIFrame.h"
--- a/content/html/content/src/nsHTMLInputElement.cpp
+++ b/content/html/content/src/nsHTMLInputElement.cpp
@@ -917,17 +917,17 @@ NS_IMETHODIMP
 nsHTMLInputElement::SetHeight(uint32_t aHeight)
 {
   return nsGenericHTMLElement::SetUnsignedIntAttr(nsGkAtoms::height, aHeight);
 }
 
 NS_IMETHODIMP
 nsHTMLInputElement::GetIndeterminate(bool* aValue)
 {
-  *aValue = mIndeterminate;
+  *aValue = Indeterminate();
   return NS_OK;
 }
 
 nsresult
 nsHTMLInputElement::SetIndeterminateInternal(bool aValue,
                                              bool aShouldInvalidate)
 {
   mIndeterminate = aValue;
@@ -1636,17 +1636,17 @@ nsHTMLInputElement::SetValueChanged(bool
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP 
 nsHTMLInputElement::GetChecked(bool* aChecked)
 {
-  *aChecked = mChecked;
+  *aChecked = Checked();
   return NS_OK;
 }
 
 void
 nsHTMLInputElement::SetCheckedChanged(bool aCheckedChanged)
 {
   DoSetCheckedChanged(aCheckedChanged, true);
 }
--- a/content/html/content/src/nsHTMLInputElement.h
+++ b/content/html/content/src/nsHTMLInputElement.h
@@ -281,20 +281,23 @@ public:
    * @param aIsFocused Whether the element is currently focused.
    *
    * @note The caller is responsible to call ContentStatesChanged.
    */
   void UpdateValidityUIBits(bool aIsFocused);
 
   bool DefaultChecked() const {
     return HasAttr(kNameSpaceID_None, nsGkAtoms::checked);
-  }
-
-  /**
-   * Fires change event if mFocusedValue and current value held are unequal.
+  }
+
+  bool Indeterminate() const { return mIndeterminate; }
+  bool Checked() const { return mChecked; }
+
+  /**
+   * Fires change event if mFocusedValue and current value held are unequal.
    */
   void FireChangeEventIfNeeded();
 
 protected:
   // Pull IsSingleLineTextControl into our scope, otherwise it'd be hidden
   // by the nsITextControlElement version.
   using nsGenericHTMLFormElement::IsSingleLineTextControl;