1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/accessible/src/base/AccCollector.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,117 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#include "AccCollector.h" 1.9 + 1.10 +#include "Accessible.h" 1.11 + 1.12 +using namespace mozilla::a11y; 1.13 + 1.14 +//////////////////////////////////////////////////////////////////////////////// 1.15 +// nsAccCollector 1.16 +//////////////////////////////////////////////////////////////////////////////// 1.17 + 1.18 +AccCollector:: 1.19 + AccCollector(Accessible* aRoot, filters::FilterFuncPtr aFilterFunc) : 1.20 + mFilterFunc(aFilterFunc), mRoot(aRoot), mRootChildIdx(0) 1.21 +{ 1.22 +} 1.23 + 1.24 +AccCollector::~AccCollector() 1.25 +{ 1.26 +} 1.27 + 1.28 +uint32_t 1.29 +AccCollector::Count() 1.30 +{ 1.31 + EnsureNGetIndex(nullptr); 1.32 + return mObjects.Length(); 1.33 +} 1.34 + 1.35 +Accessible* 1.36 +AccCollector::GetAccessibleAt(uint32_t aIndex) 1.37 +{ 1.38 + Accessible* accessible = mObjects.SafeElementAt(aIndex, nullptr); 1.39 + if (accessible) 1.40 + return accessible; 1.41 + 1.42 + return EnsureNGetObject(aIndex); 1.43 +} 1.44 + 1.45 +int32_t 1.46 +AccCollector::GetIndexAt(Accessible* aAccessible) 1.47 +{ 1.48 + int32_t index = mObjects.IndexOf(aAccessible); 1.49 + if (index != -1) 1.50 + return index; 1.51 + 1.52 + return EnsureNGetIndex(aAccessible); 1.53 +} 1.54 + 1.55 +//////////////////////////////////////////////////////////////////////////////// 1.56 +// nsAccCollector protected 1.57 + 1.58 +Accessible* 1.59 +AccCollector::EnsureNGetObject(uint32_t aIndex) 1.60 +{ 1.61 + uint32_t childCount = mRoot->ChildCount(); 1.62 + while (mRootChildIdx < childCount) { 1.63 + Accessible* child = mRoot->GetChildAt(mRootChildIdx++); 1.64 + if (!(mFilterFunc(child) & filters::eMatch)) 1.65 + continue; 1.66 + 1.67 + AppendObject(child); 1.68 + if (mObjects.Length() - 1 == aIndex) 1.69 + return mObjects[aIndex]; 1.70 + } 1.71 + 1.72 + return nullptr; 1.73 +} 1.74 + 1.75 +int32_t 1.76 +AccCollector::EnsureNGetIndex(Accessible* aAccessible) 1.77 +{ 1.78 + uint32_t childCount = mRoot->ChildCount(); 1.79 + while (mRootChildIdx < childCount) { 1.80 + Accessible* child = mRoot->GetChildAt(mRootChildIdx++); 1.81 + if (!(mFilterFunc(child) & filters::eMatch)) 1.82 + continue; 1.83 + 1.84 + AppendObject(child); 1.85 + if (child == aAccessible) 1.86 + return mObjects.Length() - 1; 1.87 + } 1.88 + 1.89 + return -1; 1.90 +} 1.91 + 1.92 +void 1.93 +AccCollector::AppendObject(Accessible* aAccessible) 1.94 +{ 1.95 + mObjects.AppendElement(aAccessible); 1.96 +} 1.97 + 1.98 +//////////////////////////////////////////////////////////////////////////////// 1.99 +// EmbeddedObjCollector 1.100 +//////////////////////////////////////////////////////////////////////////////// 1.101 + 1.102 +int32_t 1.103 +EmbeddedObjCollector::GetIndexAt(Accessible* aAccessible) 1.104 +{ 1.105 + if (aAccessible->mParent != mRoot) 1.106 + return -1; 1.107 + 1.108 + if (aAccessible->mIndexOfEmbeddedChild != -1) 1.109 + return aAccessible->mIndexOfEmbeddedChild; 1.110 + 1.111 + return mFilterFunc(aAccessible) & filters::eMatch ? 1.112 + EnsureNGetIndex(aAccessible) : -1; 1.113 +} 1.114 + 1.115 +void 1.116 +EmbeddedObjCollector::AppendObject(Accessible* aAccessible) 1.117 +{ 1.118 + aAccessible->mIndexOfEmbeddedChild = mObjects.Length(); 1.119 + mObjects.AppendElement(aAccessible); 1.120 +}