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