accessible/src/windows/uia/uiaRawElmProvider.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim: set ts=2 et sw=2 tw=80: */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
michael@0 5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #include "uiaRawElmProvider.h"
michael@0 8
michael@0 9 #include "AccessibleWrap.h"
michael@0 10 #include "ARIAMap.h"
michael@0 11 #include "nsIPersistentProperties2.h"
michael@0 12
michael@0 13 using namespace mozilla;
michael@0 14 using namespace mozilla::a11y;
michael@0 15
michael@0 16 ////////////////////////////////////////////////////////////////////////////////
michael@0 17 // uiaRawElmProvider
michael@0 18 ////////////////////////////////////////////////////////////////////////////////
michael@0 19
michael@0 20 IMPL_IUNKNOWN2(uiaRawElmProvider,
michael@0 21 IAccessibleEx,
michael@0 22 IRawElementProviderSimple)
michael@0 23
michael@0 24 ////////////////////////////////////////////////////////////////////////////////
michael@0 25 // IAccessibleEx
michael@0 26
michael@0 27 STDMETHODIMP
michael@0 28 uiaRawElmProvider::GetObjectForChild(long aIdChild,
michael@0 29 __RPC__deref_out_opt IAccessibleEx** aAccEx)
michael@0 30 {
michael@0 31 A11Y_TRYBLOCK_BEGIN
michael@0 32
michael@0 33 if (!aAccEx)
michael@0 34 return E_INVALIDARG;
michael@0 35
michael@0 36 *aAccEx = nullptr;
michael@0 37
michael@0 38 return mAcc->IsDefunct() ? CO_E_OBJNOTCONNECTED : S_OK;
michael@0 39
michael@0 40 A11Y_TRYBLOCK_END
michael@0 41 }
michael@0 42
michael@0 43 STDMETHODIMP
michael@0 44 uiaRawElmProvider::GetIAccessiblePair(__RPC__deref_out_opt IAccessible** aAcc,
michael@0 45 __RPC__out long* aIdChild)
michael@0 46 {
michael@0 47 A11Y_TRYBLOCK_BEGIN
michael@0 48
michael@0 49 if (!aAcc || !aIdChild)
michael@0 50 return E_INVALIDARG;
michael@0 51
michael@0 52 *aAcc = nullptr;
michael@0 53 *aIdChild = 0;
michael@0 54
michael@0 55 if (mAcc->IsDefunct())
michael@0 56 return CO_E_OBJNOTCONNECTED;
michael@0 57
michael@0 58 *aIdChild = CHILDID_SELF;
michael@0 59 *aAcc = mAcc;
michael@0 60 mAcc->AddRef();
michael@0 61
michael@0 62 return S_OK;
michael@0 63
michael@0 64 A11Y_TRYBLOCK_END
michael@0 65 }
michael@0 66
michael@0 67 STDMETHODIMP
michael@0 68 uiaRawElmProvider::GetRuntimeId(__RPC__deref_out_opt SAFEARRAY** aRuntimeIds)
michael@0 69 {
michael@0 70 A11Y_TRYBLOCK_BEGIN
michael@0 71
michael@0 72 if (!aRuntimeIds)
michael@0 73 return E_INVALIDARG;
michael@0 74
michael@0 75 int ids[] = { UiaAppendRuntimeId, static_cast<int>(reinterpret_cast<intptr_t>(mAcc->UniqueID())) };
michael@0 76 *aRuntimeIds = SafeArrayCreateVector(VT_I4, 0, 2);
michael@0 77 if (!*aRuntimeIds)
michael@0 78 return E_OUTOFMEMORY;
michael@0 79
michael@0 80 for (LONG i = 0; i < (LONG)ArrayLength(ids); i++)
michael@0 81 SafeArrayPutElement(*aRuntimeIds, &i, (void*)&(ids[i]));
michael@0 82
michael@0 83 return S_OK;
michael@0 84
michael@0 85 A11Y_TRYBLOCK_END
michael@0 86 }
michael@0 87
michael@0 88 STDMETHODIMP
michael@0 89 uiaRawElmProvider::ConvertReturnedElement(__RPC__in_opt IRawElementProviderSimple* aRawElmProvider,
michael@0 90 __RPC__deref_out_opt IAccessibleEx** aAccEx)
michael@0 91 {
michael@0 92 A11Y_TRYBLOCK_BEGIN
michael@0 93
michael@0 94 if (!aRawElmProvider || !aAccEx)
michael@0 95 return E_INVALIDARG;
michael@0 96
michael@0 97 *aAccEx = nullptr;
michael@0 98
michael@0 99 void* instancePtr = nullptr;
michael@0 100 HRESULT hr = aRawElmProvider->QueryInterface(IID_IAccessibleEx, &instancePtr);
michael@0 101 if (SUCCEEDED(hr))
michael@0 102 *aAccEx = static_cast<IAccessibleEx*>(instancePtr);
michael@0 103
michael@0 104 return hr;
michael@0 105
michael@0 106 A11Y_TRYBLOCK_END
michael@0 107 }
michael@0 108
michael@0 109 ////////////////////////////////////////////////////////////////////////////////
michael@0 110 // IRawElementProviderSimple
michael@0 111
michael@0 112 STDMETHODIMP
michael@0 113 uiaRawElmProvider::get_ProviderOptions(__RPC__out enum ProviderOptions* aOptions)
michael@0 114 {
michael@0 115 A11Y_TRYBLOCK_BEGIN
michael@0 116
michael@0 117 if (!aOptions)
michael@0 118 return E_INVALIDARG;
michael@0 119
michael@0 120 // This method is not used with IAccessibleEx implementations.
michael@0 121 *aOptions = ProviderOptions_ServerSideProvider;
michael@0 122 return S_OK;
michael@0 123
michael@0 124 A11Y_TRYBLOCK_END
michael@0 125 }
michael@0 126
michael@0 127 STDMETHODIMP
michael@0 128 uiaRawElmProvider::GetPatternProvider(PATTERNID aPatternId,
michael@0 129 __RPC__deref_out_opt IUnknown** aPatternProvider)
michael@0 130 {
michael@0 131 A11Y_TRYBLOCK_BEGIN
michael@0 132
michael@0 133 if (!aPatternProvider)
michael@0 134 return E_INVALIDARG;
michael@0 135
michael@0 136 *aPatternProvider = nullptr;
michael@0 137 return S_OK;
michael@0 138
michael@0 139 A11Y_TRYBLOCK_END
michael@0 140 }
michael@0 141
michael@0 142 STDMETHODIMP
michael@0 143 uiaRawElmProvider::GetPropertyValue(PROPERTYID aPropertyId,
michael@0 144 __RPC__out VARIANT* aPropertyValue)
michael@0 145 {
michael@0 146 A11Y_TRYBLOCK_BEGIN
michael@0 147
michael@0 148 if (!aPropertyValue)
michael@0 149 return E_INVALIDARG;
michael@0 150
michael@0 151 if (mAcc->IsDefunct())
michael@0 152 return CO_E_OBJNOTCONNECTED;
michael@0 153
michael@0 154 aPropertyValue->vt = VT_EMPTY;
michael@0 155
michael@0 156 switch (aPropertyId) {
michael@0 157 // Accelerator Key / shortcut.
michael@0 158 case UIA_AcceleratorKeyPropertyId: {
michael@0 159 nsAutoString keyString;
michael@0 160
michael@0 161 mAcc->KeyboardShortcut().ToString(keyString);
michael@0 162
michael@0 163 if (!keyString.IsEmpty()) {
michael@0 164 aPropertyValue->vt = VT_BSTR;
michael@0 165 aPropertyValue->bstrVal = ::SysAllocString(keyString.get());
michael@0 166 return S_OK;
michael@0 167 }
michael@0 168
michael@0 169 break;
michael@0 170 }
michael@0 171
michael@0 172 // Access Key / mneumonic.
michael@0 173 case UIA_AccessKeyPropertyId: {
michael@0 174 nsAutoString keyString;
michael@0 175
michael@0 176 mAcc->AccessKey().ToString(keyString);
michael@0 177
michael@0 178 if (!keyString.IsEmpty()) {
michael@0 179 aPropertyValue->vt = VT_BSTR;
michael@0 180 aPropertyValue->bstrVal = ::SysAllocString(keyString.get());
michael@0 181 return S_OK;
michael@0 182 }
michael@0 183
michael@0 184 break;
michael@0 185 }
michael@0 186
michael@0 187 //ARIA Role / shortcut
michael@0 188 case UIA_AriaRolePropertyId: {
michael@0 189 nsAutoString xmlRoles;
michael@0 190
michael@0 191 nsCOMPtr<nsIPersistentProperties> attributes = mAcc->Attributes();
michael@0 192 attributes->GetStringProperty(NS_LITERAL_CSTRING("xml-roles"), xmlRoles);
michael@0 193
michael@0 194 if(!xmlRoles.IsEmpty()) {
michael@0 195 aPropertyValue->vt = VT_BSTR;
michael@0 196 aPropertyValue->bstrVal = ::SysAllocString(xmlRoles.get());
michael@0 197 return S_OK;
michael@0 198 }
michael@0 199
michael@0 200 break;
michael@0 201 }
michael@0 202
michael@0 203 //ARIA Properties
michael@0 204 case UIA_AriaPropertiesPropertyId: {
michael@0 205 nsAutoString ariaProperties;
michael@0 206
michael@0 207 aria::AttrIterator attribIter(mAcc->GetContent());
michael@0 208 nsAutoString attribName, attribValue;
michael@0 209 while (attribIter.Next(attribName, attribValue)) {
michael@0 210 ariaProperties.Append(attribName);
michael@0 211 ariaProperties.Append('=');
michael@0 212 ariaProperties.Append(attribValue);
michael@0 213 ariaProperties.Append(';');
michael@0 214 }
michael@0 215
michael@0 216 if (!ariaProperties.IsEmpty()) {
michael@0 217 //remove last delimiter:
michael@0 218 ariaProperties.Truncate(ariaProperties.Length()-1);
michael@0 219 aPropertyValue->vt = VT_BSTR;
michael@0 220 aPropertyValue->bstrVal = ::SysAllocString(ariaProperties.get());
michael@0 221 return S_OK;
michael@0 222 }
michael@0 223
michael@0 224 break;
michael@0 225 }
michael@0 226 }
michael@0 227
michael@0 228 return S_OK;
michael@0 229
michael@0 230 A11Y_TRYBLOCK_END
michael@0 231 }
michael@0 232
michael@0 233 STDMETHODIMP
michael@0 234 uiaRawElmProvider::get_HostRawElementProvider(__RPC__deref_out_opt IRawElementProviderSimple** aRawElmProvider)
michael@0 235 {
michael@0 236 A11Y_TRYBLOCK_BEGIN
michael@0 237
michael@0 238 if (!aRawElmProvider)
michael@0 239 return E_INVALIDARG;
michael@0 240
michael@0 241 // This method is not used with IAccessibleEx implementations.
michael@0 242 *aRawElmProvider = nullptr;
michael@0 243 return S_OK;
michael@0 244
michael@0 245 A11Y_TRYBLOCK_END
michael@0 246 }

mercurial