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 "xpcAccessibleHyperText.h"
8 :
9 : #include "Accessible-inl.h"
10 : #include "HyperTextAccessible-inl.h"
11 : #include "TextRange.h"
12 : #include "xpcAccessibleDocument.h"
13 : #include "xpcAccessibleTextRange.h"
14 :
15 : #include "nsIPersistentProperties2.h"
16 : #include "nsIMutableArray.h"
17 :
18 : using namespace mozilla::a11y;
19 :
20 : ////////////////////////////////////////////////////////////////////////////////
21 : // nsISupports
22 :
23 0 : NS_INTERFACE_MAP_BEGIN(xpcAccessibleHyperText)
24 0 : NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIAccessibleText,
25 : mSupportedIfaces & eText)
26 0 : NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIAccessibleEditableText,
27 : mSupportedIfaces & eText)
28 0 : NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIAccessibleHyperText,
29 : mSupportedIfaces & eText)
30 0 : NS_INTERFACE_MAP_END_INHERITING(xpcAccessibleGeneric)
31 :
32 0 : NS_IMPL_ADDREF_INHERITED(xpcAccessibleHyperText, xpcAccessibleGeneric)
33 0 : NS_IMPL_RELEASE_INHERITED(xpcAccessibleHyperText, xpcAccessibleGeneric)
34 :
35 : ////////////////////////////////////////////////////////////////////////////////
36 : // nsIAccessibleText
37 :
38 : NS_IMETHODIMP
39 0 : xpcAccessibleHyperText::GetCharacterCount(int32_t* aCharacterCount)
40 : {
41 0 : NS_ENSURE_ARG_POINTER(aCharacterCount);
42 0 : *aCharacterCount = 0;
43 :
44 0 : if (mIntl.IsNull())
45 0 : return NS_ERROR_FAILURE;
46 :
47 0 : if (mIntl.IsAccessible()) {
48 0 : *aCharacterCount = Intl()->CharacterCount();
49 : } else {
50 : #if defined(XP_WIN)
51 : return NS_ERROR_NOT_IMPLEMENTED;
52 : #else
53 0 : *aCharacterCount = mIntl.AsProxy()->CharacterCount();
54 : #endif
55 : }
56 0 : return NS_OK;
57 : }
58 :
59 : NS_IMETHODIMP
60 0 : xpcAccessibleHyperText::GetText(int32_t aStartOffset, int32_t aEndOffset,
61 : nsAString& aText)
62 : {
63 0 : aText.Truncate();
64 :
65 0 : if (mIntl.IsNull())
66 0 : return NS_ERROR_FAILURE;
67 :
68 0 : if (mIntl.IsAccessible()) {
69 0 : Intl()->TextSubstring(aStartOffset, aEndOffset, aText);
70 : } else {
71 0 : nsString text;
72 0 : mIntl.AsProxy()->TextSubstring(aStartOffset, aEndOffset, text);
73 0 : aText = text;
74 : }
75 0 : return NS_OK;
76 : }
77 :
78 : NS_IMETHODIMP
79 0 : xpcAccessibleHyperText::GetTextBeforeOffset(int32_t aOffset,
80 : AccessibleTextBoundary aBoundaryType,
81 : int32_t* aStartOffset,
82 : int32_t* aEndOffset,
83 : nsAString& aText)
84 : {
85 0 : NS_ENSURE_ARG_POINTER(aStartOffset);
86 0 : NS_ENSURE_ARG_POINTER(aEndOffset);
87 0 : *aStartOffset = *aEndOffset = 0;
88 0 : aText.Truncate();
89 :
90 0 : if (mIntl.IsNull())
91 0 : return NS_ERROR_FAILURE;
92 :
93 0 : if (mIntl.IsAccessible()) {
94 0 : Intl()->TextBeforeOffset(aOffset, aBoundaryType, aStartOffset, aEndOffset,
95 0 : aText);
96 : } else {
97 0 : nsString text;
98 0 : mIntl.AsProxy()->GetTextBeforeOffset(aOffset, aBoundaryType, text,
99 0 : aStartOffset, aEndOffset);
100 0 : aText = text;
101 : }
102 0 : return NS_OK;
103 : }
104 :
105 : NS_IMETHODIMP
106 0 : xpcAccessibleHyperText::GetTextAtOffset(int32_t aOffset,
107 : AccessibleTextBoundary aBoundaryType,
108 : int32_t* aStartOffset,
109 : int32_t* aEndOffset, nsAString& aText)
110 : {
111 0 : NS_ENSURE_ARG_POINTER(aStartOffset);
112 0 : NS_ENSURE_ARG_POINTER(aEndOffset);
113 0 : *aStartOffset = *aEndOffset = 0;
114 0 : aText.Truncate();
115 :
116 0 : if (mIntl.IsNull())
117 0 : return NS_ERROR_FAILURE;
118 :
119 0 : if (mIntl.IsAccessible()) {
120 0 : Intl()->TextAtOffset(aOffset, aBoundaryType, aStartOffset, aEndOffset,
121 0 : aText);
122 : } else {
123 0 : nsString text;
124 0 : mIntl.AsProxy()->GetTextAtOffset(aOffset, aBoundaryType, text,
125 0 : aStartOffset, aEndOffset);
126 0 : aText = text;
127 : }
128 0 : return NS_OK;
129 : }
130 :
131 : NS_IMETHODIMP
132 0 : xpcAccessibleHyperText::GetTextAfterOffset(int32_t aOffset,
133 : AccessibleTextBoundary aBoundaryType,
134 : int32_t* aStartOffset,
135 : int32_t* aEndOffset, nsAString& aText)
136 : {
137 0 : NS_ENSURE_ARG_POINTER(aStartOffset);
138 0 : NS_ENSURE_ARG_POINTER(aEndOffset);
139 0 : *aStartOffset = *aEndOffset = 0;
140 0 : aText.Truncate();
141 :
142 0 : if (mIntl.IsNull())
143 0 : return NS_ERROR_FAILURE;
144 :
145 0 : if (mIntl.IsAccessible()) {
146 0 : Intl()->TextAfterOffset(aOffset, aBoundaryType, aStartOffset, aEndOffset,
147 0 : aText);
148 : } else {
149 0 : nsString text;
150 0 : mIntl.AsProxy()->GetTextAfterOffset(aOffset, aBoundaryType, text,
151 0 : aStartOffset, aEndOffset);
152 0 : aText = text;
153 : }
154 0 : return NS_OK;
155 : }
156 :
157 : NS_IMETHODIMP
158 0 : xpcAccessibleHyperText::GetCharacterAtOffset(int32_t aOffset,
159 : char16_t* aCharacter)
160 : {
161 0 : NS_ENSURE_ARG_POINTER(aCharacter);
162 0 : *aCharacter = L'\0';
163 :
164 0 : if (mIntl.IsNull())
165 0 : return NS_ERROR_FAILURE;
166 :
167 0 : if (mIntl.IsAccessible()) {
168 0 : *aCharacter = Intl()->CharAt(aOffset);
169 : } else {
170 : #if defined(XP_WIN)
171 : return NS_ERROR_NOT_IMPLEMENTED;
172 : #else
173 0 : *aCharacter = mIntl.AsProxy()->CharAt(aOffset);
174 : #endif
175 : }
176 0 : return NS_OK;
177 : }
178 :
179 : NS_IMETHODIMP
180 0 : xpcAccessibleHyperText::GetTextAttributes(bool aIncludeDefAttrs,
181 : int32_t aOffset,
182 : int32_t* aStartOffset,
183 : int32_t* aEndOffset,
184 : nsIPersistentProperties** aAttributes)
185 : {
186 0 : NS_ENSURE_ARG_POINTER(aStartOffset);
187 0 : NS_ENSURE_ARG_POINTER(aEndOffset);
188 0 : NS_ENSURE_ARG_POINTER(aAttributes);
189 0 : *aStartOffset = *aEndOffset = 0;
190 0 : *aAttributes = nullptr;
191 :
192 0 : if (mIntl.IsNull())
193 0 : return NS_ERROR_FAILURE;
194 :
195 0 : nsCOMPtr<nsIPersistentProperties> props;
196 0 : if (mIntl.IsAccessible()) {
197 0 : props = Intl()->TextAttributes(aIncludeDefAttrs, aOffset, aStartOffset,
198 0 : aEndOffset);
199 : } else {
200 : #if defined(XP_WIN)
201 : return NS_ERROR_NOT_IMPLEMENTED;
202 : #else
203 0 : AutoTArray<Attribute, 10> attrs;
204 0 : mIntl.AsProxy()->TextAttributes(aIncludeDefAttrs, aOffset, &attrs,
205 0 : aStartOffset, aEndOffset);
206 0 : uint32_t attrCount = attrs.Length();
207 0 : nsAutoString unused;
208 0 : for (uint32_t i = 0; i < attrCount; i++) {
209 0 : props->SetStringProperty(attrs[i].Name(), attrs[i].Value(), unused);
210 : }
211 : #endif
212 : }
213 0 : props.forget(aAttributes);
214 :
215 0 : return NS_OK;
216 : }
217 :
218 : NS_IMETHODIMP
219 0 : xpcAccessibleHyperText::GetDefaultTextAttributes(nsIPersistentProperties** aAttributes)
220 : {
221 0 : NS_ENSURE_ARG_POINTER(aAttributes);
222 0 : *aAttributes = nullptr;
223 :
224 0 : if (mIntl.IsNull())
225 0 : return NS_ERROR_FAILURE;
226 :
227 0 : nsCOMPtr<nsIPersistentProperties> props;
228 0 : if (mIntl.IsAccessible()) {
229 0 : props = Intl()->DefaultTextAttributes();
230 : } else {
231 : #if defined(XP_WIN)
232 : return NS_ERROR_NOT_IMPLEMENTED;
233 : #else
234 0 : AutoTArray<Attribute, 10> attrs;
235 0 : mIntl.AsProxy()->DefaultTextAttributes(&attrs);
236 0 : uint32_t attrCount = attrs.Length();
237 0 : nsAutoString unused;
238 0 : for (uint32_t i = 0; i < attrCount; i++) {
239 0 : props->SetStringProperty(attrs[i].Name(), attrs[i].Value(), unused);
240 : }
241 : #endif
242 : }
243 0 : props.forget(aAttributes);
244 :
245 0 : return NS_OK;
246 : }
247 :
248 : NS_IMETHODIMP
249 0 : xpcAccessibleHyperText::GetCharacterExtents(int32_t aOffset,
250 : int32_t* aX, int32_t* aY,
251 : int32_t* aWidth, int32_t* aHeight,
252 : uint32_t aCoordType)
253 : {
254 0 : NS_ENSURE_ARG_POINTER(aX);
255 0 : NS_ENSURE_ARG_POINTER(aY);
256 0 : NS_ENSURE_ARG_POINTER(aWidth);
257 0 : NS_ENSURE_ARG_POINTER(aHeight);
258 0 : *aX = *aY = *aWidth = *aHeight;
259 :
260 0 : if (mIntl.IsNull())
261 0 : return NS_ERROR_FAILURE;
262 :
263 0 : nsIntRect rect;
264 0 : if (mIntl.IsAccessible()) {
265 0 : rect = Intl()->CharBounds(aOffset, aCoordType);
266 : } else {
267 : #if defined(XP_WIN)
268 : return NS_ERROR_NOT_IMPLEMENTED;
269 : #else
270 0 : rect = mIntl.AsProxy()->CharBounds(aOffset, aCoordType);
271 : #endif
272 : }
273 0 : *aX = rect.x; *aY = rect.y;
274 0 : *aWidth = rect.width; *aHeight = rect.height;
275 0 : return NS_OK;
276 : }
277 :
278 : NS_IMETHODIMP
279 0 : xpcAccessibleHyperText::GetRangeExtents(int32_t aStartOffset, int32_t aEndOffset,
280 : int32_t* aX, int32_t* aY,
281 : int32_t* aWidth, int32_t* aHeight,
282 : uint32_t aCoordType)
283 : {
284 0 : NS_ENSURE_ARG_POINTER(aX);
285 0 : NS_ENSURE_ARG_POINTER(aY);
286 0 : NS_ENSURE_ARG_POINTER(aWidth);
287 0 : NS_ENSURE_ARG_POINTER(aHeight);
288 0 : *aX = *aY = *aWidth = *aHeight = 0;
289 :
290 0 : if (mIntl.IsNull())
291 0 : return NS_ERROR_FAILURE;
292 :
293 0 : nsIntRect rect;
294 0 : if (mIntl.IsAccessible()) {
295 0 : rect = Intl()->TextBounds(aStartOffset, aEndOffset, aCoordType);
296 : } else {
297 : #if defined(XP_WIN)
298 : return NS_ERROR_NOT_IMPLEMENTED;
299 : #else
300 0 : rect = mIntl.AsProxy()->TextBounds(aStartOffset, aEndOffset, aCoordType);
301 : #endif
302 : }
303 0 : *aX = rect.x; *aY = rect.y;
304 0 : *aWidth = rect.width; *aHeight = rect.height;
305 0 : return NS_OK;
306 : }
307 :
308 : NS_IMETHODIMP
309 0 : xpcAccessibleHyperText::GetOffsetAtPoint(int32_t aX, int32_t aY,
310 : uint32_t aCoordType, int32_t* aOffset)
311 : {
312 0 : NS_ENSURE_ARG_POINTER(aOffset);
313 0 : *aOffset = -1;
314 :
315 0 : if (mIntl.IsNull())
316 0 : return NS_ERROR_FAILURE;
317 :
318 0 : if (mIntl.IsAccessible()) {
319 0 : *aOffset = Intl()->OffsetAtPoint(aX, aY, aCoordType);
320 : } else {
321 : #if defined(XP_WIN)
322 : return NS_ERROR_NOT_IMPLEMENTED;
323 : #else
324 0 : *aOffset = mIntl.AsProxy()->OffsetAtPoint(aX, aY, aCoordType);
325 : #endif
326 : }
327 0 : return NS_OK;
328 : }
329 :
330 : NS_IMETHODIMP
331 0 : xpcAccessibleHyperText::GetCaretOffset(int32_t* aCaretOffset)
332 : {
333 0 : NS_ENSURE_ARG_POINTER(aCaretOffset);
334 0 : *aCaretOffset = -1;
335 :
336 0 : if (mIntl.IsNull())
337 0 : return NS_ERROR_FAILURE;
338 :
339 0 : if (mIntl.IsAccessible()) {
340 0 : *aCaretOffset = Intl()->CaretOffset();
341 : } else {
342 0 : *aCaretOffset = mIntl.AsProxy()->CaretOffset();
343 : }
344 0 : return NS_OK;
345 : }
346 :
347 : NS_IMETHODIMP
348 0 : xpcAccessibleHyperText::SetCaretOffset(int32_t aCaretOffset)
349 : {
350 0 : if (mIntl.IsNull())
351 0 : return NS_ERROR_FAILURE;
352 :
353 0 : if (mIntl.IsAccessible()) {
354 0 : Intl()->SetCaretOffset(aCaretOffset);
355 : } else {
356 0 : mIntl.AsProxy()->SetCaretOffset(aCaretOffset);
357 : }
358 0 : return NS_OK;
359 : }
360 :
361 : NS_IMETHODIMP
362 0 : xpcAccessibleHyperText::GetSelectionCount(int32_t* aSelectionCount)
363 : {
364 0 : NS_ENSURE_ARG_POINTER(aSelectionCount);
365 0 : *aSelectionCount = 0;
366 :
367 0 : if (mIntl.IsNull())
368 0 : return NS_ERROR_FAILURE;
369 :
370 0 : if (mIntl.IsAccessible()) {
371 0 : *aSelectionCount = Intl()->SelectionCount();
372 : } else {
373 : #if defined(XP_WIN)
374 : return NS_ERROR_NOT_IMPLEMENTED;
375 : #else
376 0 : *aSelectionCount = mIntl.AsProxy()->SelectionCount();
377 : #endif
378 : }
379 0 : return NS_OK;
380 : }
381 :
382 : NS_IMETHODIMP
383 0 : xpcAccessibleHyperText::GetSelectionBounds(int32_t aSelectionNum,
384 : int32_t* aStartOffset,
385 : int32_t* aEndOffset)
386 : {
387 0 : NS_ENSURE_ARG_POINTER(aStartOffset);
388 0 : NS_ENSURE_ARG_POINTER(aEndOffset);
389 0 : *aStartOffset = *aEndOffset = 0;
390 :
391 0 : if (mIntl.IsNull())
392 0 : return NS_ERROR_FAILURE;
393 :
394 0 : if (aSelectionNum < 0)
395 0 : return NS_ERROR_INVALID_ARG;
396 :
397 0 : if (mIntl.IsAccessible()) {
398 0 : if (aSelectionNum >= Intl()->SelectionCount())
399 0 : return NS_ERROR_INVALID_ARG;
400 :
401 0 : Intl()->SelectionBoundsAt(aSelectionNum, aStartOffset, aEndOffset);
402 : } else {
403 : #if defined(XP_WIN)
404 : return NS_ERROR_NOT_IMPLEMENTED;
405 : #else
406 0 : nsString unused;
407 0 : mIntl.AsProxy()->SelectionBoundsAt(aSelectionNum, unused, aStartOffset,
408 0 : aEndOffset);
409 : #endif
410 : }
411 0 : return NS_OK;
412 : }
413 :
414 : NS_IMETHODIMP
415 0 : xpcAccessibleHyperText::SetSelectionBounds(int32_t aSelectionNum,
416 : int32_t aStartOffset,
417 : int32_t aEndOffset)
418 : {
419 0 : if (mIntl.IsNull())
420 0 : return NS_ERROR_FAILURE;
421 :
422 0 : if (aSelectionNum < 0)
423 0 : return NS_ERROR_INVALID_ARG;
424 :
425 0 : if (mIntl.IsAccessible()) {
426 0 : if (!Intl()->SetSelectionBoundsAt(aSelectionNum, aStartOffset,
427 : aEndOffset)) {
428 0 : return NS_ERROR_INVALID_ARG;
429 : }
430 : } else {
431 : #if defined(XP_WIN)
432 : return NS_ERROR_NOT_IMPLEMENTED;
433 : #else
434 0 : if (!mIntl.AsProxy()->SetSelectionBoundsAt(aSelectionNum, aStartOffset,
435 : aEndOffset)) {
436 0 : return NS_ERROR_INVALID_ARG;
437 : }
438 : #endif
439 : }
440 0 : return NS_OK;
441 : }
442 :
443 : NS_IMETHODIMP
444 0 : xpcAccessibleHyperText::AddSelection(int32_t aStartOffset, int32_t aEndOffset)
445 : {
446 0 : if (mIntl.IsNull())
447 0 : return NS_ERROR_FAILURE;
448 :
449 0 : if (mIntl.IsAccessible()) {
450 0 : Intl()->AddToSelection(aStartOffset, aEndOffset);
451 : } else {
452 0 : mIntl.AsProxy()->AddToSelection(aStartOffset, aEndOffset);
453 : }
454 0 : return NS_OK;
455 : }
456 :
457 : NS_IMETHODIMP
458 0 : xpcAccessibleHyperText::RemoveSelection(int32_t aSelectionNum)
459 : {
460 0 : if (mIntl.IsNull())
461 0 : return NS_ERROR_FAILURE;
462 :
463 0 : if (mIntl.IsAccessible()) {
464 0 : Intl()->RemoveFromSelection(aSelectionNum);
465 : } else {
466 0 : mIntl.AsProxy()->RemoveFromSelection(aSelectionNum);
467 : }
468 0 : return NS_OK;
469 : }
470 :
471 : NS_IMETHODIMP
472 0 : xpcAccessibleHyperText::ScrollSubstringTo(int32_t aStartOffset,
473 : int32_t aEndOffset,
474 : uint32_t aScrollType)
475 : {
476 0 : if (mIntl.IsNull())
477 0 : return NS_ERROR_FAILURE;
478 :
479 0 : if (mIntl.IsAccessible()) {
480 0 : Intl()->ScrollSubstringTo(aStartOffset, aEndOffset, aScrollType);
481 : } else {
482 0 : mIntl.AsProxy()->ScrollSubstringTo(aStartOffset, aEndOffset, aScrollType);
483 : }
484 0 : return NS_OK;
485 : }
486 :
487 : NS_IMETHODIMP
488 0 : xpcAccessibleHyperText::ScrollSubstringToPoint(int32_t aStartOffset,
489 : int32_t aEndOffset,
490 : uint32_t aCoordinateType,
491 : int32_t aX, int32_t aY)
492 : {
493 0 : if (mIntl.IsNull())
494 0 : return NS_ERROR_FAILURE;
495 :
496 0 : if (mIntl.IsAccessible()) {
497 0 : Intl()->ScrollSubstringToPoint(aStartOffset, aEndOffset, aCoordinateType,
498 0 : aX, aY);
499 : } else {
500 0 : mIntl.AsProxy()->ScrollSubstringToPoint(aStartOffset, aEndOffset,
501 0 : aCoordinateType, aX, aY);
502 : }
503 0 : return NS_OK;
504 : }
505 :
506 : NS_IMETHODIMP
507 0 : xpcAccessibleHyperText::GetEnclosingRange(nsIAccessibleTextRange** aRange)
508 : {
509 0 : NS_ENSURE_ARG_POINTER(aRange);
510 0 : *aRange = nullptr;
511 :
512 0 : if (!Intl())
513 0 : return NS_ERROR_FAILURE;
514 :
515 0 : RefPtr<xpcAccessibleTextRange> range = new xpcAccessibleTextRange;
516 0 : Intl()->EnclosingRange(range->mRange);
517 0 : NS_ASSERTION(range->mRange.IsValid(),
518 : "Should always have an enclosing range!");
519 :
520 0 : range.forget(aRange);
521 :
522 0 : return NS_OK;
523 : }
524 :
525 : NS_IMETHODIMP
526 0 : xpcAccessibleHyperText::GetSelectionRanges(nsIArray** aRanges)
527 : {
528 0 : NS_ENSURE_ARG_POINTER(aRanges);
529 0 : *aRanges = nullptr;
530 :
531 0 : if (!Intl())
532 0 : return NS_ERROR_FAILURE;
533 :
534 0 : nsresult rv = NS_OK;
535 : nsCOMPtr<nsIMutableArray> xpcRanges =
536 0 : do_CreateInstance(NS_ARRAY_CONTRACTID, &rv);
537 0 : NS_ENSURE_SUCCESS(rv, rv);
538 :
539 0 : AutoTArray<TextRange, 1> ranges;
540 0 : Intl()->SelectionRanges(&ranges);
541 0 : uint32_t len = ranges.Length();
542 0 : for (uint32_t idx = 0; idx < len; idx++)
543 0 : xpcRanges->AppendElement(new xpcAccessibleTextRange(Move(ranges[idx])),
544 0 : false);
545 :
546 0 : xpcRanges.forget(aRanges);
547 0 : return NS_OK;
548 : }
549 :
550 : NS_IMETHODIMP
551 0 : xpcAccessibleHyperText::GetVisibleRanges(nsIArray** aRanges)
552 : {
553 0 : NS_ENSURE_ARG_POINTER(aRanges);
554 0 : *aRanges = nullptr;
555 :
556 0 : if (!Intl())
557 0 : return NS_ERROR_FAILURE;
558 :
559 0 : nsresult rv = NS_OK;
560 : nsCOMPtr<nsIMutableArray> xpcRanges =
561 0 : do_CreateInstance(NS_ARRAY_CONTRACTID, &rv);
562 0 : NS_ENSURE_SUCCESS(rv, rv);
563 :
564 0 : nsTArray<TextRange> ranges;
565 0 : Intl()->VisibleRanges(&ranges);
566 0 : uint32_t len = ranges.Length();
567 0 : for (uint32_t idx = 0; idx < len; idx++)
568 0 : xpcRanges->AppendElement(new xpcAccessibleTextRange(Move(ranges[idx])),
569 0 : false);
570 :
571 0 : xpcRanges.forget(aRanges);
572 0 : return NS_OK;
573 : }
574 :
575 : NS_IMETHODIMP
576 0 : xpcAccessibleHyperText::GetRangeByChild(nsIAccessible* aChild,
577 : nsIAccessibleTextRange** aRange)
578 : {
579 0 : NS_ENSURE_ARG_POINTER(aRange);
580 0 : *aRange = nullptr;
581 :
582 0 : if (!Intl())
583 0 : return NS_ERROR_FAILURE;
584 :
585 0 : Accessible* child = aChild->ToInternalAccessible();
586 0 : if (child) {
587 0 : RefPtr<xpcAccessibleTextRange> range = new xpcAccessibleTextRange;
588 0 : Intl()->RangeByChild(child, range->mRange);
589 0 : if (range->mRange.IsValid())
590 0 : range.forget(aRange);
591 : }
592 :
593 0 : return NS_OK;
594 : }
595 :
596 : NS_IMETHODIMP
597 0 : xpcAccessibleHyperText::GetRangeAtPoint(int32_t aX, int32_t aY,
598 : nsIAccessibleTextRange** aRange)
599 : {
600 0 : NS_ENSURE_ARG_POINTER(aRange);
601 0 : *aRange = nullptr;
602 :
603 0 : if (!Intl())
604 0 : return NS_ERROR_FAILURE;
605 :
606 0 : RefPtr<xpcAccessibleTextRange> range = new xpcAccessibleTextRange;
607 0 : Intl()->RangeAtPoint(aX, aY, range->mRange);
608 0 : if (range->mRange.IsValid())
609 0 : range.forget(aRange);
610 :
611 0 : return NS_OK;
612 : }
613 :
614 : ////////////////////////////////////////////////////////////////////////////////
615 : // nsIAccessibleEditableText
616 :
617 : NS_IMETHODIMP
618 0 : xpcAccessibleHyperText::SetTextContents(const nsAString& aText)
619 : {
620 0 : if (mIntl.IsNull())
621 0 : return NS_ERROR_FAILURE;
622 :
623 0 : if (mIntl.IsAccessible()) {
624 0 : Intl()->ReplaceText(aText);
625 : } else {
626 : #if defined(XP_WIN)
627 : return NS_ERROR_NOT_IMPLEMENTED;
628 : #else
629 0 : nsString text(aText);
630 0 : mIntl.AsProxy()->ReplaceText(text);
631 : #endif
632 : }
633 0 : return NS_OK;
634 : }
635 :
636 : NS_IMETHODIMP
637 0 : xpcAccessibleHyperText::InsertText(const nsAString& aText, int32_t aOffset)
638 : {
639 0 : if (mIntl.IsNull())
640 0 : return NS_ERROR_FAILURE;
641 :
642 0 : if (mIntl.IsAccessible()) {
643 0 : Intl()->InsertText(aText, aOffset);
644 : } else {
645 : #if defined(XP_WIN)
646 : return NS_ERROR_NOT_IMPLEMENTED;
647 : #else
648 0 : nsString text(aText);
649 0 : mIntl.AsProxy()->InsertText(text, aOffset);
650 : #endif
651 : }
652 0 : return NS_OK;
653 : }
654 :
655 : NS_IMETHODIMP
656 0 : xpcAccessibleHyperText::CopyText(int32_t aStartOffset, int32_t aEndOffset)
657 : {
658 0 : if (mIntl.IsNull())
659 0 : return NS_ERROR_FAILURE;
660 :
661 0 : if (mIntl.IsAccessible()) {
662 0 : Intl()->CopyText(aStartOffset, aEndOffset);
663 : } else {
664 : #if defined(XP_WIN)
665 : return NS_ERROR_NOT_IMPLEMENTED;
666 : #else
667 0 : mIntl.AsProxy()->CopyText(aStartOffset, aEndOffset);
668 : #endif
669 : }
670 0 : return NS_OK;
671 : }
672 :
673 : NS_IMETHODIMP
674 0 : xpcAccessibleHyperText::CutText(int32_t aStartOffset, int32_t aEndOffset)
675 : {
676 0 : if (mIntl.IsNull())
677 0 : return NS_ERROR_FAILURE;
678 :
679 0 : if (mIntl.IsAccessible()) {
680 0 : Intl()->CutText(aStartOffset, aEndOffset);
681 : } else {
682 : #if defined(XP_WIN)
683 : return NS_ERROR_NOT_IMPLEMENTED;
684 : #else
685 0 : mIntl.AsProxy()->CutText(aStartOffset, aEndOffset);
686 : #endif
687 : }
688 0 : return NS_OK;
689 : }
690 :
691 : NS_IMETHODIMP
692 0 : xpcAccessibleHyperText::DeleteText(int32_t aStartOffset, int32_t aEndOffset)
693 : {
694 0 : if (mIntl.IsNull())
695 0 : return NS_ERROR_FAILURE;
696 :
697 0 : if (mIntl.IsAccessible()) {
698 0 : Intl()->DeleteText(aStartOffset, aEndOffset);
699 : } else {
700 : #if defined(XP_WIN)
701 : return NS_ERROR_NOT_IMPLEMENTED;
702 : #else
703 0 : mIntl.AsProxy()->DeleteText(aStartOffset, aEndOffset);
704 : #endif
705 : }
706 0 : return NS_OK;
707 : }
708 :
709 : NS_IMETHODIMP
710 0 : xpcAccessibleHyperText::PasteText(int32_t aOffset)
711 : {
712 0 : if (mIntl.IsNull())
713 0 : return NS_ERROR_FAILURE;
714 :
715 0 : if (mIntl.IsAccessible()) {
716 0 : Intl()->PasteText(aOffset);
717 : } else {
718 : #if defined(XP_WIN)
719 : return NS_ERROR_NOT_IMPLEMENTED;
720 : #else
721 0 : mIntl.AsProxy()->PasteText(aOffset);
722 : #endif
723 : }
724 0 : return NS_OK;
725 : }
726 :
727 : ////////////////////////////////////////////////////////////////////////////////
728 : // nsIAccessibleHyperText
729 :
730 : NS_IMETHODIMP
731 0 : xpcAccessibleHyperText::GetLinkCount(int32_t* aLinkCount)
732 : {
733 0 : NS_ENSURE_ARG_POINTER(aLinkCount);
734 0 : *aLinkCount = 0;
735 :
736 0 : if (mIntl.IsNull())
737 0 : return NS_ERROR_FAILURE;
738 :
739 0 : if (mIntl.IsAccessible()) {
740 0 : *aLinkCount = Intl()->LinkCount();
741 : } else {
742 : #if defined(XP_WIN)
743 : return NS_ERROR_NOT_IMPLEMENTED;
744 : #else
745 0 : *aLinkCount = mIntl.AsProxy()->LinkCount();
746 : #endif
747 : }
748 0 : return NS_OK;
749 : }
750 :
751 : NS_IMETHODIMP
752 0 : xpcAccessibleHyperText::GetLinkAt(int32_t aIndex, nsIAccessibleHyperLink** aLink)
753 : {
754 0 : NS_ENSURE_ARG_POINTER(aLink);
755 0 : *aLink = nullptr;
756 :
757 0 : if (mIntl.IsNull())
758 0 : return NS_ERROR_FAILURE;
759 :
760 0 : if (mIntl.IsAccessible()) {
761 0 : NS_IF_ADDREF(*aLink = ToXPC(Intl()->LinkAt(aIndex)));
762 : } else {
763 : #if defined(XP_WIN)
764 : return NS_ERROR_NOT_IMPLEMENTED;
765 : #else
766 0 : NS_IF_ADDREF(*aLink = ToXPC(mIntl.AsProxy()->LinkAt(aIndex)));
767 : #endif
768 : }
769 0 : return NS_OK;
770 : }
771 :
772 : NS_IMETHODIMP
773 0 : xpcAccessibleHyperText::GetLinkIndex(nsIAccessibleHyperLink* aLink,
774 : int32_t* aIndex)
775 : {
776 0 : NS_ENSURE_ARG_POINTER(aLink);
777 0 : NS_ENSURE_ARG_POINTER(aIndex);
778 0 : *aIndex = -1;
779 :
780 0 : if (mIntl.IsNull())
781 0 : return NS_ERROR_FAILURE;
782 :
783 0 : nsCOMPtr<nsIAccessible> xpcLink(do_QueryInterface(aLink));
784 0 : if (Accessible* accLink = xpcLink->ToInternalAccessible()) {
785 0 : *aIndex = Intl()->LinkIndexOf(accLink);
786 : } else {
787 : #if defined(XP_WIN)
788 : return NS_ERROR_NOT_IMPLEMENTED;
789 : #else
790 : xpcAccessibleHyperText* linkHyperText =
791 0 : static_cast<xpcAccessibleHyperText*>(xpcLink.get());
792 0 : ProxyAccessible* proxyLink = linkHyperText->mIntl.AsProxy();
793 0 : if (proxyLink) {
794 0 : *aIndex = mIntl.AsProxy()->LinkIndexOf(proxyLink);
795 : }
796 : #endif
797 : }
798 :
799 0 : return NS_OK;
800 : }
801 :
802 : NS_IMETHODIMP
803 0 : xpcAccessibleHyperText::GetLinkIndexAtOffset(int32_t aOffset,
804 : int32_t* aLinkIndex)
805 : {
806 0 : NS_ENSURE_ARG_POINTER(aLinkIndex);
807 0 : *aLinkIndex = -1; // API says this magic value means 'not found'
808 :
809 0 : if (mIntl.IsNull())
810 0 : return NS_ERROR_FAILURE;
811 :
812 0 : if (mIntl.IsAccessible()) {
813 0 : *aLinkIndex = Intl()->LinkIndexAtOffset(aOffset);
814 : } else {
815 : #if defined(XP_WIN)
816 : return NS_ERROR_NOT_IMPLEMENTED;
817 : #else
818 0 : *aLinkIndex = mIntl.AsProxy()->LinkIndexAtOffset(aOffset);
819 : #endif
820 : }
821 0 : return NS_OK;
822 : }
|