Bug 873444: Implement IAccessibleHypertext2::hyperlinks. r=surkov
authorJames Teh <jteh@mozilla.com>
Fri, 27 Oct 2017 09:40:11 +1000
changeset 389301 51c759b72e9a172eae173f52fc7f7fc4b6a6b631
parent 389300 4c27ce0056bf8ec24413e149ea460dabc1d69da7
child 389302 b63c7bc7b0b1517e1ea872edc361a6a1861edd59
push id32784
push userarchaeopteryx@coole-files.de
push dateTue, 31 Oct 2017 23:34:29 +0000
treeherdermozilla-central@ae1d655ea7c7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssurkov
bugs873444
milestone58.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 873444: Implement IAccessibleHypertext2::hyperlinks. r=surkov This allows for fetching of all hyperlinks instead of one at a time, which improves performance for a cross-process client. MozReview-Commit-ID: 8wso3EqBqwP
accessible/windows/ia2/ia2AccessibleHypertext.cpp
accessible/windows/ia2/ia2AccessibleHypertext.h
accessible/windows/msaa/HyperTextAccessibleWrap.cpp
--- a/accessible/windows/ia2/ia2AccessibleHypertext.cpp
+++ b/accessible/windows/ia2/ia2AccessibleHypertext.cpp
@@ -74,8 +74,45 @@ ia2AccessibleHypertext::get_hyperlinkInd
   HyperTextAccessibleWrap* hyperAcc = static_cast<HyperTextAccessibleWrap*>(this);
   if (hyperAcc->IsDefunct())
     return CO_E_OBJNOTCONNECTED;
 
   *aHyperlinkIndex = hyperAcc->LinkIndexAtOffset(aCharIndex);
   return S_OK;
 }
 
+STDMETHODIMP
+ia2AccessibleHypertext::get_hyperlinks(IAccessibleHyperlink*** aHyperlinks,
+                                      long* aNHyperlinks)
+{
+  if (!aHyperlinks || !aNHyperlinks) {
+    return E_INVALIDARG;
+  }
+
+  *aHyperlinks = nullptr;
+  *aNHyperlinks = 0;
+
+  MOZ_ASSERT(!HyperTextProxyFor(this));
+
+  HyperTextAccessibleWrap* hyperText = static_cast<HyperTextAccessibleWrap*>(this);
+  if (hyperText->IsDefunct()) {
+    return CO_E_OBJNOTCONNECTED;
+  }
+
+  uint32_t count = hyperText->LinkCount();
+  *aNHyperlinks = count;
+
+  *aHyperlinks = static_cast<IAccessibleHyperlink**>(::CoTaskMemAlloc(
+    sizeof(IAccessibleHyperlink*) * count));
+  if (!*aHyperlinks) {
+    return E_OUTOFMEMORY;
+  }
+
+  for (uint32_t i = 0; i < count; ++i) {
+    AccessibleWrap* hyperLink =
+      static_cast<AccessibleWrap*>(hyperText->LinkAt(i));
+    MOZ_ASSERT(hyperLink);
+    (*aHyperlinks)[i] = static_cast<IAccessibleHyperlink*>(hyperLink);
+    (*aHyperlinks)[i]->AddRef();
+  }
+
+  return S_OK;
+}
--- a/accessible/windows/ia2/ia2AccessibleHypertext.h
+++ b/accessible/windows/ia2/ia2AccessibleHypertext.h
@@ -6,23 +6,23 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef _ACCESSIBLE_HYPERTEXT_H
 #define _ACCESSIBLE_HYPERTEXT_H
 
 #include "nsISupports.h"
 
 #include "ia2AccessibleText.h"
-#include "AccessibleHypertext.h"
+#include "AccessibleHypertext2.h"
 
 namespace mozilla {
 namespace a11y {
 
 class ia2AccessibleHypertext : public ia2AccessibleText,
-                               public IAccessibleHypertext
+                               public IAccessibleHypertext2
 {
 public:
 
   // IAccessibleText
   FORWARD_IACCESSIBLETEXT(ia2AccessibleText)
 
   // IAccessibleHypertext
   virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_nHyperlinks(
@@ -30,14 +30,19 @@ public:
 
   virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_hyperlink(
       /* [in] */ long index,
       /* [retval][out] */ IAccessibleHyperlink** hyperlink);
 
   virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_hyperlinkIndex(
       /* [in] */ long charIndex,
       /* [retval][out] */ long* hyperlinkIndex);
+
+  // IAccessibleHypertext2
+  virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_hyperlinks(
+      /* [out, size_is(,*nHyperlinks)] */ IAccessibleHyperlink*** hyperlinks,
+      /* [out, retval] */ long* nHyperlinks);
 };
 
 } // namespace a11y
 } // namespace mozilla
 
 #endif
--- a/accessible/windows/msaa/HyperTextAccessibleWrap.cpp
+++ b/accessible/windows/msaa/HyperTextAccessibleWrap.cpp
@@ -27,16 +27,18 @@ HyperTextAccessibleWrap::QueryInterface(
   *aInstancePtr = nullptr;
 
   if (IsTextRole()) {
     if (aIID == IID_IAccessibleText)
       *aInstancePtr =
         static_cast<IAccessibleText*>(static_cast<ia2AccessibleText*>(this));
     else if (aIID == IID_IAccessibleHypertext)
       *aInstancePtr = static_cast<IAccessibleHypertext*>(this);
+    else if (aIID == IID_IAccessibleHypertext2)
+      *aInstancePtr = static_cast<IAccessibleHypertext2*>(this);
     else if (aIID == IID_IAccessibleEditableText)
       *aInstancePtr = static_cast<IAccessibleEditableText*>(this);
 
     if (*aInstancePtr) {
       AddRef();
       return S_OK;
     }
   }