2016-01-19 15:11:41 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_a11y_AccessibleOrProxy_h
|
|
|
|
#define mozilla_a11y_AccessibleOrProxy_h
|
|
|
|
|
|
|
|
#include "mozilla/a11y/Accessible.h"
|
|
|
|
#include "mozilla/a11y/ProxyAccessible.h"
|
2016-01-22 13:54:59 +03:00
|
|
|
#include "mozilla/a11y/Role.h"
|
2016-01-19 15:11:41 +03:00
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace a11y {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class stores an Accessible* or a ProxyAccessible* in a safe manner
|
|
|
|
* with size sizeof(void*).
|
|
|
|
*/
|
|
|
|
class AccessibleOrProxy
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MOZ_IMPLICIT AccessibleOrProxy(Accessible* aAcc) :
|
|
|
|
mBits(reinterpret_cast<uintptr_t>(aAcc)) {}
|
|
|
|
MOZ_IMPLICIT AccessibleOrProxy(ProxyAccessible* aProxy) :
|
2016-04-04 23:35:55 +03:00
|
|
|
mBits(aProxy ? (reinterpret_cast<uintptr_t>(aProxy) | IS_PROXY) : 0) {}
|
2016-01-19 15:11:41 +03:00
|
|
|
MOZ_IMPLICIT AccessibleOrProxy(decltype(nullptr)) : mBits(0) {}
|
|
|
|
|
|
|
|
bool IsProxy() const { return mBits & IS_PROXY; }
|
|
|
|
ProxyAccessible* AsProxy() const
|
|
|
|
{
|
|
|
|
if (IsProxy()) {
|
|
|
|
return reinterpret_cast<ProxyAccessible*>(mBits & ~IS_PROXY);
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsAccessible() const { return !IsProxy(); }
|
|
|
|
Accessible* AsAccessible() const
|
|
|
|
{
|
|
|
|
if (IsAccessible()) {
|
|
|
|
return reinterpret_cast<Accessible*>(mBits);
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-01-22 11:19:09 +03:00
|
|
|
bool IsNull() const { return mBits == 0; }
|
|
|
|
|
2016-01-22 12:04:08 +03:00
|
|
|
uint32_t ChildCount() const
|
|
|
|
{
|
|
|
|
if (IsProxy()) {
|
|
|
|
return AsProxy()->ChildrenCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
return AsAccessible()->ChildCount();
|
|
|
|
}
|
|
|
|
|
2016-01-22 14:21:54 +03:00
|
|
|
/**
|
|
|
|
* Return the child object either an accessible or a proxied accessible at
|
|
|
|
* the given index.
|
|
|
|
*/
|
|
|
|
AccessibleOrProxy ChildAt(uint32_t aIdx)
|
|
|
|
{
|
|
|
|
if (IsProxy()) {
|
|
|
|
return AsProxy()->ChildAt(aIdx);
|
|
|
|
}
|
|
|
|
|
|
|
|
return AsAccessible()->GetChildAt(aIdx);
|
|
|
|
}
|
|
|
|
|
2016-01-22 14:44:27 +03:00
|
|
|
/**
|
|
|
|
* Return the first child object.
|
|
|
|
*/
|
|
|
|
AccessibleOrProxy FirstChild()
|
|
|
|
{
|
|
|
|
if (IsProxy()) {
|
|
|
|
return AsProxy()->FirstChild();
|
|
|
|
}
|
|
|
|
|
|
|
|
return AsAccessible()->FirstChild();
|
|
|
|
}
|
|
|
|
|
2016-01-22 14:51:45 +03:00
|
|
|
/**
|
|
|
|
* Return the first child object.
|
|
|
|
*/
|
|
|
|
AccessibleOrProxy LastChild()
|
|
|
|
{
|
|
|
|
if (IsProxy()) {
|
|
|
|
return AsProxy()->LastChild();
|
|
|
|
}
|
|
|
|
|
|
|
|
return AsAccessible()->LastChild();
|
|
|
|
}
|
|
|
|
|
2016-01-22 13:54:59 +03:00
|
|
|
role Role() const
|
|
|
|
{
|
|
|
|
if (IsProxy()) {
|
|
|
|
return AsProxy()->Role();
|
|
|
|
}
|
|
|
|
|
|
|
|
return AsAccessible()->Role();
|
|
|
|
}
|
|
|
|
|
2016-03-22 21:53:33 +03:00
|
|
|
AccessibleOrProxy Parent() const;
|
|
|
|
|
2016-01-19 15:11:41 +03:00
|
|
|
// XXX these are implementation details that ideally would not be exposed.
|
|
|
|
uintptr_t Bits() const { return mBits; }
|
|
|
|
void SetBits(uintptr_t aBits) { mBits = aBits; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
uintptr_t mBits;
|
|
|
|
static const uintptr_t IS_PROXY = 0x1;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|