Bug 1787269 [wpt PR 35624] - Further refine STP download regexs, a=testonly
[gecko.git] / accessible / xpcom / xpcAccessibleHyperLink.cpp
blobaca8734b13e894212b6af378642aafbf54b8419c
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;
16 NS_IMETHODIMP
17 xpcAccessibleHyperLink::GetStartIndex(int32_t* aStartIndex) {
18 NS_ENSURE_ARG_POINTER(aStartIndex);
19 *aStartIndex = 0;
21 if (!Intl()) return NS_ERROR_FAILURE;
23 #if defined(XP_WIN)
24 if (Intl()->IsRemote() &&
25 !StaticPrefs::accessibility_cache_enabled_AtStartup()) {
26 return NS_ERROR_NOT_IMPLEMENTED;
28 #endif
30 *aStartIndex = static_cast<int32_t>(Intl()->StartOffset());
31 return NS_OK;
34 NS_IMETHODIMP
35 xpcAccessibleHyperLink::GetEndIndex(int32_t* aEndIndex) {
36 NS_ENSURE_ARG_POINTER(aEndIndex);
37 *aEndIndex = 0;
39 if (!Intl()) return NS_ERROR_FAILURE;
41 #if defined(XP_WIN)
42 if (Intl()->IsRemote() &&
43 !StaticPrefs::accessibility_cache_enabled_AtStartup()) {
44 return NS_ERROR_NOT_IMPLEMENTED;
46 #endif
48 *aEndIndex = static_cast<int32_t>(Intl()->EndOffset());
49 return NS_OK;
52 NS_IMETHODIMP
53 xpcAccessibleHyperLink::GetAnchorCount(int32_t* aAnchorCount) {
54 NS_ENSURE_ARG_POINTER(aAnchorCount);
55 *aAnchorCount = 0;
57 if (!Intl()) return NS_ERROR_FAILURE;
59 if (Intl()->IsLocal()) {
60 *aAnchorCount = Intl()->AsLocal()->AnchorCount();
61 } else {
62 #if defined(XP_WIN)
63 return NS_ERROR_NOT_IMPLEMENTED;
64 #else
65 bool isCountValid = false;
66 uint32_t anchorCount = Intl()->AsRemote()->AnchorCount(&isCountValid);
67 if (!isCountValid) return NS_ERROR_FAILURE;
69 *aAnchorCount = anchorCount;
70 #endif
73 return NS_OK;
76 NS_IMETHODIMP
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);
90 } else {
91 #if defined(XP_WIN)
92 return NS_ERROR_NOT_IMPLEMENTED;
93 #else
94 nsCString spec;
95 bool isURIValid = false;
96 Intl()->AsRemote()->AnchorURIAt(aIndex, spec, &isURIValid);
97 if (!isURIValid) return NS_ERROR_FAILURE;
99 nsCOMPtr<nsIURI> uri;
100 nsresult rv = NS_NewURI(getter_AddRefs(uri), spec);
101 NS_ENSURE_SUCCESS(rv, rv);
103 uri.forget(aURI);
104 #endif
107 return NS_OK;
110 NS_IMETHODIMP
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)));
125 } else {
126 #if defined(XP_WIN)
127 return NS_ERROR_NOT_IMPLEMENTED;
128 #else
129 NS_IF_ADDREF(*aAccessible = ToXPC(Intl()->AsRemote()->AnchorAt(aIndex)));
130 #endif
133 return NS_OK;
136 NS_IMETHODIMP
137 xpcAccessibleHyperLink::GetValid(bool* aValid) {
138 NS_ENSURE_ARG_POINTER(aValid);
139 *aValid = false;
141 if (!Intl()) return NS_ERROR_FAILURE;
143 if (Intl()->IsLocal()) {
144 *aValid = Intl()->AsLocal()->IsLinkValid();
145 } else {
146 #if defined(XP_WIN)
147 return NS_ERROR_NOT_IMPLEMENTED;
148 #else
149 *aValid = Intl()->AsRemote()->IsLinkValid();
150 #endif
153 return NS_OK;