Bug 873444: Implement IAccessibleHypertext2::hyperlinks. r?surkov draft
authorJames Teh <jteh@mozilla.com>
Fri, 27 Oct 2017 09:40:11 +1000
changeset 689157 501214513f9ae0d3de51f66c5305a2ae7cf7a317
parent 689081 083a9c84fbd09a6ff9bfecabbf773650842fe1c0
child 738244 913bcdc1b0719a3bc87b460e1edd5c4adf34542c
push id86940
push userbmo:jteh@mozilla.com
push dateTue, 31 Oct 2017 06:17:15 +0000
reviewerssurkov
bugs873444
milestone58.0a1
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;
     }
   }