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 "xpcAccessibleHyperLink.h"
9 #include "LocalAccessible-inl.h"
10 #include "mozilla/StaticPrefs_accessibility.h"
11 #include "nsNetUtil.h"
12 #include "xpcAccessibleDocument.h"
14 using namespace mozilla::a11y
;
17 xpcAccessibleHyperLink::GetStartIndex(int32_t* aStartIndex
) {
18 NS_ENSURE_ARG_POINTER(aStartIndex
);
21 if (!Intl()) return NS_ERROR_FAILURE
;
24 if (Intl()->IsRemote() &&
25 !StaticPrefs::accessibility_cache_enabled_AtStartup()) {
26 return NS_ERROR_NOT_IMPLEMENTED
;
30 *aStartIndex
= static_cast<int32_t>(Intl()->StartOffset());
35 xpcAccessibleHyperLink::GetEndIndex(int32_t* aEndIndex
) {
36 NS_ENSURE_ARG_POINTER(aEndIndex
);
39 if (!Intl()) return NS_ERROR_FAILURE
;
42 if (Intl()->IsRemote() &&
43 !StaticPrefs::accessibility_cache_enabled_AtStartup()) {
44 return NS_ERROR_NOT_IMPLEMENTED
;
48 *aEndIndex
= static_cast<int32_t>(Intl()->EndOffset());
53 xpcAccessibleHyperLink::GetAnchorCount(int32_t* aAnchorCount
) {
54 NS_ENSURE_ARG_POINTER(aAnchorCount
);
57 if (!Intl()) return NS_ERROR_FAILURE
;
59 if (Intl()->IsLocal()) {
60 *aAnchorCount
= Intl()->AsLocal()->AnchorCount();
63 return NS_ERROR_NOT_IMPLEMENTED
;
65 bool isCountValid
= false;
66 uint32_t anchorCount
= Intl()->AsRemote()->AnchorCount(&isCountValid
);
67 if (!isCountValid
) return NS_ERROR_FAILURE
;
69 *aAnchorCount
= anchorCount
;
77 xpcAccessibleHyperLink::GetURI(int32_t aIndex
, nsIURI
** aURI
) {
78 NS_ENSURE_ARG_POINTER(aURI
);
80 if (!Intl()) return NS_ERROR_FAILURE
;
82 if (aIndex
< 0) return NS_ERROR_INVALID_ARG
;
84 if (Intl()->IsLocal()) {
85 if (aIndex
>= static_cast<int32_t>(Intl()->AsLocal()->AnchorCount())) {
86 return NS_ERROR_INVALID_ARG
;
89 RefPtr
<nsIURI
>(Intl()->AsLocal()->AnchorURIAt(aIndex
)).forget(aURI
);
92 return NS_ERROR_NOT_IMPLEMENTED
;
95 bool isURIValid
= false;
96 Intl()->AsRemote()->AnchorURIAt(aIndex
, spec
, &isURIValid
);
97 if (!isURIValid
) return NS_ERROR_FAILURE
;
100 nsresult rv
= NS_NewURI(getter_AddRefs(uri
), spec
);
101 NS_ENSURE_SUCCESS(rv
, rv
);
111 xpcAccessibleHyperLink::GetAnchor(int32_t aIndex
, nsIAccessible
** aAccessible
) {
112 NS_ENSURE_ARG_POINTER(aAccessible
);
113 *aAccessible
= nullptr;
115 if (!Intl()) return NS_ERROR_FAILURE
;
117 if (aIndex
< 0) return NS_ERROR_INVALID_ARG
;
119 if (Intl()->IsLocal()) {
120 if (aIndex
>= static_cast<int32_t>(Intl()->AsLocal()->AnchorCount())) {
121 return NS_ERROR_INVALID_ARG
;
124 NS_IF_ADDREF(*aAccessible
= ToXPC(Intl()->AsLocal()->AnchorAt(aIndex
)));
127 return NS_ERROR_NOT_IMPLEMENTED
;
129 NS_IF_ADDREF(*aAccessible
= ToXPC(Intl()->AsRemote()->AnchorAt(aIndex
)));
137 xpcAccessibleHyperLink::GetValid(bool* aValid
) {
138 NS_ENSURE_ARG_POINTER(aValid
);
141 if (!Intl()) return NS_ERROR_FAILURE
;
143 if (Intl()->IsLocal()) {
144 *aValid
= Intl()->AsLocal()->IsLinkValid();
147 return NS_ERROR_NOT_IMPLEMENTED
;
149 *aValid
= Intl()->AsRemote()->IsLinkValid();