/src/mozilla-central/accessible/xpcom/xpcAccessibleHyperLink.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
5 | | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #include "Accessible-inl.h" |
8 | | #include "xpcAccessibleDocument.h" |
9 | | #include "nsNetUtil.h" |
10 | | |
11 | | using namespace mozilla::a11y; |
12 | | |
13 | | NS_IMETHODIMP |
14 | | xpcAccessibleHyperLink::GetStartIndex(int32_t* aStartIndex) |
15 | 0 | { |
16 | 0 | NS_ENSURE_ARG_POINTER(aStartIndex); |
17 | 0 | *aStartIndex = 0; |
18 | 0 |
|
19 | 0 | if (Intl().IsNull()) |
20 | 0 | return NS_ERROR_FAILURE; |
21 | 0 | |
22 | 0 | if (Intl().IsAccessible()) { |
23 | 0 | *aStartIndex = Intl().AsAccessible()->StartOffset(); |
24 | 0 | } else { |
25 | | #if defined(XP_WIN) |
26 | | return NS_ERROR_NOT_IMPLEMENTED; |
27 | | #else |
28 | | bool isIndexValid = false; |
29 | 0 | uint32_t startOffset = Intl().AsProxy()->StartOffset(&isIndexValid); |
30 | 0 | if (!isIndexValid) |
31 | 0 | return NS_ERROR_FAILURE; |
32 | 0 | |
33 | 0 | *aStartIndex = startOffset; |
34 | 0 | #endif |
35 | 0 | } |
36 | 0 |
|
37 | 0 | return NS_OK; |
38 | 0 | } |
39 | | |
40 | | NS_IMETHODIMP |
41 | | xpcAccessibleHyperLink::GetEndIndex(int32_t* aEndIndex) |
42 | 0 | { |
43 | 0 | NS_ENSURE_ARG_POINTER(aEndIndex); |
44 | 0 | *aEndIndex = 0; |
45 | 0 |
|
46 | 0 | if (Intl().IsNull()) |
47 | 0 | return NS_ERROR_FAILURE; |
48 | 0 | |
49 | 0 | if (Intl().IsAccessible()) { |
50 | 0 | *aEndIndex = Intl().AsAccessible()->EndOffset(); |
51 | 0 | } else { |
52 | | #if defined(XP_WIN) |
53 | | return NS_ERROR_NOT_IMPLEMENTED; |
54 | | #else |
55 | | bool isIndexValid = false; |
56 | 0 | uint32_t endOffset = Intl().AsProxy()->EndOffset(&isIndexValid); |
57 | 0 | if (!isIndexValid) |
58 | 0 | return NS_ERROR_FAILURE; |
59 | 0 | |
60 | 0 | *aEndIndex = endOffset; |
61 | 0 | #endif |
62 | 0 | } |
63 | 0 |
|
64 | 0 | return NS_OK; |
65 | 0 | } |
66 | | |
67 | | NS_IMETHODIMP |
68 | | xpcAccessibleHyperLink::GetAnchorCount(int32_t* aAnchorCount) |
69 | 0 | { |
70 | 0 | NS_ENSURE_ARG_POINTER(aAnchorCount); |
71 | 0 | *aAnchorCount = 0; |
72 | 0 |
|
73 | 0 | if (Intl().IsNull()) |
74 | 0 | return NS_ERROR_FAILURE; |
75 | 0 | |
76 | 0 | if (Intl().IsAccessible()) { |
77 | 0 | *aAnchorCount = Intl().AsAccessible()->AnchorCount(); |
78 | 0 | } else { |
79 | | #if defined(XP_WIN) |
80 | | return NS_ERROR_NOT_IMPLEMENTED; |
81 | | #else |
82 | | bool isCountValid = false; |
83 | 0 | uint32_t anchorCount = Intl().AsProxy()->AnchorCount(&isCountValid); |
84 | 0 | if (!isCountValid) |
85 | 0 | return NS_ERROR_FAILURE; |
86 | 0 | |
87 | 0 | *aAnchorCount = anchorCount; |
88 | 0 | #endif |
89 | 0 | } |
90 | 0 |
|
91 | 0 | return NS_OK; |
92 | 0 | } |
93 | | |
94 | | NS_IMETHODIMP |
95 | | xpcAccessibleHyperLink::GetURI(int32_t aIndex, nsIURI** aURI) |
96 | 0 | { |
97 | 0 | NS_ENSURE_ARG_POINTER(aURI); |
98 | 0 |
|
99 | 0 | if (Intl().IsNull()) |
100 | 0 | return NS_ERROR_FAILURE; |
101 | 0 | |
102 | 0 | if (aIndex < 0) |
103 | 0 | return NS_ERROR_INVALID_ARG; |
104 | 0 | |
105 | 0 | if (Intl().IsAccessible()) { |
106 | 0 | if (aIndex >= static_cast<int32_t>(Intl().AsAccessible()->AnchorCount())) |
107 | 0 | return NS_ERROR_INVALID_ARG; |
108 | 0 | |
109 | 0 | RefPtr<nsIURI>(Intl().AsAccessible()->AnchorURIAt(aIndex)).forget(aURI); |
110 | 0 | } else { |
111 | | #if defined(XP_WIN) |
112 | | return NS_ERROR_NOT_IMPLEMENTED; |
113 | | #else |
114 | | nsCString spec; |
115 | 0 | bool isURIValid = false; |
116 | 0 | Intl().AsProxy()->AnchorURIAt(aIndex, spec, &isURIValid); |
117 | 0 | if (!isURIValid) |
118 | 0 | return NS_ERROR_FAILURE; |
119 | 0 | |
120 | 0 | nsCOMPtr<nsIURI> uri; |
121 | 0 | nsresult rv = NS_NewURI(getter_AddRefs(uri), spec); |
122 | 0 | NS_ENSURE_SUCCESS(rv, rv); |
123 | 0 |
|
124 | 0 | uri.forget(aURI); |
125 | 0 | #endif |
126 | 0 | } |
127 | 0 |
|
128 | 0 | return NS_OK; |
129 | 0 | } |
130 | | |
131 | | |
132 | | NS_IMETHODIMP |
133 | | xpcAccessibleHyperLink::GetAnchor(int32_t aIndex, nsIAccessible** aAccessible) |
134 | 0 | { |
135 | 0 | NS_ENSURE_ARG_POINTER(aAccessible); |
136 | 0 | *aAccessible = nullptr; |
137 | 0 |
|
138 | 0 | if (Intl().IsNull()) |
139 | 0 | return NS_ERROR_FAILURE; |
140 | 0 | |
141 | 0 | if (aIndex < 0) |
142 | 0 | return NS_ERROR_INVALID_ARG; |
143 | 0 | |
144 | 0 | if (Intl().IsAccessible()) { |
145 | 0 | if (aIndex >= static_cast<int32_t>(Intl().AsAccessible()->AnchorCount())) |
146 | 0 | return NS_ERROR_INVALID_ARG; |
147 | 0 | |
148 | 0 | NS_IF_ADDREF(*aAccessible = ToXPC(Intl().AsAccessible()->AnchorAt(aIndex))); |
149 | 0 | } else { |
150 | | #if defined(XP_WIN) |
151 | | return NS_ERROR_NOT_IMPLEMENTED; |
152 | | #else |
153 | 0 | NS_IF_ADDREF(*aAccessible = ToXPC(Intl().AsProxy()->AnchorAt(aIndex))); |
154 | 0 | #endif |
155 | 0 | } |
156 | 0 |
|
157 | 0 | return NS_OK; |
158 | 0 | } |
159 | | |
160 | | NS_IMETHODIMP |
161 | | xpcAccessibleHyperLink::GetValid(bool* aValid) |
162 | 0 | { |
163 | 0 | NS_ENSURE_ARG_POINTER(aValid); |
164 | 0 | *aValid = false; |
165 | 0 |
|
166 | 0 | if (Intl().IsNull()) |
167 | 0 | return NS_ERROR_FAILURE; |
168 | 0 | |
169 | 0 | if (Intl().IsAccessible()) { |
170 | 0 | *aValid = Intl().AsAccessible()->IsLinkValid(); |
171 | 0 | } else { |
172 | | #if defined(XP_WIN) |
173 | | return NS_ERROR_NOT_IMPLEMENTED; |
174 | | #else |
175 | | *aValid = Intl().AsProxy()->IsLinkValid(); |
176 | 0 | #endif |
177 | 0 | } |
178 | 0 |
|
179 | 0 | return NS_OK; |
180 | 0 | } |