Bug 1694203 - P1: Add Accessible and have LocalAccessible inherit from it. r=Jamie

Differential Revision: https://phabricator.services.mozilla.com/D104913
This commit is contained in:
Eitan Isaacson 2021-03-02 16:32:21 +00:00
parent 95cbdaa064
commit 8e9308e810
7 changed files with 133 additions and 62 deletions

View File

@ -0,0 +1,47 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
#include "Accessible.h"
#include "ARIAMap.h"
using namespace mozilla;
using namespace mozilla::a11y;
Accessible::Accessible()
: mType(static_cast<uint32_t>(0)),
mGenericTypes(static_cast<uint32_t>(0)),
mRoleMapEntryIndex(aria::NO_ROLE_MAP_ENTRY_INDEX) {}
void Accessible::StaticAsserts() const {
static_assert(eLastAccType <= (1 << kTypeBits) - 1,
"Accessible::mType was oversized by eLastAccType!");
static_assert(
eLastAccGenericType <= (1 << kGenericTypesBits) - 1,
"Accessible::mGenericType was oversized by eLastAccGenericType!");
}
const nsRoleMapEntry* Accessible::ARIARoleMap() const {
return aria::GetRoleMapFromIndex(mRoleMapEntryIndex);
}
bool Accessible::HasARIARole() const {
return mRoleMapEntryIndex != aria::NO_ROLE_MAP_ENTRY_INDEX;
}
bool Accessible::IsARIARole(nsAtom* aARIARole) const {
const nsRoleMapEntry* roleMapEntry = ARIARoleMap();
return roleMapEntry && roleMapEntry->Is(aARIARole);
}
bool Accessible::HasStrongARIARole() const {
const nsRoleMapEntry* roleMapEntry = ARIARoleMap();
return roleMapEntry && roleMapEntry->roleRule == kUseMapRole;
}
bool Accessible::HasGenericType(AccGenericType aType) const {
const nsRoleMapEntry* roleMapEntry = ARIARoleMap();
return (mGenericTypes & aType) ||
(roleMapEntry && roleMapEntry->IsOfType(aType));
}

View File

@ -0,0 +1,57 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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 _Accessible_H_
#define _Accessible_H_
#include <stdint.h>
#include "mozilla/a11y/Role.h"
#include "mozilla/a11y/AccTypes.h"
class nsAtom;
struct nsRoleMapEntry;
namespace mozilla {
namespace a11y {
class Accessible {
protected:
Accessible();
public:
/**
* Return ARIA role map if any.
*/
const nsRoleMapEntry* ARIARoleMap() const;
/**
* Return true if ARIA role is specified on the element.
*/
bool HasARIARole() const;
bool IsARIARole(nsAtom* aARIARole) const;
bool HasStrongARIARole() const;
/**
* Return true if the accessible belongs to the given accessible type.
*/
bool HasGenericType(AccGenericType aType) const;
private:
static const uint8_t kTypeBits = 6;
static const uint8_t kGenericTypesBits = 16;
void StaticAsserts() const;
protected:
uint32_t mType : kTypeBits;
uint32_t mGenericTypes : kGenericTypesBits;
uint8_t mRoleMapEntryIndex;
};
} // namespace a11y
} // namespace mozilla
#endif

View File

@ -0,0 +1,24 @@
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# 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/.
EXPORTS.mozilla.a11y += [
"Accessible.h",
]
UNIFIED_SOURCES += [
"Accessible.cpp",
]
LOCAL_INCLUDES += [
"/accessible/base",
]
FINAL_LIBRARY = "xul"
include("/ipc/chromium/chromium-config.mozbuild")
if CONFIG["CC_TYPE"] in ("clang", "gcc"):
CXXFLAGS += ["-Wno-error=shadow"]

View File

@ -29,24 +29,6 @@ inline mozilla::a11y::role LocalAccessible::Role() const {
return ARIATransformRole(roleMapEntry->role);
}
inline bool LocalAccessible::HasARIARole() const {
return mRoleMapEntryIndex != aria::NO_ROLE_MAP_ENTRY_INDEX;
}
inline bool LocalAccessible::IsARIARole(nsAtom* aARIARole) const {
const nsRoleMapEntry* roleMapEntry = ARIARoleMap();
return roleMapEntry && roleMapEntry->Is(aARIARole);
}
inline bool LocalAccessible::HasStrongARIARole() const {
const nsRoleMapEntry* roleMapEntry = ARIARoleMap();
return roleMapEntry && roleMapEntry->roleRule == kUseMapRole;
}
inline const nsRoleMapEntry* LocalAccessible::ARIARoleMap() const {
return aria::GetRoleMapFromIndex(mRoleMapEntryIndex);
}
inline mozilla::a11y::role LocalAccessible::ARIARole() {
const nsRoleMapEntry* roleMapEntry = ARIARoleMap();
if (!roleMapEntry || roleMapEntry->roleRule != kUseMapRole) {
@ -69,12 +51,6 @@ inline bool LocalAccessible::IsSearchbox() const {
nsGkAtoms::search, eCaseMatters));
}
inline bool LocalAccessible::HasGenericType(AccGenericType aType) const {
const nsRoleMapEntry* roleMapEntry = ARIARoleMap();
return (mGenericTypes & aType) ||
(roleMapEntry && roleMapEntry->IsOfType(aType));
}
inline bool LocalAccessible::NativeHasNumericValue() const {
return mStateFlags & eHasNumericValue;
}

View File

@ -105,15 +105,13 @@ NS_IMPL_CYCLE_COLLECTING_ADDREF(LocalAccessible)
NS_IMPL_CYCLE_COLLECTING_RELEASE_WITH_DESTROY(LocalAccessible, LastRelease())
LocalAccessible::LocalAccessible(nsIContent* aContent, DocAccessible* aDoc)
: mContent(aContent),
: Accessible(),
mContent(aContent),
mDoc(aDoc),
mParent(nullptr),
mIndexInParent(-1),
mRoleMapEntryIndex(aria::NO_ROLE_MAP_ENTRY_INDEX),
mStateFlags(0),
mContextFlags(0),
mType(0),
mGenericTypes(0),
mReorderEventTarget(false),
mShowEventTarget(false),
mHideEventTarget(false) {
@ -2783,14 +2781,9 @@ void LocalAccessible::StaticAsserts() const {
static_assert(
eLastStateFlag <= (1 << kStateFlagsBits) - 1,
"LocalAccessible::mStateFlags was oversized by eLastStateFlag!");
static_assert(eLastAccType <= (1 << kTypeBits) - 1,
"LocalAccessible::mType was oversized by eLastAccType!");
static_assert(
eLastContextFlag <= (1 << kContextFlagsBits) - 1,
"LocalAccessible::mContextFlags was oversized by eLastContextFlag!");
static_assert(
eLastAccGenericType <= (1 << kGenericTypesBits) - 1,
"LocalAccessible::mGenericType was oversized by eLastAccGenericType!");
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -6,6 +6,7 @@
#ifndef _LocalAccessible_H_
#define _LocalAccessible_H_
#include "mozilla/a11y/Accessible.h"
#include "mozilla/a11y/AccTypes.h"
#include "mozilla/a11y/RelationType.h"
#include "mozilla/a11y/Role.h"
@ -130,7 +131,7 @@ typedef nsRefPtrHashtable<nsPtrHashKey<const void>, LocalAccessible>
} \
}
class LocalAccessible : public nsISupports {
class LocalAccessible : public nsISupports, public Accessible {
public:
LocalAccessible(nsIContent* aContent, DocAccessible* aDoc);
@ -217,18 +218,6 @@ class LocalAccessible : public nsISupports {
*/
mozilla::a11y::role Role() const;
/**
* Return true if ARIA role is specified on the element.
*/
bool HasARIARole() const;
bool IsARIARole(nsAtom* aARIARole) const;
bool HasStrongARIARole() const;
/**
* Retrun ARIA role map if any.
*/
const nsRoleMapEntry* ARIARoleMap() const;
/**
* Return accessible role specified by ARIA (see constants in
* roles).
@ -672,11 +661,6 @@ class LocalAccessible : public nsISupports {
bool IsXULTree() const { return mType == eXULTreeType; }
XULTreeAccessible* AsXULTree();
/**
* Return true if the accessible belongs to the given accessible type.
*/
bool HasGenericType(AccGenericType aType) const;
//////////////////////////////////////////////////////////////////////////////
// ActionAccessible
@ -1168,22 +1152,12 @@ class LocalAccessible : public nsISupports {
static const uint8_t kStateFlagsBits = 11;
static const uint8_t kContextFlagsBits = 3;
static const uint8_t kTypeBits = 6;
static const uint8_t kGenericTypesBits = 16;
/**
* Non-NO_ROLE_MAP_ENTRY_INDEX indicates author-supplied role;
* possibly state & value as well
*/
uint8_t mRoleMapEntryIndex;
/**
* Keep in sync with StateFlags, ContextFlags, and AccTypes.
*/
mutable uint32_t mStateFlags : kStateFlagsBits;
uint32_t mContextFlags : kContextFlagsBits;
uint32_t mType : kTypeBits;
uint32_t mGenericTypes : kGenericTypesBits;
uint32_t mReorderEventTarget : 1;
uint32_t mShowEventTarget : 1;
uint32_t mHideEventTarget : 1;

View File

@ -17,7 +17,7 @@ elif toolkit == "android":
else:
DIRS += ["other"]
DIRS += ["aom", "base", "generic", "html", "interfaces", "ipc", "xpcom"]
DIRS += ["aom", "base", "basetypes", "generic", "html", "interfaces", "ipc", "xpcom"]
if CONFIG["MOZ_XUL"]:
DIRS += ["xul"]