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.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:expandtab:shiftwidth=2:tabstop=2:
3 */
4 /* This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 #include "Accessible2.h"
9 #include "AccessibleHyperlink.h"
10 #include "AccessibleHyperlink_i.c"
12 #include "AccessibleWrap.h"
13 #include "IUnknownImpl.h"
14 #include "nsIURI.h"
16 using namespace mozilla::a11y;
18 // IUnknown
20 STDMETHODIMP
21 ia2AccessibleHyperlink::QueryInterface(REFIID iid, void** ppv)
22 {
23 if (!ppv)
24 return E_INVALIDARG;
26 *ppv = nullptr;
28 if (IID_IAccessibleHyperlink == iid) {
29 if (!static_cast<AccessibleWrap*>(this)->IsLink())
30 return E_NOINTERFACE;
32 *ppv = static_cast<IAccessibleHyperlink*>(this);
33 (reinterpret_cast<IUnknown*>(*ppv))->AddRef();
34 return S_OK;
35 }
37 return ia2AccessibleAction::QueryInterface(iid, ppv);
38 }
40 // IAccessibleHyperlink
42 STDMETHODIMP
43 ia2AccessibleHyperlink::get_anchor(long aIndex, VARIANT* aAnchor)
44 {
45 A11Y_TRYBLOCK_BEGIN
47 if (!aAnchor)
48 return E_INVALIDARG;
50 VariantInit(aAnchor);
52 Accessible* thisObj = static_cast<AccessibleWrap*>(this);
53 if (thisObj->IsDefunct())
54 return CO_E_OBJNOTCONNECTED;
56 if (aIndex < 0 || aIndex >= static_cast<long>(thisObj->AnchorCount()))
57 return E_INVALIDARG;
59 if (!thisObj->IsLink())
60 return S_FALSE;
62 AccessibleWrap* anchor =
63 static_cast<AccessibleWrap*>(thisObj->AnchorAt(aIndex));
64 if (!anchor)
65 return S_FALSE;
67 void* instancePtr = nullptr;
68 HRESULT result = anchor->QueryInterface(IID_IUnknown, &instancePtr);
69 if (FAILED(result))
70 return result;
72 IUnknown* unknownPtr = static_cast<IUnknown*>(instancePtr);
73 aAnchor->ppunkVal = &unknownPtr;
74 aAnchor->vt = VT_UNKNOWN;
75 return S_OK;
77 A11Y_TRYBLOCK_END
78 }
80 STDMETHODIMP
81 ia2AccessibleHyperlink::get_anchorTarget(long aIndex, VARIANT* aAnchorTarget)
82 {
83 A11Y_TRYBLOCK_BEGIN
85 if (!aAnchorTarget)
86 return E_INVALIDARG;
88 VariantInit(aAnchorTarget);
90 Accessible* thisObj = static_cast<AccessibleWrap*>(this);
91 if (thisObj->IsDefunct())
92 return CO_E_OBJNOTCONNECTED;
94 if (aIndex < 0 || aIndex >= static_cast<long>(thisObj->AnchorCount()))
95 return E_INVALIDARG;
97 if (!thisObj->IsLink())
98 return S_FALSE;
100 nsCOMPtr<nsIURI> uri = thisObj->AnchorURIAt(aIndex);
101 if (!uri)
102 return S_FALSE;
104 nsAutoCString prePath;
105 nsresult rv = uri->GetPrePath(prePath);
106 if (NS_FAILED(rv))
107 return GetHRESULT(rv);
109 nsAutoCString path;
110 rv = uri->GetPath(path);
111 if (NS_FAILED(rv))
112 return GetHRESULT(rv);
114 nsAutoString stringURI;
115 AppendUTF8toUTF16(prePath, stringURI);
116 AppendUTF8toUTF16(path, stringURI);
118 aAnchorTarget->vt = VT_BSTR;
119 aAnchorTarget->bstrVal = ::SysAllocStringLen(stringURI.get(),
120 stringURI.Length());
121 return aAnchorTarget->bstrVal ? S_OK : E_OUTOFMEMORY;
123 A11Y_TRYBLOCK_END
124 }
126 STDMETHODIMP
127 ia2AccessibleHyperlink::get_startIndex(long* aIndex)
128 {
129 A11Y_TRYBLOCK_BEGIN
131 if (!aIndex)
132 return E_INVALIDARG;
134 *aIndex = 0;
136 Accessible* thisObj = static_cast<AccessibleWrap*>(this);
137 if (thisObj->IsDefunct())
138 return CO_E_OBJNOTCONNECTED;
140 if (!thisObj->IsLink())
141 return S_FALSE;
143 *aIndex = thisObj->StartOffset();
144 return S_OK;
146 A11Y_TRYBLOCK_END
147 }
149 STDMETHODIMP
150 ia2AccessibleHyperlink::get_endIndex(long* aIndex)
151 {
152 A11Y_TRYBLOCK_BEGIN
154 if (!aIndex)
155 return E_INVALIDARG;
157 *aIndex = 0;
159 Accessible* thisObj = static_cast<AccessibleWrap*>(this);
160 if (thisObj->IsDefunct())
161 return CO_E_OBJNOTCONNECTED;
163 if (!thisObj->IsLink())
164 return S_FALSE;
166 *aIndex = thisObj->EndOffset();
167 return S_OK;
169 A11Y_TRYBLOCK_END
170 }
172 STDMETHODIMP
173 ia2AccessibleHyperlink::get_valid(boolean* aValid)
174 {
175 A11Y_TRYBLOCK_BEGIN
177 if (!aValid)
178 return E_INVALIDARG;
180 *aValid = false;
182 Accessible* thisObj = static_cast<AccessibleWrap*>(this);
183 if (thisObj->IsDefunct())
184 return CO_E_OBJNOTCONNECTED;
186 if (!thisObj->IsLink())
187 return S_FALSE;
189 *aValid = thisObj->IsLinkValid();
190 return S_OK;
192 A11Y_TRYBLOCK_END
193 }