Bug 1310123 - Convert nsStyleColumn::kMaxColumnCount to a macro. r?mats draft
authorXidorn Quan <me@upsuper.org>
Fri, 14 Oct 2016 22:23:05 +1100
changeset 426185 f826dba88833005cb9ec2549f92ba99b676e8510
parent 426184 95b9968daae89443bc8475781207d08a94d58c83
child 534118 87a8edf39c09f0bcb9b1d6f8d5a88b86c24fc574
push id32643
push userxquan@mozilla.com
push dateTue, 18 Oct 2016 01:21:05 +0000
reviewersmats
bugs1310123
milestone52.0a1
Bug 1310123 - Convert nsStyleColumn::kMaxColumnCount to a macro. r?mats MozReview-Commit-ID: D27sN3QCxGg
layout/generic/nsColumnSetFrame.cpp
layout/style/nsRuleNode.cpp
layout/style/nsStyleStruct.cpp
layout/style/nsStyleStruct.h
servo/components/style/gecko_bindings/structs_debug.rs
servo/components/style/properties/gecko.mako.rs
--- a/layout/generic/nsColumnSetFrame.cpp
+++ b/layout/generic/nsColumnSetFrame.cpp
@@ -257,17 +257,17 @@ nsColumnSetFrame::ChooseColumnStrategy(c
     // available width. Compute max number of columns that fit in
     // availContentISize, satisfying colGap*(maxColumns - 1) +
     // colISize*maxColumns <= availContentISize
     if (availContentISize != NS_INTRINSICSIZE && colGap + colISize > 0
         && numColumns > 0) {
       // This expression uses truncated rounding, which is what we
       // want
       int32_t maxColumns =
-        std::min(nscoord(nsStyleColumn::kMaxColumnCount),
+        std::min(nscoord(NS_MAX_COLUMN_COUNT),
                  (availContentISize + colGap) / (colGap + colISize));
       numColumns = std::max(1, std::min(numColumns, maxColumns));
     }
   } else if (numColumns > 0 && availContentISize != NS_INTRINSICSIZE) {
     nscoord iSizeMinusGaps = availContentISize - colGap * (numColumns - 1);
     colISize = iSizeMinusGaps / numColumns;
   } else {
     colISize = NS_INTRINSICSIZE;
@@ -284,19 +284,18 @@ nsColumnSetFrame::ChooseColumnStrategy(c
     // First, determine how many columns will be showing if the column
     // count is auto
     if (numColumns <= 0) {
       // choose so that colGap*(nominalColumnCount - 1) +
       // colISize*nominalColumnCount is nearly availContentISize
       // make sure to round down
       if (colGap + colISize > 0) {
         numColumns = (availContentISize + colGap) / (colGap + colISize);
-        // The number of columns should never exceed kMaxColumnCount.
-        numColumns = std::min(nscoord(nsStyleColumn::kMaxColumnCount),
-                              numColumns);
+        // The number of columns should never exceed NS_MAX_COLUMN_COUNT.
+        numColumns = std::min(NS_MAX_COLUMN_COUNT, numColumns);
       }
       if (numColumns <= 0) {
         numColumns = 1;
       }
     }
 
     // Compute extra space and divide it among the columns
     nscoord extraSpace =
--- a/layout/style/nsRuleNode.cpp
+++ b/layout/style/nsRuleNode.cpp
@@ -9090,19 +9090,19 @@ nsRuleNode::ComputeColumnData(void* aSta
   // column-count: auto, integer, inherit
   const nsCSSValue* columnCountValue = aRuleData->ValueForColumnCount();
   if (eCSSUnit_Auto == columnCountValue->GetUnit() ||
       eCSSUnit_Initial == columnCountValue->GetUnit() ||
       eCSSUnit_Unset == columnCountValue->GetUnit()) {
     column->mColumnCount = NS_STYLE_COLUMN_COUNT_AUTO;
   } else if (eCSSUnit_Integer == columnCountValue->GetUnit()) {
     column->mColumnCount = columnCountValue->GetIntValue();
-    // Max kMaxColumnCount columns - wallpaper for bug 345583.
+    // Max NS_MAX_COLUMN_COUNT columns - wallpaper for bug 345583.
     column->mColumnCount = std::min(column->mColumnCount,
-                                    nsStyleColumn::kMaxColumnCount);
+                                    uint32_t(NS_MAX_COLUMN_COUNT));
   } else if (eCSSUnit_Inherit == columnCountValue->GetUnit()) {
     conditions.SetUncacheable();
     column->mColumnCount = parent->mColumnCount;
   }
 
   // column-rule-width: length, enum, inherit
   const nsCSSValue& widthValue = *aRuleData->ValueForColumnRuleWidth();
   if (eCSSUnit_Initial == widthValue.GetUnit() ||
--- a/layout/style/nsStyleStruct.cpp
+++ b/layout/style/nsStyleStruct.cpp
@@ -772,17 +772,16 @@ nsStyleXUL::CalcDifference(const nsStyle
     return nsChangeHint_ReconstructFrame;
   }
   return NS_STYLE_HINT_REFLOW;
 }
 
 // --------------------
 // nsStyleColumn
 //
-/* static */ const uint32_t nsStyleColumn::kMaxColumnCount = 1000;
 
 nsStyleColumn::nsStyleColumn(StyleStructContext aContext)
   : mColumnCount(NS_STYLE_COLUMN_COUNT_AUTO)
   , mColumnWidth(eStyleUnit_Auto)
   , mColumnGap(eStyleUnit_Normal)
   , mColumnRuleColor(StyleComplexColor::CurrentColor())
   , mColumnRuleStyle(NS_STYLE_BORDER_STYLE_NONE)
   , mColumnFill(NS_STYLE_COLUMN_FILL_BALANCE)
--- a/layout/style/nsStyleStruct.h
+++ b/layout/style/nsStyleStruct.h
@@ -3332,16 +3332,22 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsSt
   uint32_t      mBoxOrdinal;            // [reset] see nsStyleConsts.h
   mozilla::StyleBoxAlign mBoxAlign;         // [reset]
   mozilla::StyleBoxDirection mBoxDirection; // [reset]
   mozilla::StyleBoxOrient mBoxOrient;       // [reset]
   mozilla::StyleBoxPack mBoxPack;           // [reset]
   bool          mStretchStack;          // [reset] see nsStyleConsts.h
 };
 
+/**
+ * This is the maximum number of columns we can process. It's used in both
+ * nsColumnSetFrame and nsRuleNode.
+ */
+#define NS_MAX_COLUMN_COUNT 1000
+
 struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleColumn
 {
   explicit nsStyleColumn(StyleStructContext aContext);
   nsStyleColumn(const nsStyleColumn& aSource);
   ~nsStyleColumn();
 
   void* operator new(size_t sz, nsStyleColumn* aSelf) { return aSelf; }
   void* operator new(size_t sz, nsPresContext* aContext) {
@@ -3363,22 +3369,16 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsSt
   static nsChangeHint DifferenceAlwaysHandledForDescendants() {
     // CalcDifference never returns the reflow hints that are sometimes
     // handled for descendants as hints not handled for descendants.
     return nsChangeHint_NeedReflow |
            nsChangeHint_ReflowChangesSizeOrPosition |
            nsChangeHint_ClearAncestorIntrinsics;
   }
 
-  /**
-   * This is the maximum number of columns we can process. It's used in both
-   * nsColumnSetFrame and nsRuleNode.
-   */
-  static const uint32_t kMaxColumnCount;
-
   uint32_t     mColumnCount; // [reset] see nsStyleConsts.h
   nsStyleCoord mColumnWidth; // [reset] coord, auto
   nsStyleCoord mColumnGap;   // [reset] coord, normal
 
   mozilla::StyleComplexColor mColumnRuleColor; // [reset]
   uint8_t      mColumnRuleStyle;  // [reset]
   uint8_t      mColumnFill;  // [reset] see nsStyleConsts.h
 
--- a/servo/components/style/gecko_bindings/structs_debug.rs
+++ b/servo/components/style/gecko_bindings/structs_debug.rs
@@ -10822,32 +10822,29 @@ pub struct nsStyleXUL {
     pub mBoxPack: StyleBoxPack,
     pub mStretchStack: bool,
 }
 #[test]
 fn bindgen_test_layout_nsStyleXUL() {
     assert_eq!(::std::mem::size_of::<nsStyleXUL>() , 16usize);
     assert_eq!(::std::mem::align_of::<nsStyleXUL>() , 4usize);
 }
+pub const NS_MAX_COLUMN_COUNT: ::std::os::raw::c_uint = 1000;
 #[repr(C)]
 #[derive(Debug)]
 pub struct nsStyleColumn {
     pub mColumnCount: u32,
     pub mColumnWidth: nsStyleCoord,
     pub mColumnGap: nsStyleCoord,
     pub mColumnRuleColor: StyleComplexColor,
     pub mColumnRuleStyle: u8,
     pub mColumnFill: u8,
     pub mColumnRuleWidth: nscoord,
     pub mTwipsPerPixel: nscoord,
 }
-extern "C" {
-    #[link_name = "_ZN13nsStyleColumn15kMaxColumnCountE"]
-    pub static nsStyleColumn_kMaxColumnCount: u32;
-}
 #[test]
 fn bindgen_test_layout_nsStyleColumn() {
     assert_eq!(::std::mem::size_of::<nsStyleColumn>() , 64usize);
     assert_eq!(::std::mem::align_of::<nsStyleColumn>() , 8usize);
 }
 #[repr(u32)]
 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
 pub enum nsStyleSVGPaintType {
--- a/servo/components/style/properties/gecko.mako.rs
+++ b/servo/components/style/properties/gecko.mako.rs
@@ -1981,21 +1981,21 @@ clip-path
             None => self.gecko.mColumnWidth.set_value(CoordDataValue::Auto),
         }
     }
 
     ${impl_coord_copy('column_width', 'mColumnWidth')}
 
     #[allow(unused_unsafe)]
     pub fn set_column_count(&mut self, v: longhands::column_count::computed_value::T) {
-        use gecko_bindings::structs::{NS_STYLE_COLUMN_COUNT_AUTO, nsStyleColumn_kMaxColumnCount};
+        use gecko_bindings::structs::{NS_STYLE_COLUMN_COUNT_AUTO, NS_MAX_COLUMN_COUNT};
 
         self.gecko.mColumnCount = match v.0 {
             Some(number) => unsafe {
-                cmp::min(number, nsStyleColumn_kMaxColumnCount)
+                cmp::min(number, NS_MAX_COLUMN_COUNT)
             },
             None => NS_STYLE_COLUMN_COUNT_AUTO
         };
     }
 
     ${impl_simple_copy('column_count', 'mColumnCount')}
 </%self:impl_trait>