Bug 1089417 patch 4 - Define equality operators on nsMediaQueryResultCacheKey and the types it contains. r=heycam

This is needed for the equality comparison in
nsCSSRuleProcessor::MediumFeaturesChanged in patch 8.
This commit is contained in:
L. David Baron 2014-12-05 11:37:38 -08:00
parent 9beeb100fc
commit afa637c492

View File

@ -37,7 +37,16 @@ struct nsMediaExpression {
// aActualValue must be obtained from mFeature->mGetter
bool Matches(nsPresContext* aPresContext,
const nsCSSValue& aActualValue) const;
const nsCSSValue& aActualValue) const;
bool operator==(const nsMediaExpression& aOther) const {
return mFeature == aOther.mFeature && // pointer equality fine (atom-like)
mRange == aOther.mRange &&
mValue == aOther.mValue;
}
bool operator!=(const nsMediaExpression& aOther) const {
return !(*this == aOther);
}
};
/**
@ -73,6 +82,18 @@ public:
void AddExpression(const nsMediaExpression* aExpression,
bool aExpressionMatches);
bool Matches(nsPresContext* aPresContext) const;
/**
* An operator== that implements list equality, which isn't quite as
* good as set equality, but catches the trivial equality cases.
*/
bool operator==(const nsMediaQueryResultCacheKey& aOther) const {
return mMedium == aOther.mMedium &&
mFeatureCache == aOther.mFeatureCache;
}
bool operator!=(const nsMediaQueryResultCacheKey& aOther) const {
return !(*this == aOther);
}
private:
struct ExpressionEntry {
// FIXME: if we were better at maintaining invariants about clearing
@ -80,10 +101,26 @@ private:
// nsMediaExpression*| instead.
nsMediaExpression mExpression;
bool mExpressionMatches;
bool operator==(const ExpressionEntry& aOther) const {
return mExpression == aOther.mExpression &&
mExpressionMatches == aOther.mExpressionMatches;
}
bool operator!=(const ExpressionEntry& aOther) const {
return !(*this == aOther);
}
};
struct FeatureEntry {
const nsMediaFeature *mFeature;
InfallibleTArray<ExpressionEntry> mExpressions;
bool operator==(const FeatureEntry& aOther) const {
return mFeature == aOther.mFeature &&
mExpressions == aOther.mExpressions;
}
bool operator!=(const FeatureEntry& aOther) const {
return !(*this == aOther);
}
};
nsCOMPtr<nsIAtom> mMedium;
nsTArray<FeatureEntry> mFeatureCache;