Backed out changeset 06f41c22f3a6 (bug 1888460) for causing linux xpcshell failures...
[gecko.git] / accessible / xpcom / xpcAccessibleHyperLink.cpp
blob113e8d329720f2b0d2aa06a5b70ff69371327fb5
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 "xpcAccessibleDocument.h"
11 using namespace mozilla::a11y;
13 NS_IMETHODIMP
14 xpcAccessibleHyperLink::GetStartIndex(int32_t* aStartIndex) {
15 NS_ENSURE_ARG_POINTER(aStartIndex);
16 *aStartIndex = 0;
18 if (!Intl()) return NS_ERROR_FAILURE;
20 *aStartIndex = static_cast<int32_t>(Intl()->StartOffset());
21 return NS_OK;
24 NS_IMETHODIMP
25 xpcAccessibleHyperLink::GetEndIndex(int32_t* aEndIndex) {
26 NS_ENSURE_ARG_POINTER(aEndIndex);
27 *aEndIndex = 0;
29 if (!Intl()) return NS_ERROR_FAILURE;
31 *aEndIndex = static_cast<int32_t>(Intl()->EndOffset());
32 return NS_OK;
35 NS_IMETHODIMP
36 xpcAccessibleHyperLink::GetAnchorCount(int32_t* aAnchorCount) {
37 NS_ENSURE_ARG_POINTER(aAnchorCount);
38 *aAnchorCount = 0;
40 if (!Intl()) return NS_ERROR_FAILURE;
42 *aAnchorCount = Intl()->AnchorCount();
44 return NS_OK;
47 NS_IMETHODIMP
48 xpcAccessibleHyperLink::GetURI(int32_t aIndex, nsIURI** aURI) {
49 NS_ENSURE_ARG_POINTER(aURI);
51 if (!Intl()) {
52 return NS_ERROR_FAILURE;
55 if (aIndex < 0 || aIndex >= static_cast<int32_t>(Intl()->AnchorCount())) {
56 return NS_ERROR_INVALID_ARG;
59 RefPtr<nsIURI>(Intl()->AnchorURIAt(aIndex)).forget(aURI);
61 return NS_OK;
64 NS_IMETHODIMP
65 xpcAccessibleHyperLink::GetAnchor(int32_t aIndex, nsIAccessible** aAccessible) {
66 NS_ENSURE_ARG_POINTER(aAccessible);
67 *aAccessible = nullptr;
69 if (!Intl()) return NS_ERROR_FAILURE;
71 if (aIndex < 0) return NS_ERROR_INVALID_ARG;
73 if (aIndex >= static_cast<int32_t>(Intl()->AnchorCount())) {
74 return NS_ERROR_INVALID_ARG;
77 NS_IF_ADDREF(*aAccessible = ToXPC(Intl()->AnchorAt(aIndex)));
79 return NS_OK;
82 NS_IMETHODIMP
83 xpcAccessibleHyperLink::GetValid(bool* aValid) {
84 NS_ENSURE_ARG_POINTER(aValid);
85 *aValid = false;
87 if (!Intl()) return NS_ERROR_FAILURE;
89 *aValid = Intl()->IsLinkValid();
91 return NS_OK;