2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-05-20 11:40:25 +04:00
|
|
|
|
2016-03-31 00:55:56 +03:00
|
|
|
#include "EmbeddedObjCollector.h"
|
2010-05-20 11:40:25 +04:00
|
|
|
|
2021-02-20 02:14:32 +03:00
|
|
|
#include "LocalAccessible.h"
|
2010-06-21 17:08:27 +04:00
|
|
|
|
2012-08-28 17:13:59 +04:00
|
|
|
using namespace mozilla::a11y;
|
|
|
|
|
2016-03-30 23:11:09 +03:00
|
|
|
uint32_t EmbeddedObjCollector::Count() {
|
2012-07-30 18:20:58 +04:00
|
|
|
EnsureNGetIndex(nullptr);
|
2010-06-21 17:08:27 +04:00
|
|
|
return mObjects.Length();
|
2010-05-20 11:40:25 +04:00
|
|
|
}
|
|
|
|
|
2021-02-20 02:14:32 +03:00
|
|
|
LocalAccessible* EmbeddedObjCollector::GetAccessibleAt(uint32_t aIndex) {
|
|
|
|
LocalAccessible* accessible = mObjects.SafeElementAt(aIndex, nullptr);
|
2010-06-21 17:08:27 +04:00
|
|
|
if (accessible) return accessible;
|
2010-05-20 11:40:25 +04:00
|
|
|
|
2010-06-21 17:08:27 +04:00
|
|
|
return EnsureNGetObject(aIndex);
|
|
|
|
}
|
|
|
|
|
2021-02-20 02:14:32 +03:00
|
|
|
LocalAccessible* EmbeddedObjCollector::EnsureNGetObject(uint32_t aIndex) {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t childCount = mRoot->ChildCount();
|
2010-06-21 17:08:27 +04:00
|
|
|
while (mRootChildIdx < childCount) {
|
2021-02-20 02:14:32 +03:00
|
|
|
LocalAccessible* child = mRoot->LocalChildAt(mRootChildIdx++);
|
2016-03-31 02:20:20 +03:00
|
|
|
if (child->IsText()) continue;
|
2010-06-21 17:08:27 +04:00
|
|
|
|
2010-08-15 15:28:49 +04:00
|
|
|
AppendObject(child);
|
2010-06-21 17:08:27 +04:00
|
|
|
if (mObjects.Length() - 1 == aIndex) return mObjects[aIndex];
|
2010-05-20 11:40:25 +04:00
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2010-05-20 11:40:25 +04:00
|
|
|
}
|
|
|
|
|
2021-02-20 02:14:32 +03:00
|
|
|
int32_t EmbeddedObjCollector::EnsureNGetIndex(LocalAccessible* aAccessible) {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t childCount = mRoot->ChildCount();
|
2010-06-21 17:08:27 +04:00
|
|
|
while (mRootChildIdx < childCount) {
|
2021-02-20 02:14:32 +03:00
|
|
|
LocalAccessible* child = mRoot->LocalChildAt(mRootChildIdx++);
|
2016-03-31 02:20:20 +03:00
|
|
|
if (child->IsText()) continue;
|
2010-06-21 17:08:27 +04:00
|
|
|
|
2010-08-15 15:28:49 +04:00
|
|
|
AppendObject(child);
|
2010-06-21 17:08:27 +04:00
|
|
|
if (child == aAccessible) return mObjects.Length() - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
2010-05-20 11:40:25 +04:00
|
|
|
}
|
2010-08-15 15:28:49 +04:00
|
|
|
|
2021-02-20 02:14:32 +03:00
|
|
|
int32_t EmbeddedObjCollector::GetIndexAt(LocalAccessible* aAccessible) {
|
2010-08-15 15:28:49 +04:00
|
|
|
if (aAccessible->mParent != mRoot) return -1;
|
|
|
|
|
2015-10-08 21:40:31 +03:00
|
|
|
MOZ_ASSERT(!aAccessible->IsProxy());
|
2021-03-02 19:32:24 +03:00
|
|
|
if (aAccessible->mIndexOfEmbeddedChild != -1) {
|
|
|
|
return aAccessible->mIndexOfEmbeddedChild;
|
2021-02-20 02:14:32 +03:00
|
|
|
}
|
2010-08-15 15:28:49 +04:00
|
|
|
|
2016-03-31 02:20:20 +03:00
|
|
|
return !aAccessible->IsText() ? EnsureNGetIndex(aAccessible) : -1;
|
2010-08-15 15:28:49 +04:00
|
|
|
}
|
|
|
|
|
2021-02-20 02:14:32 +03:00
|
|
|
void EmbeddedObjCollector::AppendObject(LocalAccessible* aAccessible) {
|
2015-10-08 21:40:31 +03:00
|
|
|
MOZ_ASSERT(!aAccessible->IsProxy());
|
2021-03-02 19:32:24 +03:00
|
|
|
aAccessible->mIndexOfEmbeddedChild = mObjects.Length();
|
2010-08-15 15:28:49 +04:00
|
|
|
mObjects.AppendElement(aAccessible);
|
|
|
|
}
|