summaryrefslogtreecommitdiffstats
path: root/accessible/base/nsAccUtils.cpp
blob: 61211068ca43843ba255ccb40e1aaf4176645862 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "nsAccUtils.h"

#include "AccAttributes.h"
#include "ARIAMap.h"
#include "nsCoreUtils.h"
#include "nsGenericHTMLElement.h"
#include "DocAccessible.h"
#include "DocAccessibleParent.h"
#include "HyperTextAccessible.h"
#include "nsIAccessibleTypes.h"
#include "mozilla/a11y/Role.h"
#include "States.h"
#include "TextLeafAccessible.h"

#include "nsIBaseWindow.h"
#include "nsIDocShellTreeOwner.h"
#include "nsIDOMXULContainerElement.h"
#include "mozilla/a11y/RemoteAccessible.h"
#include "mozilla/dom/Document.h"
#include "mozilla/dom/Element.h"
#include "mozilla/dom/ElementInternals.h"
#include "nsAccessibilityService.h"

using namespace mozilla;
using namespace mozilla::a11y;

void nsAccUtils::SetAccGroupAttrs(AccAttributes* aAttributes, int32_t aLevel,
                                  int32_t aSetSize, int32_t aPosInSet) {
  nsAutoString value;

  if (aLevel) {
    aAttributes->SetAttribute(nsGkAtoms::level, aLevel);
  }

  if (aSetSize && aPosInSet) {
    aAttributes->SetAttribute(nsGkAtoms::posinset, aPosInSet);
    aAttributes->SetAttribute(nsGkAtoms::setsize, aSetSize);
  }
}

int32_t nsAccUtils::GetLevelForXULContainerItem(nsIContent* aContent) {
  nsCOMPtr<nsIDOMXULContainerItemElement> item =
      aContent->AsElement()->AsXULContainerItem();
  if (!item) return 0;

  nsCOMPtr<dom::Element> containerElement;
  item->GetParentContainer(getter_AddRefs(containerElement));
  nsCOMPtr<nsIDOMXULContainerElement> container =
      containerElement ? containerElement->AsXULContainer() : nullptr;
  if (!container) return 0;

  // Get level of the item.
  int32_t level = -1;
  while (container) {
    level++;

    container->GetParentContainer(getter_AddRefs(containerElement));
    container = containerElement ? containerElement->AsXULContainer() : nullptr;
  }

  return level;
}

void nsAccUtils::SetLiveContainerAttributes(AccAttributes* aAttributes,
                                            Accessible* aStartAcc) {
  nsAutoString live, relevant, busy;
  nsStaticAtom* role = nullptr;
  Maybe<bool> atomic;
  for (Accessible* acc = aStartAcc; acc; acc = acc->Parent()) {
    // We only want the nearest value for each attribute. If we already got a
    // value, don't bother fetching it from further ancestors.
    const bool wasLiveEmpty = live.IsEmpty();
    acc->LiveRegionAttributes(wasLiveEmpty ? &live : nullptr,
                              relevant.IsEmpty() ? &relevant : nullptr,
                              atomic ? nullptr : &atomic,
                              busy.IsEmpty() ? &busy : nullptr);
    if (wasLiveEmpty) {
      const nsRoleMapEntry* roleMap = acc->ARIARoleMap();
      if (live.IsEmpty()) {
        // aria-live wasn't explicitly set. See if an aria-live value is implied
        // by an ARIA role or markup element.
        if (roleMap) {
          GetLiveAttrValue(roleMap->liveAttRule, live);
        } else if (nsStaticAtom* value = GetAccService()->MarkupAttribute(
                       acc, nsGkAtoms::aria_live)) {
          value->ToString(live);
        }
      }
      if (!live.IsEmpty() && roleMap &&
          roleMap->roleAtom != nsGkAtoms::_empty) {
        role = roleMap->roleAtom;
      }
    }
    if (acc->IsDoc()) {
      break;
    }
  }
  if (!live.IsEmpty()) {
    aAttributes->SetAttribute(nsGkAtoms::containerLive, std::move(live));
  }
  if (role) {
    aAttributes->SetAttribute(nsGkAtoms::containerLiveRole, std::move(role));
  }
  if (!relevant.IsEmpty()) {
    aAttributes->SetAttribute(nsGkAtoms::containerRelevant,
                              std::move(relevant));
  }
  if (atomic) {
    aAttributes->SetAttribute(nsGkAtoms::containerAtomic, *atomic);
  }
  if (!busy.IsEmpty()) {
    aAttributes->SetAttribute(nsGkAtoms::containerBusy, std::move(busy));
  }
}

bool nsAccUtils::HasDefinedARIAToken(nsIContent* aContent, nsAtom* aAtom) {
  NS_ASSERTION(aContent, "aContent is null in call to HasDefinedARIAToken!");

  if (!aContent->IsElement()) return false;

  dom::Element* element = aContent->AsElement();
  if (auto* htmlElement = nsGenericHTMLElement::FromNode(element);
      htmlElement && !element->HasAttr(aAtom)) {
    const auto* defaults = GetARIADefaults(htmlElement);
    if (!defaults) {
      return false;
    }
    return HasDefinedARIAToken(defaults, aAtom);
  }
  return HasDefinedARIAToken(&element->GetAttrs(), aAtom);
}

bool nsAccUtils::HasDefinedARIAToken(const AttrArray* aAttrs, nsAtom* aAtom) {
  return aAttrs->HasAttr(aAtom) &&
         !aAttrs->AttrValueIs(kNameSpaceID_None, aAtom, nsGkAtoms::_empty,
                              eCaseMatters) &&
         !aAttrs->AttrValueIs(kNameSpaceID_None, aAtom, nsGkAtoms::_undefined,
                              eCaseMatters);
}

nsStaticAtom* nsAccUtils::NormalizeARIAToken(const AttrArray* aAttrs,
                                             nsAtom* aAttr) {
  if (!HasDefinedARIAToken(aAttrs, aAttr)) {
    return nsGkAtoms::_empty;
  }

  if (aAttr == nsGkAtoms::aria_current) {
    static AttrArray::AttrValuesArray tokens[] = {
        nsGkAtoms::page, nsGkAtoms::step, nsGkAtoms::location_,
        nsGkAtoms::date, nsGkAtoms::time, nsGkAtoms::_true,
        nullptr};
    int32_t idx =
        aAttrs->FindAttrValueIn(kNameSpaceID_None, aAttr, tokens, eCaseMatters);
    // If the token is present, return it, otherwise TRUE as per spec.
    return (idx >= 0) ? tokens[idx] : nsGkAtoms::_true;
  }

  static AttrArray::AttrValuesArray tokens[] = {
      nsGkAtoms::_false, nsGkAtoms::_true, nsGkAtoms::mixed, nullptr};
  int32_t idx =
      aAttrs->FindAttrValueIn(kNameSpaceID_None, aAttr, tokens, eCaseMatters);
  if (idx >= 0) {
    return tokens[idx];
  }

  return nullptr;
}

nsStaticAtom* nsAccUtils::NormalizeARIAToken(dom::Element* aElement,
                                             nsAtom* aAttr) {
  if (auto* htmlElement = nsGenericHTMLElement::FromNode(aElement);
      htmlElement && !aElement->HasAttr(aAttr)) {
    const auto* defaults = GetARIADefaults(htmlElement);
    if (!defaults) {
      return nsGkAtoms::_empty;
    }
    return NormalizeARIAToken(defaults, aAttr);
  }
  return NormalizeARIAToken(&aElement->GetAttrs(), aAttr);
}

Accessible* nsAccUtils::GetSelectableContainer(const Accessible* aAccessible,
                                               uint64_t aState) {
  if (!aAccessible) return nullptr;

  if (!(aState & states::SELECTABLE)) return nullptr;
  MOZ_ASSERT(!aAccessible->IsDoc());

  const Accessible* parent = aAccessible;
  while ((parent = parent->Parent()) && !parent->IsSelect()) {
    if (parent->IsDoc() || parent->Role() == roles::PANE) {
      return nullptr;
    }
  }
  return const_cast<Accessible*>(parent);
}

LocalAccessible* nsAccUtils::GetSelectableContainer(
    LocalAccessible* aAccessible, uint64_t aState) {
  Accessible* selectable =
      GetSelectableContainer(static_cast<Accessible*>(aAccessible), aState);
  return selectable ? selectable->AsLocal() : nullptr;
}

bool nsAccUtils::IsDOMAttrTrue(const LocalAccessible* aAccessible,
                               nsAtom* aAttr) {
  dom::Element* el = aAccessible->Elm();
  return el && ARIAAttrValueIs(el, aAttr, nsGkAtoms::_true, eCaseMatters);
}

Accessible* nsAccUtils::TableFor(Accessible* aAcc) {
  if (!aAcc ||
      (!aAcc->IsTable() && !aAcc->IsTableRow() && !aAcc->IsTableCell())) {
    return nullptr;
  }
  Accessible* table = aAcc;
  for (; table && !table->IsTable(); table = table->Parent()) {
  }
  // We don't assert (table && table->IsTable()) here because
  // it's possible for this tree walk to yield no table at all
  // ex. because a table part has been moved in the tree
  // using aria-owns.
  return table;
}

LocalAccessible* nsAccUtils::TableFor(LocalAccessible* aRow) {
  Accessible* table = TableFor(static_cast<Accessible*>(aRow));
  return table ? table->AsLocal() : nullptr;
}

HyperTextAccessible* nsAccUtils::GetTextContainer(nsINode* aNode) {
  // Get text accessible containing the result node.
  DocAccessible* doc = GetAccService()->GetDocAccessible(aNode->OwnerDoc());
  LocalAccessible* accessible =
      doc ? doc->GetAccessibleOrContainer(aNode) : nullptr;
  if (!accessible) return nullptr;

  do {
    HyperTextAccessible* textAcc = accessible->AsHyperText();
    if (textAcc) return textAcc;

    accessible = accessible->LocalParent();
  } while (accessible);

  return nullptr;
}

LayoutDeviceIntPoint nsAccUtils::ConvertToScreenCoords(
    int32_t aX, int32_t aY, uint32_t aCoordinateType, Accessible* aAccessible) {
  LayoutDeviceIntPoint coords(aX, aY);

  switch (aCoordinateType) {
    // Regardless of coordinate type, the coords returned
    // are in dev pixels.
    case nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE:
      break;

    case nsIAccessibleCoordinateType::COORDTYPE_WINDOW_RELATIVE: {
      coords += GetScreenCoordsForWindow(aAccessible);
      break;
    }

    case nsIAccessibleCoordinateType::COORDTYPE_PARENT_RELATIVE: {
      coords += GetScreenCoordsForParent(aAccessible);
      break;
    }

    default:
      MOZ_ASSERT_UNREACHABLE("invalid coord type!");
  }

  return coords;
}

void nsAccUtils::ConvertScreenCoordsTo(int32_t* aX, int32_t* aY,
                                       uint32_t aCoordinateType,
                                       Accessible* aAccessible) {
  switch (aCoordinateType) {
    // Regardless of coordinate type, the values returned for
    // aX and aY are in dev pixels.
    case nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE:
      break;

    case nsIAccessibleCoordinateType::COORDTYPE_WINDOW_RELATIVE: {
      LayoutDeviceIntPoint coords = GetScreenCoordsForWindow(aAccessible);
      *aX -= coords.x;
      *aY -= coords.y;
      break;
    }

    case nsIAccessibleCoordinateType::COORDTYPE_PARENT_RELATIVE: {
      LayoutDeviceIntPoint coords = GetScreenCoordsForParent(aAccessible);
      *aX -= coords.x;
      *aY -= coords.y;
      break;
    }

    default:
      MOZ_ASSERT_UNREACHABLE("invalid coord type!");
  }
}

LayoutDeviceIntPoint nsAccUtils::GetScreenCoordsForParent(
    Accessible* aAccessible) {
  if (!aAccessible) return LayoutDeviceIntPoint();

  if (Accessible* parent = aAccessible->Parent()) {
    LayoutDeviceIntRect parentBounds = parent->Bounds();
    // The rect returned from Bounds() is already in dev
    // pixels, so we don't need to do any conversion here.
    return parentBounds.TopLeft();
  }

  return LayoutDeviceIntPoint();
}

LayoutDeviceIntPoint nsAccUtils::GetScreenCoordsForWindow(
    Accessible* aAccessible) {
  LayoutDeviceIntPoint coords(0, 0);
  a11y::LocalAccessible* localAcc = aAccessible->AsLocal();
  if (!localAcc) {
    localAcc = aAccessible->AsRemote()->OuterDocOfRemoteBrowser();
    if (!localAcc) {
      // This could be null if the tab is closing but the document is still
      // being shut down.
      return coords;
    }
  }

  nsCOMPtr<nsIDocShellTreeItem> treeItem(
      nsCoreUtils::GetDocShellFor(localAcc->GetNode()));
  if (!treeItem) return coords;

  nsCOMPtr<nsIDocShellTreeOwner> treeOwner;
  treeItem->GetTreeOwner(getter_AddRefs(treeOwner));
  if (!treeOwner) return coords;

  nsCOMPtr<nsIBaseWindow> baseWindow = do_QueryInterface(treeOwner);
  if (baseWindow) {
    baseWindow->GetPosition(&coords.x.value,
                            &coords.y.value);  // in device pixels
  }

  return coords;
}

bool nsAccUtils::GetLiveAttrValue(uint32_t aRule, nsAString& aValue) {
  switch (aRule) {
    case eOffLiveAttr:
      aValue = u"off"_ns;
      return true;
    case ePoliteLiveAttr:
      aValue = u"polite"_ns;
      return true;
    case eAssertiveLiveAttr:
      aValue = u"assertive"_ns;
      return true;
  }

  return false;
}

#ifdef DEBUG

bool nsAccUtils::IsTextInterfaceSupportCorrect(LocalAccessible* aAccessible) {
  // Don't test for accessible docs, it makes us create accessibles too
  // early and fire mutation events before we need to
  if (aAccessible->IsDoc()) return true;

  bool foundText = false;
  uint32_t childCount = aAccessible->ChildCount();
  for (uint32_t childIdx = 0; childIdx < childCount; childIdx++) {
    LocalAccessible* child = aAccessible->LocalChildAt(childIdx);
    if (child && child->IsText()) {
      foundText = true;
      break;
    }
  }

  return !foundText || aAccessible->IsHyperText();
}
#endif

uint32_t nsAccUtils::TextLength(Accessible* aAccessible) {
  if (!aAccessible->IsText()) {
    return 1;
  }

  if (LocalAccessible* localAcc = aAccessible->AsLocal()) {
    TextLeafAccessible* textLeaf = localAcc->AsTextLeaf();
    if (textLeaf) {
      return textLeaf->Text().Length();
    }
  } else if (aAccessible->IsText()) {
    RemoteAccessible* remoteAcc = aAccessible->AsRemote();
    MOZ_ASSERT(remoteAcc);
    return remoteAcc->GetCachedTextLength();
  }

  // For list bullets (or anything other accessible which would compute its own
  // text. They don't have their own frame.
  // XXX In the future, list bullets may have frame and anon content, so
  // we should be able to remove this at that point
  nsAutoString text;
  aAccessible->AppendTextTo(text);  // Get all the text
  return text.Length();
}

bool nsAccUtils::MustPrune(Accessible* aAccessible) {
  MOZ_ASSERT(aAccessible);
  roles::Role role = aAccessible->Role();

  if (role == roles::SLIDER || role == roles::PROGRESSBAR) {
    // Always prune the tree for sliders and progressbars, as it doesn't make
    // sense for either to have descendants. Per the ARIA spec, children of
    // these elements are presentational. They also confuse NVDA.
    return true;
  }

  if (role != roles::MENUITEM && role != roles::COMBOBOX_OPTION &&
      role != roles::OPTION && role != roles::ENTRY &&
      role != roles::FLAT_EQUATION && role != roles::PASSWORD_TEXT &&
      role != roles::PUSHBUTTON && role != roles::TOGGLE_BUTTON &&
      role != roles::GRAPHIC && role != roles::SEPARATOR) {
    // If it doesn't match any of these roles, don't prune its children.
    return false;
  }

  if (aAccessible->ChildCount() != 1) {
    // If the accessible has more than one child, don't prune it.
    return false;
  }

  roles::Role childRole = aAccessible->FirstChild()->Role();
  // If the accessible's child is a text leaf, prune the accessible.
  return childRole == roles::TEXT_LEAF || childRole == roles::STATICTEXT;
}

bool nsAccUtils::IsARIALive(const LocalAccessible* aAccessible) {
  // Get computed aria-live property based on the closest container with the
  // attribute. Inner nodes override outer nodes within the same
  // document.
  // This should be the same as the container-live attribute, but we don't need
  // the other container-* attributes, so we can't use the same function.
  nsIContent* ancestor = aAccessible->GetContent();
  if (!ancestor) {
    return false;
  }
  dom::Document* doc = ancestor->GetComposedDoc();
  if (!doc) {
    return false;
  }
  dom::Element* topEl = doc->GetRootElement();
  while (ancestor) {
    const nsRoleMapEntry* role = nullptr;
    if (ancestor->IsElement()) {
      role = aria::GetRoleMap(ancestor->AsElement());
    }
    nsAutoString live;
    if (HasDefinedARIAToken(ancestor, nsGkAtoms::aria_live)) {
      GetARIAAttr(ancestor->AsElement(), nsGkAtoms::aria_live, live);
    } else if (role) {
      GetLiveAttrValue(role->liveAttRule, live);
    } else if (nsStaticAtom* value = GetAccService()->MarkupAttribute(
                   ancestor, nsGkAtoms::aria_live)) {
      value->ToString(live);
    }
    if (!live.IsEmpty() && !live.EqualsLiteral("off")) {
      return true;
    }

    if (ancestor == topEl) {
      break;
    }

    ancestor = ancestor->GetParent();
    if (!ancestor) {
      ancestor = topEl;  // Use <body>/<frameset>
    }
  }

  return false;
}

Accessible* nsAccUtils::DocumentFor(Accessible* aAcc) {
  if (!aAcc) {
    return nullptr;
  }
  if (LocalAccessible* localAcc = aAcc->AsLocal()) {
    return localAcc->Document();
  }
  return aAcc->AsRemote()->Document();
}

Accessible* nsAccUtils::GetAccessibleByID(Accessible* aDoc, uint64_t aID) {
  if (!aDoc) {
    return nullptr;
  }
  if (LocalAccessible* localAcc = aDoc->AsLocal()) {
    if (DocAccessible* doc = localAcc->AsDoc()) {
      if (!aID) {
        // GetAccessibleByUniqueID doesn't treat 0 as the document.
        return aDoc;
      }
      return doc->GetAccessibleByUniqueID(
          reinterpret_cast<void*>(static_cast<uintptr_t>(aID)));
    }
  } else if (DocAccessibleParent* doc = aDoc->AsRemote()->AsDoc()) {
    return doc->GetAccessible(aID);
  }
  return nullptr;
}

void nsAccUtils::DocumentURL(Accessible* aDoc, nsAString& aURL) {
  MOZ_ASSERT(aDoc && aDoc->IsDoc());
  if (LocalAccessible* localAcc = aDoc->AsLocal()) {
    return localAcc->AsDoc()->URL(aURL);
  }
  return aDoc->AsRemote()->AsDoc()->URL(aURL);
}

void nsAccUtils::DocumentMimeType(Accessible* aDoc, nsAString& aMimeType) {
  MOZ_ASSERT(aDoc && aDoc->IsDoc());
  if (LocalAccessible* localAcc = aDoc->AsLocal()) {
    return localAcc->AsDoc()->MimeType(aMimeType);
  }
  return aDoc->AsRemote()->AsDoc()->MimeType(aMimeType);
}

// ARIA Accessibility Default Accessors
const AttrArray* nsAccUtils::GetARIADefaults(dom::Element* aElement) {
  auto* element = nsGenericHTMLElement::FromNode(aElement);
  if (!element) {
    return nullptr;
  }
  auto* internals = element->GetInternals();
  if (!internals) {
    return nullptr;
  }
  return &internals->GetAttrs();
}

bool nsAccUtils::HasARIAAttr(dom::Element* aElement, const nsAtom* aName) {
  if (aElement->HasAttr(aName)) {
    return true;
  }
  const auto* defaults = GetARIADefaults(aElement);
  if (!defaults) {
    return false;
  }
  return defaults->HasAttr(aName);
}

bool nsAccUtils::GetARIAAttr(dom::Element* aElement, const nsAtom* aName,
                             nsAString& aResult) {
  if (aElement->GetAttr(aName, aResult)) {
    return true;
  }
  const auto* defaults = GetARIADefaults(aElement);
  if (!defaults) {
    return false;
  }
  return defaults->GetAttr(aName, aResult);
}

const nsAttrValue* nsAccUtils::GetARIAAttr(dom::Element* aElement,
                                           const nsAtom* aName) {
  if (const auto* val = aElement->GetParsedAttr(aName, kNameSpaceID_None)) {
    return val;
  }
  const auto* defaults = GetARIADefaults(aElement);
  if (!defaults) {
    return nullptr;
  }
  return defaults->GetAttr(aName, kNameSpaceID_None);
}

bool nsAccUtils::ARIAAttrValueIs(dom::Element* aElement, const nsAtom* aName,
                                 const nsAString& aValue,
                                 nsCaseTreatment aCaseSensitive) {
  if (aElement->HasAttr(kNameSpaceID_None, aName)) {
    return aElement->AttrValueIs(kNameSpaceID_None, aName, aValue,
                                 aCaseSensitive);
  }
  const auto* defaults = GetARIADefaults(aElement);
  if (!defaults) {
    return false;
  }
  return defaults->AttrValueIs(kNameSpaceID_None, aName, aValue,
                               aCaseSensitive);
}

bool nsAccUtils::ARIAAttrValueIs(dom::Element* aElement, const nsAtom* aName,
                                 const nsAtom* aValue,
                                 nsCaseTreatment aCaseSensitive) {
  if (aElement->HasAttr(kNameSpaceID_None, aName)) {
    return aElement->AttrValueIs(kNameSpaceID_None, aName, aValue,
                                 aCaseSensitive);
  }
  const auto* defaults = GetARIADefaults(aElement);
  if (!defaults) {
    return false;
  }
  return defaults->AttrValueIs(kNameSpaceID_None, aName, aValue,
                               aCaseSensitive);
}

int32_t nsAccUtils::FindARIAAttrValueIn(dom::Element* aElement,
                                        const nsAtom* aName,
                                        AttrArray::AttrValuesArray* aValues,
                                        nsCaseTreatment aCaseSensitive) {
  int32_t index = aElement->FindAttrValueIn(kNameSpaceID_None, aName, aValues,
                                            aCaseSensitive);
  if (index == AttrArray::ATTR_MISSING) {
    const auto* defaults = GetARIADefaults(aElement);
    if (!defaults) {
      return index;
    }
    index = defaults->FindAttrValueIn(kNameSpaceID_None, aName, aValues,
                                      aCaseSensitive);
  }
  return index;
}