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"
12 #include "mozilla/Likely.h"
14 #include <atk/atkobject.h>
15 #include <atk/atkselection.h>
17 using namespace mozilla::a11y
;
21 static gboolean
addSelectionCB(AtkSelection
* aSelection
, gint i
) {
22 Accessible
* acc
= GetInternalObj(ATK_OBJECT(aSelection
));
23 if (acc
&& acc
->IsSelect()) {
24 return acc
->AddItemToSelection(i
);
30 static gboolean
clearSelectionCB(AtkSelection
* aSelection
) {
31 Accessible
* acc
= GetInternalObj(ATK_OBJECT(aSelection
));
32 if (acc
&& acc
->IsSelect()) {
33 return acc
->UnselectAll();
39 static AtkObject
* refSelectionCB(AtkSelection
* aSelection
, gint i
) {
40 AtkObject
* atkObj
= nullptr;
41 Accessible
* acc
= GetInternalObj(ATK_OBJECT(aSelection
));
42 Accessible
* selectedItem
= acc
->GetSelectedItem(i
);
44 atkObj
= GetWrapperFor(selectedItem
);
54 static gint
getSelectionCountCB(AtkSelection
* aSelection
) {
55 Accessible
* acc
= GetInternalObj(ATK_OBJECT(aSelection
));
56 if (acc
&& acc
->IsSelect()) {
57 return acc
->SelectedItemCount();
63 static gboolean
isChildSelectedCB(AtkSelection
* aSelection
, gint i
) {
64 Accessible
* acc
= GetInternalObj(ATK_OBJECT(aSelection
));
65 if (acc
&& acc
->IsSelect()) {
66 return acc
->IsItemSelected(i
);
72 static gboolean
removeSelectionCB(AtkSelection
* aSelection
, gint i
) {
73 Accessible
* acc
= GetInternalObj(ATK_OBJECT(aSelection
));
74 if (acc
&& acc
->IsSelect()) {
75 return acc
->RemoveItemFromSelection(i
);
81 static gboolean
selectAllSelectionCB(AtkSelection
* aSelection
) {
82 Accessible
* acc
= GetInternalObj(ATK_OBJECT(aSelection
));
83 if (acc
&& acc
->IsSelect()) {
84 return acc
->SelectAll();
91 void selectionInterfaceInitCB(AtkSelectionIface
* aIface
) {
92 NS_ASSERTION(aIface
, "Invalid aIface");
93 if (MOZ_UNLIKELY(!aIface
)) return;
95 aIface
->add_selection
= addSelectionCB
;
96 aIface
->clear_selection
= clearSelectionCB
;
97 aIface
->ref_selection
= refSelectionCB
;
98 aIface
->get_selection_count
= getSelectionCountCB
;
99 aIface
->is_child_selected
= isChildSelectedCB
;
100 aIface
->remove_selection
= removeSelectionCB
;
101 aIface
->select_all_selection
= selectAllSelectionCB
;