From 1cc49697466dabfcbe33a4ccf1c7b22ed3dcabaf Mon Sep 17 00:00:00 2001 From: "L. David Baron" Date: Sat, 20 Jun 2015 21:54:15 -0700 Subject: [PATCH] Bug 1169440 patch 1 - Add bitwise operators to nsChangeHint. r=heycam I'm fed up with having to use the NS_*Hint functions, and I also have trouble reading/writing some of them since I don't remember the order of parameters. (At some point I think we should convert existing callers, but I don't plan to do that here.) --- layout/base/RestyleManager.cpp | 3 ++- layout/base/nsChangeHint.h | 43 ++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/layout/base/RestyleManager.cpp b/layout/base/RestyleManager.cpp index 11b72323f1a0..b2431378167e 100644 --- a/layout/base/RestyleManager.cpp +++ b/layout/base/RestyleManager.cpp @@ -148,7 +148,8 @@ SyncViewsAndInvalidateDescendants(nsIFrame* aFrame, { NS_PRECONDITION(gInApplyRenderingChangeToTree, "should only be called within ApplyRenderingChangeToTree"); - NS_ASSERTION(aChange == (aChange & (nsChangeHint_RepaintFrame | + NS_ASSERTION(nsChangeHint_size_t(aChange) == + (aChange & (nsChangeHint_RepaintFrame | nsChangeHint_SyncFrameView | nsChangeHint_UpdateOpacityLayer | nsChangeHint_SchedulePaint)), diff --git a/layout/base/nsChangeHint.h b/layout/base/nsChangeHint.h index edc497ce13a8..8be945cb72b0 100644 --- a/layout/base/nsChangeHint.h +++ b/layout/base/nsChangeHint.h @@ -210,6 +210,49 @@ inline bool NS_IsHintSubset(nsChangeHint aSubset, nsChangeHint aSuperSet) { return (aSubset & aSuperSet) == aSubset; } +// The functions below need an integral type to cast to to avoid +// infinite recursion. +typedef decltype(nsChangeHint(0) + nsChangeHint(0)) nsChangeHint_size_t; + +inline nsChangeHint MOZ_CONSTEXPR +operator|(nsChangeHint aLeft, nsChangeHint aRight) +{ + return nsChangeHint(nsChangeHint_size_t(aLeft) | nsChangeHint_size_t(aRight)); +} + +inline nsChangeHint MOZ_CONSTEXPR +operator&(nsChangeHint aLeft, nsChangeHint aRight) +{ + return nsChangeHint(nsChangeHint_size_t(aLeft) & nsChangeHint_size_t(aRight)); +} + +inline nsChangeHint& operator|=(nsChangeHint& aLeft, nsChangeHint aRight) +{ + return aLeft = aLeft | aRight; +} + +inline nsChangeHint& operator&=(nsChangeHint& aLeft, nsChangeHint aRight) +{ + return aLeft = aLeft & aRight; +} + +inline nsChangeHint MOZ_CONSTEXPR +operator~(nsChangeHint aArg) +{ + return nsChangeHint(~nsChangeHint_size_t(aArg)); +} + +inline nsChangeHint MOZ_CONSTEXPR +operator^(nsChangeHint aLeft, nsChangeHint aRight) +{ + return nsChangeHint(nsChangeHint_size_t(aLeft) ^ nsChangeHint_size_t(aRight)); +} + +inline nsChangeHint operator^=(nsChangeHint& aLeft, nsChangeHint aRight) +{ + return aLeft = aLeft ^ aRight; +} + /** * We have an optimization when processing change hints which prevents * us from visiting the descendants of a node when a hint on that node