ia2AccessibleHypertext.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* vim:expandtab:shiftwidth=2:tabstop=2:
  3. */
  4. /* This Source Code Form is subject to the terms of the Mozilla Public
  5. * License, v. 2.0. If a copy of the MPL was not distributed with this
  6. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  7. #include "ia2AccessibleHypertext.h"
  8. #include "AccessibleHypertext_i.c"
  9. #include "HyperTextAccessibleWrap.h"
  10. #include "IUnknownImpl.h"
  11. using namespace mozilla::a11y;
  12. // IAccessibleHypertext
  13. STDMETHODIMP
  14. ia2AccessibleHypertext::get_nHyperlinks(long* aHyperlinkCount)
  15. {
  16. if (!aHyperlinkCount)
  17. return E_INVALIDARG;
  18. *aHyperlinkCount = 0;
  19. MOZ_ASSERT(!HyperTextProxyFor(this));
  20. HyperTextAccessibleWrap* hyperText = static_cast<HyperTextAccessibleWrap*>(this);
  21. if (hyperText->IsDefunct())
  22. return CO_E_OBJNOTCONNECTED;
  23. *aHyperlinkCount = hyperText->LinkCount();
  24. return S_OK;
  25. }
  26. STDMETHODIMP
  27. ia2AccessibleHypertext::get_hyperlink(long aLinkIndex,
  28. IAccessibleHyperlink** aHyperlink)
  29. {
  30. if (!aHyperlink)
  31. return E_INVALIDARG;
  32. *aHyperlink = nullptr;
  33. AccessibleWrap* hyperLink;
  34. MOZ_ASSERT(!HyperTextProxyFor(this));
  35. HyperTextAccessibleWrap* hyperText = static_cast<HyperTextAccessibleWrap*>(this);
  36. if (hyperText->IsDefunct()) {
  37. return CO_E_OBJNOTCONNECTED;
  38. }
  39. hyperLink = static_cast<AccessibleWrap*>(hyperText->LinkAt(aLinkIndex));
  40. if (!hyperLink)
  41. return E_FAIL;
  42. *aHyperlink =
  43. static_cast<IAccessibleHyperlink*>(hyperLink);
  44. (*aHyperlink)->AddRef();
  45. return S_OK;
  46. }
  47. STDMETHODIMP
  48. ia2AccessibleHypertext::get_hyperlinkIndex(long aCharIndex, long* aHyperlinkIndex)
  49. {
  50. if (!aHyperlinkIndex)
  51. return E_INVALIDARG;
  52. *aHyperlinkIndex = 0;
  53. MOZ_ASSERT(!HyperTextProxyFor(this));
  54. HyperTextAccessibleWrap* hyperAcc = static_cast<HyperTextAccessibleWrap*>(this);
  55. if (hyperAcc->IsDefunct())
  56. return CO_E_OBJNOTCONNECTED;
  57. *aHyperlinkIndex = hyperAcc->LinkIndexAtOffset(aCharIndex);
  58. return S_OK;
  59. }