Coverage Report

Created: 2018-09-25 14:53

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