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 "LocalAccessible.h"
9 using namespace mozilla::a11y
;
11 uint32_t EmbeddedObjCollector::Count() {
12 EnsureNGetIndex(nullptr);
13 return mObjects
.Length();
16 LocalAccessible
* EmbeddedObjCollector::GetAccessibleAt(uint32_t aIndex
) {
17 LocalAccessible
* accessible
= mObjects
.SafeElementAt(aIndex
, nullptr);
18 if (accessible
) return accessible
;
20 return EnsureNGetObject(aIndex
);
23 LocalAccessible
* EmbeddedObjCollector::EnsureNGetObject(uint32_t aIndex
) {
24 uint32_t childCount
= mRoot
->ChildCount();
25 while (mRootChildIdx
< childCount
) {
26 LocalAccessible
* child
= mRoot
->LocalChildAt(mRootChildIdx
++);
27 if (child
->IsText()) continue;
30 if (mObjects
.Length() - 1 == aIndex
) return mObjects
[aIndex
];
36 int32_t EmbeddedObjCollector::EnsureNGetIndex(LocalAccessible
* aAccessible
) {
37 uint32_t childCount
= mRoot
->ChildCount();
38 while (mRootChildIdx
< childCount
) {
39 LocalAccessible
* child
= mRoot
->LocalChildAt(mRootChildIdx
++);
40 if (child
->IsText()) continue;
43 if (child
== aAccessible
) return mObjects
.Length() - 1;
49 int32_t EmbeddedObjCollector::GetIndexAt(LocalAccessible
* aAccessible
) {
50 if (aAccessible
->mParent
!= mRoot
) return -1;
52 if (aAccessible
->mIndexOfEmbeddedChild
!= -1) {
53 return aAccessible
->mIndexOfEmbeddedChild
;
56 return !aAccessible
->IsText() ? EnsureNGetIndex(aAccessible
) : -1;
59 void EmbeddedObjCollector::AppendObject(LocalAccessible
* aAccessible
) {
60 aAccessible
->mIndexOfEmbeddedChild
= mObjects
.Length();
61 mObjects
.AppendElement(aAccessible
);