Bug 1869092 - Fix timeouts in browser_PanelMultiView.js. r=twisniewski,test-only
[gecko.git] / accessible / atk / nsMaiInterfaceSelection.cpp
blob80b4d260f1f420a4c62bef8ed4f00ff76da94502
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 "mozilla/Likely.h"
14 #include <atk/atkobject.h>
15 #include <atk/atkselection.h>
17 using namespace mozilla::a11y;
19 extern "C" {
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);
27 return FALSE;
30 static gboolean clearSelectionCB(AtkSelection* aSelection) {
31 Accessible* acc = GetInternalObj(ATK_OBJECT(aSelection));
32 if (acc && acc->IsSelect()) {
33 return acc->UnselectAll();
36 return FALSE;
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);
43 if (selectedItem) {
44 atkObj = GetWrapperFor(selectedItem);
47 if (atkObj) {
48 g_object_ref(atkObj);
51 return atkObj;
54 static gint getSelectionCountCB(AtkSelection* aSelection) {
55 Accessible* acc = GetInternalObj(ATK_OBJECT(aSelection));
56 if (acc && acc->IsSelect()) {
57 return acc->SelectedItemCount();
60 return -1;
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);
69 return FALSE;
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);
78 return FALSE;
81 static gboolean selectAllSelectionCB(AtkSelection* aSelection) {
82 Accessible* acc = GetInternalObj(ATK_OBJECT(aSelection));
83 if (acc && acc->IsSelect()) {
84 return acc->SelectAll();
87 return FALSE;
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;