Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/accessible/base/EmbeddedObjCollector.cpp
Line
Count
Source (jump to first uncovered line)
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 "Accessible.h"
8
9
using namespace mozilla::a11y;
10
11
uint32_t
12
EmbeddedObjCollector::Count()
13
0
{
14
0
  EnsureNGetIndex(nullptr);
15
0
  return mObjects.Length();
16
0
}
17
18
Accessible*
19
EmbeddedObjCollector::GetAccessibleAt(uint32_t aIndex)
20
0
{
21
0
  Accessible* accessible = mObjects.SafeElementAt(aIndex, nullptr);
22
0
  if (accessible)
23
0
    return accessible;
24
0
25
0
  return EnsureNGetObject(aIndex);
26
0
}
27
28
Accessible*
29
EmbeddedObjCollector::EnsureNGetObject(uint32_t aIndex)
30
0
{
31
0
  uint32_t childCount = mRoot->ChildCount();
32
0
  while (mRootChildIdx < childCount) {
33
0
    Accessible* child = mRoot->GetChildAt(mRootChildIdx++);
34
0
    if (child->IsText())
35
0
      continue;
36
0
37
0
    AppendObject(child);
38
0
    if (mObjects.Length() - 1 == aIndex)
39
0
      return mObjects[aIndex];
40
0
  }
41
0
42
0
  return nullptr;
43
0
}
44
45
int32_t
46
EmbeddedObjCollector::EnsureNGetIndex(Accessible* aAccessible)
47
0
{
48
0
  uint32_t childCount = mRoot->ChildCount();
49
0
  while (mRootChildIdx < childCount) {
50
0
    Accessible* child = mRoot->GetChildAt(mRootChildIdx++);
51
0
    if (child->IsText())
52
0
      continue;
53
0
54
0
    AppendObject(child);
55
0
    if (child == aAccessible)
56
0
      return mObjects.Length() - 1;
57
0
  }
58
0
59
0
  return -1;
60
0
}
61
62
int32_t
63
EmbeddedObjCollector::GetIndexAt(Accessible* aAccessible)
64
0
{
65
0
  if (aAccessible->mParent != mRoot)
66
0
    return -1;
67
0
68
0
  MOZ_ASSERT(!aAccessible->IsProxy());
69
0
  if (aAccessible->mInt.mIndexOfEmbeddedChild != -1)
70
0
    return aAccessible->mInt.mIndexOfEmbeddedChild;
71
0
72
0
  return !aAccessible->IsText() ?  EnsureNGetIndex(aAccessible) : -1;
73
0
}
74
75
void
76
EmbeddedObjCollector::AppendObject(Accessible* aAccessible)
77
0
{
78
0
  MOZ_ASSERT(!aAccessible->IsProxy());
79
0
  aAccessible->mInt.mIndexOfEmbeddedChild = mObjects.Length();
80
0
  mObjects.AppendElement(aAccessible);
81
0
}