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"
20 * This class stores an Accessible* or a ProxyAccessible* in a safe manner
21 * with size sizeof(void*).
23 class AccessibleOrProxy
{
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 {
34 return reinterpret_cast<ProxyAccessible
*>(mBits
& ~IS_PROXY
);
40 bool IsAccessible() const { return !IsProxy(); }
41 Accessible
* AsAccessible() const {
43 return reinterpret_cast<Accessible
*>(mBits
);
49 bool IsNull() const { return mBits
== 0; }
51 uint32_t ChildCount() const {
53 return AsProxy()->ChildrenCount();
56 return AsAccessible()->ChildCount();
60 * Return the child object either an accessible or a proxied accessible at
63 AccessibleOrProxy
ChildAt(uint32_t aIdx
) {
65 return AsProxy()->ChildAt(aIdx
);
68 return AsAccessible()->GetChildAt(aIdx
);
72 * Return the first child object.
74 AccessibleOrProxy
FirstChild() {
76 return AsProxy()->FirstChild();
79 return AsAccessible()->FirstChild();
83 * Return the first child object.
85 AccessibleOrProxy
LastChild() {
87 return AsProxy()->LastChild();
90 return AsAccessible()->LastChild();
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
; }
109 static const uintptr_t IS_PROXY
= 0x1;
113 } // namespace mozilla