Bug 1521438: Correct IAccessible::get_accSelection implementation for no selection and single selection. r=MarcoZ
authorJames Teh <jteh@mozilla.com>
Mon, 21 Jan 2019 07:21:01 +0000
changeset 454673 311d09aeb1ab0e1ee583123634a4b28975172969
parent 454672 dbab9ee37db197462dd3dee9d947d44e9d644428
child 454674 a8e0501505f47a64d8b26ab0be981a32cddd89ae
push id111317
push userrmaries@mozilla.com
push dateMon, 21 Jan 2019 18:01:55 +0000
treeherdermozilla-inbound@19db0edfbc10 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMarcoZ
bugs1521438
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1521438: Correct IAccessible::get_accSelection implementation for no selection and single selection. r=MarcoZ Previously, we were always returning VT_UNKNOWN and an IEnumVARIANT. According to the IAccessible documentation, this should only be done for multiple selection. Change this to correctly return VT_EMPTY for no selection and VT_DISPATCH (with an accessible) for single selection. Differential Revision: https://phabricator.services.mozilla.com/D17091
accessible/windows/msaa/AccessibleWrap.cpp
--- a/accessible/windows/msaa/AccessibleWrap.cpp
+++ b/accessible/windows/msaa/AccessibleWrap.cpp
@@ -735,27 +735,35 @@ STDMETHODIMP
 AccessibleWrap::get_accSelection(VARIANT __RPC_FAR* pvarChildren) {
   if (!pvarChildren) return E_INVALIDARG;
 
   VariantInit(pvarChildren);
   pvarChildren->vt = VT_EMPTY;
 
   if (IsDefunct()) return CO_E_OBJNOTCONNECTED;
 
-  if (IsSelect()) {
-    AutoTArray<Accessible*, 10> selectedItems;
-    SelectedItems(&selectedItems);
+  if (!IsSelect()) {
+    return S_OK;
+  }
 
-    // 1) Create and initialize the enumeration
+  AutoTArray<Accessible*, 10> selectedItems;
+  SelectedItems(&selectedItems);
+  uint32_t count = selectedItems.Length();
+  if (count == 1) {
+    pvarChildren->vt = VT_DISPATCH;
+    pvarChildren->pdispVal = NativeAccessible(selectedItems[0]);
+  } else if (count > 1) {
     RefPtr<AccessibleEnumerator> pEnum =
         new AccessibleEnumerator(selectedItems);
     pvarChildren->vt =
         VT_UNKNOWN;  // this must be VT_UNKNOWN for an IEnumVARIANT
     NS_ADDREF(pvarChildren->punkVal = pEnum);
   }
+  // If count == 0, vt is already VT_EMPTY, so there's nothing else to do.
+
   return S_OK;
 }
 
 STDMETHODIMP
 AccessibleWrap::get_accDefaultAction(
     /* [optional][in] */ VARIANT varChild,
     /* [retval][out] */ BSTR __RPC_FAR* pszDefaultAction) {
   if (!pszDefaultAction) return E_INVALIDARG;