nsMaiInterfaceSelection.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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 "AccessibleWrap.h"
  8. #include "nsMai.h"
  9. #include "ProxyAccessible.h"
  10. #include "mozilla/Likely.h"
  11. #include <atk/atk.h>
  12. using namespace mozilla::a11y;
  13. extern "C" {
  14. static gboolean
  15. addSelectionCB(AtkSelection *aSelection, gint i)
  16. {
  17. AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
  18. if (accWrap && accWrap->IsSelect()) {
  19. return accWrap->AddItemToSelection(i);
  20. }
  21. if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aSelection))) {
  22. return proxy->AddItemToSelection(i);
  23. }
  24. return FALSE;
  25. }
  26. static gboolean
  27. clearSelectionCB(AtkSelection *aSelection)
  28. {
  29. AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
  30. if (accWrap && accWrap->IsSelect()) {
  31. return accWrap->UnselectAll();
  32. }
  33. if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aSelection))) {
  34. return proxy->UnselectAll();
  35. }
  36. return FALSE;
  37. }
  38. static AtkObject*
  39. refSelectionCB(AtkSelection *aSelection, gint i)
  40. {
  41. AtkObject* atkObj = nullptr;
  42. AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
  43. if (accWrap && accWrap->IsSelect()) {
  44. Accessible* selectedItem = accWrap->GetSelectedItem(i);
  45. if (!selectedItem) {
  46. return nullptr;
  47. }
  48. atkObj = AccessibleWrap::GetAtkObject(selectedItem);
  49. } else if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aSelection))) {
  50. ProxyAccessible* selectedItem = proxy->GetSelectedItem(i);
  51. if (selectedItem) {
  52. atkObj = GetWrapperFor(selectedItem);
  53. }
  54. }
  55. if (atkObj) {
  56. g_object_ref(atkObj);
  57. }
  58. return atkObj;
  59. }
  60. static gint
  61. getSelectionCountCB(AtkSelection *aSelection)
  62. {
  63. AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
  64. if (accWrap && accWrap->IsSelect()) {
  65. return accWrap->SelectedItemCount();
  66. }
  67. if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aSelection))) {
  68. return proxy->SelectedItemCount();
  69. }
  70. return -1;
  71. }
  72. static gboolean
  73. isChildSelectedCB(AtkSelection *aSelection, gint i)
  74. {
  75. AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
  76. if (accWrap && accWrap->IsSelect()) {
  77. return accWrap->IsItemSelected(i);
  78. }
  79. if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aSelection))) {
  80. return proxy->IsItemSelected(i);
  81. }
  82. return FALSE;
  83. }
  84. static gboolean
  85. removeSelectionCB(AtkSelection *aSelection, gint i)
  86. {
  87. AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
  88. if (accWrap && accWrap->IsSelect()) {
  89. return accWrap->RemoveItemFromSelection(i);
  90. }
  91. if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aSelection))) {
  92. return proxy->RemoveItemFromSelection(i);
  93. }
  94. return FALSE;
  95. }
  96. static gboolean
  97. selectAllSelectionCB(AtkSelection *aSelection)
  98. {
  99. AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
  100. if (accWrap && accWrap->IsSelect()) {
  101. return accWrap->SelectAll();
  102. }
  103. if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aSelection))) {
  104. return proxy->SelectAll();
  105. }
  106. return FALSE;
  107. }
  108. }
  109. void
  110. selectionInterfaceInitCB(AtkSelectionIface* aIface)
  111. {
  112. NS_ASSERTION(aIface, "Invalid aIface");
  113. if (MOZ_UNLIKELY(!aIface))
  114. return;
  115. aIface->add_selection = addSelectionCB;
  116. aIface->clear_selection = clearSelectionCB;
  117. aIface->ref_selection = refSelectionCB;
  118. aIface->get_selection_count = getSelectionCountCB;
  119. aIface->is_child_selected = isChildSelectedCB;
  120. aIface->remove_selection = removeSelectionCB;
  121. aIface->select_all_selection = selectAllSelectionCB;
  122. }