/src/mozilla-central/accessible/xpcom/xpcAccessibleSelectable.cpp
Line | Count | Source (jump to first uncovered line) |
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 "Accessible-inl.h" |
8 | | #include "xpcAccessibleDocument.h" |
9 | | |
10 | | #include "nsIMutableArray.h" |
11 | | |
12 | | using namespace mozilla::a11y; |
13 | | |
14 | | NS_IMETHODIMP |
15 | | xpcAccessibleSelectable::GetSelectedItems(nsIArray** aSelectedItems) |
16 | 0 | { |
17 | 0 | NS_ENSURE_ARG_POINTER(aSelectedItems); |
18 | 0 | *aSelectedItems = nullptr; |
19 | 0 |
|
20 | 0 | if (!Intl()) |
21 | 0 | return NS_ERROR_FAILURE; |
22 | 0 | MOZ_ASSERT(Intl()->IsSelect(), "Called on non selectable widget!"); |
23 | 0 |
|
24 | 0 | AutoTArray<Accessible*, 10> items; |
25 | 0 | Intl()->SelectedItems(&items); |
26 | 0 |
|
27 | 0 | uint32_t itemCount = items.Length(); |
28 | 0 | if (itemCount == 0) |
29 | 0 | return NS_OK; |
30 | 0 | |
31 | 0 | nsresult rv = NS_OK; |
32 | 0 | nsCOMPtr<nsIMutableArray> xpcItems = |
33 | 0 | do_CreateInstance(NS_ARRAY_CONTRACTID, &rv); |
34 | 0 | NS_ENSURE_SUCCESS(rv, rv); |
35 | 0 |
|
36 | 0 | for (uint32_t idx = 0; idx < itemCount; idx++) |
37 | 0 | xpcItems->AppendElement(static_cast<nsIAccessible*>(ToXPC(items[idx]))); |
38 | 0 |
|
39 | 0 | NS_ADDREF(*aSelectedItems = xpcItems); |
40 | 0 | return NS_OK; |
41 | 0 | } |
42 | | |
43 | | NS_IMETHODIMP |
44 | | xpcAccessibleSelectable::GetSelectedItemCount(uint32_t* aSelectionCount) |
45 | 0 | { |
46 | 0 | NS_ENSURE_ARG_POINTER(aSelectionCount); |
47 | 0 | *aSelectionCount = 0; |
48 | 0 |
|
49 | 0 | if (!Intl()) |
50 | 0 | return NS_ERROR_FAILURE; |
51 | 0 | MOZ_ASSERT(Intl()->IsSelect(), "Called on non selectable widget!"); |
52 | 0 |
|
53 | 0 | *aSelectionCount = Intl()->SelectedItemCount(); |
54 | 0 | return NS_OK; |
55 | 0 | } |
56 | | |
57 | | NS_IMETHODIMP |
58 | | xpcAccessibleSelectable::GetSelectedItemAt(uint32_t aIndex, |
59 | | nsIAccessible** aSelected) |
60 | 0 | { |
61 | 0 | NS_ENSURE_ARG_POINTER(aSelected); |
62 | 0 | *aSelected = nullptr; |
63 | 0 |
|
64 | 0 | if (!Intl()) |
65 | 0 | return NS_ERROR_FAILURE; |
66 | 0 | MOZ_ASSERT(Intl()->IsSelect(), "Called on non selectable widget!"); |
67 | 0 |
|
68 | 0 | *aSelected = ToXPC(Intl()->GetSelectedItem(aIndex)); |
69 | 0 | if (*aSelected) { |
70 | 0 | NS_ADDREF(*aSelected); |
71 | 0 | return NS_OK; |
72 | 0 | } |
73 | 0 |
|
74 | 0 | return NS_ERROR_INVALID_ARG; |
75 | 0 | } |
76 | | |
77 | | NS_IMETHODIMP |
78 | | xpcAccessibleSelectable::IsItemSelected(uint32_t aIndex, bool* aIsSelected) |
79 | 0 | { |
80 | 0 | NS_ENSURE_ARG_POINTER(aIsSelected); |
81 | 0 | *aIsSelected = false; |
82 | 0 |
|
83 | 0 | if (!Intl()) |
84 | 0 | return NS_ERROR_FAILURE; |
85 | 0 | MOZ_ASSERT(Intl()->IsSelect(), "Called on non selectable widget!"); |
86 | 0 |
|
87 | 0 | *aIsSelected = Intl()->IsItemSelected(aIndex); |
88 | 0 | return NS_OK; |
89 | 0 | } |
90 | | |
91 | | NS_IMETHODIMP |
92 | | xpcAccessibleSelectable::AddItemToSelection(uint32_t aIndex) |
93 | 0 | { |
94 | 0 | if (!Intl()) |
95 | 0 | return NS_ERROR_FAILURE; |
96 | 0 | MOZ_ASSERT(Intl()->IsSelect(), "Called on non selectable widget!"); |
97 | 0 |
|
98 | 0 | return Intl()->AddItemToSelection(aIndex) ? NS_OK : NS_ERROR_INVALID_ARG; |
99 | 0 | } |
100 | | |
101 | | NS_IMETHODIMP |
102 | | xpcAccessibleSelectable::RemoveItemFromSelection(uint32_t aIndex) |
103 | 0 | { |
104 | 0 | if (!Intl()) |
105 | 0 | return NS_ERROR_FAILURE; |
106 | 0 | MOZ_ASSERT(Intl()->IsSelect(), "Called on non selectable widget!"); |
107 | 0 |
|
108 | 0 | return Intl()->RemoveItemFromSelection(aIndex) ? NS_OK : NS_ERROR_INVALID_ARG; |
109 | 0 | } |
110 | | |
111 | | NS_IMETHODIMP |
112 | | xpcAccessibleSelectable::SelectAll(bool* aIsMultiSelect) |
113 | 0 | { |
114 | 0 | NS_ENSURE_ARG_POINTER(aIsMultiSelect); |
115 | 0 | *aIsMultiSelect = false; |
116 | 0 |
|
117 | 0 | if (!Intl()) |
118 | 0 | return NS_ERROR_FAILURE; |
119 | 0 | MOZ_ASSERT(Intl()->IsSelect(), "Called on non selectable widget!"); |
120 | 0 |
|
121 | 0 | *aIsMultiSelect = Intl()->SelectAll(); |
122 | 0 | return NS_OK; |
123 | 0 | } |
124 | | |
125 | | NS_IMETHODIMP |
126 | | xpcAccessibleSelectable::UnselectAll() |
127 | 0 | { |
128 | 0 | if (!Intl()) |
129 | 0 | return NS_ERROR_FAILURE; |
130 | 0 | MOZ_ASSERT(Intl()->IsSelect(), "Called on non selectable widget!"); |
131 | 0 |
|
132 | 0 | Intl()->UnselectAll(); |
133 | 0 | return NS_OK; |
134 | 0 | } |