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