|
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 "xpcAccessibleTableCell.h" |
|
8 |
|
9 #include "Accessible.h" |
|
10 #include "TableAccessible.h" |
|
11 #include "TableCellAccessible.h" |
|
12 |
|
13 #include "nsIAccessibleTable.h" |
|
14 |
|
15 #include "nsComponentManagerUtils.h" |
|
16 #include "nsIMutableArray.h" |
|
17 |
|
18 using namespace mozilla; |
|
19 using namespace mozilla::a11y; |
|
20 |
|
21 nsresult |
|
22 xpcAccessibleTableCell::GetTable(nsIAccessibleTable** aTable) |
|
23 { |
|
24 NS_ENSURE_ARG_POINTER(aTable); |
|
25 *aTable = nullptr; |
|
26 |
|
27 if (!mTableCell) |
|
28 return NS_ERROR_FAILURE; |
|
29 |
|
30 TableAccessible* table = mTableCell->Table(); |
|
31 if (!table) |
|
32 return NS_ERROR_FAILURE; |
|
33 |
|
34 nsCOMPtr<nsIAccessibleTable> xpcTable = |
|
35 do_QueryInterface(static_cast<nsIAccessible*>(table->AsAccessible())); |
|
36 xpcTable.forget(aTable); |
|
37 |
|
38 return NS_OK; |
|
39 } |
|
40 |
|
41 nsresult |
|
42 xpcAccessibleTableCell::GetColumnIndex(int32_t* aColIdx) |
|
43 { |
|
44 NS_ENSURE_ARG_POINTER(aColIdx); |
|
45 *aColIdx = -1; |
|
46 |
|
47 if (!mTableCell) |
|
48 return NS_ERROR_FAILURE; |
|
49 |
|
50 *aColIdx = mTableCell->ColIdx(); |
|
51 return NS_OK; |
|
52 } |
|
53 |
|
54 nsresult |
|
55 xpcAccessibleTableCell::GetRowIndex(int32_t* aRowIdx) |
|
56 { |
|
57 NS_ENSURE_ARG_POINTER(aRowIdx); |
|
58 *aRowIdx = -1; |
|
59 |
|
60 if (!mTableCell) |
|
61 return NS_ERROR_FAILURE; |
|
62 |
|
63 *aRowIdx = mTableCell->RowIdx(); |
|
64 |
|
65 return NS_OK; |
|
66 } |
|
67 |
|
68 nsresult |
|
69 xpcAccessibleTableCell::GetColumnExtent(int32_t* aExtent) |
|
70 { |
|
71 NS_ENSURE_ARG_POINTER(aExtent); |
|
72 *aExtent = -1; |
|
73 |
|
74 if (!mTableCell) |
|
75 return NS_ERROR_FAILURE; |
|
76 |
|
77 *aExtent = mTableCell->ColExtent(); |
|
78 |
|
79 return NS_OK; |
|
80 } |
|
81 |
|
82 nsresult |
|
83 xpcAccessibleTableCell::GetRowExtent(int32_t* aExtent) |
|
84 { |
|
85 NS_ENSURE_ARG_POINTER(aExtent); |
|
86 *aExtent = -1; |
|
87 |
|
88 if (!mTableCell) |
|
89 return NS_ERROR_FAILURE; |
|
90 |
|
91 *aExtent = mTableCell->RowExtent(); |
|
92 |
|
93 return NS_OK; |
|
94 } |
|
95 |
|
96 nsresult |
|
97 xpcAccessibleTableCell::GetColumnHeaderCells(nsIArray** aHeaderCells) |
|
98 { |
|
99 NS_ENSURE_ARG_POINTER(aHeaderCells); |
|
100 *aHeaderCells = nullptr; |
|
101 |
|
102 if (!mTableCell) |
|
103 return NS_ERROR_FAILURE; |
|
104 |
|
105 nsAutoTArray<Accessible*, 10> headerCells; |
|
106 mTableCell->ColHeaderCells(&headerCells); |
|
107 |
|
108 nsCOMPtr<nsIMutableArray> cells = do_CreateInstance(NS_ARRAY_CONTRACTID); |
|
109 NS_ENSURE_TRUE(cells, NS_ERROR_FAILURE); |
|
110 |
|
111 for (uint32_t idx = 0; idx < headerCells.Length(); idx++) { |
|
112 cells-> |
|
113 AppendElement(static_cast<nsIAccessible*>(headerCells.ElementAt(idx)), |
|
114 false); |
|
115 } |
|
116 |
|
117 NS_ADDREF(*aHeaderCells = cells); |
|
118 return NS_OK; |
|
119 } |
|
120 |
|
121 nsresult |
|
122 xpcAccessibleTableCell::GetRowHeaderCells(nsIArray** aHeaderCells) |
|
123 { |
|
124 NS_ENSURE_ARG_POINTER(aHeaderCells); |
|
125 *aHeaderCells = nullptr; |
|
126 |
|
127 if (!mTableCell) |
|
128 return NS_ERROR_FAILURE; |
|
129 |
|
130 nsAutoTArray<Accessible*, 10> headerCells; |
|
131 mTableCell->RowHeaderCells(&headerCells); |
|
132 |
|
133 nsCOMPtr<nsIMutableArray> cells = do_CreateInstance(NS_ARRAY_CONTRACTID); |
|
134 NS_ENSURE_TRUE(cells, NS_ERROR_FAILURE); |
|
135 |
|
136 for (uint32_t idx = 0; idx < headerCells.Length(); idx++) { |
|
137 cells-> |
|
138 AppendElement(static_cast<nsIAccessible*>(headerCells.ElementAt(idx)), |
|
139 false); |
|
140 } |
|
141 |
|
142 NS_ADDREF(*aHeaderCells = cells); |
|
143 return NS_OK; |
|
144 } |
|
145 |
|
146 nsresult |
|
147 xpcAccessibleTableCell::IsSelected(bool* aSelected) |
|
148 { |
|
149 NS_ENSURE_ARG_POINTER(aSelected); |
|
150 *aSelected = false; |
|
151 |
|
152 if (!mTableCell) |
|
153 return NS_ERROR_FAILURE; |
|
154 |
|
155 *aSelected = mTableCell->Selected(); |
|
156 |
|
157 return NS_OK; |
|
158 } |