/* -*- 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/. */
aValue.match(
[&aValueString](constbool& val) {
aValueString.Assign(val ? u"true" : u"false");
},
[&aValueString](constfloat& val) {
aValueString.AppendFloat(val * 100);
aValueString.Append(u"%");
},
[&aValueString](constdouble& val) { aValueString.AppendFloat(val); },
[&aValueString](const int32_t& val) { aValueString.AppendInt(val); },
[&aValueString](const RefPtr<nsAtom>& val) {
val->ToString(aValueString);
},
[&aValueString](const nsTArray<int32_t>& val) { if (const size_t len = val.Length()) { for (size_t i = 0; i < len - 1; i++) {
aValueString.AppendInt(val[i]);
aValueString.Append(u", ");
}
aValueString.AppendInt(val[len - 1]);
} else { // The array is empty
NS_WARNING( "Hmm, should we have used a DeleteEntry() for this instead?");
aValueString.Append(u"[ ]");
}
},
[&aValueString](const CSSCoord& val) {
aValueString.AppendFloat(val);
aValueString.Append(u"px");
},
[&aValueString](const FontSize& val) {
aValueString.AppendInt(val.mValue);
aValueString.Append(u"pt");
},
[&aValueString](const Color& val) {
StyleInfo::FormatColor(val.mValue, aValueString);
},
[&aValueString](const DeleteEntry& val) {
aValueString.Append(u"-delete-entry-");
},
[&aValueString](const UniquePtr<nsString>& val) {
aValueString.Assign(*val);
},
[&aValueString](const RefPtr<AccAttributes>& val) { if (val) {
aValueString.AppendPrintf("AccAttributes: %s",
ToString(*val).c_str());
} else {
aValueString.AssignASCII("");
}
},
[&aValueString](const uint64_t& val) { aValueString.AppendInt(val); },
[&aValueString](const UniquePtr<AccGroupInfo>& val) {
aValueString.Assign(u"AccGroupInfo{...}");
},
[&aValueString](const UniquePtr<gfx::Matrix4x4>& val) {
aValueString.AppendPrintf("Matrix4x4=%s", ToString(*val).c_str());
},
[&aValueString](const nsTArray<uint64_t>& val) { if (const size_t len = val.Length()) { for (size_t i = 0; i < len - 1; i++) {
aValueString.AppendInt(val[i]);
aValueString.Append(u", ");
}
aValueString.AppendInt(val[len - 1]);
} else { // The array is empty
NS_WARNING( "Hmm, should we have used a DeleteEntry() for this instead?");
aValueString.Append(u"[ ]");
}
},
[&aValueString](const nsTArray<TextOffsetAttribute>& val) { if (const size_t len = val.Length()) { for (size_t i = 0; i < len - 1; i++) {
aValueString.AppendPrintf("(%d, %d, ", val[i].mStartOffset,
val[i].mEndOffset);
aValueString.Append(nsAtomString(val[i].mAttribute));
aValueString.Append(u"), ");
}
aValueString.AppendPrintf("(%d, %d, ", val[len - 1].mStartOffset,
val[len - 1].mEndOffset);
aValueString.Append(nsAtomString(val[len - 1].mAttribute));
aValueString += ')';
} else { // The array is empty
NS_WARNING( "Hmm, should we have used a DeleteEntry() for this instead?");
aValueString.Append(u"[ ]");
}
});
}
void AccAttributes::Update(AccAttributes* aOther) { for (auto iter = aOther->mData.Iter(); !iter.Done(); iter.Next()) { if (iter.Data().is<DeleteEntry>()) {
mData.Remove(iter.Key());
} else {
mData.InsertOrUpdate(iter.Key(), std::move(iter.Data()));
}
iter.Remove();
}
}
bool AccAttributes::Equal(const AccAttributes* aOther) const { if (Count() != aOther->Count()) { returnfalse;
} for (auto iter = mData.ConstIter(); !iter.Done(); iter.Next()) { constauto otherEntry = aOther->mData.Lookup(iter.Key()); if (!otherEntry) { returnfalse;
} 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>>()) { returnfalse;
} constauto& thisStr = iter.Data().as<UniquePtr<nsString>>(); constauto& otherStr = otherEntry->as<UniquePtr<nsString>>(); if (*thisStr != *otherStr) { returnfalse;
}
} elseif (iter.Data() != otherEntry.Data()) { returnfalse;
}
} returntrue;
}
void AccAttributes::CopyTo(AccAttributes* aDest) const { for (auto iter = mData.ConstIter(); !iter.Done(); iter.Next()) {
iter.Data().match(
[&iter, &aDest](constbool& val) {
aDest->mData.InsertOrUpdate(iter.Key(), AsVariant(val));
},
[&iter, &aDest](constfloat& val) {
aDest->mData.InsertOrUpdate(iter.Key(), AsVariant(val));
},
[&iter, &aDest](constdouble& val) {
aDest->mData.InsertOrUpdate(iter.Key(), AsVariant(val));
},
[&iter, &aDest](const int32_t& val) {
aDest->mData.InsertOrUpdate(iter.Key(), AsVariant(val));
},
[&iter, &aDest](const RefPtr<nsAtom>& val) {
aDest->mData.InsertOrUpdate(iter.Key(), AsVariant(val));
},
[](const nsTArray<int32_t>& val) { // We don't copy arrays.
MOZ_ASSERT_UNREACHABLE( "Trying to copy an AccAttributes containing an array");
},
[&iter, &aDest](const CSSCoord& val) {
aDest->mData.InsertOrUpdate(iter.Key(), AsVariant(val));
},
[&iter, &aDest](const FontSize& val) {
aDest->mData.InsertOrUpdate(iter.Key(), AsVariant(val));
},
[&iter, &aDest](const Color& val) {
aDest->mData.InsertOrUpdate(iter.Key(), AsVariant(val));
},
[](const DeleteEntry& val) { // We don't copy DeleteEntry.
MOZ_ASSERT_UNREACHABLE( "Trying to copy an AccAttributes containing a DeleteEntry");
},
[&iter, &aDest](const UniquePtr<nsString>& val) {
aDest->SetAttributeStringCopy(iter.Key(), *val);
},
[](const RefPtr<AccAttributes>& val) { // We don't copy nested AccAttributes.
MOZ_ASSERT_UNREACHABLE( "Trying to copy an AccAttributes containing an AccAttributes");
},
[&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");
},
[](const UniquePtr<gfx::Matrix4x4>& val) {
MOZ_ASSERT_UNREACHABLE( "Trying to copy an AccAttributes containing a matrix");
},
[](const nsTArray<uint64_t>& val) { // We don't copy arrays.
MOZ_ASSERT_UNREACHABLE( "Trying to copy an AccAttributes containing an array");
},
[](const nsTArray<TextOffsetAttribute>& val) { // We don't copy arrays.
MOZ_ASSERT_UNREACHABLE( "Trying to copy an AccAttributes containing an array");
});
}
}
// We don't count the size of Name() since it's counted by the atoms table // memory reporter.
if (mValue->is<nsTArray<int32_t>>()) {
size += mValue->as<nsTArray<int32_t>>().ShallowSizeOfExcludingThis(
aMallocSizeOf);
} elseif (mValue->is<UniquePtr<nsString>>()) { // String data will never be shared.
size += mValue->as<UniquePtr<nsString>>()->SizeOfIncludingThisIfUnshared(
aMallocSizeOf);
} elseif (mValue->is<RefPtr<AccAttributes>>()) {
size +=
mValue->as<RefPtr<AccAttributes>>()->SizeOfIncludingThis(aMallocSizeOf);
} elseif (mValue->is<UniquePtr<AccGroupInfo>>()) {
size += mValue->as<UniquePtr<AccGroupInfo>>()->SizeOfIncludingThis(
aMallocSizeOf);
} elseif (mValue->is<UniquePtr<gfx::Matrix4x4>>()) {
size += aMallocSizeOf(mValue->as<UniquePtr<gfx::Matrix4x4>>().get());
} elseif (mValue->is<nsTArray<uint64_t>>()) {
size += mValue->as<nsTArray<uint64_t>>().ShallowSizeOfExcludingThis(
aMallocSizeOf);
} else { // This type is stored directly and already counted or is an atom and // stored and counted in the atoms table. // Assert that we have exhausted all the remaining variant types.
MOZ_ASSERT(mValue->is<RefPtr<nsAtom>>() || mValue->is<bool>() ||
mValue->is<float>() || mValue->is<double>() ||
mValue->is<int32_t>() || mValue->is<uint64_t>() ||
mValue->is<CSSCoord>() || mValue->is<FontSize>() ||
mValue->is<Color>() || mValue->is<DeleteEntry>());
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.