accessible/src/base/AccCollector.cpp

branch
TOR_BUG_9701
changeset 8
97036ab72558
equal deleted inserted replaced
-1:000000000000 0:270be3070cc1
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5 #include "AccCollector.h"
6
7 #include "Accessible.h"
8
9 using namespace mozilla::a11y;
10
11 ////////////////////////////////////////////////////////////////////////////////
12 // nsAccCollector
13 ////////////////////////////////////////////////////////////////////////////////
14
15 AccCollector::
16 AccCollector(Accessible* aRoot, filters::FilterFuncPtr aFilterFunc) :
17 mFilterFunc(aFilterFunc), mRoot(aRoot), mRootChildIdx(0)
18 {
19 }
20
21 AccCollector::~AccCollector()
22 {
23 }
24
25 uint32_t
26 AccCollector::Count()
27 {
28 EnsureNGetIndex(nullptr);
29 return mObjects.Length();
30 }
31
32 Accessible*
33 AccCollector::GetAccessibleAt(uint32_t aIndex)
34 {
35 Accessible* accessible = mObjects.SafeElementAt(aIndex, nullptr);
36 if (accessible)
37 return accessible;
38
39 return EnsureNGetObject(aIndex);
40 }
41
42 int32_t
43 AccCollector::GetIndexAt(Accessible* aAccessible)
44 {
45 int32_t index = mObjects.IndexOf(aAccessible);
46 if (index != -1)
47 return index;
48
49 return EnsureNGetIndex(aAccessible);
50 }
51
52 ////////////////////////////////////////////////////////////////////////////////
53 // nsAccCollector protected
54
55 Accessible*
56 AccCollector::EnsureNGetObject(uint32_t aIndex)
57 {
58 uint32_t childCount = mRoot->ChildCount();
59 while (mRootChildIdx < childCount) {
60 Accessible* child = mRoot->GetChildAt(mRootChildIdx++);
61 if (!(mFilterFunc(child) & filters::eMatch))
62 continue;
63
64 AppendObject(child);
65 if (mObjects.Length() - 1 == aIndex)
66 return mObjects[aIndex];
67 }
68
69 return nullptr;
70 }
71
72 int32_t
73 AccCollector::EnsureNGetIndex(Accessible* aAccessible)
74 {
75 uint32_t childCount = mRoot->ChildCount();
76 while (mRootChildIdx < childCount) {
77 Accessible* child = mRoot->GetChildAt(mRootChildIdx++);
78 if (!(mFilterFunc(child) & filters::eMatch))
79 continue;
80
81 AppendObject(child);
82 if (child == aAccessible)
83 return mObjects.Length() - 1;
84 }
85
86 return -1;
87 }
88
89 void
90 AccCollector::AppendObject(Accessible* aAccessible)
91 {
92 mObjects.AppendElement(aAccessible);
93 }
94
95 ////////////////////////////////////////////////////////////////////////////////
96 // EmbeddedObjCollector
97 ////////////////////////////////////////////////////////////////////////////////
98
99 int32_t
100 EmbeddedObjCollector::GetIndexAt(Accessible* aAccessible)
101 {
102 if (aAccessible->mParent != mRoot)
103 return -1;
104
105 if (aAccessible->mIndexOfEmbeddedChild != -1)
106 return aAccessible->mIndexOfEmbeddedChild;
107
108 return mFilterFunc(aAccessible) & filters::eMatch ?
109 EnsureNGetIndex(aAccessible) : -1;
110 }
111
112 void
113 EmbeddedObjCollector::AppendObject(Accessible* aAccessible)
114 {
115 aAccessible->mIndexOfEmbeddedChild = mObjects.Length();
116 mObjects.AppendElement(aAccessible);
117 }

mercurial