Bug 761393 - Add a method to hash an nsStyleCoord. r=dbaron

This commit is contained in:
Paul Adenot 2012-08-26 21:08:32 -07:00
parent 8096d37d90
commit ef774bffba
2 changed files with 35 additions and 0 deletions

View File

@ -11,6 +11,7 @@
#include "prlog.h"
#include "nsMathUtils.h"
#include "nsStyleContext.h"
#include "mozilla/HashFunctions.h"
nsStyleCoord::nsStyleCoord(nsStyleUnit aUnit)
: mUnit(aUnit)
@ -79,6 +80,39 @@ bool nsStyleCoord::operator==(const nsStyleCoord& aOther) const
return false;
}
uint32_t nsStyleCoord::HashValue(uint32_t aHash = 0) const
{
aHash = mozilla::AddToHash(aHash, mUnit);
switch (mUnit) {
case eStyleUnit_Null:
case eStyleUnit_Normal:
case eStyleUnit_Auto:
case eStyleUnit_None:
return mozilla::AddToHash(aHash, true);
case eStyleUnit_Percent:
case eStyleUnit_Factor:
case eStyleUnit_Degree:
case eStyleUnit_Grad:
case eStyleUnit_Radian:
case eStyleUnit_Turn:
return mozilla::AddToHash(aHash, mValue.mFloat);
case eStyleUnit_Coord:
case eStyleUnit_Integer:
case eStyleUnit_Enumerated:
return mozilla::AddToHash(aHash, mValue.mInt);
case eStyleUnit_Calc:
Calc* calcValue = GetCalcValue();
aHash = mozilla::AddToHash(aHash, calcValue->mLength);
if (HasPercent()) {
return mozilla::AddToHash(aHash, calcValue->mPercent);
}
return aHash;
}
NS_ABORT_IF_FALSE(false, "unexpected unit");
return aHash;
}
void nsStyleCoord::Reset()
{
mUnit = eStyleUnit_Null;

View File

@ -135,6 +135,7 @@ public:
double GetAngleValueInRadians() const;
Calc* GetCalcValue() const;
void GetUnionValue(nsStyleUnion& aValue) const;
uint32_t HashValue(uint32_t aHash) const;
void Reset(); // sets to null
void SetCoordValue(nscoord aValue);