Bug 1568157 - Part 4: Replace `toolbox.walker` with the contextual WalkerFront. r...
[gecko.git] / accessible / base / AccessibleOrProxy.h
blob26a32ff57d1eed5a7d2359bc8172d42a524fb78f
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/. */
7 #ifndef mozilla_a11y_AccessibleOrProxy_h
8 #define mozilla_a11y_AccessibleOrProxy_h
10 #include "mozilla/a11y/Accessible.h"
11 #include "mozilla/a11y/ProxyAccessible.h"
12 #include "mozilla/a11y/Role.h"
14 #include <stdint.h>
16 namespace mozilla {
17 namespace a11y {
19 /**
20 * This class stores an Accessible* or a ProxyAccessible* in a safe manner
21 * with size sizeof(void*).
23 class AccessibleOrProxy {
24 public:
25 MOZ_IMPLICIT AccessibleOrProxy(Accessible* aAcc)
26 : mBits(reinterpret_cast<uintptr_t>(aAcc)) {}
27 MOZ_IMPLICIT AccessibleOrProxy(ProxyAccessible* aProxy)
28 : mBits(aProxy ? (reinterpret_cast<uintptr_t>(aProxy) | IS_PROXY) : 0) {}
29 MOZ_IMPLICIT AccessibleOrProxy(decltype(nullptr)) : mBits(0) {}
31 bool IsProxy() const { return mBits & IS_PROXY; }
32 ProxyAccessible* AsProxy() const {
33 if (IsProxy()) {
34 return reinterpret_cast<ProxyAccessible*>(mBits & ~IS_PROXY);
37 return nullptr;
40 bool IsAccessible() const { return !IsProxy(); }
41 Accessible* AsAccessible() const {
42 if (IsAccessible()) {
43 return reinterpret_cast<Accessible*>(mBits);
46 return nullptr;
49 bool IsNull() const { return mBits == 0; }
51 uint32_t ChildCount() const {
52 if (IsProxy()) {
53 return AsProxy()->ChildrenCount();
56 return AsAccessible()->ChildCount();
59 /**
60 * Return the child object either an accessible or a proxied accessible at
61 * the given index.
63 AccessibleOrProxy ChildAt(uint32_t aIdx) {
64 if (IsProxy()) {
65 return AsProxy()->ChildAt(aIdx);
68 return AsAccessible()->GetChildAt(aIdx);
71 /**
72 * Return the first child object.
74 AccessibleOrProxy FirstChild() {
75 if (IsProxy()) {
76 return AsProxy()->FirstChild();
79 return AsAccessible()->FirstChild();
82 /**
83 * Return the first child object.
85 AccessibleOrProxy LastChild() {
86 if (IsProxy()) {
87 return AsProxy()->LastChild();
90 return AsAccessible()->LastChild();
93 role Role() const {
94 if (IsProxy()) {
95 return AsProxy()->Role();
98 return AsAccessible()->Role();
101 AccessibleOrProxy Parent() const;
103 // XXX these are implementation details that ideally would not be exposed.
104 uintptr_t Bits() const { return mBits; }
105 void SetBits(uintptr_t aBits) { mBits = aBits; }
107 private:
108 uintptr_t mBits;
109 static const uintptr_t IS_PROXY = 0x1;
112 } // namespace a11y
113 } // namespace mozilla
115 #endif