Bug 1626988 [wpt PR 22658] - wake lock: Remove WakeLockPermissionDescriptor, use...
[gecko.git] / accessible / base / EmbeddedObjCollector.cpp
blob96d0038d8b0be39ab4fbecfd6ec1191fa0e666b9
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/. */
5 #include "EmbeddedObjCollector.h"
7 #include "Accessible.h"
9 using namespace mozilla::a11y;
11 uint32_t EmbeddedObjCollector::Count() {
12 EnsureNGetIndex(nullptr);
13 return mObjects.Length();
16 Accessible* EmbeddedObjCollector::GetAccessibleAt(uint32_t aIndex) {
17 Accessible* accessible = mObjects.SafeElementAt(aIndex, nullptr);
18 if (accessible) return accessible;
20 return EnsureNGetObject(aIndex);
23 Accessible* EmbeddedObjCollector::EnsureNGetObject(uint32_t aIndex) {
24 uint32_t childCount = mRoot->ChildCount();
25 while (mRootChildIdx < childCount) {
26 Accessible* child = mRoot->GetChildAt(mRootChildIdx++);
27 if (child->IsText()) continue;
29 AppendObject(child);
30 if (mObjects.Length() - 1 == aIndex) return mObjects[aIndex];
33 return nullptr;
36 int32_t EmbeddedObjCollector::EnsureNGetIndex(Accessible* aAccessible) {
37 uint32_t childCount = mRoot->ChildCount();
38 while (mRootChildIdx < childCount) {
39 Accessible* child = mRoot->GetChildAt(mRootChildIdx++);
40 if (child->IsText()) continue;
42 AppendObject(child);
43 if (child == aAccessible) return mObjects.Length() - 1;
46 return -1;
49 int32_t EmbeddedObjCollector::GetIndexAt(Accessible* aAccessible) {
50 if (aAccessible->mParent != mRoot) return -1;
52 MOZ_ASSERT(!aAccessible->IsProxy());
53 if (aAccessible->mInt.mIndexOfEmbeddedChild != -1)
54 return aAccessible->mInt.mIndexOfEmbeddedChild;
56 return !aAccessible->IsText() ? EnsureNGetIndex(aAccessible) : -1;
59 void EmbeddedObjCollector::AppendObject(Accessible* aAccessible) {
60 MOZ_ASSERT(!aAccessible->IsProxy());
61 aAccessible->mInt.mIndexOfEmbeddedChild = mObjects.Length();
62 mObjects.AppendElement(aAccessible);