Bug 977991 patch 0 - Add bitwise operators to nsRestyleHint. r=birtles

This avoids having to cast back to nsRestyleHint after using bitwise
operators, and allows |= (etc.).

(In the future we should consider converting nsRestyleHint, and probably
also nsChangeHint, to use MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS.)
This commit is contained in:
L. David Baron 2014-09-13 06:17:36 -07:00
parent 5f37fd1a6e
commit 86f1147a3a

View File

@ -9,6 +9,7 @@
#define nsChangeHint_h___
#include "nsDebug.h"
#include "mozilla/Types.h"
// Defines for various style related constants
@ -322,5 +323,46 @@ enum nsRestyleHint {
eRestyle_ForceDescendants = (1<<9),
};
// The functions below need an integral type to cast to to avoid
// infinite recursion.
typedef decltype(nsRestyleHint(0) + nsRestyleHint(0)) nsRestyleHint_size_t;
inline nsRestyleHint operator|(nsRestyleHint aLeft, nsRestyleHint aRight)
{
return nsRestyleHint(nsRestyleHint_size_t(aLeft) |
nsRestyleHint_size_t(aRight));
}
inline nsRestyleHint operator&(nsRestyleHint aLeft, nsRestyleHint aRight)
{
return nsRestyleHint(nsRestyleHint_size_t(aLeft) &
nsRestyleHint_size_t(aRight));
}
inline nsRestyleHint& operator|=(nsRestyleHint& aLeft, nsRestyleHint aRight)
{
return aLeft = aLeft | aRight;
}
inline nsRestyleHint& operator&=(nsRestyleHint& aLeft, nsRestyleHint aRight)
{
return aLeft = aLeft & aRight;
}
inline nsRestyleHint operator~(nsRestyleHint aArg)
{
return nsRestyleHint(~nsRestyleHint_size_t(aArg));
}
inline nsRestyleHint operator^(nsRestyleHint aLeft, nsRestyleHint aRight)
{
return nsRestyleHint(nsRestyleHint_size_t(aLeft) ^
nsRestyleHint_size_t(aRight));
}
inline nsRestyleHint operator^=(nsRestyleHint& aLeft, nsRestyleHint aRight)
{
return aLeft = aLeft ^ aRight;
}
#endif /* nsChangeHint_h___ */