diff --git a/accessible/basetypes/Accessible.cpp b/accessible/basetypes/Accessible.cpp new file mode 100644 index 000000000000..fcf999268063 --- /dev/null +++ b/accessible/basetypes/Accessible.cpp @@ -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(0)), + mGenericTypes(static_cast(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)); +} diff --git a/accessible/basetypes/Accessible.h b/accessible/basetypes/Accessible.h new file mode 100644 index 000000000000..1e402920c9ec --- /dev/null +++ b/accessible/basetypes/Accessible.h @@ -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 +#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 diff --git a/accessible/basetypes/moz.build b/accessible/basetypes/moz.build new file mode 100644 index 000000000000..fe7b1547aea2 --- /dev/null +++ b/accessible/basetypes/moz.build @@ -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"] diff --git a/accessible/generic/LocalAccessible-inl.h b/accessible/generic/LocalAccessible-inl.h index 3555c8cf2cde..40375036a4ad 100644 --- a/accessible/generic/LocalAccessible-inl.h +++ b/accessible/generic/LocalAccessible-inl.h @@ -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; } diff --git a/accessible/generic/LocalAccessible.cpp b/accessible/generic/LocalAccessible.cpp index 47520c646ace..61c9b395d68e 100644 --- a/accessible/generic/LocalAccessible.cpp +++ b/accessible/generic/LocalAccessible.cpp @@ -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!"); } //////////////////////////////////////////////////////////////////////////////// diff --git a/accessible/generic/LocalAccessible.h b/accessible/generic/LocalAccessible.h index c709accaef97..01a8890e0ca2 100644 --- a/accessible/generic/LocalAccessible.h +++ b/accessible/generic/LocalAccessible.h @@ -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, 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; diff --git a/accessible/moz.build b/accessible/moz.build index f0ddf25cb396..f156a4f31c4d 100644 --- a/accessible/moz.build +++ b/accessible/moz.build @@ -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"]