/src/mozilla-central/accessible/base/AccessibleOrProxy.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #ifndef mozilla_a11y_AccessibleOrProxy_h |
8 | | #define mozilla_a11y_AccessibleOrProxy_h |
9 | | |
10 | | #include "mozilla/a11y/Accessible.h" |
11 | | #include "mozilla/a11y/ProxyAccessible.h" |
12 | | #include "mozilla/a11y/Role.h" |
13 | | |
14 | | #include <stdint.h> |
15 | | |
16 | | namespace mozilla { |
17 | | namespace a11y { |
18 | | |
19 | | /** |
20 | | * This class stores an Accessible* or a ProxyAccessible* in a safe manner |
21 | | * with size sizeof(void*). |
22 | | */ |
23 | | class AccessibleOrProxy |
24 | | { |
25 | | public: |
26 | | MOZ_IMPLICIT AccessibleOrProxy(Accessible* aAcc) : |
27 | 0 | mBits(reinterpret_cast<uintptr_t>(aAcc)) {} |
28 | | MOZ_IMPLICIT AccessibleOrProxy(ProxyAccessible* aProxy) : |
29 | 0 | mBits(aProxy ? (reinterpret_cast<uintptr_t>(aProxy) | IS_PROXY) : 0) {} |
30 | 0 | MOZ_IMPLICIT AccessibleOrProxy(decltype(nullptr)) : mBits(0) {} |
31 | | |
32 | 0 | bool IsProxy() const { return mBits & IS_PROXY; } |
33 | | ProxyAccessible* AsProxy() const |
34 | 0 | { |
35 | 0 | if (IsProxy()) { |
36 | 0 | return reinterpret_cast<ProxyAccessible*>(mBits & ~IS_PROXY); |
37 | 0 | } |
38 | 0 | |
39 | 0 | return nullptr; |
40 | 0 | } |
41 | | |
42 | 0 | bool IsAccessible() const { return !IsProxy(); } |
43 | | Accessible* AsAccessible() const |
44 | 0 | { |
45 | 0 | if (IsAccessible()) { |
46 | 0 | return reinterpret_cast<Accessible*>(mBits); |
47 | 0 | } |
48 | 0 | |
49 | 0 | return nullptr; |
50 | 0 | } |
51 | | |
52 | 0 | bool IsNull() const { return mBits == 0; } |
53 | | |
54 | | uint32_t ChildCount() const |
55 | 0 | { |
56 | 0 | if (IsProxy()) { |
57 | 0 | return AsProxy()->ChildrenCount(); |
58 | 0 | } |
59 | 0 | |
60 | 0 | return AsAccessible()->ChildCount(); |
61 | 0 | } |
62 | | |
63 | | /** |
64 | | * Return the child object either an accessible or a proxied accessible at |
65 | | * the given index. |
66 | | */ |
67 | | AccessibleOrProxy ChildAt(uint32_t aIdx) |
68 | 0 | { |
69 | 0 | if (IsProxy()) { |
70 | 0 | return AsProxy()->ChildAt(aIdx); |
71 | 0 | } |
72 | 0 | |
73 | 0 | return AsAccessible()->GetChildAt(aIdx); |
74 | 0 | } |
75 | | |
76 | | /** |
77 | | * Return the first child object. |
78 | | */ |
79 | | AccessibleOrProxy FirstChild() |
80 | 0 | { |
81 | 0 | if (IsProxy()) { |
82 | 0 | return AsProxy()->FirstChild(); |
83 | 0 | } |
84 | 0 | |
85 | 0 | return AsAccessible()->FirstChild(); |
86 | 0 | } |
87 | | |
88 | | /** |
89 | | * Return the first child object. |
90 | | */ |
91 | | AccessibleOrProxy LastChild() |
92 | 0 | { |
93 | 0 | if (IsProxy()) { |
94 | 0 | return AsProxy()->LastChild(); |
95 | 0 | } |
96 | 0 | |
97 | 0 | return AsAccessible()->LastChild(); |
98 | 0 | } |
99 | | |
100 | | role Role() const |
101 | 0 | { |
102 | 0 | if (IsProxy()) { |
103 | 0 | return AsProxy()->Role(); |
104 | 0 | } |
105 | 0 | |
106 | 0 | return AsAccessible()->Role(); |
107 | 0 | } |
108 | | |
109 | | AccessibleOrProxy Parent() const; |
110 | | |
111 | | // XXX these are implementation details that ideally would not be exposed. |
112 | 0 | uintptr_t Bits() const { return mBits; } |
113 | 0 | void SetBits(uintptr_t aBits) { mBits = aBits; } |
114 | | |
115 | | private: |
116 | | uintptr_t mBits; |
117 | | static const uintptr_t IS_PROXY = 0x1; |
118 | | }; |
119 | | |
120 | | } |
121 | | } |
122 | | |
123 | | #endif |