Bug 1510476 - Don't expose the keyboard accelerator in IAccessible::get_accKeyboardShortcut if a XUL menu item does not have an access key, r=Jamie

The default implementation of get_accKeyboardShortcut falls back to using the keyboard accelerator if an access key is not available. For XUL menu items, this is not appropriate since the accelerator gets exposed as part of the accessible name already.

The result was a double announcement of the keyboard accelerator on menu items that did not have an access key (underlined letter).

Differential Revision: https://phabricator.services.mozilla.com/D14533

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Marco Zehe 2018-12-17 06:09:48 +00:00
parent ad64da67ba
commit 47edbd91c4
2 changed files with 30 additions and 0 deletions

View file

@ -3,6 +3,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "AccessibleWrap.h"
#include "EnumVariant.h"
#include "XULMenuAccessibleWrap.h"
#include "nsNameSpaceManager.h"
@ -31,3 +33,27 @@ ENameValueFlag XULMenuitemAccessibleWrap::Name(nsString& aName) const {
return eNameOK;
}
STDMETHODIMP
XULMenuitemAccessibleWrap::get_accKeyboardShortcut(
/* [optional][in] */ VARIANT varChild,
/* [retval][out] */ BSTR __RPC_FAR* pszKeyboardShortcut) {
if (!pszKeyboardShortcut) return E_INVALIDARG;
*pszKeyboardShortcut = nullptr;
if (varChild.vt != VT_I4 || varChild.lVal != CHILDID_SELF) {
return AccessibleWrap::get_accKeyboardShortcut(varChild,
pszKeyboardShortcut);
}
KeyBinding keyBinding = AccessKey();
if (keyBinding.IsEmpty()) {
return S_FALSE;
}
nsAutoString shortcut;
keyBinding.ToString(shortcut);
*pszKeyboardShortcut = ::SysAllocStringLen(shortcut.get(), shortcut.Length());
return *pszKeyboardShortcut ? S_OK : E_OUTOFMEMORY;
}

View file

@ -18,6 +18,10 @@ class XULMenuitemAccessibleWrap : public XULMenuitemAccessible {
// nsIAccessible
virtual mozilla::a11y::ENameValueFlag Name(nsString& aName) const override;
virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_accKeyboardShortcut(
/* [optional][in] */ VARIANT varChild,
/* [retval][out] */ BSTR __RPC_FAR* pszKeyboardShortcut) override;
};
} // namespace a11y