Bug 1700051: part 36) Reduce accessibility of `SoftText::mBegin` to `private`. r...
[gecko.git] / accessible / atk / nsMaiInterfaceSelection.cpp
blob010377211471bd081e2d675aefe1469cc77918a6
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "InterfaceInitFuncs.h"
9 #include "LocalAccessible-inl.h"
10 #include "AccessibleWrap.h"
11 #include "nsMai.h"
12 #include "RemoteAccessible.h"
13 #include "mozilla/Likely.h"
15 #include <atk/atk.h>
17 using namespace mozilla::a11y;
19 extern "C" {
21 static gboolean addSelectionCB(AtkSelection* aSelection, gint i) {
22 AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
23 if (accWrap && accWrap->IsSelect()) {
24 return accWrap->AddItemToSelection(i);
27 if (RemoteAccessible* proxy = GetProxy(ATK_OBJECT(aSelection))) {
28 return proxy->AddItemToSelection(i);
31 return FALSE;
34 static gboolean clearSelectionCB(AtkSelection* aSelection) {
35 AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
36 if (accWrap && accWrap->IsSelect()) {
37 return accWrap->UnselectAll();
40 if (RemoteAccessible* proxy = GetProxy(ATK_OBJECT(aSelection))) {
41 return proxy->UnselectAll();
44 return FALSE;
47 static AtkObject* refSelectionCB(AtkSelection* aSelection, gint i) {
48 AtkObject* atkObj = nullptr;
49 AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
50 if (accWrap && accWrap->IsSelect()) {
51 LocalAccessible* selectedItem = accWrap->GetSelectedItem(i);
52 if (!selectedItem) {
53 return nullptr;
56 atkObj = AccessibleWrap::GetAtkObject(selectedItem);
57 } else if (RemoteAccessible* proxy = GetProxy(ATK_OBJECT(aSelection))) {
58 RemoteAccessible* selectedItem = proxy->GetSelectedItem(i);
59 if (selectedItem) {
60 atkObj = GetWrapperFor(selectedItem);
64 if (atkObj) {
65 g_object_ref(atkObj);
68 return atkObj;
71 static gint getSelectionCountCB(AtkSelection* aSelection) {
72 AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
73 if (accWrap && accWrap->IsSelect()) {
74 return accWrap->SelectedItemCount();
77 if (RemoteAccessible* proxy = GetProxy(ATK_OBJECT(aSelection))) {
78 return proxy->SelectedItemCount();
81 return -1;
84 static gboolean isChildSelectedCB(AtkSelection* aSelection, gint i) {
85 AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
86 if (accWrap && accWrap->IsSelect()) {
87 return accWrap->IsItemSelected(i);
90 if (RemoteAccessible* proxy = GetProxy(ATK_OBJECT(aSelection))) {
91 return proxy->IsItemSelected(i);
94 return FALSE;
97 static gboolean removeSelectionCB(AtkSelection* aSelection, gint i) {
98 AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
99 if (accWrap && accWrap->IsSelect()) {
100 return accWrap->RemoveItemFromSelection(i);
103 if (RemoteAccessible* proxy = GetProxy(ATK_OBJECT(aSelection))) {
104 return proxy->RemoveItemFromSelection(i);
107 return FALSE;
110 static gboolean selectAllSelectionCB(AtkSelection* aSelection) {
111 AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
112 if (accWrap && accWrap->IsSelect()) {
113 return accWrap->SelectAll();
116 if (RemoteAccessible* proxy = GetProxy(ATK_OBJECT(aSelection))) {
117 return proxy->SelectAll();
120 return FALSE;
124 void selectionInterfaceInitCB(AtkSelectionIface* aIface) {
125 NS_ASSERTION(aIface, "Invalid aIface");
126 if (MOZ_UNLIKELY(!aIface)) return;
128 aIface->add_selection = addSelectionCB;
129 aIface->clear_selection = clearSelectionCB;
130 aIface->ref_selection = refSelectionCB;
131 aIface->get_selection_count = getSelectionCountCB;
132 aIface->is_child_selected = isChildSelectedCB;
133 aIface->remove_selection = removeSelectionCB;
134 aIface->select_all_selection = selectAllSelectionCB;