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

This commit is contained in:
aaronleventhal%moonset.net 2005-03-14 23:10:53 +00:00
Родитель 346f4ad9b0
Коммит f97e388d87
8 изменённых файлов: 49 добавлений и 87 удалений

Просмотреть файл

@ -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

Просмотреть файл

@ -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); */

Просмотреть файл

@ -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<nsIDOMHTMLInputElement> 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<nsIDOMXULControlElement> 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

Просмотреть файл

@ -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);

Просмотреть файл

@ -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<nsIContent> content(do_QueryInterface(mDOMNode));
if (!content) {
return NS_ERROR_FAILURE; // Node has been Shutdown()
}
nsAccessible::GetState(_retval);
*_retval |= STATE_FOCUSABLE;
nsCOMPtr<nsIDOMHTMLTextAreaElement> textArea(do_QueryInterface(mDOMNode));
nsCOMPtr<nsIDOMHTMLInputElement> inputElement(do_QueryInterface(mDOMNode));
nsCOMPtr<nsIDOMElement> 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<nsISelectionController> selCon;
frame->GetSelectionController(context,getter_AddRefs(selCon));
if (selCon) {
nsCOMPtr<nsISelection> 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;

Просмотреть файл

@ -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

Просмотреть файл

@ -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<nsIContent> 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;

Просмотреть файл

@ -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; }
};