accessible/src/base/AccCollector.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     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 "AccCollector.h"
     7 #include "Accessible.h"
     9 using namespace mozilla::a11y;
    11 ////////////////////////////////////////////////////////////////////////////////
    12 // nsAccCollector
    13 ////////////////////////////////////////////////////////////////////////////////
    15 AccCollector::
    16   AccCollector(Accessible* aRoot, filters::FilterFuncPtr aFilterFunc) :
    17   mFilterFunc(aFilterFunc), mRoot(aRoot), mRootChildIdx(0)
    18 {
    19 }
    21 AccCollector::~AccCollector()
    22 {
    23 }
    25 uint32_t
    26 AccCollector::Count()
    27 {
    28   EnsureNGetIndex(nullptr);
    29   return mObjects.Length();
    30 }
    32 Accessible*
    33 AccCollector::GetAccessibleAt(uint32_t aIndex)
    34 {
    35   Accessible* accessible = mObjects.SafeElementAt(aIndex, nullptr);
    36   if (accessible)
    37     return accessible;
    39   return EnsureNGetObject(aIndex);
    40 }
    42 int32_t
    43 AccCollector::GetIndexAt(Accessible* aAccessible)
    44 {
    45   int32_t index = mObjects.IndexOf(aAccessible);
    46   if (index != -1)
    47     return index;
    49   return EnsureNGetIndex(aAccessible);
    50 }
    52 ////////////////////////////////////////////////////////////////////////////////
    53 // nsAccCollector protected
    55 Accessible*
    56 AccCollector::EnsureNGetObject(uint32_t aIndex)
    57 {
    58   uint32_t childCount = mRoot->ChildCount();
    59   while (mRootChildIdx < childCount) {
    60     Accessible* child = mRoot->GetChildAt(mRootChildIdx++);
    61     if (!(mFilterFunc(child) & filters::eMatch))
    62       continue;
    64     AppendObject(child);
    65     if (mObjects.Length() - 1 == aIndex)
    66       return mObjects[aIndex];
    67   }
    69   return nullptr;
    70 }
    72 int32_t
    73 AccCollector::EnsureNGetIndex(Accessible* aAccessible)
    74 {
    75   uint32_t childCount = mRoot->ChildCount();
    76   while (mRootChildIdx < childCount) {
    77     Accessible* child = mRoot->GetChildAt(mRootChildIdx++);
    78     if (!(mFilterFunc(child) & filters::eMatch))
    79       continue;
    81     AppendObject(child);
    82     if (child == aAccessible)
    83       return mObjects.Length() - 1;
    84   }
    86   return -1;
    87 }
    89 void
    90 AccCollector::AppendObject(Accessible* aAccessible)
    91 {
    92   mObjects.AppendElement(aAccessible);
    93 }
    95 ////////////////////////////////////////////////////////////////////////////////
    96 // EmbeddedObjCollector
    97 ////////////////////////////////////////////////////////////////////////////////
    99 int32_t
   100 EmbeddedObjCollector::GetIndexAt(Accessible* aAccessible)
   101 {
   102   if (aAccessible->mParent != mRoot)
   103     return -1;
   105   if (aAccessible->mIndexOfEmbeddedChild != -1)
   106     return aAccessible->mIndexOfEmbeddedChild;
   108   return mFilterFunc(aAccessible) & filters::eMatch ?
   109     EnsureNGetIndex(aAccessible) : -1;
   110 }
   112 void
   113 EmbeddedObjCollector::AppendObject(Accessible* aAccessible)
   114 {
   115   aAccessible->mIndexOfEmbeddedChild = mObjects.Length();
   116   mObjects.AppendElement(aAccessible);
   117 }

mercurial