mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 05:41:12 +00:00
Bug 1730096 part 1: Add AccAttributes::Equal to compare attributes in two instances. r=eeejay
This will be used later to check whether text attributes are different between two Accessibles. I added this as a method instead of operator== because callers always hold a pointer to AccAttributes, and *a1 == *a2 is weird and will probably lead to mistakes. This required adding operator== for our value structs. Differential Revision: https://phabricator.services.mozilla.com/D129467
This commit is contained in:
parent
146d799d27
commit
39c9ee45b8
@ -71,3 +71,27 @@ void AccAttributes::Update(AccAttributes* aOther) {
|
||||
iter.Remove();
|
||||
}
|
||||
}
|
||||
|
||||
bool AccAttributes::Equal(const AccAttributes* aOther) const {
|
||||
if (Count() != aOther->Count()) {
|
||||
return false;
|
||||
}
|
||||
for (auto iter = mData.ConstIter(); !iter.Done(); iter.Next()) {
|
||||
const auto otherEntry = aOther->mData.Lookup(iter.Key());
|
||||
if (iter.Data().is<UniquePtr<nsString>>()) {
|
||||
// Because we store nsString in a UniquePtr, we must handle it specially
|
||||
// so we compare the string and not the pointer.
|
||||
if (!otherEntry->is<UniquePtr<nsString>>()) {
|
||||
return false;
|
||||
}
|
||||
const auto& thisStr = iter.Data().as<UniquePtr<nsString>>();
|
||||
const auto& otherStr = otherEntry->as<UniquePtr<nsString>>();
|
||||
if (*thisStr != *otherStr) {
|
||||
return false;
|
||||
}
|
||||
} else if (!otherEntry || iter.Data() != otherEntry.Data()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -29,10 +29,22 @@ namespace a11y {
|
||||
|
||||
struct FontSize {
|
||||
int32_t mValue;
|
||||
|
||||
bool operator==(const FontSize& aOther) const {
|
||||
return mValue == aOther.mValue;
|
||||
}
|
||||
|
||||
bool operator!=(const FontSize& aOther) const {
|
||||
return mValue != aOther.mValue;
|
||||
}
|
||||
};
|
||||
|
||||
struct Color {
|
||||
nscolor mValue;
|
||||
|
||||
bool operator==(const Color& aOther) const { return mValue == aOther.mValue; }
|
||||
|
||||
bool operator!=(const Color& aOther) const { return mValue != aOther.mValue; }
|
||||
};
|
||||
|
||||
// A special type. If an entry has a value of this type, it instructs the
|
||||
@ -40,6 +52,10 @@ struct Color {
|
||||
struct DeleteEntry {
|
||||
DeleteEntry() : mValue(true) {}
|
||||
bool mValue;
|
||||
|
||||
bool operator==(const DeleteEntry& aOther) const { return true; }
|
||||
|
||||
bool operator!=(const DeleteEntry& aOther) const { return false; }
|
||||
};
|
||||
|
||||
class AccAttributes {
|
||||
@ -112,6 +128,12 @@ class AccAttributes {
|
||||
// will be emptied.
|
||||
void Update(AccAttributes* aOther);
|
||||
|
||||
/**
|
||||
* Return true if all the attributes in this instance are equal to all the
|
||||
* attributes in another instance.
|
||||
*/
|
||||
bool Equal(const AccAttributes* aOther) const;
|
||||
|
||||
// An entry class for our iterator.
|
||||
class Entry {
|
||||
public:
|
||||
|
Loading…
Reference in New Issue
Block a user