|
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/. */ |
|
7 |
|
8 #include "Accessible2.h" |
|
9 #include "AccessibleHyperlink.h" |
|
10 #include "AccessibleHyperlink_i.c" |
|
11 |
|
12 #include "AccessibleWrap.h" |
|
13 #include "IUnknownImpl.h" |
|
14 #include "nsIURI.h" |
|
15 |
|
16 using namespace mozilla::a11y; |
|
17 |
|
18 // IUnknown |
|
19 |
|
20 STDMETHODIMP |
|
21 ia2AccessibleHyperlink::QueryInterface(REFIID iid, void** ppv) |
|
22 { |
|
23 if (!ppv) |
|
24 return E_INVALIDARG; |
|
25 |
|
26 *ppv = nullptr; |
|
27 |
|
28 if (IID_IAccessibleHyperlink == iid) { |
|
29 if (!static_cast<AccessibleWrap*>(this)->IsLink()) |
|
30 return E_NOINTERFACE; |
|
31 |
|
32 *ppv = static_cast<IAccessibleHyperlink*>(this); |
|
33 (reinterpret_cast<IUnknown*>(*ppv))->AddRef(); |
|
34 return S_OK; |
|
35 } |
|
36 |
|
37 return ia2AccessibleAction::QueryInterface(iid, ppv); |
|
38 } |
|
39 |
|
40 // IAccessibleHyperlink |
|
41 |
|
42 STDMETHODIMP |
|
43 ia2AccessibleHyperlink::get_anchor(long aIndex, VARIANT* aAnchor) |
|
44 { |
|
45 A11Y_TRYBLOCK_BEGIN |
|
46 |
|
47 if (!aAnchor) |
|
48 return E_INVALIDARG; |
|
49 |
|
50 VariantInit(aAnchor); |
|
51 |
|
52 Accessible* thisObj = static_cast<AccessibleWrap*>(this); |
|
53 if (thisObj->IsDefunct()) |
|
54 return CO_E_OBJNOTCONNECTED; |
|
55 |
|
56 if (aIndex < 0 || aIndex >= static_cast<long>(thisObj->AnchorCount())) |
|
57 return E_INVALIDARG; |
|
58 |
|
59 if (!thisObj->IsLink()) |
|
60 return S_FALSE; |
|
61 |
|
62 AccessibleWrap* anchor = |
|
63 static_cast<AccessibleWrap*>(thisObj->AnchorAt(aIndex)); |
|
64 if (!anchor) |
|
65 return S_FALSE; |
|
66 |
|
67 void* instancePtr = nullptr; |
|
68 HRESULT result = anchor->QueryInterface(IID_IUnknown, &instancePtr); |
|
69 if (FAILED(result)) |
|
70 return result; |
|
71 |
|
72 IUnknown* unknownPtr = static_cast<IUnknown*>(instancePtr); |
|
73 aAnchor->ppunkVal = &unknownPtr; |
|
74 aAnchor->vt = VT_UNKNOWN; |
|
75 return S_OK; |
|
76 |
|
77 A11Y_TRYBLOCK_END |
|
78 } |
|
79 |
|
80 STDMETHODIMP |
|
81 ia2AccessibleHyperlink::get_anchorTarget(long aIndex, VARIANT* aAnchorTarget) |
|
82 { |
|
83 A11Y_TRYBLOCK_BEGIN |
|
84 |
|
85 if (!aAnchorTarget) |
|
86 return E_INVALIDARG; |
|
87 |
|
88 VariantInit(aAnchorTarget); |
|
89 |
|
90 Accessible* thisObj = static_cast<AccessibleWrap*>(this); |
|
91 if (thisObj->IsDefunct()) |
|
92 return CO_E_OBJNOTCONNECTED; |
|
93 |
|
94 if (aIndex < 0 || aIndex >= static_cast<long>(thisObj->AnchorCount())) |
|
95 return E_INVALIDARG; |
|
96 |
|
97 if (!thisObj->IsLink()) |
|
98 return S_FALSE; |
|
99 |
|
100 nsCOMPtr<nsIURI> uri = thisObj->AnchorURIAt(aIndex); |
|
101 if (!uri) |
|
102 return S_FALSE; |
|
103 |
|
104 nsAutoCString prePath; |
|
105 nsresult rv = uri->GetPrePath(prePath); |
|
106 if (NS_FAILED(rv)) |
|
107 return GetHRESULT(rv); |
|
108 |
|
109 nsAutoCString path; |
|
110 rv = uri->GetPath(path); |
|
111 if (NS_FAILED(rv)) |
|
112 return GetHRESULT(rv); |
|
113 |
|
114 nsAutoString stringURI; |
|
115 AppendUTF8toUTF16(prePath, stringURI); |
|
116 AppendUTF8toUTF16(path, stringURI); |
|
117 |
|
118 aAnchorTarget->vt = VT_BSTR; |
|
119 aAnchorTarget->bstrVal = ::SysAllocStringLen(stringURI.get(), |
|
120 stringURI.Length()); |
|
121 return aAnchorTarget->bstrVal ? S_OK : E_OUTOFMEMORY; |
|
122 |
|
123 A11Y_TRYBLOCK_END |
|
124 } |
|
125 |
|
126 STDMETHODIMP |
|
127 ia2AccessibleHyperlink::get_startIndex(long* aIndex) |
|
128 { |
|
129 A11Y_TRYBLOCK_BEGIN |
|
130 |
|
131 if (!aIndex) |
|
132 return E_INVALIDARG; |
|
133 |
|
134 *aIndex = 0; |
|
135 |
|
136 Accessible* thisObj = static_cast<AccessibleWrap*>(this); |
|
137 if (thisObj->IsDefunct()) |
|
138 return CO_E_OBJNOTCONNECTED; |
|
139 |
|
140 if (!thisObj->IsLink()) |
|
141 return S_FALSE; |
|
142 |
|
143 *aIndex = thisObj->StartOffset(); |
|
144 return S_OK; |
|
145 |
|
146 A11Y_TRYBLOCK_END |
|
147 } |
|
148 |
|
149 STDMETHODIMP |
|
150 ia2AccessibleHyperlink::get_endIndex(long* aIndex) |
|
151 { |
|
152 A11Y_TRYBLOCK_BEGIN |
|
153 |
|
154 if (!aIndex) |
|
155 return E_INVALIDARG; |
|
156 |
|
157 *aIndex = 0; |
|
158 |
|
159 Accessible* thisObj = static_cast<AccessibleWrap*>(this); |
|
160 if (thisObj->IsDefunct()) |
|
161 return CO_E_OBJNOTCONNECTED; |
|
162 |
|
163 if (!thisObj->IsLink()) |
|
164 return S_FALSE; |
|
165 |
|
166 *aIndex = thisObj->EndOffset(); |
|
167 return S_OK; |
|
168 |
|
169 A11Y_TRYBLOCK_END |
|
170 } |
|
171 |
|
172 STDMETHODIMP |
|
173 ia2AccessibleHyperlink::get_valid(boolean* aValid) |
|
174 { |
|
175 A11Y_TRYBLOCK_BEGIN |
|
176 |
|
177 if (!aValid) |
|
178 return E_INVALIDARG; |
|
179 |
|
180 *aValid = false; |
|
181 |
|
182 Accessible* thisObj = static_cast<AccessibleWrap*>(this); |
|
183 if (thisObj->IsDefunct()) |
|
184 return CO_E_OBJNOTCONNECTED; |
|
185 |
|
186 if (!thisObj->IsLink()) |
|
187 return S_FALSE; |
|
188 |
|
189 *aValid = thisObj->IsLinkValid(); |
|
190 return S_OK; |
|
191 |
|
192 A11Y_TRYBLOCK_END |
|
193 } |
|
194 |