1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/accessible/src/windows/uia/uiaRawElmProvider.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,246 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim: set ts=2 et sw=2 tw=80: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.8 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#include "uiaRawElmProvider.h" 1.11 + 1.12 +#include "AccessibleWrap.h" 1.13 +#include "ARIAMap.h" 1.14 +#include "nsIPersistentProperties2.h" 1.15 + 1.16 +using namespace mozilla; 1.17 +using namespace mozilla::a11y; 1.18 + 1.19 +//////////////////////////////////////////////////////////////////////////////// 1.20 +// uiaRawElmProvider 1.21 +//////////////////////////////////////////////////////////////////////////////// 1.22 + 1.23 +IMPL_IUNKNOWN2(uiaRawElmProvider, 1.24 + IAccessibleEx, 1.25 + IRawElementProviderSimple) 1.26 + 1.27 +//////////////////////////////////////////////////////////////////////////////// 1.28 +// IAccessibleEx 1.29 + 1.30 +STDMETHODIMP 1.31 +uiaRawElmProvider::GetObjectForChild(long aIdChild, 1.32 + __RPC__deref_out_opt IAccessibleEx** aAccEx) 1.33 +{ 1.34 + A11Y_TRYBLOCK_BEGIN 1.35 + 1.36 + if (!aAccEx) 1.37 + return E_INVALIDARG; 1.38 + 1.39 + *aAccEx = nullptr; 1.40 + 1.41 + return mAcc->IsDefunct() ? CO_E_OBJNOTCONNECTED : S_OK; 1.42 + 1.43 + A11Y_TRYBLOCK_END 1.44 +} 1.45 + 1.46 +STDMETHODIMP 1.47 +uiaRawElmProvider::GetIAccessiblePair(__RPC__deref_out_opt IAccessible** aAcc, 1.48 + __RPC__out long* aIdChild) 1.49 +{ 1.50 + A11Y_TRYBLOCK_BEGIN 1.51 + 1.52 + if (!aAcc || !aIdChild) 1.53 + return E_INVALIDARG; 1.54 + 1.55 + *aAcc = nullptr; 1.56 + *aIdChild = 0; 1.57 + 1.58 + if (mAcc->IsDefunct()) 1.59 + return CO_E_OBJNOTCONNECTED; 1.60 + 1.61 + *aIdChild = CHILDID_SELF; 1.62 + *aAcc = mAcc; 1.63 + mAcc->AddRef(); 1.64 + 1.65 + return S_OK; 1.66 + 1.67 + A11Y_TRYBLOCK_END 1.68 +} 1.69 + 1.70 +STDMETHODIMP 1.71 +uiaRawElmProvider::GetRuntimeId(__RPC__deref_out_opt SAFEARRAY** aRuntimeIds) 1.72 +{ 1.73 + A11Y_TRYBLOCK_BEGIN 1.74 + 1.75 + if (!aRuntimeIds) 1.76 + return E_INVALIDARG; 1.77 + 1.78 + int ids[] = { UiaAppendRuntimeId, static_cast<int>(reinterpret_cast<intptr_t>(mAcc->UniqueID())) }; 1.79 + *aRuntimeIds = SafeArrayCreateVector(VT_I4, 0, 2); 1.80 + if (!*aRuntimeIds) 1.81 + return E_OUTOFMEMORY; 1.82 + 1.83 + for (LONG i = 0; i < (LONG)ArrayLength(ids); i++) 1.84 + SafeArrayPutElement(*aRuntimeIds, &i, (void*)&(ids[i])); 1.85 + 1.86 + return S_OK; 1.87 + 1.88 + A11Y_TRYBLOCK_END 1.89 +} 1.90 + 1.91 +STDMETHODIMP 1.92 +uiaRawElmProvider::ConvertReturnedElement(__RPC__in_opt IRawElementProviderSimple* aRawElmProvider, 1.93 + __RPC__deref_out_opt IAccessibleEx** aAccEx) 1.94 +{ 1.95 + A11Y_TRYBLOCK_BEGIN 1.96 + 1.97 + if (!aRawElmProvider || !aAccEx) 1.98 + return E_INVALIDARG; 1.99 + 1.100 + *aAccEx = nullptr; 1.101 + 1.102 + void* instancePtr = nullptr; 1.103 + HRESULT hr = aRawElmProvider->QueryInterface(IID_IAccessibleEx, &instancePtr); 1.104 + if (SUCCEEDED(hr)) 1.105 + *aAccEx = static_cast<IAccessibleEx*>(instancePtr); 1.106 + 1.107 + return hr; 1.108 + 1.109 + A11Y_TRYBLOCK_END 1.110 +} 1.111 + 1.112 +//////////////////////////////////////////////////////////////////////////////// 1.113 +// IRawElementProviderSimple 1.114 + 1.115 +STDMETHODIMP 1.116 +uiaRawElmProvider::get_ProviderOptions(__RPC__out enum ProviderOptions* aOptions) 1.117 +{ 1.118 + A11Y_TRYBLOCK_BEGIN 1.119 + 1.120 + if (!aOptions) 1.121 + return E_INVALIDARG; 1.122 + 1.123 + // This method is not used with IAccessibleEx implementations. 1.124 + *aOptions = ProviderOptions_ServerSideProvider; 1.125 + return S_OK; 1.126 + 1.127 + A11Y_TRYBLOCK_END 1.128 +} 1.129 + 1.130 +STDMETHODIMP 1.131 +uiaRawElmProvider::GetPatternProvider(PATTERNID aPatternId, 1.132 + __RPC__deref_out_opt IUnknown** aPatternProvider) 1.133 +{ 1.134 + A11Y_TRYBLOCK_BEGIN 1.135 + 1.136 + if (!aPatternProvider) 1.137 + return E_INVALIDARG; 1.138 + 1.139 + *aPatternProvider = nullptr; 1.140 + return S_OK; 1.141 + 1.142 + A11Y_TRYBLOCK_END 1.143 +} 1.144 + 1.145 +STDMETHODIMP 1.146 +uiaRawElmProvider::GetPropertyValue(PROPERTYID aPropertyId, 1.147 + __RPC__out VARIANT* aPropertyValue) 1.148 +{ 1.149 + A11Y_TRYBLOCK_BEGIN 1.150 + 1.151 + if (!aPropertyValue) 1.152 + return E_INVALIDARG; 1.153 + 1.154 + if (mAcc->IsDefunct()) 1.155 + return CO_E_OBJNOTCONNECTED; 1.156 + 1.157 + aPropertyValue->vt = VT_EMPTY; 1.158 + 1.159 + switch (aPropertyId) { 1.160 + // Accelerator Key / shortcut. 1.161 + case UIA_AcceleratorKeyPropertyId: { 1.162 + nsAutoString keyString; 1.163 + 1.164 + mAcc->KeyboardShortcut().ToString(keyString); 1.165 + 1.166 + if (!keyString.IsEmpty()) { 1.167 + aPropertyValue->vt = VT_BSTR; 1.168 + aPropertyValue->bstrVal = ::SysAllocString(keyString.get()); 1.169 + return S_OK; 1.170 + } 1.171 + 1.172 + break; 1.173 + } 1.174 + 1.175 + // Access Key / mneumonic. 1.176 + case UIA_AccessKeyPropertyId: { 1.177 + nsAutoString keyString; 1.178 + 1.179 + mAcc->AccessKey().ToString(keyString); 1.180 + 1.181 + if (!keyString.IsEmpty()) { 1.182 + aPropertyValue->vt = VT_BSTR; 1.183 + aPropertyValue->bstrVal = ::SysAllocString(keyString.get()); 1.184 + return S_OK; 1.185 + } 1.186 + 1.187 + break; 1.188 + } 1.189 + 1.190 + //ARIA Role / shortcut 1.191 + case UIA_AriaRolePropertyId: { 1.192 + nsAutoString xmlRoles; 1.193 + 1.194 + nsCOMPtr<nsIPersistentProperties> attributes = mAcc->Attributes(); 1.195 + attributes->GetStringProperty(NS_LITERAL_CSTRING("xml-roles"), xmlRoles); 1.196 + 1.197 + if(!xmlRoles.IsEmpty()) { 1.198 + aPropertyValue->vt = VT_BSTR; 1.199 + aPropertyValue->bstrVal = ::SysAllocString(xmlRoles.get()); 1.200 + return S_OK; 1.201 + } 1.202 + 1.203 + break; 1.204 + } 1.205 + 1.206 + //ARIA Properties 1.207 + case UIA_AriaPropertiesPropertyId: { 1.208 + nsAutoString ariaProperties; 1.209 + 1.210 + aria::AttrIterator attribIter(mAcc->GetContent()); 1.211 + nsAutoString attribName, attribValue; 1.212 + while (attribIter.Next(attribName, attribValue)) { 1.213 + ariaProperties.Append(attribName); 1.214 + ariaProperties.Append('='); 1.215 + ariaProperties.Append(attribValue); 1.216 + ariaProperties.Append(';'); 1.217 + } 1.218 + 1.219 + if (!ariaProperties.IsEmpty()) { 1.220 + //remove last delimiter: 1.221 + ariaProperties.Truncate(ariaProperties.Length()-1); 1.222 + aPropertyValue->vt = VT_BSTR; 1.223 + aPropertyValue->bstrVal = ::SysAllocString(ariaProperties.get()); 1.224 + return S_OK; 1.225 + } 1.226 + 1.227 + break; 1.228 + } 1.229 + } 1.230 + 1.231 + return S_OK; 1.232 + 1.233 + A11Y_TRYBLOCK_END 1.234 +} 1.235 + 1.236 +STDMETHODIMP 1.237 +uiaRawElmProvider::get_HostRawElementProvider(__RPC__deref_out_opt IRawElementProviderSimple** aRawElmProvider) 1.238 +{ 1.239 + A11Y_TRYBLOCK_BEGIN 1.240 + 1.241 + if (!aRawElmProvider) 1.242 + return E_INVALIDARG; 1.243 + 1.244 + // This method is not used with IAccessibleEx implementations. 1.245 + *aRawElmProvider = nullptr; 1.246 + return S_OK; 1.247 + 1.248 + A11Y_TRYBLOCK_END 1.249 +}