Bug 775624 Part 1 - Convert nsReflowStatus to a class mimicking uint32_t. r?dholbert draft
authorTing-Yu Lin <tlin@mozilla.com>
Fri, 10 Feb 2017 17:29:10 +0800
changeset 486986 2a9fb4b2fd6255a86f2adbc90726a077ae64d71c
parent 486741 16effd5b21ab03629feca04b5b83911bb757394c
child 486987 4683ff56ac4681f8eb0886f6fc1b783e0e8b8acc
push id46110
push userbmo:tlin@mozilla.com
push dateMon, 20 Feb 2017 11:14:45 +0000
reviewersdholbert
bugs775624
milestone54.0a1
Bug 775624 Part 1 - Convert nsReflowStatus to a class mimicking uint32_t. r?dholbert Lay down the foundation for this refactor work so that nsReflowStatus could be converted to bit-fields piece by piece, and each patch can be built (but may not pass tests). This change causes some build warnings, due to some debug logs printing nsReflowStatus as an integer, but that will be fixed by Part 24 later. All the operators related to uint32_t will be removed at the end of this patch series by Part 23. The yoda conditions are swapped in order to build successfully. DisplayReflowExit() incorrectly declares aStatus as uint32_t. Change it to const reference because nsReflowStatus is now a class. MozReview-Commit-ID: 5DOpaP85ywJ
layout/generic/nsFrame.cpp
layout/generic/nsFrame.h
layout/generic/nsIFrame.h
layout/tables/nsTableRowGroupFrame.cpp
--- a/layout/generic/nsFrame.cpp
+++ b/layout/generic/nsFrame.cpp
@@ -10332,17 +10332,17 @@ void
 nsFrame::Trace(const char* aMethod, bool aEnter, nsReflowStatus aStatus)
 {
   if (NS_FRAME_LOG_TEST(sFrameLogModule, NS_FRAME_TRACE_CALLS)) {
     char tagbuf[40];
     GetTagName(this, mContent, sizeof(tagbuf), tagbuf);
     PR_LogPrint("%s: %s %s, status=%scomplete%s",
                 tagbuf, aEnter ? "enter" : "exit", aMethod,
                 NS_FRAME_IS_NOT_COMPLETE(aStatus) ? "not" : "",
-                (NS_FRAME_REFLOW_NEXTINFLOW & aStatus) ? "+reflow" : "");
+                (aStatus & NS_FRAME_REFLOW_NEXTINFLOW) ? "+reflow" : "");
   }
 }
 
 void
 nsFrame::TraceMsg(const char* aFormatString, ...)
 {
   if (NS_FRAME_LOG_TEST(sFrameLogModule, NS_FRAME_TRACE_CALLS)) {
     // Format arguments into a buffer
@@ -11193,21 +11193,21 @@ void* nsFrame::DisplayIntrinsicSizeEnter
   DR_FrameTreeNode* treeNode = DR_state->CreateTreeNode(aFrame, nullptr);
   if (treeNode && treeNode->mDisplay) {
     DR_state->DisplayFrameTypeInfo(aFrame, treeNode->mIndent);
     printf("Get%sSize\n", aType);
   }
   return treeNode;
 }
 
-void nsFrame::DisplayReflowExit(nsPresContext*      aPresContext,
-                                nsIFrame*            aFrame,
+void nsFrame::DisplayReflowExit(nsPresContext* aPresContext,
+                                nsIFrame* aFrame,
                                 ReflowOutput& aMetrics,
-                                nsReflowStatus       aStatus,
-                                void*                aFrameTreeNode)
+                                const nsReflowStatus& aStatus,
+                                void* aFrameTreeNode)
 {
   if (!DR_state->mActive) return;
 
   NS_ASSERTION(aFrame, "DisplayReflowExit - invalid call");
   if (!aFrameTreeNode) return;
 
   DR_FrameTreeNode* treeNode = (DR_FrameTreeNode*)aFrameTreeNode;
   if (treeNode->mDisplay) {
--- a/layout/generic/nsFrame.h
+++ b/layout/generic/nsFrame.h
@@ -502,21 +502,21 @@ public:
   static void* DisplayReflowEnter(nsPresContext*          aPresContext,
                                   nsIFrame*                aFrame,
                                   const ReflowInput& aReflowInput);
   static void* DisplayLayoutEnter(nsIFrame* aFrame);
   static void* DisplayIntrinsicISizeEnter(nsIFrame* aFrame,
                                           const char* aType);
   static void* DisplayIntrinsicSizeEnter(nsIFrame* aFrame,
                                          const char* aType);
-  static void DisplayReflowExit(nsPresContext*      aPresContext,
-                                 nsIFrame*            aFrame,
-                                 ReflowOutput& aMetrics,
-                                 uint32_t             aStatus,
-                                 void*                aFrameTreeNode);
+  static void DisplayReflowExit(nsPresContext* aPresContext,
+                                nsIFrame* aFrame,
+                                ReflowOutput& aMetrics,
+                                const nsReflowStatus& aStatus,
+                                void* aFrameTreeNode);
   static void DisplayLayoutExit(nsIFrame* aFrame,
                                  void* aFrameTreeNode);
   static void DisplayIntrinsicISizeExit(nsIFrame* aFrame,
                                          const char* aType,
                                          nscoord aResult,
                                          void* aFrameTreeNode);
   static void DisplayIntrinsicSizeExit(nsIFrame* aFrame,
                                         const char* aType,
--- a/layout/generic/nsIFrame.h
+++ b/layout/generic/nsIFrame.h
@@ -225,17 +225,63 @@ enum nsSpread {
  *
  * The low 8 bits of the nsReflowStatus are reserved for future extensions;
  * the remaining 24 bits are zero (and available for extensions; however
  * API's that accept/return nsReflowStatus must not receive/return any
  * extension bits).
  *
  * @see #Reflow()
  */
-typedef uint32_t nsReflowStatus;
+
+class nsReflowStatus final {
+public:
+  nsReflowStatus()
+    : mStatus(0)
+  {}
+
+  nsReflowStatus(uint32_t aStatus)
+    : mStatus(aStatus)
+  {}
+
+  uint32_t& operator=(uint32_t aRhs) {
+    mStatus = aRhs;
+    return mStatus;
+  }
+
+  uint32_t operator&(uint32_t aRhs) const {
+    return mStatus & aRhs;
+  }
+
+  uint32_t operator&=(uint32_t aRhs) {
+    return mStatus = mStatus & aRhs;
+  }
+
+  uint32_t operator|(uint32_t aRhs) const {
+    return mStatus | aRhs;
+  }
+
+  uint32_t operator|=(uint32_t aRhs) {
+    return mStatus = mStatus | aRhs;
+  }
+
+  uint32_t operator>>(uint32_t aRhs) const {
+    return mStatus >> aRhs;
+  }
+
+  bool operator==(uint32_t aRhs) const {
+    return mStatus == aRhs;
+  }
+
+  bool operator!=(uint32_t aRhs) const {
+    return !(*this == aRhs);
+  }
+
+private:
+  uint32_t mStatus;
+};
 
 #define NS_FRAME_COMPLETE             0       // Note: not a bit!
 #define NS_FRAME_NOT_COMPLETE         0x1
 #define NS_FRAME_REFLOW_NEXTINFLOW    0x2
 #define NS_FRAME_OVERFLOW_INCOMPLETE  0x4
 
 #define NS_FRAME_IS_COMPLETE(status) \
   (0 == ((status) & NS_FRAME_NOT_COMPLETE))
--- a/layout/tables/nsTableRowGroupFrame.cpp
+++ b/layout/tables/nsTableRowGroupFrame.cpp
@@ -1386,17 +1386,17 @@ nsTableRowGroupFrame::Reflow(nsPresConte
   bool splitDueToPageBreak = false;
   ReflowChildren(aPresContext, aDesiredSize, state, aStatus,
                  &splitDueToPageBreak);
 
   // See if all the frames fit. Do not try to split anything if we're
   // not paginated ... we can't split across columns yet.
   if (aReflowInput.mFlags.mTableIsSplittable &&
       NS_UNCONSTRAINEDSIZE != aReflowInput.AvailableHeight() &&
-      (NS_FRAME_NOT_COMPLETE == aStatus || splitDueToPageBreak ||
+      (aStatus == NS_FRAME_NOT_COMPLETE || splitDueToPageBreak ||
        aDesiredSize.Height() > aReflowInput.AvailableHeight())) {
     // Nope, find a place to split the row group
     bool specialReflow = (bool)aReflowInput.mFlags.mSpecialBSizeReflow;
     ((ReflowInput::ReflowInputFlags&)aReflowInput.mFlags).mSpecialBSizeReflow = false;
 
     SplitRowGroup(aPresContext, aDesiredSize, aReflowInput, tableFrame, aStatus,
                   splitDueToPageBreak);