Bug 1297982 - Replace NS_STYLE_BOX_PACK_* with enum class; r?xidorn draft
authorRavi Shankar <wafflespeanut@gmail.com>
Fri, 26 Aug 2016 12:41:54 +0530
changeset 405958 6b9c5c3b71bc38dd9aa7f0790cc63e6dec388620
parent 405957 13fff399a93a85e15b2a4878b8ccc334914f942e
child 405959 2cd0c9f87f15069839feb0b90471ff99a6839a0f
push id27614
push userwafflespeanut@gmail.com
push dateFri, 26 Aug 2016 07:20:49 +0000
reviewersxidorn
bugs1297982
milestone51.0a1
Bug 1297982 - Replace NS_STYLE_BOX_PACK_* with enum class; r?xidorn MozReview-Commit-ID: Cx20hOJbmad
layout/generic/nsFlexContainerFrame.cpp
layout/style/nsCSSProps.cpp
layout/style/nsRuleNode.cpp
layout/style/nsStyleConsts.h
layout/style/nsStyleStruct.cpp
layout/style/nsStyleStruct.h
layout/xul/nsBoxFrame.cpp
--- a/layout/generic/nsFlexContainerFrame.cpp
+++ b/layout/generic/nsFlexContainerFrame.cpp
@@ -143,23 +143,23 @@ ConvertLegacyStyleToAlignItems(const nsS
 
 // Returns the "justify-content" value that's equivalent to the legacy
 // "box-pack" value in the given style struct.
 static uint8_t
 ConvertLegacyStyleToJustifyContent(const nsStyleXUL* aStyleXUL)
 {
   // -[moz|webkit]-box-pack corresponds to modern "justify-content"
   switch (aStyleXUL->mBoxPack) {
-    case NS_STYLE_BOX_PACK_START:
+    case StyleBoxPack::Start:
       return NS_STYLE_ALIGN_FLEX_START;
-    case NS_STYLE_BOX_PACK_CENTER:
+    case StyleBoxPack::Center:
       return NS_STYLE_ALIGN_CENTER;
-    case NS_STYLE_BOX_PACK_END:
+    case StyleBoxPack::End:
       return NS_STYLE_ALIGN_FLEX_END;
-    case NS_STYLE_BOX_PACK_JUSTIFY:
+    case StyleBoxPack::Justify:
       return NS_STYLE_ALIGN_SPACE_BETWEEN;
   }
 
   MOZ_ASSERT_UNREACHABLE("Unrecognized mBoxPack enum value");
   // Fall back to default value of "justify-content" property:
   return NS_STYLE_ALIGN_FLEX_START;
 }
 
--- a/layout/style/nsCSSProps.cpp
+++ b/layout/style/nsCSSProps.cpp
@@ -2260,20 +2260,20 @@ const KTableEntry nsCSSProps::kBoxOrient
   { eCSSKeyword_horizontal, NS_STYLE_BOX_ORIENT_HORIZONTAL },
   { eCSSKeyword_vertical, NS_STYLE_BOX_ORIENT_VERTICAL },
   { eCSSKeyword_inline_axis, NS_STYLE_BOX_ORIENT_HORIZONTAL },
   { eCSSKeyword_block_axis, NS_STYLE_BOX_ORIENT_VERTICAL },
   { eCSSKeyword_UNKNOWN, -1 }
 };
 
 const KTableEntry nsCSSProps::kBoxPackKTable[] = {
-  { eCSSKeyword_start, NS_STYLE_BOX_PACK_START },
-  { eCSSKeyword_center, NS_STYLE_BOX_PACK_CENTER },
-  { eCSSKeyword_end, NS_STYLE_BOX_PACK_END },
-  { eCSSKeyword_justify, NS_STYLE_BOX_PACK_JUSTIFY },
+  { eCSSKeyword_start, StyleBoxPack::Start },
+  { eCSSKeyword_center, StyleBoxPack::Center },
+  { eCSSKeyword_end, StyleBoxPack::End },
+  { eCSSKeyword_justify, StyleBoxPack::Justify },
   { eCSSKeyword_UNKNOWN, -1 }
 };
 
 // keyword tables for SVG properties
 
 const KTableEntry nsCSSProps::kDominantBaselineKTable[] = {
   { eCSSKeyword_auto, NS_STYLE_DOMINANT_BASELINE_AUTO },
   { eCSSKeyword_use_script, NS_STYLE_DOMINANT_BASELINE_USE_SCRIPT },
--- a/layout/style/nsRuleNode.cpp
+++ b/layout/style/nsRuleNode.cpp
@@ -1330,16 +1330,17 @@ struct SetEnumValueHelper
     auto value = aValue.GetIntValue(); \
     MOZ_ASSERT(value >= static_cast<decltype(value)>(type_::min_) && \
                value <= static_cast<decltype(value)>(type_::max_), \
                "inappropriate value"); \
     aField = static_cast<type_>(value); \
   }
 
   DEFINE_ENUM_CLASS_SETTER(StyleBoxAlign, Stretch, End)
+  DEFINE_ENUM_CLASS_SETTER(StyleBoxPack, Start, Justify)
   DEFINE_ENUM_CLASS_SETTER(StyleBoxSizing, Content, Border)
   DEFINE_ENUM_CLASS_SETTER(StyleFillRule, Nonzero, Evenodd)
   DEFINE_ENUM_CLASS_SETTER(StyleFloat, None_, InlineEnd)
   DEFINE_ENUM_CLASS_SETTER(StyleFloatEdge, ContentBox, MarginBox)
   DEFINE_ENUM_CLASS_SETTER(StyleUserFocus, None_, SelectMenu)
   DEFINE_ENUM_CLASS_SETTER(StyleUserSelect, None_, MozText)
 
 #undef DEF_SET_ENUMERATED_VALUE
@@ -9116,17 +9117,17 @@ nsRuleNode::ComputeXULData(void* aStartS
            parentXUL->mBoxOrient,
            NS_STYLE_BOX_ORIENT_HORIZONTAL);
 
   // box-pack: enum, inherit, initial
   SetValue(*aRuleData->ValueForBoxPack(),
            xul->mBoxPack, conditions,
            SETVAL_ENUMERATED | SETVAL_UNSET_INITIAL,
            parentXUL->mBoxPack,
-           NS_STYLE_BOX_PACK_START);
+           StyleBoxPack::Start);
 
   // box-ordinal-group: integer, inherit, initial
   SetValue(*aRuleData->ValueForBoxOrdinalGroup(),
            xul->mBoxOrdinal, conditions,
            SETVAL_INTEGER | SETVAL_UNSET_INITIAL,
            parentXUL->mBoxOrdinal, 1);
 
   const nsCSSValue* stackSizingValue = aRuleData->ValueForStackSizing();
--- a/layout/style/nsStyleConsts.h
+++ b/layout/style/nsStyleConsts.h
@@ -66,16 +66,24 @@ enum class StyleBasicShapeType : uint8_t
 enum class StyleBoxAlign : uint8_t {
   Stretch,
   Start,
   Center,
   Baseline,
   End,
 };
 
+// box-pack
+enum class StyleBoxPack : uint8_t {
+  Start,
+  Center,
+  End,
+  Justify,
+};
+
 // box-sizing
 enum class StyleBoxSizing : uint8_t {
   Content,
   Border
 };
 
 // box-shadow
 enum class StyleBoxShadowType : uint8_t {
@@ -172,22 +180,16 @@ enum class StyleUserSelect : uint8_t {
 #define NS_STYLE_USER_MODIFY_READ_WRITE  1
 #define NS_STYLE_USER_MODIFY_WRITE_ONLY  2
 
 // -moz-window-dragging
 #define NS_STYLE_WINDOW_DRAGGING_DEFAULT 0
 #define NS_STYLE_WINDOW_DRAGGING_DRAG    1
 #define NS_STYLE_WINDOW_DRAGGING_NO_DRAG 2
 
-// box-pack
-#define NS_STYLE_BOX_PACK_START        0
-#define NS_STYLE_BOX_PACK_CENTER       1
-#define NS_STYLE_BOX_PACK_END          2
-#define NS_STYLE_BOX_PACK_JUSTIFY      3
-
 // box-decoration-break
 #define NS_STYLE_BOX_DECORATION_BREAK_SLICE  0
 #define NS_STYLE_BOX_DECORATION_BREAK_CLONE  1
 
 // box-direction
 #define NS_STYLE_BOX_DIRECTION_NORMAL    0
 #define NS_STYLE_BOX_DIRECTION_REVERSE   1
 
--- a/layout/style/nsStyleStruct.cpp
+++ b/layout/style/nsStyleStruct.cpp
@@ -826,17 +826,17 @@ nsStyleList::sNoneQuotes;
 // nsStyleXUL
 //
 nsStyleXUL::nsStyleXUL(StyleStructContext aContext)
   : mBoxFlex(0.0f)
   , mBoxOrdinal(1)
   , mBoxAlign(StyleBoxAlign::Stretch)
   , mBoxDirection(NS_STYLE_BOX_DIRECTION_NORMAL)
   , mBoxOrient(NS_STYLE_BOX_ORIENT_HORIZONTAL)
-  , mBoxPack(NS_STYLE_BOX_PACK_START)
+  , mBoxPack(StyleBoxPack::Start)
   , mStretchStack(true)
 {
   MOZ_COUNT_CTOR(nsStyleXUL);
 }
 
 nsStyleXUL::~nsStyleXUL()
 {
   MOZ_COUNT_DTOR(nsStyleXUL);
--- a/layout/style/nsStyleStruct.h
+++ b/layout/style/nsStyleStruct.h
@@ -3434,17 +3434,17 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsSt
            nsChangeHint_ClearAncestorIntrinsics;
   }
 
   float         mBoxFlex;               // [reset] see nsStyleConsts.h
   uint32_t      mBoxOrdinal;            // [reset] see nsStyleConsts.h
   mozilla::StyleBoxAlign mBoxAlign;         // [reset]
   uint8_t       mBoxDirection;          // [reset] see nsStyleConsts.h
   uint8_t       mBoxOrient;             // [reset] see nsStyleConsts.h
-  uint8_t       mBoxPack;               // [reset] see nsStyleConsts.h
+  mozilla::StyleBoxPack mBoxPack;           // [reset]
   bool          mStretchStack;          // [reset] see nsStyleConsts.h
 };
 
 struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleColumn
 {
   explicit nsStyleColumn(StyleStructContext aContext);
   nsStyleColumn(const nsStyleColumn& aSource);
   ~nsStyleColumn();
--- a/layout/xul/nsBoxFrame.cpp
+++ b/layout/xul/nsBoxFrame.cpp
@@ -333,23 +333,23 @@ nsBoxFrame::GetInitialHAlignment(nsBoxFr
   }
 
   // Now that we've checked for the attribute it's time to check CSS.  For 
   // horizontal boxes we're checking PACK.  For vertical boxes we are checking
   // ALIGN.
   const nsStyleXUL* boxInfo = StyleXUL();
   if (IsXULHorizontal()) {
     switch (boxInfo->mBoxPack) {
-      case NS_STYLE_BOX_PACK_START:
+      case StyleBoxPack::Start:
         aHalign = nsBoxFrame::hAlign_Left;
         return true;
-      case NS_STYLE_BOX_PACK_CENTER:
+      case StyleBoxPack::Center:
         aHalign = nsBoxFrame::hAlign_Center;
         return true;
-      case NS_STYLE_BOX_PACK_END:
+      case StyleBoxPack::End:
         aHalign = nsBoxFrame::hAlign_Right;
         return true;
       default: // Nonsensical value. Just bail.
         return false;
     }
   }
   else {
     switch (boxInfo->mBoxAlign) {
@@ -426,23 +426,23 @@ nsBoxFrame::GetInitialVAlignment(nsBoxFr
         aValign = nsBoxFrame::vAlign_Bottom;
         return true;
       default: // Nonsensical value. Just bail.
         return false;
     }
   }
   else {
     switch (boxInfo->mBoxPack) {
-      case NS_STYLE_BOX_PACK_START:
+      case StyleBoxPack::Start:
         aValign = nsBoxFrame::vAlign_Top;
         return true;
-      case NS_STYLE_BOX_PACK_CENTER:
+      case StyleBoxPack::Center:
         aValign = nsBoxFrame::vAlign_Middle;
         return true;
-      case NS_STYLE_BOX_PACK_END:
+      case StyleBoxPack::End:
         aValign = nsBoxFrame::vAlign_Bottom;
         return true;
       default: // Nonsensical value. Just bail.
         return false;
     }
   }
 
   return false;