Bug 873439 - Implement IAccessible2_2::relationTargetsOfType, r=tbsaunde
authorAlexander Surkov <surkov.alexander@gmail.com>
Thu, 24 Oct 2013 15:18:01 -0400
changeset 166783 98614ea8ce7ff8e8674fdc85200bf4c3a75a7284
parent 166782 9ba57b6051db4e538db6982269432dfaa2459810
child 166784 4feb44a01f69cc219d3bbf04f7b0126296fa19e9
push id428
push userbbajaj@mozilla.com
push dateTue, 28 Jan 2014 00:16:25 +0000
treeherdermozilla-release@cd72a7ff3a75 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstbsaunde
bugs873439
milestone27.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 873439 - Implement IAccessible2_2::relationTargetsOfType, r=tbsaunde
accessible/src/windows/ia2/ia2Accessible.cpp
accessible/src/windows/ia2/ia2Accessible.h
--- a/accessible/src/windows/ia2/ia2Accessible.cpp
+++ b/accessible/src/windows/ia2/ia2Accessible.cpp
@@ -2,16 +2,17 @@
 /* vim: set ts=2 et sw=2 tw=80: */
 /* 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 "Accessible2_i.c"
+#include "Accessible2_2_i.c"
 #include "AccessibleRole.h"
 #include "AccessibleStates.h"
 
 #include "Compatibility.h"
 #include "ia2AccessibleRelation.h"
 #include "IUnknownImpl.h"
 #include "nsCoreUtils.h"
 #include "nsIAccessibleTypes.h"
@@ -30,18 +31,22 @@ using namespace mozilla::a11y;
 STDMETHODIMP
 ia2Accessible::QueryInterface(REFIID iid, void** ppv)
 {
   if (!ppv)
     return E_INVALIDARG;
 
   *ppv = nullptr;
 
-  if (IID_IAccessible2 == iid && !Compatibility::IsIA2Off()) {
+  if (IID_IAccessible2_2 == iid)
+    *ppv = static_cast<IAccessible2_2*>(this);
+  else if (IID_IAccessible2 == iid && !Compatibility::IsIA2Off())
     *ppv = static_cast<IAccessible2*>(this);
+
+  if (*ppv) {
     (reinterpret_cast<IUnknown*>(*ppv))->AddRef();
     return S_OK;
   }
 
   return E_NOINTERFACE;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -518,16 +523,99 @@ ia2Accessible::get_attributes(BSTR* aAtt
   // characters ":;=,\".
   nsCOMPtr<nsIPersistentProperties> attributes = acc->Attributes();
   return ConvertToIA2Attributes(attributes, aAttributes);
 
   A11Y_TRYBLOCK_END
 }
 
 ////////////////////////////////////////////////////////////////////////////////
+// IAccessible2_2
+
+STDMETHODIMP
+ia2Accessible::get_attribute(BSTR name, VARIANT* aAttribute)
+{
+  A11Y_TRYBLOCK_BEGIN
+
+  if (!aAttribute)
+    return E_INVALIDARG;
+
+  return E_NOTIMPL;
+
+  A11Y_TRYBLOCK_END
+}
+
+STDMETHODIMP
+ia2Accessible::get_accessibleWithCaret(IUnknown** aAccessible,
+                                       long* aCaretOffset)
+{
+  A11Y_TRYBLOCK_BEGIN
+
+  if (!aAccessible || !aCaretOffset)
+    return E_INVALIDARG;
+
+  *aAccessible = nullptr;
+  *aCaretOffset = -1;
+  return E_NOTIMPL;
+
+  A11Y_TRYBLOCK_END
+}
+
+STDMETHODIMP
+ia2Accessible::get_relationTargetsOfType(BSTR aType,
+                                         long aMaxTargets,
+                                         IUnknown*** aTargets,
+                                         long* aNTargets)
+{
+  A11Y_TRYBLOCK_BEGIN
+
+  if (!aTargets || !aNTargets)
+    return E_INVALIDARG;
+  *aNTargets = 0;
+
+  Maybe<RelationType> relationType;
+  for (uint32_t idx = 0; idx < ArrayLength(sRelationTypePairs); idx++) {
+    if (wcscmp(aType, sRelationTypePairs[idx].second) == 0) {
+      relationType.construct(sRelationTypePairs[idx].first);
+      break;
+    }
+  }
+  if (relationType.empty())
+    return E_INVALIDARG;
+
+  AccessibleWrap* acc = static_cast<AccessibleWrap*>(this);
+  if (acc->IsDefunct())
+    return CO_E_OBJNOTCONNECTED;
+
+  Relation rel = acc->RelationByType(relationType.ref());
+
+  nsTArray<Accessible*> targets;
+  Accessible* target = nullptr;
+  while ((target = rel.Next()) &&
+         static_cast<long>(targets.Length()) <= aMaxTargets)
+    targets.AppendElement(target);
+
+  *aNTargets = targets.Length();
+  *aTargets = static_cast<IUnknown**>(
+    ::CoTaskMemAlloc(sizeof(IUnknown*) * *aNTargets));
+  if (!*aTargets)
+    return E_OUTOFMEMORY;
+
+  for (int32_t i = 0; i < *aNTargets; i++) {
+    AccessibleWrap* target= static_cast<AccessibleWrap*>(targets[i]);
+    (*aTargets)[i] = static_cast<IAccessible2*>(target);
+    (*aTargets)[i]->AddRef();
+  }
+
+  return S_OK;
+
+  A11Y_TRYBLOCK_END
+}
+
+////////////////////////////////////////////////////////////////////////////////
 // Helpers
 
 HRESULT
 ia2Accessible::ConvertToIA2Attributes(nsIPersistentProperties* aAttributes,
                                       BSTR* aIA2Attributes)
 {
   *aIA2Attributes = nullptr;
 
--- a/accessible/src/windows/ia2/ia2Accessible.h
+++ b/accessible/src/windows/ia2/ia2Accessible.h
@@ -4,22 +4,22 @@
  * 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/. */
 
 #ifndef mozilla_a11y_ia2Accessible_h_
 #define mozilla_a11y_ia2Accessible_h_
 
 #include "nsISupports.h"
 
-#include "Accessible2.h"
+#include "Accessible2_2.h"
 
 namespace mozilla {
 namespace a11y {
 
-class ia2Accessible : public IAccessible2
+class ia2Accessible : public IAccessible2_2
 {
 public:
 
   // IUnknown
   STDMETHODIMP QueryInterface(REFIID, void**);
 
   // IAccessible2
   virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_nRelations(
@@ -82,16 +82,31 @@ public:
     /* [retval][out] */ long* indexInParent);
 
   virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_locale(
     /* [retval][out] */ IA2Locale* locale);
 
   virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_attributes(
     /* [retval][out] */ BSTR* attributes);
 
+  // IAccessible2_2
+  virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_attribute(
+    /* [in] */ BSTR name,
+    /* [out, retval] */ VARIANT* attribute);
+
+  virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_accessibleWithCaret(
+    /* [out] */ IUnknown** accessible,
+    /* [out, retval] */ long* caretOffset);
+
+  virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_relationTargetsOfType(
+    /* [in] */ BSTR type,
+    /* [in] */ long maxTargets,
+    /* [out, size_is(,*nTargets)] */ IUnknown*** targets,
+    /* [out, retval] */ long* nTargets
+  );
 
   // Helper method
   static HRESULT ConvertToIA2Attributes(nsIPersistentProperties* aAttributes,
                                         BSTR* aIA2Attributes);
 };
 
 } // namespace a11y
 } // namespace mozilla