Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 "uiaRawElmProvider.h"
9 #include "AccessibleWrap.h"
10 #include "ARIAMap.h"
11 #include "nsIPersistentProperties2.h"
13 using namespace mozilla;
14 using namespace mozilla::a11y;
16 ////////////////////////////////////////////////////////////////////////////////
17 // uiaRawElmProvider
18 ////////////////////////////////////////////////////////////////////////////////
20 IMPL_IUNKNOWN2(uiaRawElmProvider,
21 IAccessibleEx,
22 IRawElementProviderSimple)
24 ////////////////////////////////////////////////////////////////////////////////
25 // IAccessibleEx
27 STDMETHODIMP
28 uiaRawElmProvider::GetObjectForChild(long aIdChild,
29 __RPC__deref_out_opt IAccessibleEx** aAccEx)
30 {
31 A11Y_TRYBLOCK_BEGIN
33 if (!aAccEx)
34 return E_INVALIDARG;
36 *aAccEx = nullptr;
38 return mAcc->IsDefunct() ? CO_E_OBJNOTCONNECTED : S_OK;
40 A11Y_TRYBLOCK_END
41 }
43 STDMETHODIMP
44 uiaRawElmProvider::GetIAccessiblePair(__RPC__deref_out_opt IAccessible** aAcc,
45 __RPC__out long* aIdChild)
46 {
47 A11Y_TRYBLOCK_BEGIN
49 if (!aAcc || !aIdChild)
50 return E_INVALIDARG;
52 *aAcc = nullptr;
53 *aIdChild = 0;
55 if (mAcc->IsDefunct())
56 return CO_E_OBJNOTCONNECTED;
58 *aIdChild = CHILDID_SELF;
59 *aAcc = mAcc;
60 mAcc->AddRef();
62 return S_OK;
64 A11Y_TRYBLOCK_END
65 }
67 STDMETHODIMP
68 uiaRawElmProvider::GetRuntimeId(__RPC__deref_out_opt SAFEARRAY** aRuntimeIds)
69 {
70 A11Y_TRYBLOCK_BEGIN
72 if (!aRuntimeIds)
73 return E_INVALIDARG;
75 int ids[] = { UiaAppendRuntimeId, static_cast<int>(reinterpret_cast<intptr_t>(mAcc->UniqueID())) };
76 *aRuntimeIds = SafeArrayCreateVector(VT_I4, 0, 2);
77 if (!*aRuntimeIds)
78 return E_OUTOFMEMORY;
80 for (LONG i = 0; i < (LONG)ArrayLength(ids); i++)
81 SafeArrayPutElement(*aRuntimeIds, &i, (void*)&(ids[i]));
83 return S_OK;
85 A11Y_TRYBLOCK_END
86 }
88 STDMETHODIMP
89 uiaRawElmProvider::ConvertReturnedElement(__RPC__in_opt IRawElementProviderSimple* aRawElmProvider,
90 __RPC__deref_out_opt IAccessibleEx** aAccEx)
91 {
92 A11Y_TRYBLOCK_BEGIN
94 if (!aRawElmProvider || !aAccEx)
95 return E_INVALIDARG;
97 *aAccEx = nullptr;
99 void* instancePtr = nullptr;
100 HRESULT hr = aRawElmProvider->QueryInterface(IID_IAccessibleEx, &instancePtr);
101 if (SUCCEEDED(hr))
102 *aAccEx = static_cast<IAccessibleEx*>(instancePtr);
104 return hr;
106 A11Y_TRYBLOCK_END
107 }
109 ////////////////////////////////////////////////////////////////////////////////
110 // IRawElementProviderSimple
112 STDMETHODIMP
113 uiaRawElmProvider::get_ProviderOptions(__RPC__out enum ProviderOptions* aOptions)
114 {
115 A11Y_TRYBLOCK_BEGIN
117 if (!aOptions)
118 return E_INVALIDARG;
120 // This method is not used with IAccessibleEx implementations.
121 *aOptions = ProviderOptions_ServerSideProvider;
122 return S_OK;
124 A11Y_TRYBLOCK_END
125 }
127 STDMETHODIMP
128 uiaRawElmProvider::GetPatternProvider(PATTERNID aPatternId,
129 __RPC__deref_out_opt IUnknown** aPatternProvider)
130 {
131 A11Y_TRYBLOCK_BEGIN
133 if (!aPatternProvider)
134 return E_INVALIDARG;
136 *aPatternProvider = nullptr;
137 return S_OK;
139 A11Y_TRYBLOCK_END
140 }
142 STDMETHODIMP
143 uiaRawElmProvider::GetPropertyValue(PROPERTYID aPropertyId,
144 __RPC__out VARIANT* aPropertyValue)
145 {
146 A11Y_TRYBLOCK_BEGIN
148 if (!aPropertyValue)
149 return E_INVALIDARG;
151 if (mAcc->IsDefunct())
152 return CO_E_OBJNOTCONNECTED;
154 aPropertyValue->vt = VT_EMPTY;
156 switch (aPropertyId) {
157 // Accelerator Key / shortcut.
158 case UIA_AcceleratorKeyPropertyId: {
159 nsAutoString keyString;
161 mAcc->KeyboardShortcut().ToString(keyString);
163 if (!keyString.IsEmpty()) {
164 aPropertyValue->vt = VT_BSTR;
165 aPropertyValue->bstrVal = ::SysAllocString(keyString.get());
166 return S_OK;
167 }
169 break;
170 }
172 // Access Key / mneumonic.
173 case UIA_AccessKeyPropertyId: {
174 nsAutoString keyString;
176 mAcc->AccessKey().ToString(keyString);
178 if (!keyString.IsEmpty()) {
179 aPropertyValue->vt = VT_BSTR;
180 aPropertyValue->bstrVal = ::SysAllocString(keyString.get());
181 return S_OK;
182 }
184 break;
185 }
187 //ARIA Role / shortcut
188 case UIA_AriaRolePropertyId: {
189 nsAutoString xmlRoles;
191 nsCOMPtr<nsIPersistentProperties> attributes = mAcc->Attributes();
192 attributes->GetStringProperty(NS_LITERAL_CSTRING("xml-roles"), xmlRoles);
194 if(!xmlRoles.IsEmpty()) {
195 aPropertyValue->vt = VT_BSTR;
196 aPropertyValue->bstrVal = ::SysAllocString(xmlRoles.get());
197 return S_OK;
198 }
200 break;
201 }
203 //ARIA Properties
204 case UIA_AriaPropertiesPropertyId: {
205 nsAutoString ariaProperties;
207 aria::AttrIterator attribIter(mAcc->GetContent());
208 nsAutoString attribName, attribValue;
209 while (attribIter.Next(attribName, attribValue)) {
210 ariaProperties.Append(attribName);
211 ariaProperties.Append('=');
212 ariaProperties.Append(attribValue);
213 ariaProperties.Append(';');
214 }
216 if (!ariaProperties.IsEmpty()) {
217 //remove last delimiter:
218 ariaProperties.Truncate(ariaProperties.Length()-1);
219 aPropertyValue->vt = VT_BSTR;
220 aPropertyValue->bstrVal = ::SysAllocString(ariaProperties.get());
221 return S_OK;
222 }
224 break;
225 }
226 }
228 return S_OK;
230 A11Y_TRYBLOCK_END
231 }
233 STDMETHODIMP
234 uiaRawElmProvider::get_HostRawElementProvider(__RPC__deref_out_opt IRawElementProviderSimple** aRawElmProvider)
235 {
236 A11Y_TRYBLOCK_BEGIN
238 if (!aRawElmProvider)
239 return E_INVALIDARG;
241 // This method is not used with IAccessibleEx implementations.
242 *aRawElmProvider = nullptr;
243 return S_OK;
245 A11Y_TRYBLOCK_END
246 }