EmbeddedObjCollector.cpp (1843B)
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 "LocalAccessible.h" 8 9 using namespace mozilla::a11y; 10 11 uint32_t EmbeddedObjCollector::Count() { 12 EnsureNGetIndex(nullptr); 13 return mObjects.Length(); 14 } 15 16 LocalAccessible* EmbeddedObjCollector::GetAccessibleAt(uint32_t aIndex) { 17 LocalAccessible* accessible = mObjects.SafeElementAt(aIndex, nullptr); 18 if (accessible) return accessible; 19 20 return EnsureNGetObject(aIndex); 21 } 22 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; 28 29 AppendObject(child); 30 if (mObjects.Length() - 1 == aIndex) return mObjects[aIndex]; 31 } 32 33 return nullptr; 34 } 35 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; 41 42 AppendObject(child); 43 if (child == aAccessible) return mObjects.Length() - 1; 44 } 45 46 return -1; 47 } 48 49 int32_t EmbeddedObjCollector::GetIndexAt(LocalAccessible* aAccessible) { 50 if (aAccessible->mParent != mRoot) return -1; 51 52 if (aAccessible->mIndexOfEmbeddedChild != -1) { 53 return aAccessible->mIndexOfEmbeddedChild; 54 } 55 56 return !aAccessible->IsText() ? EnsureNGetIndex(aAccessible) : -1; 57 } 58 59 void EmbeddedObjCollector::AppendObject(LocalAccessible* aAccessible) { 60 aAccessible->mIndexOfEmbeddedChild = mObjects.Length(); 61 mObjects.AppendElement(aAccessible); 62 }