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
|
|
|
|
2012-05-29 05:18:45 +04:00
|
|
|
#include "Accessible.h"
|
2010-06-21 17:08:27 +04:00
|
|
|
|
2012-08-28 17:13:59 +04:00
|
|
|
using namespace mozilla::a11y;
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t
|
2016-03-30 23:11:09 +03:00
|
|
|
EmbeddedObjCollector::Count()
|
2010-06-21 17:08:27 +04:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2012-05-29 05:18:45 +04:00
|
|
|
Accessible*
|
2016-03-30 23:26:47 +03:00
|
|
|
EmbeddedObjCollector::GetAccessibleAt(uint32_t aIndex)
|
2010-05-20 11:40:25 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
Accessible* 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);
|
|
|
|
}
|
|
|
|
|
2012-05-29 05:18:45 +04:00
|
|
|
Accessible*
|
2016-03-30 23:40:34 +03:00
|
|
|
EmbeddedObjCollector::EnsureNGetObject(uint32_t aIndex)
|
2010-06-21 17:08:27 +04:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t childCount = mRoot->ChildCount();
|
2010-06-21 17:08:27 +04:00
|
|
|
while (mRootChildIdx < childCount) {
|
2012-05-29 05:18:45 +04:00
|
|
|
Accessible* child = mRoot->GetChildAt(mRootChildIdx++);
|
2016-03-31 02:20:20 +03:00
|
|
|
if (child->IsText())
|
2010-06-21 17:08:27 +04:00
|
|
|
continue;
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t
|
2016-03-30 23:43:19 +03:00
|
|
|
EmbeddedObjCollector::EnsureNGetIndex(Accessible* aAccessible)
|
2010-05-20 11:40:25 +04:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t childCount = mRoot->ChildCount();
|
2010-06-21 17:08:27 +04:00
|
|
|
while (mRootChildIdx < childCount) {
|
2012-05-29 05:18:45 +04:00
|
|
|
Accessible* child = mRoot->GetChildAt(mRootChildIdx++);
|
2016-03-31 02:20:20 +03:00
|
|
|
if (child->IsText())
|
2010-06-21 17:08:27 +04:00
|
|
|
continue;
|
|
|
|
|
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
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t
|
2012-05-29 05:18:45 +04:00
|
|
|
EmbeddedObjCollector::GetIndexAt(Accessible* 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());
|
|
|
|
if (aAccessible->mInt.mIndexOfEmbeddedChild != -1)
|
|
|
|
return aAccessible->mInt.mIndexOfEmbeddedChild;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-05-29 05:18:45 +04:00
|
|
|
EmbeddedObjCollector::AppendObject(Accessible* aAccessible)
|
2010-08-15 15:28:49 +04:00
|
|
|
{
|
2015-10-08 21:40:31 +03:00
|
|
|
MOZ_ASSERT(!aAccessible->IsProxy());
|
|
|
|
aAccessible->mInt.mIndexOfEmbeddedChild = mObjects.Length();
|
2010-08-15 15:28:49 +04:00
|
|
|
mObjects.AppendElement(aAccessible);
|
|
|
|
}
|