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
authorMarco Zehe <mzehe@mozilla.com>
Mon, 17 Dec 2018 06:09:48 +0000
changeset 450894 7ce7e9407a751e1047379635510c0acdc6486200
parent 450893 c9c531cbe1881f72d9c80dc4af8b73e69ae05d9b
child 450895 f0b091b21fdd750d0bfd9010cce1a0289d257702
child 450920 59b5076086538e943d4d89858bbcb70a7cc93691
push id35219
push userrmaries@mozilla.com
push dateMon, 17 Dec 2018 09:37:26 +0000
treeherdermozilla-central@7ce7e9407a75 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersJamie
bugs1510476
milestone66.0a1
first release with
nightly linux32
7ce7e9407a75 / 66.0a1 / 20181217093726 / files
nightly linux64
7ce7e9407a75 / 66.0a1 / 20181217093726 / files
nightly mac
7ce7e9407a75 / 66.0a1 / 20181217093726 / files
nightly win32
7ce7e9407a75 / 66.0a1 / 20181217093726 / files
nightly win64
7ce7e9407a75 / 66.0a1 / 20181217093726 / files
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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
accessible/windows/msaa/XULMenuAccessibleWrap.cpp
accessible/windows/msaa/XULMenuAccessibleWrap.h
--- a/accessible/windows/msaa/XULMenuAccessibleWrap.cpp
+++ b/accessible/windows/msaa/XULMenuAccessibleWrap.cpp
@@ -1,13 +1,15 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * 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"
 
 using namespace mozilla::a11y;
 
 ////////////////////////////////////////////////////////////////////////////////
 // XULMenuAccessibleWrap
 ////////////////////////////////////////////////////////////////////////////////
@@ -26,8 +28,32 @@ ENameValueFlag XULMenuitemAccessibleWrap
   if (mContent->IsElement()) {
     mContent->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::acceltext,
                                    accel);
   }
   if (!accel.IsEmpty()) aName += NS_LITERAL_STRING("\t") + accel;
 
   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;
+}
--- a/accessible/windows/msaa/XULMenuAccessibleWrap.h
+++ b/accessible/windows/msaa/XULMenuAccessibleWrap.h
@@ -13,14 +13,18 @@ namespace a11y {
 
 class XULMenuitemAccessibleWrap : public XULMenuitemAccessible {
  public:
   XULMenuitemAccessibleWrap(nsIContent* aContent, DocAccessible* aDoc);
   virtual ~XULMenuitemAccessibleWrap() {}
 
   // 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
 }  // namespace mozilla
 
 #endif