Bug 122312. Active Accessibility: support default actions for menu items and options. r=jgaunt, sr=alecf

This commit is contained in:
aaronl%netscape.com 2002-04-26 04:50:21 +00:00
Родитель 7fb4a4610b
Коммит e00af508fc
8 изменённых файлов: 174 добавлений и 16 удалений

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

@ -67,7 +67,7 @@ class nsAccessible : public nsGenericAccessible
{
public:
// to eliminate the confusion of "magic numbers" -- if ( 0 ){ foo; }
enum { eAction_Switch=0, eAction_Jump=0, eAction_Click=0 };
enum { eAction_Switch=0, eAction_Jump=0, eAction_Click=0, eAction_Select=0 };
// how many actions
enum { eNo_Action=0, eSingle_Action=1 };

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

@ -140,16 +140,6 @@ nsLeafAccessible(aDOMNode, aShell)
}
}
/** click us! */
NS_IMETHODIMP nsSelectOptionAccessible::GetAccActionName(PRUint8 index, nsAString& _retval)
{
if (index == eAction_Click) {
nsAccessible::GetTranslatedString(NS_LITERAL_STRING("select"), _retval);
return NS_OK;
}
return NS_ERROR_INVALID_ARG;
}
/** We are a ListItem */
NS_IMETHODIMP nsSelectOptionAccessible::GetAccRole(PRUint32 *_retval)
{

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

@ -82,7 +82,6 @@ public:
virtual ~nsSelectOptionAccessible() {}
/* ----- nsIAccessible ----- */
NS_IMETHOD GetAccActionName(PRUint8 index, nsAString& _retval);
NS_IMETHOD GetAccName(nsAString& _retval);
NS_IMETHOD GetAccParent(nsIAccessible **_retval);
NS_IMETHOD GetAccRole(PRUint32 *_retval);

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

@ -50,6 +50,7 @@
#include "nsIDOMHTMLSelectElement.h"
#include "nsIDOMHTMLOListElement.h"
#include "nsIListControlFrame.h"
#include "nsIComboboxControlFrame.h"
#include "nsIServiceManager.h"
#include "nsLayoutAtoms.h"
#include "nsIDocument.h"
@ -307,6 +308,82 @@ NS_IMETHODIMP nsHTMLSelectOptionAccessible::GetAccState(PRUint32 *_retval)
return NS_OK;
}
/** select us! close combo box if necessary*/
NS_IMETHODIMP nsHTMLSelectOptionAccessible::GetAccActionName(PRUint8 index, nsAString& _retval)
{
if (index == eAction_Select) {
nsAccessible::GetTranslatedString(NS_LITERAL_STRING("select"), _retval);
return NS_OK;
}
return NS_ERROR_INVALID_ARG;
}
NS_IMETHODIMP nsHTMLSelectOptionAccessible::GetAccNumActions(PRUint8 *_retval)
{
*_retval = eSingle_Action;
return NS_OK;
}
NS_IMETHODIMP nsHTMLSelectOptionAccessible::AccDoAction(PRUint8 index)
{
if (index == eAction_Select) { // default action
nsCOMPtr<nsIDOMHTMLOptionElement> newHTMLOption(do_QueryInterface(mDOMNode));
if (!newHTMLOption)
return NS_ERROR_FAILURE;
// Clear old selection
nsCOMPtr<nsIDOMNode> oldHTMLOptionNode, selectNode;
mParent->AccGetDOMNode(getter_AddRefs(selectNode));
nsHTMLSelectOptionAccessible::GetFocusedOptionNode(selectNode, oldHTMLOptionNode);
nsCOMPtr<nsIDOMHTMLOptionElement> oldHTMLOption(do_QueryInterface(oldHTMLOptionNode));
if (oldHTMLOption)
oldHTMLOption->SetSelected(PR_FALSE);
// Set new selection
newHTMLOption->SetSelected(PR_TRUE);
// If combo box, and open, close it
// First, get the <select> widgets list control frame
nsCOMPtr<nsIDOMNode> testSelectNode;
nsCOMPtr<nsIDOMNode> thisNode(do_QueryInterface(mDOMNode));
do {
thisNode->GetParentNode(getter_AddRefs(testSelectNode));
nsCOMPtr<nsIDOMHTMLSelectElement> selectControl(do_QueryInterface(testSelectNode));
if (selectControl)
break;
thisNode = testSelectNode;
} while (testSelectNode);
nsCOMPtr<nsIPresShell> presShell(do_QueryReferent(mPresShell));
nsCOMPtr<nsIContent> selectContent(do_QueryInterface(testSelectNode));
nsCOMPtr<nsIDOMHTMLOptionElement> option(do_QueryInterface(mDOMNode));
if (!testSelectNode || !selectContent || !presShell || !option)
return NS_ERROR_FAILURE;
nsIFrame *selectFrame = nsnull;
presShell->GetPrimaryFrameFor(selectContent, &selectFrame);
nsCOMPtr<nsIComboboxControlFrame> comboBoxFrame(do_QueryInterface(selectFrame));
if (comboBoxFrame) {
nsIFrame *listFrame = nsnull;
comboBoxFrame->GetDropDown(&listFrame);
PRBool isDroppedDown;
comboBoxFrame->IsDroppedDown(&isDroppedDown);
if (isDroppedDown && listFrame) {
// use this list control frame to roll up the list
nsCOMPtr<nsIListControlFrame> listControlFrame(do_QueryInterface(listFrame));
if (listControlFrame) {
PRInt32 newIndex = 0;
option->GetIndex(&newIndex);
listControlFrame->ComboboxFinish(newIndex);
}
}
}
return NS_OK;
}
return NS_ERROR_INVALID_ARG;
}
/**
* Helper method for getting the focused DOM Node from our parent(list) node. We
* need to use the frame to get the focused option because for some reason we
@ -383,6 +460,23 @@ NS_IMETHODIMP nsHTMLSelectOptGroupAccessible::GetAccState(PRUint32 *_retval)
return NS_OK;
}
NS_IMETHODIMP nsHTMLSelectOptGroupAccessible::AccDoAction(PRUint8 index)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsHTMLSelectOptGroupAccessible::GetAccActionName(PRUint8 index, nsAString& _retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsHTMLSelectOptGroupAccessible::GetAccNumActions(PRUint8 *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/** ------------------------------------------------------ */
/** Secondly, the Listbox widget */
/** ------------------------------------------------------ */

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

@ -101,7 +101,9 @@ public:
NS_IMETHOD GetAccState(PRUint32 *_retval);
NS_IMETHOD GetAccNextSibling(nsIAccessible **_retval);
NS_IMETHOD GetAccPreviousSibling(nsIAccessible **_retval);
NS_IMETHOD AccDoAction(PRUint8 index);
NS_IMETHOD GetAccActionName(PRUint8 index, nsAString& _retval);
NS_IMETHOD GetAccNumActions(PRUint8 *_retval);
static nsresult GetFocusedOptionNode(nsIDOMNode *aListNode, nsCOMPtr<nsIDOMNode>& aFocusedOptionNode);
};
@ -118,6 +120,9 @@ public:
/* ----- nsIAccessible ----- */
NS_IMETHOD GetAccState(PRUint32 *_retval);
NS_IMETHOD AccDoAction(PRUint8 index);
NS_IMETHOD GetAccActionName(PRUint8 index, nsAString& _retval);
NS_IMETHOD GetAccNumActions(PRUint8 *_retval);
};
@ -198,7 +203,6 @@ public:
NS_IMETHOD GetAccNextSibling(nsIAccessible **_retval);
NS_IMETHOD GetAccPreviousSibling(nsIAccessible **_retval);
NS_IMETHOD AccDoAction(PRUint8 index);
};
/*

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

@ -41,7 +41,8 @@
#include "nsAccessible.h"
#include "nsIAccessible.h"
#include "nsIDOMElement.h"
#include "nsIDOMXULPopupElement.h"
#include "nsIDOMXULElement.h"
#include "nsIDOMXULSelectCntrlItemEl.h"
// ------------------------ Menu Item -----------------------------
@ -153,6 +154,56 @@ NS_IMETHODIMP nsXULMenuitemAccessible::GetAccChildCount(PRInt32 *aAccChildCount)
return NS_OK;
}
NS_IMETHODIMP nsXULMenuitemAccessible::AccDoAction(PRUint8 index)
{
if (index == eAction_Select) { // default action
nsCOMPtr<nsIDOMXULSelectControlItemElement> selectItem(do_QueryInterface(mDOMNode));
if (selectItem)
selectItem->DoCommand();
else {
nsCOMPtr<nsIDOMXULElement> xulElement(do_QueryInterface(mDOMNode));
if (xulElement) {
xulElement->Click();
}
}
nsCOMPtr<nsIAccessible> parentAccessible;
GetAccParent(getter_AddRefs(parentAccessible));
if (parentAccessible) {
PRUint32 role;
parentAccessible->GetAccRole(&role);
if (role == ROLE_LIST) {
nsCOMPtr<nsIAccessible> buttonAccessible;
parentAccessible->GetAccPreviousSibling(getter_AddRefs(buttonAccessible));
PRUint32 state;
buttonAccessible->GetAccState(&state);
if (state & STATE_PRESSED)
buttonAccessible->AccDoAction(eAction_Click);
}
}
return NS_OK;
}
return NS_ERROR_INVALID_ARG;
}
/** select us! close combo box if necessary*/
NS_IMETHODIMP nsXULMenuitemAccessible::GetAccActionName(PRUint8 index, nsAString& _retval)
{
if (index == eAction_Select) {
nsAccessible::GetTranslatedString(NS_LITERAL_STRING("select"), _retval);
return NS_OK;
}
return NS_ERROR_INVALID_ARG;
}
NS_IMETHODIMP nsXULMenuitemAccessible::GetAccNumActions(PRUint8 *_retval)
{
*_retval = eSingle_Action;
return NS_OK;
}
// ------------------------ Menu Separator ----------------------------
nsXULMenuSeparatorAccessible::nsXULMenuSeparatorAccessible(nsIDOMNode* aDOMNode, nsIWeakReference* aShell):
@ -181,6 +232,20 @@ NS_IMETHODIMP nsXULMenuSeparatorAccessible::GetAccRole(PRUint32 *_retval)
return NS_OK;
}
NS_IMETHODIMP nsXULMenuSeparatorAccessible::AccDoAction(PRUint8 index)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsXULMenuSeparatorAccessible::GetAccActionName(PRUint8 index, nsAString& _retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsXULMenuSeparatorAccessible::GetAccNumActions(PRUint8 *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
// ------------------------ Menu Popup -----------------------------
nsXULMenupopupAccessible::nsXULMenupopupAccessible(nsIDOMNode* aDOMNode, nsIWeakReference* aShell): nsAccessible(aDOMNode, aShell)

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

@ -55,6 +55,9 @@ public:
NS_IMETHOD GetAccFirstChild(nsIAccessible **aAccFirstChild);
NS_IMETHOD GetAccLastChild(nsIAccessible **aAccLastChild);
NS_IMETHOD GetAccChildCount(PRInt32 *aAccChildCount);
NS_IMETHOD AccDoAction(PRUint8 index);
NS_IMETHOD GetAccActionName(PRUint8 index, nsAString& _retval);
NS_IMETHOD GetAccNumActions(PRUint8 *_retval);
};
class nsXULMenuSeparatorAccessible : public nsXULMenuitemAccessible
@ -64,6 +67,9 @@ public:
NS_IMETHOD GetAccName(nsAString& _retval);
NS_IMETHOD GetAccState(PRUint32 *_retval);
NS_IMETHOD GetAccRole(PRUint32 *_retval);
NS_IMETHOD AccDoAction(PRUint8 index);
NS_IMETHOD GetAccActionName(PRUint8 index, nsAString& _retval);
NS_IMETHOD GetAccNumActions(PRUint8 *_retval);
};
class nsXULMenupopupAccessible : public nsAccessible

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

@ -24,7 +24,7 @@
<![CDATA[
if (this.localName == "popup" || this.localName == "menupopup") {
var accService = Components.classes["@mozilla.org/accessibilityService;1"].getService(Components.interfaces.nsIAccessibilityService);
return (this.parentNode.localName == "menulist")? accService.createXULComboboxWindowAccessible: accService.createXULMenupopupAccessible(this);
return (this.parentNode.localName == "menulist")? accService.createXULSelectListAccessible(this): accService.createXULMenupopupAccessible(this);
}
return null;
]]>