summaryrefslogtreecommitdiffstats
path: root/accessible/html/HTMLListAccessible.cpp
blob: d7a2fc23aec15ecf7a9453cf6e7d42626bee47ad (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
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/* 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 "HTMLListAccessible.h"

#include "AccAttributes.h"
#include "nsAccessibilityService.h"
#include "mozilla/a11y/Role.h"
#include "States.h"

#include "nsLayoutUtils.h"

using namespace mozilla;
using namespace mozilla::a11y;

////////////////////////////////////////////////////////////////////////////////
// HTMLListAccessible
////////////////////////////////////////////////////////////////////////////////

role HTMLListAccessible::NativeRole() const {
  a11y::role r = GetAccService()->MarkupRole(mContent);
  return r != roles::NOTHING ? r : roles::LIST;
}

uint64_t HTMLListAccessible::NativeState() const {
  return HyperTextAccessible::NativeState() | states::READONLY;
}

////////////////////////////////////////////////////////////////////////////////
// HTMLLIAccessible
////////////////////////////////////////////////////////////////////////////////

HTMLLIAccessible::HTMLLIAccessible(nsIContent* aContent, DocAccessible* aDoc)
    : HyperTextAccessible(aContent, aDoc) {
  mType = eHTMLLiType;
}

role HTMLLIAccessible::NativeRole() const {
  a11y::role r = GetAccService()->MarkupRole(mContent);
  return r != roles::NOTHING ? r : roles::LISTITEM;
}

uint64_t HTMLLIAccessible::NativeState() const {
  return HyperTextAccessible::NativeState() | states::READONLY;
}

nsRect HTMLLIAccessible::BoundsInAppUnits() const {
  nsRect rect = AccessibleWrap::BoundsInAppUnits();

  LocalAccessible* bullet = Bullet();
  nsIFrame* frame = GetFrame();
  MOZ_ASSERT(!(bullet && !frame), "Cannot have a bullet if there is no frame");

  if (bullet && frame &&
      frame->StyleList()->mListStylePosition !=
          StyleListStylePosition::Inside) {
    nsRect bulletRect = bullet->BoundsInAppUnits();
    return rect.Union(bulletRect);
  }

  return rect;
}

LocalAccessible* HTMLLIAccessible::Bullet() const {
  LocalAccessible* firstChild = LocalFirstChild();
  if (firstChild && firstChild->NativeRole() == roles::LISTITEM_MARKER) {
    return firstChild;
  }

  return nullptr;
}

////////////////////////////////////////////////////////////////////////////////
// HTMLListBulletAccessible
////////////////////////////////////////////////////////////////////////////////
HTMLListBulletAccessible::HTMLListBulletAccessible(nsIContent* aContent,
                                                   DocAccessible* aDoc)
    : LeafAccessible(aContent, aDoc) {
  mGenericTypes |= eText;
}

////////////////////////////////////////////////////////////////////////////////
// HTMLListBulletAccessible: LocalAccessible

ENameValueFlag HTMLListBulletAccessible::Name(nsString& aName) const {
  nsLayoutUtils::GetMarkerSpokenText(mContent, aName);
  return eNameOK;
}

role HTMLListBulletAccessible::NativeRole() const {
  return roles::LISTITEM_MARKER;
}

uint64_t HTMLListBulletAccessible::NativeState() const {
  return LeafAccessible::NativeState() | states::READONLY;
}

already_AddRefed<AccAttributes> HTMLListBulletAccessible::NativeAttributes() {
  RefPtr<AccAttributes> attributes = new AccAttributes();
  return attributes.forget();
}

void HTMLListBulletAccessible::AppendTextTo(nsAString& aText,
                                            uint32_t aStartOffset,
                                            uint32_t aLength) {
  nsAutoString bulletText;
  Name(bulletText);
  aText.Append(Substring(bulletText, aStartOffset, aLength));
}