Bug 1295111 part 2 - Add static_assert to ensure that is updated properly. r=dbaron draft
authorXidorn Quan <xidorn+moz@upsuper.org>
Mon, 15 Aug 2016 20:52:05 +1000
changeset 400921 0ecbe3e09a8783c7149959c3580116d9e3ecd449
parent 400920 16336f07a549e22a22721776c53765f2afd17bab
child 528344 cfe8630f7331a45a2509cf3073d8e6a589e1e800
push id26300
push userxquan@mozilla.com
push dateTue, 16 Aug 2016 00:02:31 +0000
reviewersdbaron
bugs1295111
milestone51.0a1
Bug 1295111 part 2 - Add static_assert to ensure that is updated properly. r=dbaron MozReview-Commit-ID: G2RNUcXs4yQ
layout/base/RestyleManagerBase.cpp
layout/base/nsChangeHint.h
layout/style/nsStyleContext.cpp
--- a/layout/base/RestyleManagerBase.cpp
+++ b/layout/base/RestyleManagerBase.cpp
@@ -150,16 +150,18 @@ RestyleManagerBase::ChangeHintToString(n
     "UpdateSubtreeOverflow", "UpdatePostTransformOverflow",
     "UpdateParentOverflow",
     "ChildrenOnlyTransform", "RecomputePosition", "AddOrRemoveTransform",
     "BorderStyleNoneChange", "UpdateTextPath", "SchedulePaint",
     "NeutralChange", "InvalidateRenderingObservers",
     "ReflowChangesSizeOrPosition", "UpdateComputedBSize",
     "UpdateUsesOpacity", "UpdateBackgroundPosition"
   };
+  static_assert(nsChangeHint_AllHints == (1 << ArrayLength(names)) - 1,
+                "Name list doesn't match change hints.");
   uint32_t hint = aHint & ((1 << ArrayLength(names)) - 1);
   uint32_t rest = aHint & ~((1 << ArrayLength(names)) - 1);
   if (hint == nsChangeHint_Hints_NotHandledForDescendants) {
     result.AppendLiteral("nsChangeHint_Hints_NotHandledForDescendants");
     hint = 0;
     any = true;
   } else {
     if ((hint & NS_STYLE_HINT_REFLOW) == NS_STYLE_HINT_REFLOW) {
--- a/layout/base/nsChangeHint.h
+++ b/layout/base/nsChangeHint.h
@@ -201,19 +201,25 @@ enum nsChangeHint {
    * Indicates that the 'background-position' property changed.
    * Regular frames can invalidate these changes using DLBI, but
    * for some frame types we need to repaint the whole frame because
    * the frame does not build individual background image display items
    * for each background layer.
    */
   nsChangeHint_UpdateBackgroundPosition = 1 << 26,
 
-  // IMPORTANT NOTE: When adding new hints, consider whether you need to
-  // add them to NS_HintsNotHandledForDescendantsIn() below.  Please also
-  // add them to RestyleManager::ChangeHintToString.
+  // IMPORTANT NOTE: When adding new hints, consider whether you need
+  // to add them to NS_HintsNotHandledForDescendantsIn() below. Please
+  // also add them to RestyleManager::ChangeHintToString and modify
+  // nsChangeHint_AllHints below accordingly.
+
+  /**
+   * Dummy hint value for all hints. It exists for compile time check.
+   */
+  nsChangeHint_AllHints = (1 << 27) - 1,
 };
 
 // Redefine these operators to return nothing. This will catch any use
 // of these operators on hints. We should not be using these operators
 // on nsChangeHints
 inline void operator<(nsChangeHint s1, nsChangeHint s2) {}
 inline void operator>(nsChangeHint s1, nsChangeHint s2) {}
 inline void operator!=(nsChangeHint s1, nsChangeHint s2) {}
--- a/layout/style/nsStyleContext.cpp
+++ b/layout/style/nsStyleContext.cpp
@@ -1215,16 +1215,18 @@ nsStyleContext::CalcStyleDifferenceInter
       }
     }
 
     if (change) {
       hint |= nsChangeHint_RepaintFrame;
     }
   }
 
+  MOZ_ASSERT(NS_IsHintSubset(hint, nsChangeHint_AllHints),
+             "Added a new hint without bumping AllHints?");
   return hint & ~nsChangeHint_NeutralChange;
 }
 
 nsChangeHint
 nsStyleContext::CalcStyleDifference(nsStyleContext* aNewContext,
                                     nsChangeHint aParentHintsNotHandledForDescendants,
                                     uint32_t* aEqualStructs,
                                     uint32_t* aSamePointerStructs)