Line data Source code
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 "EmbeddedObjCollector.h"
6 :
7 : #include "Accessible.h"
8 :
9 : using namespace mozilla::a11y;
10 :
11 : uint32_t
12 0 : EmbeddedObjCollector::Count()
13 : {
14 0 : EnsureNGetIndex(nullptr);
15 0 : return mObjects.Length();
16 : }
17 :
18 : Accessible*
19 0 : EmbeddedObjCollector::GetAccessibleAt(uint32_t aIndex)
20 : {
21 0 : Accessible* accessible = mObjects.SafeElementAt(aIndex, nullptr);
22 0 : if (accessible)
23 0 : return accessible;
24 :
25 0 : return EnsureNGetObject(aIndex);
26 : }
27 :
28 : Accessible*
29 0 : EmbeddedObjCollector::EnsureNGetObject(uint32_t aIndex)
30 : {
31 0 : uint32_t childCount = mRoot->ChildCount();
32 0 : while (mRootChildIdx < childCount) {
33 0 : Accessible* child = mRoot->GetChildAt(mRootChildIdx++);
34 0 : if (child->IsText())
35 0 : continue;
36 :
37 0 : AppendObject(child);
38 0 : if (mObjects.Length() - 1 == aIndex)
39 0 : return mObjects[aIndex];
40 : }
41 :
42 0 : return nullptr;
43 : }
44 :
45 : int32_t
46 0 : EmbeddedObjCollector::EnsureNGetIndex(Accessible* aAccessible)
47 : {
48 0 : uint32_t childCount = mRoot->ChildCount();
49 0 : while (mRootChildIdx < childCount) {
50 0 : Accessible* child = mRoot->GetChildAt(mRootChildIdx++);
51 0 : if (child->IsText())
52 0 : continue;
53 :
54 0 : AppendObject(child);
55 0 : if (child == aAccessible)
56 0 : return mObjects.Length() - 1;
57 : }
58 :
59 0 : return -1;
60 : }
61 :
62 : int32_t
63 0 : EmbeddedObjCollector::GetIndexAt(Accessible* aAccessible)
64 : {
65 0 : if (aAccessible->mParent != mRoot)
66 0 : return -1;
67 :
68 0 : MOZ_ASSERT(!aAccessible->IsProxy());
69 0 : if (aAccessible->mInt.mIndexOfEmbeddedChild != -1)
70 0 : return aAccessible->mInt.mIndexOfEmbeddedChild;
71 :
72 0 : return !aAccessible->IsText() ? EnsureNGetIndex(aAccessible) : -1;
73 : }
74 :
75 : void
76 0 : EmbeddedObjCollector::AppendObject(Accessible* aAccessible)
77 : {
78 0 : MOZ_ASSERT(!aAccessible->IsProxy());
79 0 : aAccessible->mInt.mIndexOfEmbeddedChild = mObjects.Length();
80 0 : mObjects.AppendElement(aAccessible);
81 0 : }
|