Skip to content

Commit

Permalink
Bug 1737944 - P2: Allow AccAttributes to store a UniquePtr of AccGrou…
Browse files Browse the repository at this point in the history
…pInfo. r=Jamie

Differential Revision: https://phabricator.services.mozilla.com/D134205
  • Loading branch information
eeejay committed Jan 4, 2022
1 parent 1dbe5fa commit 86a0789
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 31 deletions.
9 changes: 8 additions & 1 deletion accessible/base/AccAttributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ void AccAttributes::StringFromValueAndName(nsAtom* aAttrName,
[&aValueString](const RefPtr<AccAttributes>& val) {
aValueString.Assign(u"AccAttributes{...}");
},
[&aValueString](const uint64_t& val) { aValueString.AppendInt(val); });
[&aValueString](const uint64_t& val) { aValueString.AppendInt(val); },
[&aValueString](const UniquePtr<AccGroupInfo>& val) {
aValueString.Assign(u"AccGroupInfo{...}");
});
}

void AccAttributes::Update(AccAttributes* aOther) {
Expand Down Expand Up @@ -147,6 +150,10 @@ void AccAttributes::CopyTo(AccAttributes* aDest) const {
},
[&iter, &aDest](const uint64_t& val) {
aDest->mData.InsertOrUpdate(iter.Key(), AsVariant(val));
},
[](const UniquePtr<AccGroupInfo>& val) {
MOZ_ASSERT_UNREACHABLE(
"Trying to copy an AccAttributes containing an AccGroupInfo");
});
}
}
19 changes: 14 additions & 5 deletions accessible/base/AccAttributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#define AccAttributes_h_

#include "mozilla/ServoStyleConsts.h"
#include "mozilla/a11y/AccGroupInfo.h"
#include "mozilla/Variant.h"
#include "nsTHashMap.h"
#include "nsAtom.h"
Expand Down Expand Up @@ -67,7 +68,7 @@ class AccAttributes {
using AttrValueType =
Variant<bool, float, double, int32_t, RefPtr<nsAtom>, nsTArray<int32_t>,
CSSCoord, FontSize, Color, DeleteEntry, UniquePtr<nsString>,
RefPtr<AccAttributes>, uint64_t>;
RefPtr<AccAttributes>, uint64_t, UniquePtr<AccGroupInfo>>;
static_assert(sizeof(AttrValueType) <= 16);
using AtomVariantMap = nsTHashMap<nsRefPtrHashKey<nsAtom>, AttrValueType>;

Expand All @@ -83,10 +84,11 @@ class AccAttributes {

NS_INLINE_DECL_REFCOUNTING(mozilla::a11y::AccAttributes)

template <typename T,
typename std::enable_if<!std::is_convertible_v<T, nsString> &&
!std::is_convertible_v<T, nsAtom*>,
bool>::type = true>
template <typename T, typename std::enable_if<
!std::is_convertible_v<T, nsString> &&
!std::is_convertible_v<T, AccGroupInfo*> &&
!std::is_convertible_v<T, nsAtom*>,
bool>::type = true>
void SetAttribute(nsAtom* aAttrName, T&& aAttrValue) {
mData.InsertOrUpdate(aAttrName, AsVariant(std::forward<T>(aAttrValue)));
}
Expand All @@ -97,6 +99,11 @@ class AccAttributes {
mData.InsertOrUpdate(aAttrName, AsVariant(std::move(value)));
}

void SetAttribute(nsAtom* aAttrName, AccGroupInfo* aAttrValue) {
UniquePtr<AccGroupInfo> value(aAttrValue);
mData.InsertOrUpdate(aAttrName, AsVariant(std::move(value)));
}

void SetAttributeStringCopy(nsAtom* aAttrName, nsString aAttrValue) {
SetAttribute(aAttrName, std::move(aAttrValue));
}
Expand Down Expand Up @@ -139,6 +146,8 @@ class AccAttributes {

bool HasAttribute(nsAtom* aAttrName) { return mData.Contains(aAttrName); }

bool Remove(nsAtom* aAttrName) { return mData.Remove(aAttrName); }

uint32_t Count() const { return mData.Count(); }

// Update one instance with the entries in another. The supplied AccAttributes
Expand Down
26 changes: 25 additions & 1 deletion accessible/base/AccGroupInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "AccGroupInfo.h"
#include "LocalAccessible-inl.h"
#include "nsAccUtils.h"
#include "TableAccessible.h"

#include "Role.h"
#include "States.h"

using namespace mozilla::a11y;
Expand Down Expand Up @@ -147,6 +147,30 @@ void AccGroupInfo::Update() {
}
}

AccGroupInfo* AccGroupInfo::CreateGroupInfo(
const LocalAccessible* aAccessible) {
mozilla::a11y::role role = aAccessible->Role();
if (role != mozilla::a11y::roles::ROW &&
role != mozilla::a11y::roles::OUTLINEITEM &&
role != mozilla::a11y::roles::OPTION &&
role != mozilla::a11y::roles::LISTITEM &&
role != mozilla::a11y::roles::MENUITEM &&
role != mozilla::a11y::roles::COMBOBOX_OPTION &&
role != mozilla::a11y::roles::RICH_OPTION &&
role != mozilla::a11y::roles::CHECK_RICH_OPTION &&
role != mozilla::a11y::roles::PARENT_MENUITEM &&
role != mozilla::a11y::roles::CHECK_MENU_ITEM &&
role != mozilla::a11y::roles::RADIO_MENU_ITEM &&
role != mozilla::a11y::roles::RADIOBUTTON &&
role != mozilla::a11y::roles::PAGETAB &&
role != mozilla::a11y::roles::COMMENT) {
return nullptr;
}

AccGroupInfo* info = new AccGroupInfo(aAccessible, BaseRole(role));
return info;
}

LocalAccessible* AccGroupInfo::FirstItemOf(const LocalAccessible* aContainer) {
// ARIA tree can be arranged by ARIA groups case #1 (previous sibling of a
// group is a parent) or by aria-level.
Expand Down
33 changes: 9 additions & 24 deletions accessible/base/AccGroupInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,25 @@
#ifndef AccGroupInfo_h_
#define AccGroupInfo_h_

#include "LocalAccessible-inl.h"
#include "nsISupportsImpl.h"
#include "Role.h"

namespace mozilla {
namespace a11y {

class LocalAccessible;

/**
* Calculate and store group information.
*/
class AccGroupInfo {
public:
MOZ_COUNTED_DTOR(AccGroupInfo)

AccGroupInfo() = default;
AccGroupInfo(AccGroupInfo&&) = default;
AccGroupInfo& operator=(AccGroupInfo&&) = default;

/**
* Return 1-based position in the group.
*/
Expand All @@ -41,28 +48,7 @@ class AccGroupInfo {
/**
* Create group info.
*/
static AccGroupInfo* CreateGroupInfo(const LocalAccessible* aAccessible) {
mozilla::a11y::role role = aAccessible->Role();
if (role != mozilla::a11y::roles::ROW &&
role != mozilla::a11y::roles::OUTLINEITEM &&
role != mozilla::a11y::roles::OPTION &&
role != mozilla::a11y::roles::LISTITEM &&
role != mozilla::a11y::roles::MENUITEM &&
role != mozilla::a11y::roles::COMBOBOX_OPTION &&
role != mozilla::a11y::roles::RICH_OPTION &&
role != mozilla::a11y::roles::CHECK_RICH_OPTION &&
role != mozilla::a11y::roles::PARENT_MENUITEM &&
role != mozilla::a11y::roles::CHECK_MENU_ITEM &&
role != mozilla::a11y::roles::RADIO_MENU_ITEM &&
role != mozilla::a11y::roles::RADIOBUTTON &&
role != mozilla::a11y::roles::PAGETAB &&
role != mozilla::a11y::roles::COMMENT) {
return nullptr;
}

AccGroupInfo* info = new AccGroupInfo(aAccessible, BaseRole(role));
return info;
}
static AccGroupInfo* CreateGroupInfo(const LocalAccessible* aAccessible);

/**
* Return a first item for the given container.
Expand All @@ -85,7 +71,6 @@ class AccGroupInfo {
AccGroupInfo(const LocalAccessible* aItem, a11y::role aRole);

private:
AccGroupInfo() = delete;
AccGroupInfo(const AccGroupInfo&) = delete;
AccGroupInfo& operator=(const AccGroupInfo&) = delete;

Expand Down
1 change: 1 addition & 0 deletions accessible/base/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ EXPORTS += ["AccEvent.h", "nsAccessibilityService.h"]

EXPORTS.mozilla.a11y += [
"AccAttributes.h",
"AccGroupInfo.h",
"AccTypes.h",
"CacheConstants.h",
"DocManager.h",
Expand Down
16 changes: 16 additions & 0 deletions accessible/ipc/IPCTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# include "mozilla/a11y/AccTypes.h"
# include "mozilla/a11y/CacheConstants.h"
# include "mozilla/a11y/Role.h"
# include "mozilla/a11y/AccGroupInfo.h"
# include "mozilla/GfxMessageUtils.h"
# include "ipc/EnumSerializer.h"
# include "ipc/IPCMessageUtilsSpecializations.h"
Expand Down Expand Up @@ -72,6 +73,21 @@ struct ParamTraits<mozilla::a11y::DeleteEntry> {
}
};

template <>
struct ParamTraits<mozilla::a11y::AccGroupInfo> {
typedef mozilla::a11y::AccGroupInfo paramType;

static void Write(Message* aMsg, const paramType& aParam) {
MOZ_ASSERT_UNREACHABLE("Cannot serialize AccGroupInfo");
}

static bool Read(const Message* aMsg, PickleIterator* aIter,
paramType* aResult) {
MOZ_ASSERT_UNREACHABLE("Cannot de-serialize AccGroupInfo");
return false;
}
};

template <>
struct ParamTraits<mozilla::a11y::Color> {
typedef mozilla::a11y::Color paramType;
Expand Down

0 comments on commit 86a0789

Please sign in to comment.