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/. */
7 #include "Accessible-inl.h"
9 #include "nsIAccessible.h"
10 #include "nsIMutableArray.h"
11 #include "xpcAccessibleDocument.h"
12 #include "xpcAccessibleSelectable.h"
14 using namespace mozilla::a11y
;
17 xpcAccessibleSelectable::GetSelectedItems(nsIArray
** aSelectedItems
) {
18 NS_ENSURE_ARG_POINTER(aSelectedItems
);
19 *aSelectedItems
= nullptr;
21 if (!Intl()) return NS_ERROR_FAILURE
;
22 MOZ_ASSERT(Intl()->IsSelect(), "Called on non selectable widget!");
24 AutoTArray
<Accessible
*, 10> items
;
25 Intl()->SelectedItems(&items
);
27 uint32_t itemCount
= items
.Length();
28 if (itemCount
== 0) return NS_OK
;
31 nsCOMPtr
<nsIMutableArray
> xpcItems
=
32 do_CreateInstance(NS_ARRAY_CONTRACTID
, &rv
);
33 NS_ENSURE_SUCCESS(rv
, rv
);
35 for (uint32_t idx
= 0; idx
< itemCount
; idx
++)
36 xpcItems
->AppendElement(static_cast<nsIAccessible
*>(ToXPC(items
[idx
])));
38 NS_ADDREF(*aSelectedItems
= xpcItems
);
43 xpcAccessibleSelectable::GetSelectedItemCount(uint32_t* aSelectionCount
) {
44 NS_ENSURE_ARG_POINTER(aSelectionCount
);
47 if (!Intl()) return NS_ERROR_FAILURE
;
48 MOZ_ASSERT(Intl()->IsSelect(), "Called on non selectable widget!");
50 *aSelectionCount
= Intl()->SelectedItemCount();
55 xpcAccessibleSelectable::GetSelectedItemAt(uint32_t aIndex
,
56 nsIAccessible
** aSelected
) {
57 NS_ENSURE_ARG_POINTER(aSelected
);
60 if (!Intl()) return NS_ERROR_FAILURE
;
61 MOZ_ASSERT(Intl()->IsSelect(), "Called on non selectable widget!");
63 *aSelected
= ToXPC(Intl()->GetSelectedItem(aIndex
));
65 NS_ADDREF(*aSelected
);
69 return NS_ERROR_INVALID_ARG
;
73 xpcAccessibleSelectable::IsItemSelected(uint32_t aIndex
, bool* aIsSelected
) {
74 NS_ENSURE_ARG_POINTER(aIsSelected
);
77 if (!Intl()) return NS_ERROR_FAILURE
;
78 MOZ_ASSERT(Intl()->IsSelect(), "Called on non selectable widget!");
80 *aIsSelected
= Intl()->IsItemSelected(aIndex
);
85 xpcAccessibleSelectable::AddItemToSelection(uint32_t aIndex
) {
86 if (!Intl()) return NS_ERROR_FAILURE
;
87 MOZ_ASSERT(Intl()->IsSelect(), "Called on non selectable widget!");
89 return Intl()->AddItemToSelection(aIndex
) ? NS_OK
: NS_ERROR_INVALID_ARG
;
93 xpcAccessibleSelectable::RemoveItemFromSelection(uint32_t aIndex
) {
94 if (!Intl()) return NS_ERROR_FAILURE
;
95 MOZ_ASSERT(Intl()->IsSelect(), "Called on non selectable widget!");
97 return Intl()->RemoveItemFromSelection(aIndex
) ? NS_OK
: NS_ERROR_INVALID_ARG
;
101 xpcAccessibleSelectable::SelectAll(bool* aIsMultiSelect
) {
102 NS_ENSURE_ARG_POINTER(aIsMultiSelect
);
103 *aIsMultiSelect
= false;
105 if (!Intl()) return NS_ERROR_FAILURE
;
106 MOZ_ASSERT(Intl()->IsSelect(), "Called on non selectable widget!");
108 *aIsMultiSelect
= Intl()->SelectAll();
113 xpcAccessibleSelectable::UnselectAll() {
114 if (!Intl()) return NS_ERROR_FAILURE
;
115 MOZ_ASSERT(Intl()->IsSelect(), "Called on non selectable widget!");
117 Intl()->UnselectAll();