|
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 "xpcAccessibleHyperText.h" |
|
8 |
|
9 #include "HyperTextAccessible-inl.h" |
|
10 #include "TextRange.h" |
|
11 #include "xpcAccessibleTextRange.h" |
|
12 |
|
13 #include "nsIPersistentProperties2.h" |
|
14 #include "nsIMutableArray.h" |
|
15 |
|
16 using namespace mozilla::a11y; |
|
17 |
|
18 //////////////////////////////////////////////////////////////////////////////// |
|
19 // nsISupports |
|
20 |
|
21 nsresult |
|
22 xpcAccessibleHyperText::QueryInterface(REFNSIID aIID, void** aInstancePtr) |
|
23 { |
|
24 *aInstancePtr = nullptr; |
|
25 |
|
26 HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); |
|
27 if (!text->IsTextRole()) |
|
28 return NS_ERROR_NO_INTERFACE; |
|
29 |
|
30 if (aIID.Equals(NS_GET_IID(nsIAccessibleText))) |
|
31 *aInstancePtr = static_cast<nsIAccessibleText*>(text); |
|
32 else if (aIID.Equals(NS_GET_IID(nsIAccessibleEditableText))) |
|
33 *aInstancePtr = static_cast<nsIAccessibleEditableText*>(text); |
|
34 else if (aIID.Equals(NS_GET_IID(nsIAccessibleHyperText))) |
|
35 *aInstancePtr = static_cast<nsIAccessibleHyperText*>(text); |
|
36 else |
|
37 return NS_ERROR_NO_INTERFACE; |
|
38 |
|
39 NS_ADDREF(text); |
|
40 return NS_OK; |
|
41 } |
|
42 |
|
43 //////////////////////////////////////////////////////////////////////////////// |
|
44 // nsIAccessibleText |
|
45 |
|
46 NS_IMETHODIMP |
|
47 xpcAccessibleHyperText::GetCharacterCount(int32_t* aCharacterCount) |
|
48 { |
|
49 NS_ENSURE_ARG_POINTER(aCharacterCount); |
|
50 *aCharacterCount = 0; |
|
51 |
|
52 HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); |
|
53 if (text->IsDefunct()) |
|
54 return NS_ERROR_FAILURE; |
|
55 |
|
56 *aCharacterCount = text->CharacterCount(); |
|
57 return NS_OK; |
|
58 } |
|
59 |
|
60 NS_IMETHODIMP |
|
61 xpcAccessibleHyperText::GetText(int32_t aStartOffset, int32_t aEndOffset, |
|
62 nsAString& aText) |
|
63 { |
|
64 aText.Truncate(); |
|
65 |
|
66 HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); |
|
67 if (text->IsDefunct()) |
|
68 return NS_ERROR_FAILURE; |
|
69 |
|
70 text->TextSubstring(aStartOffset, aEndOffset, aText); |
|
71 return NS_OK; |
|
72 } |
|
73 |
|
74 NS_IMETHODIMP |
|
75 xpcAccessibleHyperText::GetTextBeforeOffset(int32_t aOffset, |
|
76 AccessibleTextBoundary aBoundaryType, |
|
77 int32_t* aStartOffset, |
|
78 int32_t* aEndOffset, |
|
79 nsAString& aText) |
|
80 { |
|
81 NS_ENSURE_ARG_POINTER(aStartOffset); |
|
82 NS_ENSURE_ARG_POINTER(aEndOffset); |
|
83 *aStartOffset = *aEndOffset = 0; |
|
84 aText.Truncate(); |
|
85 |
|
86 HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); |
|
87 if (text->IsDefunct()) |
|
88 return NS_ERROR_FAILURE; |
|
89 |
|
90 text->TextBeforeOffset(aOffset, aBoundaryType, aStartOffset, aEndOffset, aText); |
|
91 return NS_OK; |
|
92 } |
|
93 |
|
94 NS_IMETHODIMP |
|
95 xpcAccessibleHyperText::GetTextAtOffset(int32_t aOffset, |
|
96 AccessibleTextBoundary aBoundaryType, |
|
97 int32_t* aStartOffset, |
|
98 int32_t* aEndOffset, nsAString& aText) |
|
99 { |
|
100 NS_ENSURE_ARG_POINTER(aStartOffset); |
|
101 NS_ENSURE_ARG_POINTER(aEndOffset); |
|
102 *aStartOffset = *aEndOffset = 0; |
|
103 aText.Truncate(); |
|
104 |
|
105 HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); |
|
106 if (text->IsDefunct()) |
|
107 return NS_ERROR_FAILURE; |
|
108 |
|
109 text->TextAtOffset(aOffset, aBoundaryType, aStartOffset, aEndOffset, aText); |
|
110 return NS_OK; |
|
111 } |
|
112 |
|
113 NS_IMETHODIMP |
|
114 xpcAccessibleHyperText::GetTextAfterOffset(int32_t aOffset, |
|
115 AccessibleTextBoundary aBoundaryType, |
|
116 int32_t* aStartOffset, |
|
117 int32_t* aEndOffset, nsAString& aText) |
|
118 { |
|
119 NS_ENSURE_ARG_POINTER(aStartOffset); |
|
120 NS_ENSURE_ARG_POINTER(aEndOffset); |
|
121 *aStartOffset = *aEndOffset = 0; |
|
122 aText.Truncate(); |
|
123 |
|
124 HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); |
|
125 if (text->IsDefunct()) |
|
126 return NS_ERROR_FAILURE; |
|
127 |
|
128 text->TextAfterOffset(aOffset, aBoundaryType, aStartOffset, aEndOffset, aText); |
|
129 return NS_OK; |
|
130 } |
|
131 |
|
132 NS_IMETHODIMP |
|
133 xpcAccessibleHyperText::GetCharacterAtOffset(int32_t aOffset, |
|
134 char16_t* aCharacter) |
|
135 { |
|
136 NS_ENSURE_ARG_POINTER(aCharacter); |
|
137 *aCharacter = L'\0'; |
|
138 |
|
139 HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); |
|
140 if (text->IsDefunct()) |
|
141 return NS_ERROR_FAILURE; |
|
142 |
|
143 *aCharacter = text->CharAt(aOffset); |
|
144 return NS_OK; |
|
145 } |
|
146 |
|
147 NS_IMETHODIMP |
|
148 xpcAccessibleHyperText::GetTextAttributes(bool aIncludeDefAttrs, |
|
149 int32_t aOffset, |
|
150 int32_t* aStartOffset, |
|
151 int32_t* aEndOffset, |
|
152 nsIPersistentProperties** aAttributes) |
|
153 { |
|
154 NS_ENSURE_ARG_POINTER(aStartOffset); |
|
155 NS_ENSURE_ARG_POINTER(aEndOffset); |
|
156 NS_ENSURE_ARG_POINTER(aAttributes); |
|
157 *aStartOffset = *aEndOffset = 0; |
|
158 *aAttributes = nullptr; |
|
159 |
|
160 HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); |
|
161 if (text->IsDefunct()) |
|
162 return NS_ERROR_FAILURE; |
|
163 |
|
164 nsCOMPtr<nsIPersistentProperties> attrs = |
|
165 text->TextAttributes(aIncludeDefAttrs, aOffset, aStartOffset, aEndOffset); |
|
166 attrs.swap(*aAttributes); |
|
167 |
|
168 return NS_OK; |
|
169 } |
|
170 |
|
171 NS_IMETHODIMP |
|
172 xpcAccessibleHyperText::GetDefaultTextAttributes(nsIPersistentProperties** aAttributes) |
|
173 { |
|
174 NS_ENSURE_ARG_POINTER(aAttributes); |
|
175 *aAttributes = nullptr; |
|
176 |
|
177 HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); |
|
178 if (text->IsDefunct()) |
|
179 return NS_ERROR_FAILURE; |
|
180 |
|
181 nsCOMPtr<nsIPersistentProperties> attrs = text->DefaultTextAttributes(); |
|
182 attrs.swap(*aAttributes); |
|
183 return NS_OK; |
|
184 } |
|
185 |
|
186 NS_IMETHODIMP |
|
187 xpcAccessibleHyperText::GetCharacterExtents(int32_t aOffset, |
|
188 int32_t* aX, int32_t* aY, |
|
189 int32_t* aWidth, int32_t* aHeight, |
|
190 uint32_t aCoordType) |
|
191 { |
|
192 NS_ENSURE_ARG_POINTER(aX); |
|
193 NS_ENSURE_ARG_POINTER(aY); |
|
194 NS_ENSURE_ARG_POINTER(aWidth); |
|
195 NS_ENSURE_ARG_POINTER(aHeight); |
|
196 *aX = *aY = *aWidth = *aHeight; |
|
197 |
|
198 HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); |
|
199 if (text->IsDefunct()) |
|
200 return NS_ERROR_FAILURE; |
|
201 |
|
202 nsIntRect rect = text->CharBounds(aOffset, aCoordType); |
|
203 *aX = rect.x; *aY = rect.y; |
|
204 *aWidth = rect.width; *aHeight = rect.height; |
|
205 return NS_OK; |
|
206 } |
|
207 |
|
208 NS_IMETHODIMP |
|
209 xpcAccessibleHyperText::GetRangeExtents(int32_t aStartOffset, int32_t aEndOffset, |
|
210 int32_t* aX, int32_t* aY, |
|
211 int32_t* aWidth, int32_t* aHeight, |
|
212 uint32_t aCoordType) |
|
213 { |
|
214 NS_ENSURE_ARG_POINTER(aX); |
|
215 NS_ENSURE_ARG_POINTER(aY); |
|
216 NS_ENSURE_ARG_POINTER(aWidth); |
|
217 NS_ENSURE_ARG_POINTER(aHeight); |
|
218 *aX = *aY = *aWidth = *aHeight = 0; |
|
219 |
|
220 HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); |
|
221 if (text->IsDefunct()) |
|
222 return NS_ERROR_FAILURE; |
|
223 |
|
224 nsIntRect rect = text->TextBounds(aStartOffset, aEndOffset, aCoordType); |
|
225 *aX = rect.x; *aY = rect.y; |
|
226 *aWidth = rect.width; *aHeight = rect.height; |
|
227 return NS_OK; |
|
228 } |
|
229 |
|
230 NS_IMETHODIMP |
|
231 xpcAccessibleHyperText::GetOffsetAtPoint(int32_t aX, int32_t aY, |
|
232 uint32_t aCoordType, int32_t* aOffset) |
|
233 { |
|
234 NS_ENSURE_ARG_POINTER(aOffset); |
|
235 *aOffset = -1; |
|
236 |
|
237 HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); |
|
238 if (text->IsDefunct()) |
|
239 return NS_ERROR_FAILURE; |
|
240 |
|
241 *aOffset = text->OffsetAtPoint(aX, aY, aCoordType); |
|
242 return NS_OK; |
|
243 } |
|
244 |
|
245 NS_IMETHODIMP |
|
246 xpcAccessibleHyperText::GetScriptableCaretOffset(int32_t* aCaretOffset) |
|
247 { |
|
248 NS_ENSURE_ARG_POINTER(aCaretOffset); |
|
249 *aCaretOffset = -1; |
|
250 |
|
251 HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); |
|
252 if (text->IsDefunct()) |
|
253 return NS_ERROR_FAILURE; |
|
254 |
|
255 *aCaretOffset = text->CaretOffset(); |
|
256 return NS_OK; |
|
257 } |
|
258 |
|
259 NS_IMETHODIMP |
|
260 xpcAccessibleHyperText::SetScriptableCaretOffset(int32_t aCaretOffset) |
|
261 { |
|
262 HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); |
|
263 if (text->IsDefunct()) |
|
264 return NS_ERROR_FAILURE; |
|
265 |
|
266 text->SetCaretOffset(aCaretOffset); |
|
267 return NS_OK; |
|
268 } |
|
269 |
|
270 NS_IMETHODIMP |
|
271 xpcAccessibleHyperText::GetSelectionCount(int32_t* aSelectionCount) |
|
272 { |
|
273 NS_ENSURE_ARG_POINTER(aSelectionCount); |
|
274 *aSelectionCount = 0; |
|
275 |
|
276 HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); |
|
277 if (text->IsDefunct()) |
|
278 return NS_ERROR_FAILURE; |
|
279 |
|
280 *aSelectionCount = text->SelectionCount(); |
|
281 return NS_OK; |
|
282 } |
|
283 |
|
284 NS_IMETHODIMP |
|
285 xpcAccessibleHyperText::GetSelectionBounds(int32_t aSelectionNum, |
|
286 int32_t* aStartOffset, |
|
287 int32_t* aEndOffset) |
|
288 { |
|
289 NS_ENSURE_ARG_POINTER(aStartOffset); |
|
290 NS_ENSURE_ARG_POINTER(aEndOffset); |
|
291 *aStartOffset = *aEndOffset = 0; |
|
292 |
|
293 HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); |
|
294 if (text->IsDefunct()) |
|
295 return NS_ERROR_FAILURE; |
|
296 |
|
297 if (aSelectionNum < 0 || aSelectionNum >= text->SelectionCount()) |
|
298 return NS_ERROR_INVALID_ARG; |
|
299 |
|
300 text->SelectionBoundsAt(aSelectionNum, aStartOffset, aEndOffset); |
|
301 return NS_OK; |
|
302 } |
|
303 |
|
304 NS_IMETHODIMP |
|
305 xpcAccessibleHyperText::SetSelectionBounds(int32_t aSelectionNum, |
|
306 int32_t aStartOffset, |
|
307 int32_t aEndOffset) |
|
308 { |
|
309 HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); |
|
310 if (text->IsDefunct()) |
|
311 return NS_ERROR_FAILURE; |
|
312 |
|
313 if (aSelectionNum < 0 || |
|
314 !text->SetSelectionBoundsAt(aSelectionNum, aStartOffset, aEndOffset)) |
|
315 return NS_ERROR_INVALID_ARG; |
|
316 |
|
317 return NS_OK; |
|
318 } |
|
319 |
|
320 NS_IMETHODIMP |
|
321 xpcAccessibleHyperText::AddSelection(int32_t aStartOffset, int32_t aEndOffset) |
|
322 { |
|
323 HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); |
|
324 if (text->IsDefunct()) |
|
325 return NS_ERROR_FAILURE; |
|
326 |
|
327 text->AddToSelection(aStartOffset, aEndOffset); |
|
328 return NS_OK; |
|
329 } |
|
330 |
|
331 NS_IMETHODIMP |
|
332 xpcAccessibleHyperText::RemoveSelection(int32_t aSelectionNum) |
|
333 { |
|
334 HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); |
|
335 if (text->IsDefunct()) |
|
336 return NS_ERROR_FAILURE; |
|
337 |
|
338 text->RemoveFromSelection(aSelectionNum); |
|
339 return NS_OK; |
|
340 } |
|
341 |
|
342 NS_IMETHODIMP |
|
343 xpcAccessibleHyperText::ScriptableScrollSubstringTo(int32_t aStartOffset, |
|
344 int32_t aEndOffset, |
|
345 uint32_t aScrollType) |
|
346 { |
|
347 HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); |
|
348 if (text->IsDefunct()) |
|
349 return NS_ERROR_FAILURE; |
|
350 |
|
351 text->ScrollSubstringTo(aStartOffset, aEndOffset, aScrollType); |
|
352 return NS_OK; |
|
353 } |
|
354 |
|
355 NS_IMETHODIMP |
|
356 xpcAccessibleHyperText::ScriptableScrollSubstringToPoint(int32_t aStartOffset, |
|
357 int32_t aEndOffset, |
|
358 uint32_t aCoordinateType, |
|
359 int32_t aX, int32_t aY) |
|
360 { |
|
361 HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); |
|
362 if (text->IsDefunct()) |
|
363 return NS_ERROR_FAILURE; |
|
364 |
|
365 text->ScrollSubstringToPoint(aStartOffset, aEndOffset, aCoordinateType, aX, aY); |
|
366 return NS_OK; |
|
367 } |
|
368 |
|
369 NS_IMETHODIMP |
|
370 xpcAccessibleHyperText::GetEnclosingRange(nsIAccessibleTextRange** aRange) |
|
371 { |
|
372 NS_ENSURE_ARG_POINTER(aRange); |
|
373 *aRange = nullptr; |
|
374 |
|
375 HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); |
|
376 if (text->IsDefunct()) |
|
377 return NS_ERROR_FAILURE; |
|
378 |
|
379 nsRefPtr<xpcAccessibleTextRange> range = new xpcAccessibleTextRange; |
|
380 text->EnclosingRange(range->mRange); |
|
381 NS_ASSERTION(range->mRange.IsValid(), |
|
382 "Should always have an enclosing range!"); |
|
383 |
|
384 range.forget(aRange); |
|
385 |
|
386 return NS_OK; |
|
387 } |
|
388 |
|
389 NS_IMETHODIMP |
|
390 xpcAccessibleHyperText::GetSelectionRanges(nsIArray** aRanges) |
|
391 { |
|
392 NS_ENSURE_ARG_POINTER(aRanges); |
|
393 *aRanges = nullptr; |
|
394 |
|
395 HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); |
|
396 if (text->IsDefunct()) |
|
397 return NS_ERROR_FAILURE; |
|
398 |
|
399 nsresult rv = NS_OK; |
|
400 nsCOMPtr<nsIMutableArray> xpcRanges = |
|
401 do_CreateInstance(NS_ARRAY_CONTRACTID, &rv); |
|
402 NS_ENSURE_SUCCESS(rv, rv); |
|
403 |
|
404 nsAutoTArray<TextRange, 1> ranges; |
|
405 text->SelectionRanges(&ranges); |
|
406 uint32_t len = ranges.Length(); |
|
407 for (uint32_t idx = 0; idx < len; idx++) |
|
408 xpcRanges->AppendElement(new xpcAccessibleTextRange(Move(ranges[idx])), |
|
409 false); |
|
410 |
|
411 xpcRanges.forget(aRanges); |
|
412 return NS_OK; |
|
413 } |
|
414 |
|
415 NS_IMETHODIMP |
|
416 xpcAccessibleHyperText::GetVisibleRanges(nsIArray** aRanges) |
|
417 { |
|
418 NS_ENSURE_ARG_POINTER(aRanges); |
|
419 *aRanges = nullptr; |
|
420 |
|
421 HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); |
|
422 if (text->IsDefunct()) |
|
423 return NS_ERROR_FAILURE; |
|
424 |
|
425 nsresult rv = NS_OK; |
|
426 nsCOMPtr<nsIMutableArray> xpcRanges = |
|
427 do_CreateInstance(NS_ARRAY_CONTRACTID, &rv); |
|
428 NS_ENSURE_SUCCESS(rv, rv); |
|
429 |
|
430 nsTArray<TextRange> ranges; |
|
431 text->VisibleRanges(&ranges); |
|
432 uint32_t len = ranges.Length(); |
|
433 for (uint32_t idx = 0; idx < len; idx++) |
|
434 xpcRanges->AppendElement(new xpcAccessibleTextRange(Move(ranges[idx])), |
|
435 false); |
|
436 |
|
437 xpcRanges.forget(aRanges); |
|
438 return NS_OK; |
|
439 } |
|
440 |
|
441 NS_IMETHODIMP |
|
442 xpcAccessibleHyperText::GetRangeByChild(nsIAccessible* aChild, |
|
443 nsIAccessibleTextRange** aRange) |
|
444 { |
|
445 NS_ENSURE_ARG_POINTER(aRange); |
|
446 *aRange = nullptr; |
|
447 |
|
448 HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); |
|
449 if (text->IsDefunct()) |
|
450 return NS_ERROR_FAILURE; |
|
451 |
|
452 nsRefPtr<Accessible> child = do_QueryObject(aChild); |
|
453 if (child) { |
|
454 nsRefPtr<xpcAccessibleTextRange> range = new xpcAccessibleTextRange; |
|
455 text->RangeByChild(child, range->mRange); |
|
456 if (range->mRange.IsValid()) |
|
457 range.forget(aRange); |
|
458 } |
|
459 |
|
460 return NS_OK; |
|
461 } |
|
462 |
|
463 NS_IMETHODIMP |
|
464 xpcAccessibleHyperText::GetRangeAtPoint(int32_t aX, int32_t aY, |
|
465 nsIAccessibleTextRange** aRange) |
|
466 { |
|
467 NS_ENSURE_ARG_POINTER(aRange); |
|
468 *aRange = nullptr; |
|
469 |
|
470 HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); |
|
471 if (text->IsDefunct()) |
|
472 return NS_ERROR_FAILURE; |
|
473 |
|
474 nsRefPtr<xpcAccessibleTextRange> range = new xpcAccessibleTextRange; |
|
475 text->RangeAtPoint(aX, aY, range->mRange); |
|
476 if (range->mRange.IsValid()) |
|
477 range.forget(aRange); |
|
478 |
|
479 return NS_OK; |
|
480 } |
|
481 |
|
482 //////////////////////////////////////////////////////////////////////////////// |
|
483 // nsIAccessibleEditableText |
|
484 |
|
485 NS_IMETHODIMP |
|
486 xpcAccessibleHyperText::SetTextContents(const nsAString& aText) |
|
487 { |
|
488 HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); |
|
489 if (text->IsDefunct()) |
|
490 return NS_ERROR_FAILURE; |
|
491 |
|
492 text->ReplaceText(aText); |
|
493 return NS_OK; |
|
494 } |
|
495 |
|
496 NS_IMETHODIMP |
|
497 xpcAccessibleHyperText::ScriptableInsertText(const nsAString& aText, |
|
498 int32_t aOffset) |
|
499 { |
|
500 HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); |
|
501 if (text->IsDefunct()) |
|
502 return NS_ERROR_FAILURE; |
|
503 |
|
504 text->InsertText(aText, aOffset); |
|
505 return NS_OK; |
|
506 } |
|
507 |
|
508 NS_IMETHODIMP |
|
509 xpcAccessibleHyperText::ScriptableCopyText(int32_t aStartOffset, |
|
510 int32_t aEndOffset) |
|
511 { |
|
512 HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); |
|
513 if (text->IsDefunct()) |
|
514 return NS_ERROR_FAILURE; |
|
515 |
|
516 text->CopyText(aStartOffset, aEndOffset); |
|
517 return NS_OK; |
|
518 } |
|
519 |
|
520 NS_IMETHODIMP |
|
521 xpcAccessibleHyperText::ScriptableCutText(int32_t aStartOffset, |
|
522 int32_t aEndOffset) |
|
523 { |
|
524 HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); |
|
525 if (text->IsDefunct()) |
|
526 return NS_ERROR_FAILURE; |
|
527 |
|
528 text->CutText(aStartOffset, aEndOffset); |
|
529 return NS_OK; |
|
530 } |
|
531 |
|
532 NS_IMETHODIMP |
|
533 xpcAccessibleHyperText::ScriptableDeleteText(int32_t aStartOffset, |
|
534 int32_t aEndOffset) |
|
535 { |
|
536 HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); |
|
537 if (text->IsDefunct()) |
|
538 return NS_ERROR_FAILURE; |
|
539 |
|
540 text->DeleteText(aStartOffset, aEndOffset); |
|
541 return NS_OK; |
|
542 } |
|
543 |
|
544 NS_IMETHODIMP |
|
545 xpcAccessibleHyperText::ScriptablePasteText(int32_t aOffset) |
|
546 { |
|
547 HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); |
|
548 if (text->IsDefunct()) |
|
549 return NS_ERROR_FAILURE; |
|
550 |
|
551 text->PasteText(aOffset); |
|
552 return NS_OK; |
|
553 } |
|
554 |
|
555 //////////////////////////////////////////////////////////////////////////////// |
|
556 // nsIAccessibleHyperText |
|
557 |
|
558 NS_IMETHODIMP |
|
559 xpcAccessibleHyperText::GetLinkCount(int32_t* aLinkCount) |
|
560 { |
|
561 NS_ENSURE_ARG_POINTER(aLinkCount); |
|
562 *aLinkCount = 0; |
|
563 |
|
564 HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); |
|
565 if (text->IsDefunct()) |
|
566 return NS_ERROR_FAILURE; |
|
567 |
|
568 *aLinkCount = text->LinkCount(); |
|
569 return NS_OK; |
|
570 } |
|
571 |
|
572 NS_IMETHODIMP |
|
573 xpcAccessibleHyperText::GetLinkAt(int32_t aIndex, nsIAccessibleHyperLink** aLink) |
|
574 { |
|
575 NS_ENSURE_ARG_POINTER(aLink); |
|
576 *aLink = nullptr; |
|
577 |
|
578 HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); |
|
579 if (text->IsDefunct()) |
|
580 return NS_ERROR_FAILURE; |
|
581 |
|
582 nsCOMPtr<nsIAccessibleHyperLink> link = text->LinkAt(aIndex); |
|
583 link.forget(aLink); |
|
584 |
|
585 return NS_OK; |
|
586 } |
|
587 |
|
588 NS_IMETHODIMP |
|
589 xpcAccessibleHyperText::GetLinkIndex(nsIAccessibleHyperLink* aLink, |
|
590 int32_t* aIndex) |
|
591 { |
|
592 NS_ENSURE_ARG_POINTER(aLink); |
|
593 NS_ENSURE_ARG_POINTER(aIndex); |
|
594 *aIndex = -1; |
|
595 |
|
596 HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); |
|
597 if (text->IsDefunct()) |
|
598 return NS_ERROR_FAILURE; |
|
599 |
|
600 nsRefPtr<Accessible> link(do_QueryObject(aLink)); |
|
601 *aIndex = text->LinkIndexOf(link); |
|
602 return NS_OK; |
|
603 } |
|
604 |
|
605 NS_IMETHODIMP |
|
606 xpcAccessibleHyperText::GetLinkIndexAtOffset(int32_t aOffset, |
|
607 int32_t* aLinkIndex) |
|
608 { |
|
609 NS_ENSURE_ARG_POINTER(aLinkIndex); |
|
610 *aLinkIndex = -1; // API says this magic value means 'not found' |
|
611 |
|
612 HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); |
|
613 if (text->IsDefunct()) |
|
614 return NS_ERROR_FAILURE; |
|
615 |
|
616 *aLinkIndex = text->LinkIndexAtOffset(aOffset); |
|
617 return NS_OK; |
|
618 } |