1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/accessible/src/windows/ia2/ia2AccessibleHyperlink.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,194 @@ 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 "Accessible2.h" 1.12 +#include "AccessibleHyperlink.h" 1.13 +#include "AccessibleHyperlink_i.c" 1.14 + 1.15 +#include "AccessibleWrap.h" 1.16 +#include "IUnknownImpl.h" 1.17 +#include "nsIURI.h" 1.18 + 1.19 +using namespace mozilla::a11y; 1.20 + 1.21 +// IUnknown 1.22 + 1.23 +STDMETHODIMP 1.24 +ia2AccessibleHyperlink::QueryInterface(REFIID iid, void** ppv) 1.25 +{ 1.26 + if (!ppv) 1.27 + return E_INVALIDARG; 1.28 + 1.29 + *ppv = nullptr; 1.30 + 1.31 + if (IID_IAccessibleHyperlink == iid) { 1.32 + if (!static_cast<AccessibleWrap*>(this)->IsLink()) 1.33 + return E_NOINTERFACE; 1.34 + 1.35 + *ppv = static_cast<IAccessibleHyperlink*>(this); 1.36 + (reinterpret_cast<IUnknown*>(*ppv))->AddRef(); 1.37 + return S_OK; 1.38 + } 1.39 + 1.40 + return ia2AccessibleAction::QueryInterface(iid, ppv); 1.41 +} 1.42 + 1.43 +// IAccessibleHyperlink 1.44 + 1.45 +STDMETHODIMP 1.46 +ia2AccessibleHyperlink::get_anchor(long aIndex, VARIANT* aAnchor) 1.47 +{ 1.48 + A11Y_TRYBLOCK_BEGIN 1.49 + 1.50 + if (!aAnchor) 1.51 + return E_INVALIDARG; 1.52 + 1.53 + VariantInit(aAnchor); 1.54 + 1.55 + Accessible* thisObj = static_cast<AccessibleWrap*>(this); 1.56 + if (thisObj->IsDefunct()) 1.57 + return CO_E_OBJNOTCONNECTED; 1.58 + 1.59 + if (aIndex < 0 || aIndex >= static_cast<long>(thisObj->AnchorCount())) 1.60 + return E_INVALIDARG; 1.61 + 1.62 + if (!thisObj->IsLink()) 1.63 + return S_FALSE; 1.64 + 1.65 + AccessibleWrap* anchor = 1.66 + static_cast<AccessibleWrap*>(thisObj->AnchorAt(aIndex)); 1.67 + if (!anchor) 1.68 + return S_FALSE; 1.69 + 1.70 + void* instancePtr = nullptr; 1.71 + HRESULT result = anchor->QueryInterface(IID_IUnknown, &instancePtr); 1.72 + if (FAILED(result)) 1.73 + return result; 1.74 + 1.75 + IUnknown* unknownPtr = static_cast<IUnknown*>(instancePtr); 1.76 + aAnchor->ppunkVal = &unknownPtr; 1.77 + aAnchor->vt = VT_UNKNOWN; 1.78 + return S_OK; 1.79 + 1.80 + A11Y_TRYBLOCK_END 1.81 +} 1.82 + 1.83 +STDMETHODIMP 1.84 +ia2AccessibleHyperlink::get_anchorTarget(long aIndex, VARIANT* aAnchorTarget) 1.85 +{ 1.86 + A11Y_TRYBLOCK_BEGIN 1.87 + 1.88 + if (!aAnchorTarget) 1.89 + return E_INVALIDARG; 1.90 + 1.91 + VariantInit(aAnchorTarget); 1.92 + 1.93 + Accessible* thisObj = static_cast<AccessibleWrap*>(this); 1.94 + if (thisObj->IsDefunct()) 1.95 + return CO_E_OBJNOTCONNECTED; 1.96 + 1.97 + if (aIndex < 0 || aIndex >= static_cast<long>(thisObj->AnchorCount())) 1.98 + return E_INVALIDARG; 1.99 + 1.100 + if (!thisObj->IsLink()) 1.101 + return S_FALSE; 1.102 + 1.103 + nsCOMPtr<nsIURI> uri = thisObj->AnchorURIAt(aIndex); 1.104 + if (!uri) 1.105 + return S_FALSE; 1.106 + 1.107 + nsAutoCString prePath; 1.108 + nsresult rv = uri->GetPrePath(prePath); 1.109 + if (NS_FAILED(rv)) 1.110 + return GetHRESULT(rv); 1.111 + 1.112 + nsAutoCString path; 1.113 + rv = uri->GetPath(path); 1.114 + if (NS_FAILED(rv)) 1.115 + return GetHRESULT(rv); 1.116 + 1.117 + nsAutoString stringURI; 1.118 + AppendUTF8toUTF16(prePath, stringURI); 1.119 + AppendUTF8toUTF16(path, stringURI); 1.120 + 1.121 + aAnchorTarget->vt = VT_BSTR; 1.122 + aAnchorTarget->bstrVal = ::SysAllocStringLen(stringURI.get(), 1.123 + stringURI.Length()); 1.124 + return aAnchorTarget->bstrVal ? S_OK : E_OUTOFMEMORY; 1.125 + 1.126 + A11Y_TRYBLOCK_END 1.127 +} 1.128 + 1.129 +STDMETHODIMP 1.130 +ia2AccessibleHyperlink::get_startIndex(long* aIndex) 1.131 +{ 1.132 + A11Y_TRYBLOCK_BEGIN 1.133 + 1.134 + if (!aIndex) 1.135 + return E_INVALIDARG; 1.136 + 1.137 + *aIndex = 0; 1.138 + 1.139 + Accessible* thisObj = static_cast<AccessibleWrap*>(this); 1.140 + if (thisObj->IsDefunct()) 1.141 + return CO_E_OBJNOTCONNECTED; 1.142 + 1.143 + if (!thisObj->IsLink()) 1.144 + return S_FALSE; 1.145 + 1.146 + *aIndex = thisObj->StartOffset(); 1.147 + return S_OK; 1.148 + 1.149 + A11Y_TRYBLOCK_END 1.150 +} 1.151 + 1.152 +STDMETHODIMP 1.153 +ia2AccessibleHyperlink::get_endIndex(long* aIndex) 1.154 +{ 1.155 + A11Y_TRYBLOCK_BEGIN 1.156 + 1.157 + if (!aIndex) 1.158 + return E_INVALIDARG; 1.159 + 1.160 + *aIndex = 0; 1.161 + 1.162 + Accessible* thisObj = static_cast<AccessibleWrap*>(this); 1.163 + if (thisObj->IsDefunct()) 1.164 + return CO_E_OBJNOTCONNECTED; 1.165 + 1.166 + if (!thisObj->IsLink()) 1.167 + return S_FALSE; 1.168 + 1.169 + *aIndex = thisObj->EndOffset(); 1.170 + return S_OK; 1.171 + 1.172 + A11Y_TRYBLOCK_END 1.173 +} 1.174 + 1.175 +STDMETHODIMP 1.176 +ia2AccessibleHyperlink::get_valid(boolean* aValid) 1.177 +{ 1.178 + A11Y_TRYBLOCK_BEGIN 1.179 + 1.180 + if (!aValid) 1.181 + return E_INVALIDARG; 1.182 + 1.183 + *aValid = false; 1.184 + 1.185 + Accessible* thisObj = static_cast<AccessibleWrap*>(this); 1.186 + if (thisObj->IsDefunct()) 1.187 + return CO_E_OBJNOTCONNECTED; 1.188 + 1.189 + if (!thisObj->IsLink()) 1.190 + return S_FALSE; 1.191 + 1.192 + *aValid = thisObj->IsLinkValid(); 1.193 + return S_OK; 1.194 + 1.195 + A11Y_TRYBLOCK_END 1.196 +} 1.197 +