Bumping gaia.json for 2 gaia revision(s) a=gaia-bump
[gecko.git] / accessible / ipc / DocAccessibleChild.cpp
blob678e021a8920d7698653c3a66ab4ab9ff778502b
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"
14 namespace mozilla {
15 namespace a11y {
17 void
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())
28 childCount = 0;
30 aTree.AppendElement(AccessibleData(id, role, childCount));
31 for (uint32_t i = 0; i < childCount; i++)
32 SerializeTree(aRoot->GetChildAt(i), aTree);
35 void
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());
44 SendShowEvent(data);
47 bool
48 DocAccessibleChild::RecvState(const uint64_t& aID, uint64_t* aState)
50 Accessible* acc = mDoc->GetAccessibleByUniqueID((void*)aID);
51 if (!acc) {
52 *aState = states::DEFUNCT;
53 return true;
56 *aState = acc->State();
58 return true;
61 bool
62 DocAccessibleChild::RecvName(const uint64_t& aID, nsString* aName)
64 Accessible* acc = mDoc->GetAccessibleByUniqueID((void*)aID);
65 if (!acc)
66 return true;
68 acc->Name(*aName);
69 return true;
72 bool
73 DocAccessibleChild::RecvDescription(const uint64_t& aID, nsString* aDesc)
75 Accessible* acc = mDoc->GetAccessibleByUniqueID((void*)aID);
76 if (!acc)
77 return true;
79 acc->Description(*aDesc);
80 return true;
83 bool
84 DocAccessibleChild::RecvAttributes(const uint64_t& aID, nsTArray<Attribute>* aAttributes)
86 Accessible* acc = mDoc->GetAccessibleByUniqueID((void*)aID);
87 if (!acc)
88 return true;
90 nsCOMPtr<nsIPersistentProperties> props = acc->Attributes();
91 if (!props)
92 return true;
94 nsCOMPtr<nsISimpleEnumerator> propEnum;
95 nsresult rv = props->Enumerate(getter_AddRefs(propEnum));
96 NS_ENSURE_SUCCESS(rv, false);
98 bool hasMore;
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);
107 nsAutoCString name;
108 rv = propElem->GetKey(name);
109 NS_ENSURE_SUCCESS(rv, false);
111 nsAutoString value;
112 rv = propElem->GetValue(value);
113 NS_ENSURE_SUCCESS(rv, false);
115 aAttributes->AppendElement(Attribute(name, value));
118 return true;