1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/accessible/src/windows/ia2/ia2AccessibleAction.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,195 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim:expandtab:shiftwidth=2:tabstop=2: 1.6 + */ 1.7 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.8 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.9 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.10 + 1.11 +#include "ia2AccessibleAction.h" 1.12 + 1.13 +#include "AccessibleAction_i.c" 1.14 + 1.15 +#include "AccessibleWrap.h" 1.16 +#include "IUnknownImpl.h" 1.17 + 1.18 +using namespace mozilla::a11y; 1.19 + 1.20 +// IUnknown 1.21 + 1.22 +STDMETHODIMP 1.23 +ia2AccessibleAction::QueryInterface(REFIID iid, void** ppv) 1.24 +{ 1.25 + if (!ppv) 1.26 + return E_INVALIDARG; 1.27 + 1.28 + *ppv = nullptr; 1.29 + 1.30 + if (IID_IAccessibleAction == iid) { 1.31 + *ppv = static_cast<IAccessibleAction*>(this); 1.32 + (reinterpret_cast<IUnknown*>(*ppv))->AddRef(); 1.33 + return S_OK; 1.34 + } 1.35 + 1.36 + return E_NOINTERFACE; 1.37 +} 1.38 + 1.39 +// IAccessibleAction 1.40 + 1.41 +STDMETHODIMP 1.42 +ia2AccessibleAction::nActions(long* aActionCount) 1.43 +{ 1.44 + A11Y_TRYBLOCK_BEGIN 1.45 + 1.46 + if (!aActionCount) 1.47 + return E_INVALIDARG; 1.48 + 1.49 + *aActionCount = 0; 1.50 + 1.51 + AccessibleWrap* acc = static_cast<AccessibleWrap*>(this); 1.52 + if (acc->IsDefunct()) 1.53 + return CO_E_OBJNOTCONNECTED; 1.54 + 1.55 + *aActionCount = acc->ActionCount(); 1.56 + return S_OK; 1.57 + 1.58 + A11Y_TRYBLOCK_END 1.59 +} 1.60 + 1.61 +STDMETHODIMP 1.62 +ia2AccessibleAction::doAction(long aActionIndex) 1.63 +{ 1.64 + A11Y_TRYBLOCK_BEGIN 1.65 + 1.66 + AccessibleWrap* acc = static_cast<AccessibleWrap*>(this); 1.67 + if (acc->IsDefunct()) 1.68 + return CO_E_OBJNOTCONNECTED; 1.69 + 1.70 + uint8_t index = static_cast<uint8_t>(aActionIndex); 1.71 + nsresult rv = acc->DoAction(index); 1.72 + return GetHRESULT(rv); 1.73 + 1.74 + A11Y_TRYBLOCK_END 1.75 +} 1.76 + 1.77 +STDMETHODIMP 1.78 +ia2AccessibleAction::get_description(long aActionIndex, BSTR *aDescription) 1.79 +{ 1.80 + A11Y_TRYBLOCK_BEGIN 1.81 + 1.82 + if (!aDescription) 1.83 + return E_INVALIDARG; 1.84 + 1.85 + *aDescription = nullptr; 1.86 + 1.87 + AccessibleWrap* acc = static_cast<AccessibleWrap*>(this); 1.88 + if (acc->IsDefunct()) 1.89 + return CO_E_OBJNOTCONNECTED; 1.90 + 1.91 + nsAutoString description; 1.92 + uint8_t index = static_cast<uint8_t>(aActionIndex); 1.93 + nsresult rv = acc->GetActionDescription(index, description); 1.94 + if (NS_FAILED(rv)) 1.95 + return GetHRESULT(rv); 1.96 + 1.97 + if (description.IsEmpty()) 1.98 + return S_FALSE; 1.99 + 1.100 + *aDescription = ::SysAllocStringLen(description.get(), 1.101 + description.Length()); 1.102 + return *aDescription ? S_OK : E_OUTOFMEMORY; 1.103 + 1.104 + A11Y_TRYBLOCK_END 1.105 +} 1.106 + 1.107 +STDMETHODIMP 1.108 +ia2AccessibleAction::get_keyBinding(long aActionIndex, long aNumMaxBinding, 1.109 + BSTR **aKeyBinding, 1.110 + long *aNumBinding) 1.111 +{ 1.112 + A11Y_TRYBLOCK_BEGIN 1.113 + 1.114 + if (!aKeyBinding) 1.115 + return E_INVALIDARG; 1.116 + *aKeyBinding = nullptr; 1.117 + 1.118 + if (!aNumBinding) 1.119 + return E_INVALIDARG; 1.120 + *aNumBinding = 0; 1.121 + 1.122 + if (aActionIndex != 0 || aNumMaxBinding < 1) 1.123 + return E_INVALIDARG; 1.124 + 1.125 + AccessibleWrap* acc = static_cast<AccessibleWrap*>(this); 1.126 + if (acc->IsDefunct()) 1.127 + return CO_E_OBJNOTCONNECTED; 1.128 + 1.129 + // Expose keyboard shortcut if it's not exposed via MSAA keyboard shortcut. 1.130 + KeyBinding keyBinding = acc->AccessKey(); 1.131 + if (keyBinding.IsEmpty()) 1.132 + return S_FALSE; 1.133 + 1.134 + keyBinding = acc->KeyboardShortcut(); 1.135 + if (keyBinding.IsEmpty()) 1.136 + return S_FALSE; 1.137 + 1.138 + nsAutoString keyStr; 1.139 + keyBinding.ToString(keyStr); 1.140 + 1.141 + *aKeyBinding = static_cast<BSTR*>(::CoTaskMemAlloc(sizeof(BSTR*))); 1.142 + if (!*aKeyBinding) 1.143 + return E_OUTOFMEMORY; 1.144 + 1.145 + *(aKeyBinding[0]) = ::SysAllocStringLen(keyStr.get(), keyStr.Length()); 1.146 + if (!*(aKeyBinding[0])) { 1.147 + ::CoTaskMemFree(*aKeyBinding); 1.148 + return E_OUTOFMEMORY; 1.149 + } 1.150 + 1.151 + *aNumBinding = 1; 1.152 + return S_OK; 1.153 + 1.154 + A11Y_TRYBLOCK_END 1.155 +} 1.156 + 1.157 +STDMETHODIMP 1.158 +ia2AccessibleAction::get_name(long aActionIndex, BSTR *aName) 1.159 +{ 1.160 + A11Y_TRYBLOCK_BEGIN 1.161 + 1.162 + if (!aName) 1.163 + return E_INVALIDARG; 1.164 + 1.165 + *aName = nullptr; 1.166 + 1.167 + AccessibleWrap* acc = static_cast<AccessibleWrap*>(this); 1.168 + if (acc->IsDefunct()) 1.169 + return CO_E_OBJNOTCONNECTED; 1.170 + 1.171 + nsAutoString name; 1.172 + uint8_t index = static_cast<uint8_t>(aActionIndex); 1.173 + nsresult rv = acc->GetActionName(index, name); 1.174 + if (NS_FAILED(rv)) 1.175 + return GetHRESULT(rv); 1.176 + 1.177 + if (name.IsEmpty()) 1.178 + return S_FALSE; 1.179 + 1.180 + *aName = ::SysAllocStringLen(name.get(), name.Length()); 1.181 + return *aName ? S_OK : E_OUTOFMEMORY; 1.182 + 1.183 + A11Y_TRYBLOCK_END 1.184 +} 1.185 + 1.186 +STDMETHODIMP 1.187 +ia2AccessibleAction::get_localizedName(long aActionIndex, BSTR *aLocalizedName) 1.188 +{ 1.189 + A11Y_TRYBLOCK_BEGIN 1.190 + 1.191 + if (!aLocalizedName) 1.192 + return E_INVALIDARG; 1.193 + 1.194 + *aLocalizedName = nullptr; 1.195 + return E_NOTIMPL; 1.196 + 1.197 + A11Y_TRYBLOCK_END 1.198 +}