Bug 187208 give more information for menu
r=kyle.yuan, sr=bryner git-svn-id: svn://10.0.0.236/trunk@136226 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -44,6 +44,7 @@ interface nsIAccessible : nsISupports
|
||||
|
||||
readonly attribute AString accDescription;
|
||||
readonly attribute AString accKeyboardShortcut;
|
||||
readonly attribute AString accKeybinding;
|
||||
|
||||
readonly attribute unsigned long accRole;
|
||||
readonly attribute unsigned long accState;
|
||||
|
||||
@@ -128,6 +128,12 @@ NS_IMETHODIMP nsGenericAccessible::GetAccKeyboardShortcut(nsAString& _retval)
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* DOMString getKeybinding (); */
|
||||
NS_IMETHODIMP nsGenericAccessible::GetAccKeybinding(nsAString& _retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* unsigned long getAccRole (); */
|
||||
NS_IMETHODIMP nsGenericAccessible::GetAccRole(PRUint32 *_retval)
|
||||
{
|
||||
|
||||
@@ -114,6 +114,7 @@ NS_IMETHODIMP nsXULMenuitemAccessible::GetAccName(nsAString& _retval)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//return menu accesskey: N or Alt+F
|
||||
NS_IMETHODIMP nsXULMenuitemAccessible::GetAccKeyboardShortcut(nsAString& _retval)
|
||||
{
|
||||
static PRInt32 gMenuAccesskeyModifier = -1; // magic value of -1 indicates unitialized state
|
||||
@@ -157,6 +158,22 @@ NS_IMETHODIMP nsXULMenuitemAccessible::GetAccKeyboardShortcut(nsAString& _retval
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
//return menu shortcut: Ctrl+F or Ctrl+Shift+L
|
||||
NS_IMETHODIMP nsXULMenuitemAccessible::GetAccKeybinding(nsAString& _retval)
|
||||
{
|
||||
nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(mDOMNode));
|
||||
if (elt) {
|
||||
nsAutoString accelText;
|
||||
elt->GetAttribute(NS_LITERAL_STRING("acceltext"), accelText);
|
||||
if (accelText.IsEmpty())
|
||||
return NS_OK;
|
||||
|
||||
_retval = accelText;
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsXULMenuitemAccessible::GetAccRole(PRUint32 *_retval)
|
||||
{
|
||||
*_retval = ROLE_MENUITEM;
|
||||
|
||||
@@ -51,6 +51,7 @@ public:
|
||||
nsXULMenuitemAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell);
|
||||
NS_IMETHOD GetAccName(nsAString& _retval);
|
||||
NS_IMETHOD GetAccKeyboardShortcut(nsAString& _retval);
|
||||
NS_IMETHOD GetAccKeybinding(nsAString& _retval);
|
||||
NS_IMETHOD GetAccState(PRUint32 *_retval);
|
||||
NS_IMETHOD GetAccRole(PRUint32 *_retval);
|
||||
NS_IMETHOD GetAccFirstChild(nsIAccessible **aAccFirstChild);
|
||||
|
||||
@@ -133,12 +133,101 @@ MaiInterfaceAction::GetName(gint aActionIndex)
|
||||
const gchar *
|
||||
MaiInterfaceAction::GetKeybinding(gint aActionIndex)
|
||||
{
|
||||
//return all Keybindings including accesskey and shortcut
|
||||
|
||||
nsIAccessible *accessible = GetNSAccessible();
|
||||
g_return_val_if_fail(accessible != NULL, NULL);
|
||||
|
||||
/* this is not supported in nsIAccessible yet */
|
||||
if (!mKeyBinding.IsEmpty())
|
||||
return mKeyBinding.get();
|
||||
|
||||
return NULL;
|
||||
nsAutoString allKeybinding;
|
||||
|
||||
//get accesskey
|
||||
nsAutoString accessKey;
|
||||
nsresult rv = accessible->GetAccKeyboardShortcut(accessKey);
|
||||
|
||||
if (NS_SUCCEEDED(rv) && !accessKey.IsEmpty()) {
|
||||
nsCOMPtr<nsIAccessible> parentAccessible;
|
||||
accessible->GetAccParent(getter_AddRefs(parentAccessible));
|
||||
if (parentAccessible) {
|
||||
PRUint32 role;
|
||||
parentAccessible->GetAccRole(&role);
|
||||
|
||||
if (role == ATK_ROLE_MENU_BAR) {
|
||||
//it is topmenu, change from "Alt+f" to "f;<Alt>f"
|
||||
nsAutoString rightChar;
|
||||
accessKey.Right(rightChar, 1);
|
||||
allKeybinding = rightChar + NS_LITERAL_STRING(";<Alt>") +
|
||||
rightChar;
|
||||
}
|
||||
else if ((role == ATK_ROLE_MENU) || (role == ATK_ROLE_MENU_ITEM)) {
|
||||
//it is submenu, change from "s" to "s;<Alt>fs"
|
||||
nsAutoString allKey = accessKey;
|
||||
nsCOMPtr<nsIAccessible> grandParentAcc = parentAccessible;
|
||||
|
||||
while ((grandParentAcc) && (role != ATK_ROLE_MENU_BAR)) {
|
||||
nsAutoString grandParentKey;
|
||||
grandParentAcc->GetAccKeyboardShortcut(grandParentKey);
|
||||
|
||||
if (!grandParentKey.IsEmpty()) {
|
||||
nsAutoString rightChar;
|
||||
grandParentKey.Right(rightChar, 1);
|
||||
allKey = rightChar + allKey;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIAccessible> tempAcc = grandParentAcc;
|
||||
tempAcc->GetAccParent(getter_AddRefs(grandParentAcc));
|
||||
if (grandParentAcc)
|
||||
grandParentAcc->GetAccRole(&role);
|
||||
}
|
||||
allKeybinding = accessKey + NS_LITERAL_STRING(";<Alt>") +
|
||||
allKey;
|
||||
}
|
||||
}
|
||||
else {
|
||||
//default process, rarely happens.
|
||||
nsAutoString rightChar;
|
||||
accessKey.Right(rightChar, 1);
|
||||
allKeybinding = rightChar + NS_LITERAL_STRING(";<Alt>") + rightChar;
|
||||
}
|
||||
}
|
||||
else //don't have accesskey
|
||||
allKeybinding = NS_LITERAL_STRING(";");
|
||||
|
||||
//get shortcut
|
||||
nsAutoString keyBinding, subShortcut;
|
||||
rv = accessible->GetAccKeybinding(keyBinding);
|
||||
|
||||
if (NS_SUCCEEDED(rv) && !keyBinding.IsEmpty()) {
|
||||
//change the shortcut from "Ctrl+Shift+L" to "<Control><Shift>L"
|
||||
PRInt32 oldPos, curPos=0;
|
||||
while ((curPos != -1) && (curPos < (PRInt32)keyBinding.Length())) {
|
||||
oldPos = curPos;
|
||||
nsAutoString subString;
|
||||
curPos = keyBinding.FindChar('+', oldPos);
|
||||
if (curPos == -1) {
|
||||
keyBinding.Mid(subString, oldPos, keyBinding.Length() - oldPos);
|
||||
subShortcut += subString;
|
||||
}
|
||||
else {
|
||||
keyBinding.Mid(subString, oldPos, curPos - oldPos);
|
||||
|
||||
//change "Ctrl" to "Control"
|
||||
if (subString.EqualsIgnoreCase("ctrl"))
|
||||
subString = NS_LITERAL_STRING("Control");
|
||||
|
||||
subShortcut += NS_LITERAL_STRING("<") + subString +
|
||||
NS_LITERAL_STRING(">");
|
||||
curPos++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
allKeybinding += NS_LITERAL_STRING(";") + subShortcut;
|
||||
mKeyBinding = NS_ConvertUCS2toUTF8(allKeybinding);
|
||||
|
||||
return mKeyBinding.get();
|
||||
}
|
||||
|
||||
gboolean
|
||||
|
||||
@@ -64,6 +64,7 @@ public:
|
||||
|
||||
private:
|
||||
nsCString mName;
|
||||
nsCString mKeyBinding;
|
||||
};
|
||||
|
||||
#endif /* __MAI_INTERFACE_ACTION_H__ */
|
||||
|
||||
Reference in New Issue
Block a user