nsMaiInterfaceHypertext.cpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #include "InterfaceInitFuncs.h"
  6. #include "Accessible-inl.h"
  7. #include "HyperTextAccessible.h"
  8. #include "nsMai.h"
  9. #include "nsMaiHyperlink.h"
  10. #include "ProxyAccessible.h"
  11. #include "mozilla/Likely.h"
  12. using namespace mozilla::a11y;
  13. extern "C" {
  14. static AtkHyperlink*
  15. getLinkCB(AtkHypertext *aText, gint aLinkIndex)
  16. {
  17. AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
  18. AtkObject* atkHyperLink = nullptr;
  19. if (accWrap) {
  20. HyperTextAccessible* hyperText = accWrap->AsHyperText();
  21. NS_ENSURE_TRUE(hyperText, nullptr);
  22. Accessible* hyperLink = hyperText->LinkAt(aLinkIndex);
  23. if (!hyperLink || !hyperLink->IsLink()) {
  24. return nullptr;
  25. }
  26. atkHyperLink = AccessibleWrap::GetAtkObject(hyperLink);
  27. } else if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) {
  28. ProxyAccessible* proxyLink = proxy->LinkAt(aLinkIndex);
  29. if (!proxyLink)
  30. return nullptr;
  31. atkHyperLink = GetWrapperFor(proxyLink);
  32. }
  33. NS_ENSURE_TRUE(IS_MAI_OBJECT(atkHyperLink), nullptr);
  34. return MAI_ATK_OBJECT(atkHyperLink)->GetAtkHyperlink();
  35. }
  36. static gint
  37. getLinkCountCB(AtkHypertext *aText)
  38. {
  39. AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
  40. if (accWrap) {
  41. HyperTextAccessible* hyperText = accWrap->AsHyperText();
  42. NS_ENSURE_TRUE(hyperText, -1);
  43. return hyperText->LinkCount();
  44. }
  45. if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) {
  46. return proxy->LinkCount();
  47. }
  48. return -1;
  49. }
  50. static gint
  51. getLinkIndexCB(AtkHypertext *aText, gint aCharIndex)
  52. {
  53. AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
  54. if (accWrap) {
  55. HyperTextAccessible* hyperText = accWrap->AsHyperText();
  56. NS_ENSURE_TRUE(hyperText, -1);
  57. return hyperText->LinkIndexAtOffset(aCharIndex);
  58. }
  59. if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) {
  60. return proxy->LinkIndexAtOffset(aCharIndex);
  61. }
  62. return -1;
  63. }
  64. }
  65. void
  66. hypertextInterfaceInitCB(AtkHypertextIface* aIface)
  67. {
  68. NS_ASSERTION(aIface, "no interface!");
  69. if (MOZ_UNLIKELY(!aIface))
  70. return;
  71. aIface->get_link = getLinkCB;
  72. aIface->get_n_links = getLinkCountCB;
  73. aIface->get_link_index = getLinkIndexCB;
  74. }