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 "DocAccessibleChild.h"
9 #include "Accessible-inl.h"
11 #include "nsIPersistentProperties2.h"
12 #include "nsISimpleEnumerator.h"
18 SerializeTree(Accessible
* aRoot
, nsTArray
<AccessibleData
>& aTree
)
20 uint64_t id
= reinterpret_cast<uint64_t>(aRoot
->UniqueID());
21 uint32_t role
= aRoot
->Role();
22 uint32_t childCount
= aRoot
->ChildCount();
24 // OuterDocAccessibles are special because we don't want to serialize the
25 // child doc here, we'll call PDocAccessibleConstructor in
26 // NotificationController.
27 if (childCount
== 1 && aRoot
->GetChildAt(0)->IsDoc())
30 aTree
.AppendElement(AccessibleData(id
, role
, childCount
));
31 for (uint32_t i
= 0; i
< childCount
; i
++)
32 SerializeTree(aRoot
->GetChildAt(i
), aTree
);
36 DocAccessibleChild::ShowEvent(AccShowEvent
* aShowEvent
)
38 Accessible
* parent
= aShowEvent
->Parent();
39 uint64_t parentID
= parent
->IsDoc() ? 0 : reinterpret_cast<uint64_t>(parent
->UniqueID());
40 uint32_t idxInParent
= aShowEvent
->GetAccessible()->IndexInParent();
41 nsTArray
<AccessibleData
> shownTree
;
42 ShowEventData
data(parentID
, idxInParent
, shownTree
);
43 SerializeTree(aShowEvent
->GetAccessible(), data
.NewTree());
48 DocAccessibleChild::RecvState(const uint64_t& aID
, uint64_t* aState
)
50 Accessible
* acc
= mDoc
->GetAccessibleByUniqueID((void*)aID
);
52 *aState
= states::DEFUNCT
;
56 *aState
= acc
->State();
62 DocAccessibleChild::RecvName(const uint64_t& aID
, nsString
* aName
)
64 Accessible
* acc
= mDoc
->GetAccessibleByUniqueID((void*)aID
);
73 DocAccessibleChild::RecvDescription(const uint64_t& aID
, nsString
* aDesc
)
75 Accessible
* acc
= mDoc
->GetAccessibleByUniqueID((void*)aID
);
79 acc
->Description(*aDesc
);
84 DocAccessibleChild::RecvAttributes(const uint64_t& aID
, nsTArray
<Attribute
>* aAttributes
)
86 Accessible
* acc
= mDoc
->GetAccessibleByUniqueID((void*)aID
);
90 nsCOMPtr
<nsIPersistentProperties
> props
= acc
->Attributes();
94 nsCOMPtr
<nsISimpleEnumerator
> propEnum
;
95 nsresult rv
= props
->Enumerate(getter_AddRefs(propEnum
));
96 NS_ENSURE_SUCCESS(rv
, false);
99 while (NS_SUCCEEDED(propEnum
->HasMoreElements(&hasMore
)) && hasMore
) {
100 nsCOMPtr
<nsISupports
> sup
;
101 rv
= propEnum
->GetNext(getter_AddRefs(sup
));
102 NS_ENSURE_SUCCESS(rv
, false);
104 nsCOMPtr
<nsIPropertyElement
> propElem(do_QueryInterface(sup
));
105 NS_ENSURE_TRUE(propElem
, false);
108 rv
= propElem
->GetKey(name
);
109 NS_ENSURE_SUCCESS(rv
, false);
112 rv
= propElem
->GetValue(value
);
113 NS_ENSURE_SUCCESS(rv
, false);
115 aAttributes
->AppendElement(Attribute(name
, value
));