Bug 1468398: Enable keep-alive connections in wdclient for wdspec tests. r=whimboo
[gecko.git] / accessible / xpcom / xpcAccessibleHyperLink.cpp
blob30337b7fc54ed5610a1ed8cf44d36883e81183c8
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/. */
7 #include "Accessible-inl.h"
8 #include "xpcAccessibleDocument.h"
9 #include "nsNetUtil.h"
11 using namespace mozilla::a11y;
13 NS_IMETHODIMP
14 xpcAccessibleHyperLink::GetStartIndex(int32_t* aStartIndex)
16 NS_ENSURE_ARG_POINTER(aStartIndex);
17 *aStartIndex = 0;
19 if (Intl().IsNull())
20 return NS_ERROR_FAILURE;
22 if (Intl().IsAccessible()) {
23 *aStartIndex = Intl().AsAccessible()->StartOffset();
24 } else {
25 #if defined(XP_WIN)
26 return NS_ERROR_NOT_IMPLEMENTED;
27 #else
28 bool isIndexValid = false;
29 uint32_t startOffset = Intl().AsProxy()->StartOffset(&isIndexValid);
30 if (!isIndexValid)
31 return NS_ERROR_FAILURE;
33 *aStartIndex = startOffset;
34 #endif
37 return NS_OK;
40 NS_IMETHODIMP
41 xpcAccessibleHyperLink::GetEndIndex(int32_t* aEndIndex)
43 NS_ENSURE_ARG_POINTER(aEndIndex);
44 *aEndIndex = 0;
46 if (Intl().IsNull())
47 return NS_ERROR_FAILURE;
49 if (Intl().IsAccessible()) {
50 *aEndIndex = Intl().AsAccessible()->EndOffset();
51 } else {
52 #if defined(XP_WIN)
53 return NS_ERROR_NOT_IMPLEMENTED;
54 #else
55 bool isIndexValid = false;
56 uint32_t endOffset = Intl().AsProxy()->EndOffset(&isIndexValid);
57 if (!isIndexValid)
58 return NS_ERROR_FAILURE;
60 *aEndIndex = endOffset;
61 #endif
64 return NS_OK;
67 NS_IMETHODIMP
68 xpcAccessibleHyperLink::GetAnchorCount(int32_t* aAnchorCount)
70 NS_ENSURE_ARG_POINTER(aAnchorCount);
71 *aAnchorCount = 0;
73 if (Intl().IsNull())
74 return NS_ERROR_FAILURE;
76 if (Intl().IsAccessible()) {
77 *aAnchorCount = Intl().AsAccessible()->AnchorCount();
78 } else {
79 #if defined(XP_WIN)
80 return NS_ERROR_NOT_IMPLEMENTED;
81 #else
82 bool isCountValid = false;
83 uint32_t anchorCount = Intl().AsProxy()->AnchorCount(&isCountValid);
84 if (!isCountValid)
85 return NS_ERROR_FAILURE;
87 *aAnchorCount = anchorCount;
88 #endif
91 return NS_OK;
94 NS_IMETHODIMP
95 xpcAccessibleHyperLink::GetURI(int32_t aIndex, nsIURI** aURI)
97 NS_ENSURE_ARG_POINTER(aURI);
99 if (Intl().IsNull())
100 return NS_ERROR_FAILURE;
102 if (aIndex < 0)
103 return NS_ERROR_INVALID_ARG;
105 if (Intl().IsAccessible()) {
106 if (aIndex >= static_cast<int32_t>(Intl().AsAccessible()->AnchorCount()))
107 return NS_ERROR_INVALID_ARG;
109 RefPtr<nsIURI>(Intl().AsAccessible()->AnchorURIAt(aIndex)).forget(aURI);
110 } else {
111 #if defined(XP_WIN)
112 return NS_ERROR_NOT_IMPLEMENTED;
113 #else
114 nsCString spec;
115 bool isURIValid = false;
116 Intl().AsProxy()->AnchorURIAt(aIndex, spec, &isURIValid);
117 if (!isURIValid)
118 return NS_ERROR_FAILURE;
120 nsCOMPtr<nsIURI> uri;
121 nsresult rv = NS_NewURI(getter_AddRefs(uri), spec);
122 NS_ENSURE_SUCCESS(rv, rv);
124 uri.forget(aURI);
125 #endif
128 return NS_OK;
132 NS_IMETHODIMP
133 xpcAccessibleHyperLink::GetAnchor(int32_t aIndex, nsIAccessible** aAccessible)
135 NS_ENSURE_ARG_POINTER(aAccessible);
136 *aAccessible = nullptr;
138 if (Intl().IsNull())
139 return NS_ERROR_FAILURE;
141 if (aIndex < 0)
142 return NS_ERROR_INVALID_ARG;
144 if (Intl().IsAccessible()) {
145 if (aIndex >= static_cast<int32_t>(Intl().AsAccessible()->AnchorCount()))
146 return NS_ERROR_INVALID_ARG;
148 NS_IF_ADDREF(*aAccessible = ToXPC(Intl().AsAccessible()->AnchorAt(aIndex)));
149 } else {
150 #if defined(XP_WIN)
151 return NS_ERROR_NOT_IMPLEMENTED;
152 #else
153 NS_IF_ADDREF(*aAccessible = ToXPC(Intl().AsProxy()->AnchorAt(aIndex)));
154 #endif
157 return NS_OK;
160 NS_IMETHODIMP
161 xpcAccessibleHyperLink::GetValid(bool* aValid)
163 NS_ENSURE_ARG_POINTER(aValid);
164 *aValid = false;
166 if (Intl().IsNull())
167 return NS_ERROR_FAILURE;
169 if (Intl().IsAccessible()) {
170 *aValid = Intl().AsAccessible()->IsLinkValid();
171 } else {
172 #if defined(XP_WIN)
173 return NS_ERROR_NOT_IMPLEMENTED;
174 #else
175 *aValid = Intl().AsProxy()->IsLinkValid();
176 #endif
179 return NS_OK;