|
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 file, |
|
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 |
|
7 #include "xpcAccessibleSelectable.h" |
|
8 |
|
9 #include "Accessible-inl.h" |
|
10 |
|
11 using namespace mozilla::a11y; |
|
12 |
|
13 NS_IMETHODIMP |
|
14 xpcAccessibleSelectable::GetSelectedItems(nsIArray** aSelectedItems) |
|
15 { |
|
16 NS_ENSURE_ARG_POINTER(aSelectedItems); |
|
17 *aSelectedItems = nullptr; |
|
18 |
|
19 Accessible* acc = static_cast<Accessible*>(this); |
|
20 if (acc->IsDefunct()) |
|
21 return NS_ERROR_FAILURE; |
|
22 NS_PRECONDITION(acc->IsSelect(), "Called on non selectable widget!"); |
|
23 |
|
24 nsCOMPtr<nsIArray> items = acc->SelectedItems(); |
|
25 if (items) { |
|
26 uint32_t length = 0; |
|
27 items->GetLength(&length); |
|
28 if (length) |
|
29 items.swap(*aSelectedItems); |
|
30 } |
|
31 |
|
32 return NS_OK; |
|
33 } |
|
34 |
|
35 NS_IMETHODIMP |
|
36 xpcAccessibleSelectable::GetSelectedItemCount(uint32_t* aSelectionCount) |
|
37 { |
|
38 NS_ENSURE_ARG_POINTER(aSelectionCount); |
|
39 *aSelectionCount = 0; |
|
40 |
|
41 Accessible* acc = static_cast<Accessible*>(this); |
|
42 if (acc->IsDefunct()) |
|
43 return NS_ERROR_FAILURE; |
|
44 NS_PRECONDITION(acc->IsSelect(), "Called on non selectable widget!"); |
|
45 |
|
46 *aSelectionCount = acc->SelectedItemCount(); |
|
47 return NS_OK; |
|
48 } |
|
49 |
|
50 NS_IMETHODIMP |
|
51 xpcAccessibleSelectable::GetSelectedItemAt(uint32_t aIndex, |
|
52 nsIAccessible** aSelected) |
|
53 { |
|
54 NS_ENSURE_ARG_POINTER(aSelected); |
|
55 *aSelected = nullptr; |
|
56 |
|
57 Accessible* acc = static_cast<Accessible*>(this); |
|
58 if (acc->IsDefunct()) |
|
59 return NS_ERROR_FAILURE; |
|
60 NS_PRECONDITION(acc->IsSelect(), "Called on non selectable widget!"); |
|
61 |
|
62 *aSelected = acc->GetSelectedItem(aIndex); |
|
63 if (*aSelected) { |
|
64 NS_ADDREF(*aSelected); |
|
65 return NS_OK; |
|
66 } |
|
67 |
|
68 return NS_ERROR_INVALID_ARG; |
|
69 } |
|
70 |
|
71 NS_IMETHODIMP |
|
72 xpcAccessibleSelectable::ScriptableIsItemSelected(uint32_t aIndex, |
|
73 bool* aIsSelected) |
|
74 { |
|
75 NS_ENSURE_ARG_POINTER(aIsSelected); |
|
76 *aIsSelected = false; |
|
77 |
|
78 Accessible* acc = static_cast<Accessible*>(this); |
|
79 if (acc->IsDefunct()) |
|
80 return NS_ERROR_FAILURE; |
|
81 NS_PRECONDITION(acc->IsSelect(), "Called on non selectable widget!"); |
|
82 |
|
83 *aIsSelected = acc->IsItemSelected(aIndex); |
|
84 return NS_OK; |
|
85 } |
|
86 |
|
87 NS_IMETHODIMP |
|
88 xpcAccessibleSelectable::ScriptableAddItemToSelection(uint32_t aIndex) |
|
89 { |
|
90 Accessible* acc = static_cast<Accessible*>(this); |
|
91 if (acc->IsDefunct()) |
|
92 return NS_ERROR_FAILURE; |
|
93 NS_PRECONDITION(acc->IsSelect(), "Called on non selectable widget!"); |
|
94 |
|
95 return acc->AddItemToSelection(aIndex) ? NS_OK : NS_ERROR_INVALID_ARG; |
|
96 } |
|
97 |
|
98 NS_IMETHODIMP |
|
99 xpcAccessibleSelectable::ScriptableRemoveItemFromSelection(uint32_t aIndex) |
|
100 { |
|
101 Accessible* acc = static_cast<Accessible*>(this); |
|
102 if (acc->IsDefunct()) |
|
103 return NS_ERROR_FAILURE; |
|
104 NS_PRECONDITION(acc->IsSelect(), "Called on non selectable widget!"); |
|
105 |
|
106 return acc->RemoveItemFromSelection(aIndex) ? NS_OK : NS_ERROR_INVALID_ARG; |
|
107 } |
|
108 |
|
109 NS_IMETHODIMP |
|
110 xpcAccessibleSelectable::ScriptableSelectAll(bool* aIsMultiSelect) |
|
111 { |
|
112 NS_ENSURE_ARG_POINTER(aIsMultiSelect); |
|
113 *aIsMultiSelect = false; |
|
114 |
|
115 Accessible* acc = static_cast<Accessible*>(this); |
|
116 if (acc->IsDefunct()) |
|
117 return NS_ERROR_FAILURE; |
|
118 NS_PRECONDITION(acc->IsSelect(), "Called on non selectable widget!"); |
|
119 |
|
120 *aIsMultiSelect = acc->SelectAll(); |
|
121 return NS_OK; |
|
122 } |
|
123 |
|
124 NS_IMETHODIMP |
|
125 xpcAccessibleSelectable::ScriptableUnselectAll() |
|
126 { |
|
127 Accessible* acc = static_cast<Accessible*>(this); |
|
128 if (acc->IsDefunct()) |
|
129 return NS_ERROR_FAILURE; |
|
130 NS_PRECONDITION(acc->IsSelect(), "Called on non selectable widget!"); |
|
131 |
|
132 acc->UnselectAll(); |
|
133 return NS_OK; |
|
134 } |