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 "nsAccessibilityService.h"
11 #include "mozilla/a11y/Role.h"
14 #include "nsLayoutUtils.h"
16 using namespace mozilla
;
17 using namespace mozilla::a11y
;
19 ////////////////////////////////////////////////////////////////////////////////
21 ////////////////////////////////////////////////////////////////////////////////
23 role
HTMLListAccessible::NativeRole() const {
24 a11y::role r
= GetAccService()->MarkupRole(mContent
);
25 return r
!= roles::NOTHING
? r
: roles::LIST
;
28 uint64_t HTMLListAccessible::NativeState() const {
29 return HyperTextAccessible::NativeState() | states::READONLY
;
32 ////////////////////////////////////////////////////////////////////////////////
34 ////////////////////////////////////////////////////////////////////////////////
36 HTMLLIAccessible::HTMLLIAccessible(nsIContent
* aContent
, DocAccessible
* aDoc
)
37 : HyperTextAccessible(aContent
, aDoc
) {
41 role
HTMLLIAccessible::NativeRole() const {
42 a11y::role r
= GetAccService()->MarkupRole(mContent
);
43 return r
!= roles::NOTHING
? r
: roles::LISTITEM
;
46 uint64_t HTMLLIAccessible::NativeState() const {
47 return HyperTextAccessible::NativeState() | states::READONLY
;
50 nsRect
HTMLLIAccessible::BoundsInAppUnits() const {
51 nsRect rect
= AccessibleWrap::BoundsInAppUnits();
53 LocalAccessible
* bullet
= Bullet();
54 nsIFrame
* frame
= GetFrame();
55 MOZ_ASSERT(!(bullet
&& !frame
), "Cannot have a bullet if there is no frame");
57 if (bullet
&& frame
&&
58 frame
->StyleList()->mListStylePosition
!=
59 StyleListStylePosition::Inside
) {
60 nsRect bulletRect
= bullet
->BoundsInAppUnits();
61 return rect
.Union(bulletRect
);
67 LocalAccessible
* HTMLLIAccessible::Bullet() const {
68 LocalAccessible
* firstChild
= LocalFirstChild();
69 if (firstChild
&& firstChild
->NativeRole() == roles::LISTITEM_MARKER
) {
76 ////////////////////////////////////////////////////////////////////////////////
77 // HTMLListBulletAccessible
78 ////////////////////////////////////////////////////////////////////////////////
79 HTMLListBulletAccessible::HTMLListBulletAccessible(nsIContent
* aContent
,
81 : LeafAccessible(aContent
, aDoc
) {
82 mGenericTypes
|= eText
;
85 ////////////////////////////////////////////////////////////////////////////////
86 // HTMLListBulletAccessible: LocalAccessible
88 ENameValueFlag
HTMLListBulletAccessible::Name(nsString
& aName
) const {
89 nsLayoutUtils::GetMarkerSpokenText(mContent
, aName
);
93 role
HTMLListBulletAccessible::NativeRole() const {
94 return roles::LISTITEM_MARKER
;
97 uint64_t HTMLListBulletAccessible::NativeState() const {
98 return LeafAccessible::NativeState() | states::READONLY
;
101 already_AddRefed
<AccAttributes
> HTMLListBulletAccessible::NativeAttributes() {
102 RefPtr
<AccAttributes
> attributes
= new AccAttributes();
103 return attributes
.forget();
106 void HTMLListBulletAccessible::AppendTextTo(nsAString
& aText
,
107 uint32_t aStartOffset
,
109 nsAutoString bulletText
;
111 aText
.Append(Substring(bulletText
, aStartOffset
, aLength
));