From 0b986179c40e9dd05b385856786d9e3cdc612c1f Mon Sep 17 00:00:00 2001 From: James Teh Date: Wed, 6 Oct 2021 10:13:08 +0000 Subject: [PATCH] Bug 1730088 part 1: Add hyperTextAccessibleBase class. r=eeejay This will contain methods that can be used for both local and remote Accessibles. It is inherited into both HyperTextAccessible (local) and RemoteAccessibleBase. Differential Revision: https://phabricator.services.mozilla.com/D127206 --- accessible/basetypes/Accessible.h | 3 +++ .../basetypes/HyperTextAccessibleBase.h | 21 +++++++++++++++++++ accessible/basetypes/moz.build | 1 + accessible/generic/HyperTextAccessible.h | 14 ++++++------- accessible/generic/LocalAccessible.h | 2 ++ accessible/ipc/RemoteAccessibleBase.cpp | 3 --- accessible/ipc/RemoteAccessibleBase.h | 8 ++++++- 7 files changed, 41 insertions(+), 11 deletions(-) create mode 100644 accessible/basetypes/HyperTextAccessibleBase.h diff --git a/accessible/basetypes/Accessible.h b/accessible/basetypes/Accessible.h index cd5d1474eb4f..b5ed42b11050 100644 --- a/accessible/basetypes/Accessible.h +++ b/accessible/basetypes/Accessible.h @@ -18,6 +18,7 @@ struct nsRoleMapEntry; namespace mozilla { namespace a11y { +class HyperTextAccessibleBase; class LocalAccessible; class RemoteAccessible; @@ -252,6 +253,8 @@ class Accessible { bool IsLocal() { return !IsRemote(); } LocalAccessible* AsLocal(); + virtual HyperTextAccessibleBase* AsHyperTextBase() { return nullptr; } + private: static const uint8_t kTypeBits = 6; static const uint8_t kGenericTypesBits = 18; diff --git a/accessible/basetypes/HyperTextAccessibleBase.h b/accessible/basetypes/HyperTextAccessibleBase.h new file mode 100644 index 000000000000..491107b737c5 --- /dev/null +++ b/accessible/basetypes/HyperTextAccessibleBase.h @@ -0,0 +1,21 @@ +/* -*- 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 _HyperTextAccessibleBase_H_ +#define _HyperTextAccessibleBase_H_ + +namespace mozilla::a11y { + +// This character marks where in the text returned via Text interface, +// that embedded object characters exist +const char16_t kEmbeddedObjectChar = 0xfffc; +const char16_t kImaginaryEmbeddedObjectChar = ' '; +const char16_t kForcedNewLineChar = '\n'; + +class HyperTextAccessibleBase {}; + +} // namespace mozilla::a11y + +#endif diff --git a/accessible/basetypes/moz.build b/accessible/basetypes/moz.build index fe7b1547aea2..bdefd1fa95d7 100644 --- a/accessible/basetypes/moz.build +++ b/accessible/basetypes/moz.build @@ -6,6 +6,7 @@ EXPORTS.mozilla.a11y += [ "Accessible.h", + "HyperTextAccessibleBase.h", ] UNIFIED_SOURCES += [ diff --git a/accessible/generic/HyperTextAccessible.h b/accessible/generic/HyperTextAccessible.h index 72ea781935a3..b98390b3c345 100644 --- a/accessible/generic/HyperTextAccessible.h +++ b/accessible/generic/HyperTextAccessible.h @@ -7,6 +7,7 @@ #define mozilla_a11y_HyperTextAccessible_h__ #include "AccessibleWrap.h" +#include "mozilla/a11y/HyperTextAccessibleBase.h" #include "nsIAccessibleText.h" #include "nsIAccessibleTypes.h" #include "nsIFrame.h" // only for nsSelectionAmount @@ -38,16 +39,11 @@ struct DOMPoint { int32_t idx; }; -// This character marks where in the text returned via Text interface, -// that embedded object characters exist -const char16_t kEmbeddedObjectChar = 0xfffc; -const char16_t kImaginaryEmbeddedObjectChar = ' '; -const char16_t kForcedNewLineChar = '\n'; - /** * Special Accessible that knows how contain both text and embedded objects */ -class HyperTextAccessible : public AccessibleWrap { +class HyperTextAccessible : public HyperTextAccessibleBase, + public AccessibleWrap { public: HyperTextAccessible(nsIContent* aContent, DocAccessible* aDoc); @@ -561,6 +557,10 @@ inline HyperTextAccessible* LocalAccessible::AsHyperText() { return IsHyperText() ? static_cast(this) : nullptr; } +inline HyperTextAccessibleBase* LocalAccessible::AsHyperTextBase() { + return AsHyperText(); +} + } // namespace a11y } // namespace mozilla diff --git a/accessible/generic/LocalAccessible.h b/accessible/generic/LocalAccessible.h index c88a57ebb826..8cf5d9033f69 100644 --- a/accessible/generic/LocalAccessible.h +++ b/accessible/generic/LocalAccessible.h @@ -44,6 +44,7 @@ class HTMLImageMapAccessible; class HTMLLIAccessible; class HTMLLinkAccessible; class HyperTextAccessible; +class HyperTextAccessibleBase; class ImageAccessible; class KeyBinding; class OuterDocAccessible; @@ -529,6 +530,7 @@ class LocalAccessible : public nsISupports, public Accessible { DocAccessible* AsDoc(); HyperTextAccessible* AsHyperText(); + virtual HyperTextAccessibleBase* AsHyperTextBase() override; HTMLLIAccessible* AsHTMLListItem(); diff --git a/accessible/ipc/RemoteAccessibleBase.cpp b/accessible/ipc/RemoteAccessibleBase.cpp index abb0ef6f580a..2c6bbbb7294d 100644 --- a/accessible/ipc/RemoteAccessibleBase.cpp +++ b/accessible/ipc/RemoteAccessibleBase.cpp @@ -7,9 +7,6 @@ #include "DocAccessible.h" #include "mozilla/a11y/DocAccessibleParent.h" #include "mozilla/a11y/DocManager.h" -// XXX HyperTextAccessible.h is needed for kEmbeddedObjectChar, etc. These -// constants will be moved to HyperTextAccessibleBase soon. -#include "mozilla/a11y/HyperTextAccessible.h" #include "mozilla/a11y/Platform.h" #include "mozilla/a11y/RemoteAccessibleBase.h" #include "mozilla/a11y/RemoteAccessible.h" diff --git a/accessible/ipc/RemoteAccessibleBase.h b/accessible/ipc/RemoteAccessibleBase.h index 6be316ad8dfe..08ec511f9731 100644 --- a/accessible/ipc/RemoteAccessibleBase.h +++ b/accessible/ipc/RemoteAccessibleBase.h @@ -9,6 +9,7 @@ #include "mozilla/a11y/Accessible.h" #include "mozilla/a11y/CacheConstants.h" +#include "mozilla/a11y/HyperTextAccessibleBase.h" #include "mozilla/a11y/Role.h" #include "AccAttributes.h" #include "nsIAccessibleText.h" @@ -26,7 +27,7 @@ class RemoteAccessible; enum class RelationType; template -class RemoteAccessibleBase : public Accessible { +class RemoteAccessibleBase : public Accessible, public HyperTextAccessibleBase { public: virtual ~RemoteAccessibleBase() { MOZ_ASSERT(!mWrapper); } @@ -217,6 +218,11 @@ class RemoteAccessibleBase : public Accessible { uint32_t GetCachedTextLength(); Maybe&> GetCachedTextLines(); + virtual HyperTextAccessibleBase* AsHyperTextBase() override { + return IsHyperText() ? static_cast(this) + : nullptr; + } + protected: RemoteAccessibleBase(uint64_t aID, Derived* aParent, DocAccessibleParent* aDoc, role aRole, AccType aType,