|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* vim:expandtab:shiftwidth=2:tabstop=2: |
|
3 */ |
|
4 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
5 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
7 |
|
8 #include "ia2AccessibleAction.h" |
|
9 |
|
10 #include "AccessibleAction_i.c" |
|
11 |
|
12 #include "AccessibleWrap.h" |
|
13 #include "IUnknownImpl.h" |
|
14 |
|
15 using namespace mozilla::a11y; |
|
16 |
|
17 // IUnknown |
|
18 |
|
19 STDMETHODIMP |
|
20 ia2AccessibleAction::QueryInterface(REFIID iid, void** ppv) |
|
21 { |
|
22 if (!ppv) |
|
23 return E_INVALIDARG; |
|
24 |
|
25 *ppv = nullptr; |
|
26 |
|
27 if (IID_IAccessibleAction == iid) { |
|
28 *ppv = static_cast<IAccessibleAction*>(this); |
|
29 (reinterpret_cast<IUnknown*>(*ppv))->AddRef(); |
|
30 return S_OK; |
|
31 } |
|
32 |
|
33 return E_NOINTERFACE; |
|
34 } |
|
35 |
|
36 // IAccessibleAction |
|
37 |
|
38 STDMETHODIMP |
|
39 ia2AccessibleAction::nActions(long* aActionCount) |
|
40 { |
|
41 A11Y_TRYBLOCK_BEGIN |
|
42 |
|
43 if (!aActionCount) |
|
44 return E_INVALIDARG; |
|
45 |
|
46 *aActionCount = 0; |
|
47 |
|
48 AccessibleWrap* acc = static_cast<AccessibleWrap*>(this); |
|
49 if (acc->IsDefunct()) |
|
50 return CO_E_OBJNOTCONNECTED; |
|
51 |
|
52 *aActionCount = acc->ActionCount(); |
|
53 return S_OK; |
|
54 |
|
55 A11Y_TRYBLOCK_END |
|
56 } |
|
57 |
|
58 STDMETHODIMP |
|
59 ia2AccessibleAction::doAction(long aActionIndex) |
|
60 { |
|
61 A11Y_TRYBLOCK_BEGIN |
|
62 |
|
63 AccessibleWrap* acc = static_cast<AccessibleWrap*>(this); |
|
64 if (acc->IsDefunct()) |
|
65 return CO_E_OBJNOTCONNECTED; |
|
66 |
|
67 uint8_t index = static_cast<uint8_t>(aActionIndex); |
|
68 nsresult rv = acc->DoAction(index); |
|
69 return GetHRESULT(rv); |
|
70 |
|
71 A11Y_TRYBLOCK_END |
|
72 } |
|
73 |
|
74 STDMETHODIMP |
|
75 ia2AccessibleAction::get_description(long aActionIndex, BSTR *aDescription) |
|
76 { |
|
77 A11Y_TRYBLOCK_BEGIN |
|
78 |
|
79 if (!aDescription) |
|
80 return E_INVALIDARG; |
|
81 |
|
82 *aDescription = nullptr; |
|
83 |
|
84 AccessibleWrap* acc = static_cast<AccessibleWrap*>(this); |
|
85 if (acc->IsDefunct()) |
|
86 return CO_E_OBJNOTCONNECTED; |
|
87 |
|
88 nsAutoString description; |
|
89 uint8_t index = static_cast<uint8_t>(aActionIndex); |
|
90 nsresult rv = acc->GetActionDescription(index, description); |
|
91 if (NS_FAILED(rv)) |
|
92 return GetHRESULT(rv); |
|
93 |
|
94 if (description.IsEmpty()) |
|
95 return S_FALSE; |
|
96 |
|
97 *aDescription = ::SysAllocStringLen(description.get(), |
|
98 description.Length()); |
|
99 return *aDescription ? S_OK : E_OUTOFMEMORY; |
|
100 |
|
101 A11Y_TRYBLOCK_END |
|
102 } |
|
103 |
|
104 STDMETHODIMP |
|
105 ia2AccessibleAction::get_keyBinding(long aActionIndex, long aNumMaxBinding, |
|
106 BSTR **aKeyBinding, |
|
107 long *aNumBinding) |
|
108 { |
|
109 A11Y_TRYBLOCK_BEGIN |
|
110 |
|
111 if (!aKeyBinding) |
|
112 return E_INVALIDARG; |
|
113 *aKeyBinding = nullptr; |
|
114 |
|
115 if (!aNumBinding) |
|
116 return E_INVALIDARG; |
|
117 *aNumBinding = 0; |
|
118 |
|
119 if (aActionIndex != 0 || aNumMaxBinding < 1) |
|
120 return E_INVALIDARG; |
|
121 |
|
122 AccessibleWrap* acc = static_cast<AccessibleWrap*>(this); |
|
123 if (acc->IsDefunct()) |
|
124 return CO_E_OBJNOTCONNECTED; |
|
125 |
|
126 // Expose keyboard shortcut if it's not exposed via MSAA keyboard shortcut. |
|
127 KeyBinding keyBinding = acc->AccessKey(); |
|
128 if (keyBinding.IsEmpty()) |
|
129 return S_FALSE; |
|
130 |
|
131 keyBinding = acc->KeyboardShortcut(); |
|
132 if (keyBinding.IsEmpty()) |
|
133 return S_FALSE; |
|
134 |
|
135 nsAutoString keyStr; |
|
136 keyBinding.ToString(keyStr); |
|
137 |
|
138 *aKeyBinding = static_cast<BSTR*>(::CoTaskMemAlloc(sizeof(BSTR*))); |
|
139 if (!*aKeyBinding) |
|
140 return E_OUTOFMEMORY; |
|
141 |
|
142 *(aKeyBinding[0]) = ::SysAllocStringLen(keyStr.get(), keyStr.Length()); |
|
143 if (!*(aKeyBinding[0])) { |
|
144 ::CoTaskMemFree(*aKeyBinding); |
|
145 return E_OUTOFMEMORY; |
|
146 } |
|
147 |
|
148 *aNumBinding = 1; |
|
149 return S_OK; |
|
150 |
|
151 A11Y_TRYBLOCK_END |
|
152 } |
|
153 |
|
154 STDMETHODIMP |
|
155 ia2AccessibleAction::get_name(long aActionIndex, BSTR *aName) |
|
156 { |
|
157 A11Y_TRYBLOCK_BEGIN |
|
158 |
|
159 if (!aName) |
|
160 return E_INVALIDARG; |
|
161 |
|
162 *aName = nullptr; |
|
163 |
|
164 AccessibleWrap* acc = static_cast<AccessibleWrap*>(this); |
|
165 if (acc->IsDefunct()) |
|
166 return CO_E_OBJNOTCONNECTED; |
|
167 |
|
168 nsAutoString name; |
|
169 uint8_t index = static_cast<uint8_t>(aActionIndex); |
|
170 nsresult rv = acc->GetActionName(index, name); |
|
171 if (NS_FAILED(rv)) |
|
172 return GetHRESULT(rv); |
|
173 |
|
174 if (name.IsEmpty()) |
|
175 return S_FALSE; |
|
176 |
|
177 *aName = ::SysAllocStringLen(name.get(), name.Length()); |
|
178 return *aName ? S_OK : E_OUTOFMEMORY; |
|
179 |
|
180 A11Y_TRYBLOCK_END |
|
181 } |
|
182 |
|
183 STDMETHODIMP |
|
184 ia2AccessibleAction::get_localizedName(long aActionIndex, BSTR *aLocalizedName) |
|
185 { |
|
186 A11Y_TRYBLOCK_BEGIN |
|
187 |
|
188 if (!aLocalizedName) |
|
189 return E_INVALIDARG; |
|
190 |
|
191 *aLocalizedName = nullptr; |
|
192 return E_NOTIMPL; |
|
193 |
|
194 A11Y_TRYBLOCK_END |
|
195 } |