From f97e388d874df1e6d5d239c28c441002664dccba Mon Sep 17 00:00:00 2001 From: "aaronleventhal%moonset.net" Date: Mon, 14 Mar 2005 23:10:53 +0000 Subject: [PATCH] Bug 285285. Add SINGLE_LINE and MULTI_LINE extended state to single line text inputbox and clean up form control state code somewhat. r=louie.zhao, sr=henry.jia --- accessible/src/base/nsAccessibilityAtomList.h | 3 + accessible/src/base/nsAccessible.cpp | 8 ++- .../src/base/nsFormControlAccessible.cpp | 34 ---------- accessible/src/base/nsFormControlAccessible.h | 1 - .../src/html/nsHTMLFormControlAccessible.cpp | 68 ++++++------------- .../src/html/nsHTMLFormControlAccessible.h | 3 +- .../src/xul/nsXULFormControlAccessible.cpp | 18 ++++- .../src/xul/nsXULFormControlAccessible.h | 1 + 8 files changed, 49 insertions(+), 87 deletions(-) diff --git a/accessible/src/base/nsAccessibilityAtomList.h b/accessible/src/base/nsAccessibilityAtomList.h index b0ec6dc61793..20d5b6d67db9 100755 --- a/accessible/src/base/nsAccessibilityAtomList.h +++ b/accessible/src/base/nsAccessibilityAtomList.h @@ -88,9 +88,12 @@ ACCESSIBILITY_ATOM(disabled, "disabled") ACCESSIBILITY_ATOM(_for, "for") ACCESSIBILITY_ATOM(id, "id") ACCESSIBILITY_ATOM(name, "name") +ACCESSIBILITY_ATOM(readonly, "readonly") ACCESSIBILITY_ATOM(tabindex, "tabindex") ACCESSIBILITY_ATOM(title, "title") ACCESSIBILITY_ATOM(tooltiptext, "tooltiptext") +ACCESSIBILITY_ATOM(type, "type") +ACCESSIBILITY_ATOM(multiline, "multiline") // DHTML accessibility attributes ACCESSIBILITY_ATOM(valuenow, "valuenow") // For DHTML widget values diff --git a/accessible/src/base/nsAccessible.cpp b/accessible/src/base/nsAccessible.cpp index de746d0fe114..c1092a3eb244 100644 --- a/accessible/src/base/nsAccessible.cpp +++ b/accessible/src/base/nsAccessible.cpp @@ -1546,9 +1546,13 @@ NS_IMETHODIMP nsAccessible::ExtendSelection() } /* unsigned long getExtState (); */ -NS_IMETHODIMP nsAccessible::GetExtState(PRUint32 *_retval) +NS_IMETHODIMP nsAccessible::GetExtState(PRUint32 *aExtState) { - return NS_ERROR_NOT_IMPLEMENTED; + if (!mDOMNode) { + return NS_ERROR_FAILURE; // Node shut down + } + *aExtState = 0; + return NS_OK; } /* [noscript] void getNativeInterface(out voidPtr aOutAccessible); */ diff --git a/accessible/src/base/nsFormControlAccessible.cpp b/accessible/src/base/nsFormControlAccessible.cpp index a26976d656dc..6e9c8f953cc1 100644 --- a/accessible/src/base/nsFormControlAccessible.cpp +++ b/accessible/src/base/nsFormControlAccessible.cpp @@ -55,40 +55,6 @@ nsAccessibleWrap(aNode, aShell) NS_IMPL_ISUPPORTS_INHERITED0(nsFormControlAccessible, nsAccessible) -/** - * XUL states: focused, unavailable(disabled), focusable, ?protected? - * HTML states: focused, unabailable(disabled), focusable, protected - */ -NS_IMETHODIMP nsFormControlAccessible::GetState(PRUint32 *_retval) -{ - // Get the focused state from the nsAccessible - nsAccessible::GetState(_retval); - - PRBool disabled = PR_FALSE; - nsresult rv = NS_ERROR_FAILURE; - nsCOMPtr htmlFormElement(do_QueryInterface(mDOMNode, &rv)); - if (NS_SUCCEEDED(rv) && htmlFormElement) { - htmlFormElement->GetDisabled(&disabled); - nsAutoString typeString; - htmlFormElement->GetType(typeString); - if (typeString.LowerCaseEqualsLiteral("password")) - *_retval |= STATE_PROTECTED; - } - else { - nsCOMPtr xulFormElement(do_QueryInterface(mDOMNode, &rv)); - if (NS_SUCCEEDED(rv) && xulFormElement) { - xulFormElement->GetDisabled(&disabled); - /* XXX jgaunt do XUL elements support password fields? */ - } - } - if (disabled) - *_retval |= STATE_UNAVAILABLE; - else - *_retval |= STATE_FOCUSABLE; - - return NS_OK; -} - /** * Will be called by both HTML and XUL elements, this method * merely checks who is calling and then calls the appropriate diff --git a/accessible/src/base/nsFormControlAccessible.h b/accessible/src/base/nsFormControlAccessible.h index 4eb0dd75a1d1..712bf6be7974 100644 --- a/accessible/src/base/nsFormControlAccessible.h +++ b/accessible/src/base/nsFormControlAccessible.h @@ -52,7 +52,6 @@ public: nsFormControlAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell); NS_DECL_ISUPPORTS_INHERITED NS_IMETHOD GetName(nsAString& _retval); - NS_IMETHOD GetState(PRUint32 *_retval); NS_IMETHOD GetFirstChild(nsIAccessible **_retval); NS_IMETHOD GetLastChild(nsIAccessible **_retval); NS_IMETHOD GetChildCount(PRInt32 *_retval); diff --git a/accessible/src/html/nsHTMLFormControlAccessible.cpp b/accessible/src/html/nsHTMLFormControlAccessible.cpp index 936cbd4c4c6d..23dce9d5d7a9 100644 --- a/accessible/src/html/nsHTMLFormControlAccessible.cpp +++ b/accessible/src/html/nsHTMLFormControlAccessible.cpp @@ -38,12 +38,14 @@ // NOTE: alphabetically ordered #include "nsAccessibleTreeWalker.h" +#include "nsAccessibilityAtoms.h" #include "nsHTMLFormControlAccessible.h" #include "nsIDOMHTMLInputElement.h" #include "nsIDOMNSHTMLButtonElement.h" #include "nsIDOMHTMLLegendElement.h" #include "nsIDOMHTMLTextAreaElement.h" #include "nsIFrame.h" +#include "nsINameSpaceManager.h" #include "nsISelectionController.h" // --- checkbox ----- @@ -327,64 +329,34 @@ NS_IMETHODIMP nsHTMLTextFieldAccessible::GetValue(nsAString& _retval) return NS_ERROR_FAILURE; } -NS_IMETHODIMP nsHTMLTextFieldAccessible::GetState(PRUint32 *_retval) +NS_IMETHODIMP nsHTMLTextFieldAccessible::GetState(PRUint32 *aState) { - // can be - // focusable, focused, protected. readonly, unavailable, selected - if (!mDOMNode) { + // can be focusable, focused, protected. readonly, unavailable, selected + nsCOMPtr content(do_QueryInterface(mDOMNode)); + if (!content) { return NS_ERROR_FAILURE; // Node has been Shutdown() } - nsAccessible::GetState(_retval); - *_retval |= STATE_FOCUSABLE; - - nsCOMPtr textArea(do_QueryInterface(mDOMNode)); - nsCOMPtr inputElement(do_QueryInterface(mDOMNode)); - - nsCOMPtr elt(do_QueryInterface(mDOMNode)); - PRBool isReadOnly = PR_FALSE; - elt->HasAttribute(NS_LITERAL_STRING("readonly"), &isReadOnly); - if (isReadOnly) - *_retval |= STATE_READONLY; - - nsIFrame *frame = GetFrame(); - if (frame) { - nsPresContext *context = GetPresContext(); - NS_ENSURE_TRUE(context, NS_ERROR_FAILURE); - nsCOMPtr selCon; - frame->GetSelectionController(context,getter_AddRefs(selCon)); - if (selCon) { - nsCOMPtr domSel; - selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(domSel)); - if (domSel) { - PRBool isCollapsed = PR_TRUE; - domSel->GetIsCollapsed(&isCollapsed); - if (!isCollapsed) - *_retval |=STATE_SELECTED; - } - } + nsFormControlAccessible::GetState(aState); + nsAutoString typeString; + content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::type, typeString); + if (typeString.LowerCaseEqualsLiteral("password")) { + *aState |= STATE_PROTECTED; } - - - if (!textArea) { - if (inputElement) { - /////// ====== Must be a password field, so it uses nsIDOMHTMLFormControl ==== /////// - PRUint32 moreStates = 0; - nsresult rv = nsFormControlAccessible::GetState(&moreStates); - *_retval |= moreStates; - return rv; - } - return NS_ERROR_FAILURE; + if (content->HasAttr(kNameSpaceID_None, nsAccessibilityAtoms::readonly)) { + *aState |= STATE_READONLY; } - PRBool disabled = PR_FALSE; - textArea->GetDisabled(&disabled); - if (disabled) - *_retval |= STATE_UNAVAILABLE; - return NS_OK; } +NS_IMETHODIMP nsHTMLTextFieldAccessible::GetExtState(PRUint32 *aExtState) +{ + nsresult rv = nsFormControlAccessible::GetExtState(aExtState); + *aExtState |= EXT_STATE_SINGLE_LINE; + return rv; +} + NS_IMETHODIMP nsHTMLTextFieldAccessible::GetNumActions(PRUint8 *_retval) { *_retval = eSingle_Action; diff --git a/accessible/src/html/nsHTMLFormControlAccessible.h b/accessible/src/html/nsHTMLFormControlAccessible.h index 54f6c5741ed0..6d361003dc72 100644 --- a/accessible/src/html/nsHTMLFormControlAccessible.h +++ b/accessible/src/html/nsHTMLFormControlAccessible.h @@ -50,7 +50,7 @@ public: NS_IMETHOD GetNumActions(PRUint8 *_retval); NS_IMETHOD GetActionName(PRUint8 index, nsAString& _retval); NS_IMETHOD DoAction(PRUint8 index); - NS_IMETHOD GetState(PRUint32 *_retval); + NS_IMETHOD GetState(PRUint32 *aState); }; class nsHTMLRadioButtonAccessible : public nsRadioButtonAccessible @@ -102,6 +102,7 @@ public: NS_IMETHOD GetNumActions(PRUint8 *_retval); NS_IMETHOD GetActionName(PRUint8 index, nsAString& _retval); NS_IMETHOD DoAction(PRUint8 index); + NS_IMETHOD GetExtState(PRUint32 *aExtState); }; class nsHTMLGroupboxAccessible : public nsAccessibleWrap diff --git a/accessible/src/xul/nsXULFormControlAccessible.cpp b/accessible/src/xul/nsXULFormControlAccessible.cpp index 81fc32a5b621..47ac1ddbea69 100644 --- a/accessible/src/xul/nsXULFormControlAccessible.cpp +++ b/accessible/src/xul/nsXULFormControlAccessible.cpp @@ -40,13 +40,15 @@ // NOTE: alphabetically ordered #include "nsXULFormControlAccessible.h" #include "nsHTMLFormControlAccessible.h" +#include "nsAccessibilityAtoms.h" +#include "nsAccessibleTreeWalker.h" #include "nsIDOMHTMLInputElement.h" #include "nsIDOMXULButtonElement.h" #include "nsIDOMXULCheckboxElement.h" #include "nsIDOMXULMenuListElement.h" #include "nsIDOMXULSelectCntrlItemEl.h" #include "nsIDOMXULTextboxElement.h" -#include "nsAccessibleTreeWalker.h" +#include "nsINameSpaceManager.h" /** * XUL Button: can contain arbitrary HTML content @@ -639,6 +641,20 @@ NS_IMETHODIMP nsXULTextFieldAccessible::GetValue(nsAString& aValue) return NS_ERROR_FAILURE; } +NS_IMETHODIMP nsXULTextFieldAccessible::GetExtState(PRUint32 *aExtState) +{ + nsresult rv = nsAccessible::GetExtState(aExtState); + if (NS_FAILED(rv)) { + return rv; + } + nsCOMPtr content(do_QueryInterface(mDOMNode)); + NS_ASSERTION(content, "Should not have gotten past nsAccessible::GetExtState() without node"); + + PRBool isMultiLine = content->HasAttr(kNameSpaceID_None, nsAccessibilityAtoms::multiline); + *aExtState |= (isMultiLine ? EXT_STATE_MULTI_LINE : EXT_STATE_SINGLE_LINE); + return NS_OK; +} + NS_IMETHODIMP nsXULTextFieldAccessible::GetState(PRUint32 *aState) { *aState = 0; diff --git a/accessible/src/xul/nsXULFormControlAccessible.h b/accessible/src/xul/nsXULFormControlAccessible.h index 3d553a02f189..2ce6bf40eb5e 100644 --- a/accessible/src/xul/nsXULFormControlAccessible.h +++ b/accessible/src/xul/nsXULFormControlAccessible.h @@ -154,6 +154,7 @@ public: NS_IMETHOD GetName(nsAString& aName) { return GetXULName(aName); } NS_IMETHOD GetValue(nsAString& aValue); NS_IMETHOD GetState(PRUint32 *aState); + NS_IMETHOD GetExtState(PRUint32 *aExtState); NS_IMETHOD GetRole(PRUint32 *aRole) { *aRole = ROLE_TEXT; return NS_OK; } };