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
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "mozilla/a11y/DocAccessibleChildBase.h"
8 #include "mozilla/a11y/ProxyAccessible.h"
10 #include "Accessible-inl.h"
16 uint32_t DocAccessibleChildBase::InterfacesFor(Accessible
* aAcc
) {
17 uint32_t interfaces
= 0;
18 if (aAcc
->IsHyperText() && aAcc
->AsHyperText()->IsTextRole())
19 interfaces
|= Interfaces::HYPERTEXT
;
21 if (aAcc
->IsLink()) interfaces
|= Interfaces::HYPERLINK
;
23 if (aAcc
->HasNumericValue()) interfaces
|= Interfaces::VALUE
;
25 if (aAcc
->IsImage()) interfaces
|= Interfaces::IMAGE
;
27 if (aAcc
->IsTable()) {
28 interfaces
|= Interfaces::TABLE
;
31 if (aAcc
->IsTableCell()) interfaces
|= Interfaces::TABLECELL
;
33 if (aAcc
->IsDoc()) interfaces
|= Interfaces::DOCUMENT
;
35 if (aAcc
->IsSelect()) {
36 interfaces
|= Interfaces::SELECTION
;
39 if (aAcc
->ActionCount()) {
40 interfaces
|= Interfaces::ACTION
;
47 void DocAccessibleChildBase::SerializeTree(Accessible
* aRoot
,
48 nsTArray
<AccessibleData
>& aTree
) {
49 uint64_t id
= reinterpret_cast<uint64_t>(aRoot
->UniqueID());
51 int32_t msaaId
= AccessibleWrap::GetChildIDFor(aRoot
);
53 a11y::role role
= aRoot
->Role();
54 uint32_t childCount
= aRoot
->ChildCount();
55 uint32_t interfaces
= InterfacesFor(aRoot
);
57 // OuterDocAccessibles are special because we don't want to serialize the
58 // child doc here, we'll call PDocAccessibleConstructor in
59 // NotificationController.
60 MOZ_ASSERT(!aRoot
->IsDoc(), "documents shouldn't be serialized");
61 if (aRoot
->IsOuterDoc()) {
66 aTree
.AppendElement(AccessibleData(id
, msaaId
, role
, childCount
, interfaces
));
68 aTree
.AppendElement(AccessibleData(id
, role
, childCount
, interfaces
));
71 for (uint32_t i
= 0; i
< childCount
; i
++) {
72 SerializeTree(aRoot
->GetChildAt(i
), aTree
);
76 void DocAccessibleChildBase::InsertIntoIpcTree(Accessible
* aParent
,
78 uint32_t aIdxInParent
) {
80 aParent
->IsDoc() ? 0 : reinterpret_cast<uint64_t>(aParent
->UniqueID());
81 nsTArray
<AccessibleData
> shownTree
;
82 ShowEventData
data(parentID
, aIdxInParent
, shownTree
, true);
83 SerializeTree(aChild
, data
.NewTree());
84 MaybeSendShowEvent(data
, false);
87 void DocAccessibleChildBase::ShowEvent(AccShowEvent
* aShowEvent
) {
88 Accessible
* parent
= aShowEvent
->Parent();
90 parent
->IsDoc() ? 0 : reinterpret_cast<uint64_t>(parent
->UniqueID());
91 uint32_t idxInParent
= aShowEvent
->GetAccessible()->IndexInParent();
92 nsTArray
<AccessibleData
> shownTree
;
93 ShowEventData
data(parentID
, idxInParent
, shownTree
, false);
94 SerializeTree(aShowEvent
->GetAccessible(), data
.NewTree());
95 MaybeSendShowEvent(data
, aShowEvent
->IsFromUserInput());
99 } // namespace mozilla