Bug 82207. XUL Checkbox working with MSAA. r=jgaunt, sr=hyatt

git-svn-id: svn://10.0.0.236/trunk@102588 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
aaronl%netscape.com
2001-09-08 16:22:09 +00:00
parent 306f3914a2
commit d45d392f62
27 changed files with 508 additions and 61 deletions

View File

@@ -29,12 +29,12 @@
#include "nsHTMLAtoms.h"
#include "nsIDOMHTMLButtonElement.h"
#include "nsReadableUtils.h"
#include "nsString.h"
#include "nsAccessible.h"
#include "nsIFrame.h"
#include "nsIDOMHTMLLabelElement.h"
#include "nsIDOMHTMLFormElement.h"
#include "nsISelectionController.h"
#include "nsIDOMXULCheckboxElement.h"
nsHTMLFormControlAccessible::nsHTMLFormControlAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell):
nsLeafAccessible(aNode, aShell)
@@ -117,25 +117,29 @@ NS_IMETHODIMP nsHTMLFormControlAccessible::GetAccName(nsAWritableString& _retval
NS_IMETHODIMP nsHTMLFormControlAccessible::GetAccState(PRUint32 *_retval)
{
// can be
// focusable, focused, checked, protected, unavailable
nsCOMPtr<nsIDOMHTMLInputElement> element(do_QueryInterface(mDOMNode));
// focusable, focused, protected, unavailable
nsCOMPtr<nsIDOMHTMLInputElement> htmlFormElement(do_QueryInterface(mDOMNode));
nsAccessible::GetAccState(_retval);
*_retval |= STATE_FOCUSABLE;
PRBool checked = PR_FALSE;
element->GetChecked(&checked);
if (checked) *_retval |= STATE_CHECKED;
PRBool disabled = PR_FALSE;
element->GetDisabled(&disabled);
if (htmlFormElement) {
htmlFormElement->GetDisabled(&disabled);
nsAutoString typeString;
htmlFormElement->GetType(typeString);
if (typeString.EqualsIgnoreCase("password"))
*_retval |= STATE_PROTECTED;
}
else {
nsCOMPtr<nsIDOMXULControlElement> xulFormElement(do_QueryInterface(mDOMNode));
if (xulFormElement)
xulFormElement->GetDisabled(&disabled);
}
if (disabled)
*_retval |= STATE_UNAVAILABLE;
nsAutoString typeString;
element->GetType(typeString);
if (typeString.EqualsIgnoreCase("password"))
*_retval |= STATE_PROTECTED;
else
*_retval |= STATE_FOCUSABLE;
return NS_OK;
}
@@ -164,15 +168,12 @@ NS_IMETHODIMP nsHTMLCheckboxAccessible::GetAccNumActions(PRUint8 *_retval)
/* wstring getAccActionName (in PRUint8 index); */
NS_IMETHODIMP nsHTMLCheckboxAccessible::GetAccActionName(PRUint8 index, nsAWritableString& _retval)
{
if (index == 0) {
if (index == 0) { // 0 is the magic value for default action
// check or uncheck
nsCOMPtr<nsIDOMHTMLInputElement> element(do_QueryInterface(mDOMNode));
PRUint32 state;
GetAccState(&state);
PRBool checked = PR_FALSE;
if (element)
element->GetChecked(&checked);
if (checked)
if (state & STATE_CHECKED)
_retval = NS_LITERAL_STRING("uncheck");
else
_retval = NS_LITERAL_STRING("check");
@@ -186,15 +187,43 @@ NS_IMETHODIMP nsHTMLCheckboxAccessible::GetAccActionName(PRUint8 index, nsAWrita
NS_IMETHODIMP nsHTMLCheckboxAccessible::AccDoAction(PRUint8 index)
{
if (index == 0) { // 0 is the magic value for default action
nsCOMPtr<nsIDOMHTMLInputElement> element(do_QueryInterface(mDOMNode));
nsCOMPtr<nsIDOMHTMLInputElement> htmlCheckboxElement(do_QueryInterface(mDOMNode));
PRBool checked = PR_FALSE;
element->GetChecked(&checked);
element->SetChecked(checked ? PR_FALSE : PR_TRUE);
if (htmlCheckboxElement) {
htmlCheckboxElement->GetChecked(&checked);
htmlCheckboxElement->SetChecked(!checked);
}
else {
nsCOMPtr<nsIDOMXULCheckboxElement> xulCheckboxElement(do_QueryInterface(mDOMNode));
if (xulCheckboxElement) {
xulCheckboxElement->GetChecked(&checked);
xulCheckboxElement->SetChecked(!checked);
}
}
return NS_OK;
}
return NS_ERROR_INVALID_ARG;
}
NS_IMETHODIMP nsHTMLCheckboxAccessible::GetAccState(PRUint32 *_retval)
{
nsHTMLFormControlAccessible::GetAccState(_retval);
PRBool checked = PR_FALSE; // Radio buttons and check boxes can be checked
nsCOMPtr<nsIDOMHTMLInputElement> htmlCheckboxElement(do_QueryInterface(mDOMNode));
if (htmlCheckboxElement)
htmlCheckboxElement->GetChecked(&checked);
else {
nsCOMPtr<nsIDOMXULCheckboxElement> xulCheckboxElement(do_QueryInterface(mDOMNode));
if (xulCheckboxElement)
xulCheckboxElement->GetChecked(&checked);
}
if (checked)
*_retval |= STATE_CHECKED;
return NS_OK;
}
//------ Radio button -------
@@ -240,6 +269,28 @@ NS_IMETHODIMP nsHTMLRadioButtonAccessible::GetAccRole(PRUint32 *_retval)
return NS_OK;
}
NS_IMETHODIMP nsHTMLRadioButtonAccessible::GetAccState(PRUint32 *_retval)
{
nsHTMLFormControlAccessible::GetAccState(_retval);
PRBool checked = PR_FALSE; // Radio buttons and check boxes can be checked
nsCOMPtr<nsIDOMHTMLInputElement> htmlRadioElement(do_QueryInterface(mDOMNode));
if (htmlRadioElement)
htmlRadioElement->GetChecked(&checked);
/* ----- Need to add this code soon
nsCOMPtr<nsIDOMXULRadioElement> xulRadioElement(do_QueryInteface(mDOMNode));
if (xulRadioElement)
xulRadioElement->GetChecked(&checked);
*/
if (checked)
*_retval |= STATE_CHECKED;
return NS_OK;
}
// ----- Button -----
nsHTMLButtonAccessible::nsHTMLButtonAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell):
@@ -387,6 +438,11 @@ NS_IMETHODIMP nsHTMLTextFieldAccessible::GetAccRole(PRUint32 *_retval)
/* wstring getAccValue (); */
NS_IMETHODIMP nsHTMLTextFieldAccessible::GetAccValue(nsAWritableString& _retval)
{
PRUint32 state;
GetAccState(&state);
if (state & STATE_PROTECTED) // Don't return password text!
return NS_ERROR_FAILURE;
nsCOMPtr<nsIDOMHTMLTextAreaElement> textArea(do_QueryInterface(mDOMNode));
if (textArea) {
textArea->GetValue(_retval);