Bug 1734067 [wpt PR 31108] - Update wpt metadata, a=testonly
[gecko.git] / accessible / html / HTMLListAccessible.cpp
bloba3eb5847f3a5b8bb3cbc81bafb60a4e7ef5f9e75
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/. */
7 #include "HTMLListAccessible.h"
9 #include "AccAttributes.h"
10 #include "DocAccessible.h"
11 #include "EventTree.h"
12 #include "nsAccUtils.h"
13 #include "nsPersistentProperties.h"
14 #include "Role.h"
15 #include "States.h"
17 #include "nsLayoutUtils.h"
19 using namespace mozilla;
20 using namespace mozilla::a11y;
22 ////////////////////////////////////////////////////////////////////////////////
23 // HTMLListAccessible
24 ////////////////////////////////////////////////////////////////////////////////
26 role HTMLListAccessible::NativeRole() const {
27 a11y::role r = GetAccService()->MarkupRole(mContent);
28 return r != roles::NOTHING ? r : roles::LIST;
31 uint64_t HTMLListAccessible::NativeState() const {
32 return HyperTextAccessibleWrap::NativeState() | states::READONLY;
35 ////////////////////////////////////////////////////////////////////////////////
36 // HTMLLIAccessible
37 ////////////////////////////////////////////////////////////////////////////////
39 HTMLLIAccessible::HTMLLIAccessible(nsIContent* aContent, DocAccessible* aDoc)
40 : HyperTextAccessibleWrap(aContent, aDoc) {
41 mType = eHTMLLiType;
44 role HTMLLIAccessible::NativeRole() const {
45 a11y::role r = GetAccService()->MarkupRole(mContent);
46 return r != roles::NOTHING ? r : roles::LISTITEM;
49 uint64_t HTMLLIAccessible::NativeState() const {
50 return HyperTextAccessibleWrap::NativeState() | states::READONLY;
53 nsRect HTMLLIAccessible::BoundsInAppUnits() const {
54 nsRect rect = AccessibleWrap::BoundsInAppUnits();
56 LocalAccessible* bullet = Bullet();
57 nsIFrame* frame = GetFrame();
58 MOZ_ASSERT(!(bullet && !frame), "Cannot have a bullet if there is no frame");
60 if (bullet && frame &&
61 frame->StyleList()->mListStylePosition !=
62 NS_STYLE_LIST_STYLE_POSITION_INSIDE) {
63 nsRect bulletRect = bullet->BoundsInAppUnits();
64 return rect.Union(bulletRect);
67 return rect;
70 LocalAccessible* HTMLLIAccessible::Bullet() const {
71 LocalAccessible* firstChild = LocalFirstChild();
72 if (firstChild && firstChild->NativeRole() == roles::LISTITEM_MARKER) {
73 return firstChild;
76 return nullptr;
79 ////////////////////////////////////////////////////////////////////////////////
80 // HTMLListBulletAccessible
81 ////////////////////////////////////////////////////////////////////////////////
82 HTMLListBulletAccessible::HTMLListBulletAccessible(nsIContent* aContent,
83 DocAccessible* aDoc)
84 : LeafAccessible(aContent, aDoc) {
85 mGenericTypes |= eText;
88 ////////////////////////////////////////////////////////////////////////////////
89 // HTMLListBulletAccessible: LocalAccessible
91 ENameValueFlag HTMLListBulletAccessible::Name(nsString& aName) const {
92 nsLayoutUtils::GetMarkerSpokenText(mContent, aName);
93 return eNameOK;
96 role HTMLListBulletAccessible::NativeRole() const {
97 return roles::LISTITEM_MARKER;
100 uint64_t HTMLListBulletAccessible::NativeState() const {
101 return LeafAccessible::NativeState() | states::READONLY;
104 already_AddRefed<AccAttributes> HTMLListBulletAccessible::NativeAttributes() {
105 RefPtr<AccAttributes> attributes = new AccAttributes();
106 return attributes.forget();
109 void HTMLListBulletAccessible::AppendTextTo(nsAString& aText,
110 uint32_t aStartOffset,
111 uint32_t aLength) {
112 nsAutoString bulletText;
113 Name(bulletText);
114 aText.Append(Substring(bulletText, aStartOffset, aLength));