Line data Source code
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 0 : xpcAccessibleHyperLink::GetStartIndex(int32_t* aStartIndex)
15 : {
16 0 : NS_ENSURE_ARG_POINTER(aStartIndex);
17 0 : *aStartIndex = 0;
18 :
19 0 : if (Intl().IsNull())
20 0 : return NS_ERROR_FAILURE;
21 :
22 0 : if (Intl().IsAccessible()) {
23 0 : *aStartIndex = Intl().AsAccessible()->StartOffset();
24 : } else {
25 : #if defined(XP_WIN)
26 : return NS_ERROR_NOT_IMPLEMENTED;
27 : #else
28 0 : bool isIndexValid = false;
29 0 : uint32_t startOffset = Intl().AsProxy()->StartOffset(&isIndexValid);
30 0 : if (!isIndexValid)
31 0 : return NS_ERROR_FAILURE;
32 :
33 0 : *aStartIndex = startOffset;
34 : #endif
35 : }
36 :
37 0 : return NS_OK;
38 : }
39 :
40 : NS_IMETHODIMP
41 0 : xpcAccessibleHyperLink::GetEndIndex(int32_t* aEndIndex)
42 : {
43 0 : NS_ENSURE_ARG_POINTER(aEndIndex);
44 0 : *aEndIndex = 0;
45 :
46 0 : if (Intl().IsNull())
47 0 : return NS_ERROR_FAILURE;
48 :
49 0 : if (Intl().IsAccessible()) {
50 0 : *aEndIndex = Intl().AsAccessible()->EndOffset();
51 : } else {
52 : #if defined(XP_WIN)
53 : return NS_ERROR_NOT_IMPLEMENTED;
54 : #else
55 0 : bool isIndexValid = false;
56 0 : uint32_t endOffset = Intl().AsProxy()->EndOffset(&isIndexValid);
57 0 : if (!isIndexValid)
58 0 : return NS_ERROR_FAILURE;
59 :
60 0 : *aEndIndex = endOffset;
61 : #endif
62 : }
63 :
64 0 : return NS_OK;
65 : }
66 :
67 : NS_IMETHODIMP
68 0 : xpcAccessibleHyperLink::GetAnchorCount(int32_t* aAnchorCount)
69 : {
70 0 : NS_ENSURE_ARG_POINTER(aAnchorCount);
71 0 : *aAnchorCount = 0;
72 :
73 0 : if (Intl().IsNull())
74 0 : return NS_ERROR_FAILURE;
75 :
76 0 : if (Intl().IsAccessible()) {
77 0 : *aAnchorCount = Intl().AsAccessible()->AnchorCount();
78 : } else {
79 : #if defined(XP_WIN)
80 : return NS_ERROR_NOT_IMPLEMENTED;
81 : #else
82 0 : bool isCountValid = false;
83 0 : uint32_t anchorCount = Intl().AsProxy()->AnchorCount(&isCountValid);
84 0 : if (!isCountValid)
85 0 : return NS_ERROR_FAILURE;
86 :
87 0 : *aAnchorCount = anchorCount;
88 : #endif
89 : }
90 :
91 0 : return NS_OK;
92 : }
93 :
94 : NS_IMETHODIMP
95 0 : xpcAccessibleHyperLink::GetURI(int32_t aIndex, nsIURI** aURI)
96 : {
97 0 : NS_ENSURE_ARG_POINTER(aURI);
98 :
99 0 : if (Intl().IsNull())
100 0 : return NS_ERROR_FAILURE;
101 :
102 0 : if (aIndex < 0)
103 0 : return NS_ERROR_INVALID_ARG;
104 :
105 0 : if (Intl().IsAccessible()) {
106 0 : if (aIndex >= static_cast<int32_t>(Intl().AsAccessible()->AnchorCount()))
107 0 : return NS_ERROR_INVALID_ARG;
108 :
109 0 : RefPtr<nsIURI>(Intl().AsAccessible()->AnchorURIAt(aIndex)).forget(aURI);
110 : } else {
111 : #if defined(XP_WIN)
112 : return NS_ERROR_NOT_IMPLEMENTED;
113 : #else
114 0 : 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 :
120 0 : nsCOMPtr<nsIURI> uri;
121 0 : nsresult rv = NS_NewURI(getter_AddRefs(uri), spec);
122 0 : NS_ENSURE_SUCCESS(rv, rv);
123 :
124 0 : uri.forget(aURI);
125 : #endif
126 : }
127 :
128 0 : return NS_OK;
129 : }
130 :
131 :
132 : NS_IMETHODIMP
133 0 : xpcAccessibleHyperLink::GetAnchor(int32_t aIndex, nsIAccessible** aAccessible)
134 : {
135 0 : NS_ENSURE_ARG_POINTER(aAccessible);
136 0 : *aAccessible = nullptr;
137 :
138 0 : if (Intl().IsNull())
139 0 : return NS_ERROR_FAILURE;
140 :
141 0 : if (aIndex < 0)
142 0 : return NS_ERROR_INVALID_ARG;
143 :
144 0 : if (Intl().IsAccessible()) {
145 0 : if (aIndex >= static_cast<int32_t>(Intl().AsAccessible()->AnchorCount()))
146 0 : return NS_ERROR_INVALID_ARG;
147 :
148 0 : 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 0 : NS_IF_ADDREF(*aAccessible = ToXPC(Intl().AsProxy()->AnchorAt(aIndex)));
154 : #endif
155 : }
156 :
157 0 : return NS_OK;
158 : }
159 :
160 : NS_IMETHODIMP
161 0 : xpcAccessibleHyperLink::GetValid(bool* aValid)
162 : {
163 0 : NS_ENSURE_ARG_POINTER(aValid);
164 0 : *aValid = false;
165 :
166 0 : if (Intl().IsNull())
167 0 : return NS_ERROR_FAILURE;
168 :
169 0 : if (Intl().IsAccessible()) {
170 0 : *aValid = Intl().AsAccessible()->IsLinkValid();
171 : } else {
172 : #if defined(XP_WIN)
173 : return NS_ERROR_NOT_IMPLEMENTED;
174 : #else
175 0 : *aValid = Intl().AsProxy()->IsLinkValid();
176 : #endif
177 : }
178 :
179 0 : return NS_OK;
180 : }
|