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