Line data Source code
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/. */
6 :
7 : #include "mozilla/a11y/DocAccessibleChildBase.h"
8 : #include "mozilla/a11y/ProxyAccessible.h"
9 :
10 : #include "Accessible-inl.h"
11 :
12 : namespace mozilla {
13 : namespace a11y {
14 :
15 : /* static */ uint32_t
16 0 : DocAccessibleChildBase::InterfacesFor(Accessible* aAcc)
17 : {
18 0 : uint32_t interfaces = 0;
19 0 : if (aAcc->IsHyperText() && aAcc->AsHyperText()->IsTextRole())
20 0 : interfaces |= Interfaces::HYPERTEXT;
21 :
22 0 : if (aAcc->IsLink())
23 0 : interfaces |= Interfaces::HYPERLINK;
24 :
25 0 : if (aAcc->HasNumericValue())
26 0 : interfaces |= Interfaces::VALUE;
27 :
28 0 : if (aAcc->IsImage())
29 0 : interfaces |= Interfaces::IMAGE;
30 :
31 0 : if (aAcc->IsTable()) {
32 0 : interfaces |= Interfaces::TABLE;
33 : }
34 :
35 0 : if (aAcc->IsTableCell())
36 0 : interfaces |= Interfaces::TABLECELL;
37 :
38 0 : if (aAcc->IsDoc())
39 0 : interfaces |= Interfaces::DOCUMENT;
40 :
41 0 : if (aAcc->IsSelect()) {
42 0 : interfaces |= Interfaces::SELECTION;
43 : }
44 :
45 0 : if (aAcc->ActionCount()) {
46 0 : interfaces |= Interfaces::ACTION;
47 : }
48 :
49 0 : return interfaces;
50 : }
51 :
52 : /* static */ void
53 0 : DocAccessibleChildBase::SerializeTree(Accessible* aRoot,
54 : nsTArray<AccessibleData>& aTree)
55 : {
56 0 : uint64_t id = reinterpret_cast<uint64_t>(aRoot->UniqueID());
57 : #if defined(XP_WIN)
58 : int32_t msaaId = AccessibleWrap::GetChildIDFor(aRoot);
59 : #endif
60 0 : uint32_t role = aRoot->Role();
61 0 : uint32_t childCount = aRoot->ChildCount();
62 0 : uint32_t interfaces = InterfacesFor(aRoot);
63 :
64 : // OuterDocAccessibles are special because we don't want to serialize the
65 : // child doc here, we'll call PDocAccessibleConstructor in
66 : // NotificationController.
67 0 : MOZ_ASSERT(!aRoot->IsDoc(), "documents shouldn't be serialized");
68 0 : if (aRoot->IsOuterDoc()) {
69 0 : childCount = 0;
70 : }
71 :
72 : #if defined(XP_WIN)
73 : aTree.AppendElement(AccessibleData(id, msaaId, role, childCount, interfaces));
74 : #else
75 0 : aTree.AppendElement(AccessibleData(id, role, childCount, interfaces));
76 : #endif
77 :
78 0 : for (uint32_t i = 0; i < childCount; i++) {
79 0 : SerializeTree(aRoot->GetChildAt(i), aTree);
80 : }
81 0 : }
82 :
83 : void
84 0 : DocAccessibleChildBase::ShowEvent(AccShowEvent* aShowEvent)
85 : {
86 0 : Accessible* parent = aShowEvent->Parent();
87 0 : uint64_t parentID = parent->IsDoc() ? 0 : reinterpret_cast<uint64_t>(parent->UniqueID());
88 0 : uint32_t idxInParent = aShowEvent->GetAccessible()->IndexInParent();
89 0 : nsTArray<AccessibleData> shownTree;
90 0 : ShowEventData data(parentID, idxInParent, shownTree);
91 0 : SerializeTree(aShowEvent->GetAccessible(), data.NewTree());
92 0 : MaybeSendShowEvent(data, aShowEvent->IsFromUserInput());
93 0 : }
94 :
95 : } // namespace a11y
96 : } // namespace mozilla
97 :
|