Bug 1166728 - Remove support for "box-sizing: padding-box", per CSS WG resolution. r=dholbert r=mats draft
authorKyle Zentner <kzentner@mozilla.com>
Sat, 18 Jun 2016 19:45:18 +0100
changeset 379892 0077126d8eebd9cba2a8bd0b52d4b75200a41e23
parent 379877 3ce53bd1e25b93140484d3933c9339a829e0c1eb
child 523594 574812d1f969b8ac69916092fb2dac71963ea874
push id21079
push userdholbert@mozilla.com
push dateSat, 18 Jun 2016 18:45:54 +0000
reviewersdholbert, mats
bugs1166728
milestone50.0a1
Bug 1166728 - Remove support for "box-sizing: padding-box", per CSS WG resolution. r=dholbert r=mats MozReview-Commit-ID: JClqoCUrm11
layout/base/nsLayoutUtils.cpp
layout/generic/nsFrame.cpp
layout/generic/nsHTMLReflowState.cpp
layout/style/nsCSSProps.cpp
layout/style/nsComputedDOMStyle.cpp
layout/style/nsStyleConsts.h
layout/style/test/property_database.js
layout/tables/BasicTableLayoutStrategy.cpp
layout/tables/FixedTableLayoutStrategy.cpp
layout/tables/nsTableRowFrame.cpp
layout/xul/nsResizerFrame.cpp
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -4590,25 +4590,21 @@ GetPercentBSize(const nsStyleCoord& aSty
 // padding should be ignored.
 static nscoord
 GetBSizeTakenByBoxSizing(StyleBoxSizing aBoxSizing,
                          nsIFrame* aFrame,
                          bool aHorizontalAxis,
                          bool aIgnorePadding)
 {
   nscoord bSizeTakenByBoxSizing = 0;
-  switch (aBoxSizing) {
-  case StyleBoxSizing::Border: {
+  if (aBoxSizing == StyleBoxSizing::Border) {
     const nsStyleBorder* styleBorder = aFrame->StyleBorder();
     bSizeTakenByBoxSizing +=
       aHorizontalAxis ? styleBorder->GetComputedBorder().TopBottom()
                       : styleBorder->GetComputedBorder().LeftRight();
-    MOZ_FALLTHROUGH;
-  }
-  case StyleBoxSizing::Padding: {
     if (!aIgnorePadding) {
       const nsStyleSides& stylePadding =
         aFrame->StylePadding()->mPadding;
       const nsStyleCoord& paddingStart =
         stylePadding.Get(aHorizontalAxis ? NS_SIDE_TOP : NS_SIDE_LEFT);
       const nsStyleCoord& paddingEnd =
         stylePadding.Get(aHorizontalAxis ? NS_SIDE_BOTTOM : NS_SIDE_RIGHT);
       nscoord pad;
@@ -4621,21 +4617,16 @@ GetBSizeTakenByBoxSizing(StyleBoxSizing 
           GetPercentBSize(paddingStart, aFrame, aHorizontalAxis, pad)) {
         bSizeTakenByBoxSizing += pad;
       }
       if (GetAbsoluteCoord(paddingEnd, pad) ||
           GetPercentBSize(paddingEnd, aFrame, aHorizontalAxis, pad)) {
         bSizeTakenByBoxSizing += pad;
       }
     }
-    MOZ_FALLTHROUGH;
-  }
-  case StyleBoxSizing::Content:
-  default:
-    break;
   }
   return bSizeTakenByBoxSizing;
 }
 
 // Handles only -moz-max-content and -moz-min-content, and
 // -moz-fit-content for min-width and max-width, since the others
 // (-moz-fit-content for width, and -moz-available) have no effect on
 // intrinsic widths.
@@ -4769,25 +4760,16 @@ AddIntrinsicSizeOffset(nsRenderingContex
   nscoord min = aContentMinSize;
   nscoord coordOutsideSize = 0;
   float pctOutsideSize = 0;
   float pctTotal = 0.0f;
 
   if (!(aFlags & nsLayoutUtils::IGNORE_PADDING)) {
     coordOutsideSize += aOffsets.hPadding;
     pctOutsideSize += aOffsets.hPctPadding;
-
-    if (aBoxSizing == StyleBoxSizing::Padding) {
-      min += coordOutsideSize;
-      result = NSCoordSaturatingAdd(result, coordOutsideSize);
-      pctTotal += pctOutsideSize;
-
-      coordOutsideSize = 0;
-      pctOutsideSize = 0.0f;
-    }
   }
 
   coordOutsideSize += aOffsets.hBorder;
 
   if (aBoxSizing == StyleBoxSizing::Border) {
     min += coordOutsideSize;
     result = NSCoordSaturatingAdd(result, coordOutsideSize);
     pctTotal += pctOutsideSize;
@@ -5461,26 +5443,18 @@ nsLayoutUtils::ComputeSizeWithIntrinsicD
   // Note: throughout the following section of the function, I avoid
   // a * (b / c) because of its reduced accuracy relative to a * b / c
   // or (a * b) / c (which are equivalent).
 
   const bool isAutoISize = inlineStyleCoord->GetUnit() == eStyleUnit_Auto;
   bool isAutoBSize = IsAutoBSize(*blockStyleCoord, aCBSize.BSize(aWM));
 
   LogicalSize boxSizingAdjust(aWM);
-  switch (stylePos->mBoxSizing) {
-    case StyleBoxSizing::Border:
-      boxSizingAdjust += aBorder;
-      MOZ_FALLTHROUGH;
-    case StyleBoxSizing::Padding:
-      boxSizingAdjust += aPadding;
-      MOZ_FALLTHROUGH;
-    case StyleBoxSizing::Content:
-      // nothing
-      break;
+  if (stylePos->mBoxSizing == StyleBoxSizing::Border) {
+    boxSizingAdjust = aBorder + aPadding;
   }
   nscoord boxSizingToMarginEdgeISize =
     aMargin.ISize(aWM) + aBorder.ISize(aWM) + aPadding.ISize(aWM) -
       boxSizingAdjust.ISize(aWM);
 
   nscoord iSize, minISize, maxISize, bSize, minBSize, maxBSize;
 
   if (!isAutoISize) {
--- a/layout/generic/nsFrame.cpp
+++ b/layout/generic/nsFrame.cpp
@@ -4645,29 +4645,21 @@ nsFrame::ComputeSize(nsRenderingContext 
 {
   MOZ_ASSERT(GetIntrinsicRatio() == nsSize(0,0),
              "Please override this method and call "
              "nsLayoutUtils::ComputeSizeWithIntrinsicDimensions instead.");
   LogicalSize result = ComputeAutoSize(aRenderingContext, aWM,
                                        aCBSize, aAvailableISize,
                                        aMargin, aBorder, aPadding,
                                        aFlags & ComputeSizeFlags::eShrinkWrap);
+  const nsStylePosition *stylePos = StylePosition();
+
   LogicalSize boxSizingAdjust(aWM);
-  const nsStylePosition *stylePos = StylePosition();
-
-  switch (stylePos->mBoxSizing) {
-    case StyleBoxSizing::Border:
-      boxSizingAdjust += aBorder;
-      MOZ_FALLTHROUGH;
-    case StyleBoxSizing::Padding:
-      boxSizingAdjust += aPadding;
-      MOZ_FALLTHROUGH;
-    case StyleBoxSizing::Content:
-      // nothing
-      break;
+  if (stylePos->mBoxSizing == StyleBoxSizing::Border) {
+    boxSizingAdjust = aBorder + aPadding;
   }
   nscoord boxSizingToMarginEdgeISize =
     aMargin.ISize(aWM) + aBorder.ISize(aWM) + aPadding.ISize(aWM) -
     boxSizingAdjust.ISize(aWM);
 
   const nsStyleCoord* inlineStyleCoord = &stylePos->ISize(aWM);
   const nsStyleCoord* blockStyleCoord = &stylePos->BSize(aWM);
 
--- a/layout/generic/nsHTMLReflowState.cpp
+++ b/layout/generic/nsHTMLReflowState.cpp
@@ -266,50 +266,34 @@ nsCSSOffsetState::ComputeISizeValue(nsco
 nscoord
 nsCSSOffsetState::ComputeISizeValue(nscoord aContainingBlockISize,
                                     StyleBoxSizing aBoxSizing,
                                     const nsStyleCoord& aCoord) const
 {
   WritingMode wm = GetWritingMode();
   nscoord inside = 0, outside = ComputedLogicalBorderPadding().IStartEnd(wm) +
                                 ComputedLogicalMargin().IStartEnd(wm);
-  switch (aBoxSizing) {
-    case StyleBoxSizing::Border:
-      inside = ComputedLogicalBorderPadding().IStartEnd(wm);
-      break;
-    case StyleBoxSizing::Padding:
-      inside = ComputedLogicalPadding().IStartEnd(wm);
-      break;
-    case StyleBoxSizing::Content:
-      // nothing
-      break;
+  if (aBoxSizing == StyleBoxSizing::Border) {
+    inside = ComputedLogicalBorderPadding().IStartEnd(wm);
   }
   outside -= inside;
 
   return ComputeISizeValue(aContainingBlockISize, inside,
                            outside, aCoord);
 }
 
 nscoord
 nsCSSOffsetState::ComputeBSizeValue(nscoord aContainingBlockBSize,
                                     StyleBoxSizing aBoxSizing,
                                     const nsStyleCoord& aCoord) const
 {
   WritingMode wm = GetWritingMode();
   nscoord inside = 0;
-  switch (aBoxSizing) {
-    case StyleBoxSizing::Border:
-      inside = ComputedLogicalBorderPadding().BStartEnd(wm);
-      break;
-    case StyleBoxSizing::Padding:
-      inside = ComputedLogicalPadding().BStartEnd(wm);
-      break;
-    case StyleBoxSizing::Content:
-      // nothing
-      break;
+  if (aBoxSizing == StyleBoxSizing::Border) {
+    inside = ComputedLogicalBorderPadding().BStartEnd(wm);
   }
   return nsLayoutUtils::ComputeBSizeValue(aContainingBlockBSize,
                                           inside, aCoord);
 }
 
 void
 nsHTMLReflowState::SetComputedWidth(nscoord aComputedWidth)
 {
@@ -1176,26 +1160,18 @@ nsHTMLReflowState::CalculateBorderPaddin
         ComputeCBDependentValue(aContainingBlockSize,
                                 mStyleMargin->mMargin.Get(endSide));
     }
     marginStartEnd = start + end;
   }
 
   nscoord outside = paddingStartEnd + borderStartEnd + marginStartEnd;
   nscoord inside = 0;
-  switch (mStylePosition->mBoxSizing) {
-    case StyleBoxSizing::Border:
-      inside += borderStartEnd;
-      MOZ_FALLTHROUGH;
-    case StyleBoxSizing::Padding:
-      inside += paddingStartEnd;
-      MOZ_FALLTHROUGH;
-    case StyleBoxSizing::Content:
-      // nothing
-      break;
+  if (mStylePosition->mBoxSizing == StyleBoxSizing::Border) {
+    inside = borderStartEnd + paddingStartEnd;
   }
   outside -= inside;
   *aInsideBoxSizing = inside;
   *aOutsideBoxSizing = outside;
   return;
 }
 
 /**
--- a/layout/style/nsCSSProps.cpp
+++ b/layout/style/nsCSSProps.cpp
@@ -1042,17 +1042,16 @@ const KTableEntry nsCSSProps::kBoxDecora
 const KTableEntry nsCSSProps::kBoxShadowTypeKTable[] = {
   { eCSSKeyword_inset, NS_STYLE_BOX_SHADOW_INSET },
   { eCSSKeyword_UNKNOWN, -1 }
 };
 
 const KTableEntry nsCSSProps::kBoxSizingKTable[] = {
   { eCSSKeyword_content_box,  uint8_t(StyleBoxSizing::Content) },
   { eCSSKeyword_border_box,   uint8_t(StyleBoxSizing::Border) },
-  { eCSSKeyword_padding_box,  uint8_t(StyleBoxSizing::Padding) },
   { eCSSKeyword_UNKNOWN,      -1 }
 };
 
 const KTableEntry nsCSSProps::kCaptionSideKTable[] = {
   { eCSSKeyword_top,                  NS_STYLE_CAPTION_SIDE_TOP },
   { eCSSKeyword_right,                NS_STYLE_CAPTION_SIDE_RIGHT },
   { eCSSKeyword_bottom,               NS_STYLE_CAPTION_SIDE_BOTTOM },
   { eCSSKeyword_left,                 NS_STYLE_CAPTION_SIDE_LEFT },
--- a/layout/style/nsComputedDOMStyle.cpp
+++ b/layout/style/nsComputedDOMStyle.cpp
@@ -533,26 +533,18 @@ nsComputedDOMStyle::GetStyleContextForEl
 nsMargin
 nsComputedDOMStyle::GetAdjustedValuesForBoxSizing()
 {
   // We want the width/height of whatever parts 'width' or 'height' controls,
   // which can be different depending on the value of the 'box-sizing' property.
   const nsStylePosition* stylePos = StylePosition();
 
   nsMargin adjustment;
-  switch(stylePos->mBoxSizing) {
-    case StyleBoxSizing::Border:
-      adjustment += mInnerFrame->GetUsedBorder();
-      MOZ_FALLTHROUGH;
-    case StyleBoxSizing::Padding:
-      adjustment += mInnerFrame->GetUsedPadding();
-      MOZ_FALLTHROUGH;
-    case StyleBoxSizing::Content:
-      // nothing
-      break;
+  if (stylePos->mBoxSizing == StyleBoxSizing::Border) {
+    adjustment = mInnerFrame->GetUsedBorderAndPadding();
   }
 
   return adjustment;
 }
 
 /* static */
 nsIPresShell*
 nsComputedDOMStyle::GetPresShellForContent(nsIContent* aContent)
--- a/layout/style/nsStyleConsts.h
+++ b/layout/style/nsStyleConsts.h
@@ -53,17 +53,16 @@ static inline css::Side operator++(css::
 #define NS_SIDE_TO_FULL_CORNER(side_, second_) \
   (((side_) + !!(second_)) % 4)
 #define NS_SIDE_TO_HALF_CORNER(side_, second_, parallel_) \
   ((((side_) + !!(second_))*2 + ((side_) + !(parallel_))%2) % 8)
 
 // box-sizing
 enum class StyleBoxSizing : uint8_t {
   Content,
-  Padding,
   Border
 };
 
 // clip-path sizing
 #define NS_STYLE_CLIP_SHAPE_SIZING_NOBOX   0
 #define NS_STYLE_CLIP_SHAPE_SIZING_CONTENT 1
 #define NS_STYLE_CLIP_SHAPE_SIZING_PADDING 2
 #define NS_STYLE_CLIP_SHAPE_SIZING_BORDER  3
--- a/layout/style/test/property_database.js
+++ b/layout/style/test/property_database.js
@@ -1354,17 +1354,17 @@ var gCSSProperties = {
     invalid_values: []
   },
   "box-sizing": {
     domProp: "boxSizing",
     inherited: false,
     type: CSS_TYPE_LONGHAND,
     initial_values: [ "content-box" ],
     other_values: [ "border-box" ],
-    invalid_values: [ "margin-box", "content", "padding", "border", "margin" ]
+    invalid_values: [ "padding-box", "margin-box", "content", "padding", "border", "margin" ]
   },
   "-moz-box-sizing": {
     domProp: "MozBoxSizing",
     inherited: false,
     type: CSS_TYPE_SHORTHAND_AND_LONGHAND,
     alias_for: "box-sizing",
     subproperties: [ "box-sizing" ],
   },
--- a/layout/tables/BasicTableLayoutStrategy.cpp
+++ b/layout/tables/BasicTableLayoutStrategy.cpp
@@ -111,34 +111,23 @@ GetISizeInfo(nsRenderingContext *aRender
 
         // In quirks mode, table cell isize should be content-box,
         // but bsize should be border box.
         // Because of this historic anomaly, we do not use quirk.css.
         // (We can't specify one value of box-sizing for isize and another
         // for bsize).
         // For this reason, we also do not use box-sizing for just one of
         // them, as this may be confusing.
-        if (isQuirks) {
+        if (isQuirks || stylePos->mBoxSizing == StyleBoxSizing::Content) {
             boxSizingToBorderEdge = offsets.hPadding + offsets.hBorder;
         }
         else {
-            switch (stylePos->mBoxSizing) {
-                case StyleBoxSizing::Content:
-                    boxSizingToBorderEdge = offsets.hPadding + offsets.hBorder;
-                    break;
-                case StyleBoxSizing::Padding:
-                    minCoord += offsets.hPadding;
-                    prefCoord += offsets.hPadding;
-                    boxSizingToBorderEdge = offsets.hBorder;
-                    break;
-                case StyleBoxSizing::Border:
-                    minCoord += offsets.hPadding + offsets.hBorder;
-                    prefCoord += offsets.hPadding + offsets.hBorder;
-                    break;
-            }
+            // StyleBoxSizing::Border and standards-mode
+            minCoord += offsets.hPadding + offsets.hBorder;
+            prefCoord += offsets.hPadding + offsets.hBorder;
         }
     } else {
         minCoord = 0;
         prefCoord = 0;
     }
     float prefPercent = 0.0f;
     bool hasSpecifiedISize = false;
 
--- a/layout/tables/FixedTableLayoutStrategy.cpp
+++ b/layout/tables/FixedTableLayoutStrategy.cpp
@@ -230,50 +230,41 @@ FixedTableLayoutStrategy::ComputeColumnI
 
       // The 'table-layout: fixed' algorithm considers only cells in the
       // first row.
       bool originates;
       int32_t colSpan;
       nsTableCellFrame *cellFrame = cellMap->GetCellInfoAt(0, col, &originates,
                                                            &colSpan);
       if (cellFrame) {
-        styleISize = &cellFrame->StylePosition()->ISize(wm);
+        const nsStylePosition* cellStylePos = cellFrame->StylePosition();
+        styleISize = &cellStylePos->ISize(wm);
         if (styleISize->ConvertsToLength() ||
             (styleISize->GetUnit() == eStyleUnit_Enumerated &&
              (styleISize->GetIntValue() == NS_STYLE_WIDTH_MAX_CONTENT ||
               styleISize->GetIntValue() == NS_STYLE_WIDTH_MIN_CONTENT))) {
           // XXX This should use real percentage padding
           // Note that the difference between MIN_ISIZE and PREF_ISIZE
           // shouldn't matter for any of these values of styleISize; use
           // MIN_ISIZE for symmetry with GetMinISize above, just in case
           // there is a difference.
           colISize =
             nsLayoutUtils::IntrinsicForContainer(aReflowState.rendContext,
                                                  cellFrame,
                                                  nsLayoutUtils::MIN_ISIZE);
         } else if (styleISize->GetUnit() == eStyleUnit_Percent) {
           // XXX This should use real percentage padding
-          nsIFrame::IntrinsicISizeOffsetData offsets =
-            cellFrame->IntrinsicISizeOffsets();
           float pct = styleISize->GetPercentValue();
           colISize = NSToCoordFloor(pct * float(tableISize));
 
-          nscoord boxSizingAdjust = 0;
-          switch (cellFrame->StylePosition()->mBoxSizing) {
-            case StyleBoxSizing::Content:
-              boxSizingAdjust += offsets.hPadding;
-              MOZ_FALLTHROUGH;
-            case StyleBoxSizing::Padding:
-              boxSizingAdjust += offsets.hBorder;
-              MOZ_FALLTHROUGH;
-            case StyleBoxSizing::Border:
-              // Don't add anything
-              break;
+          if (cellStylePos->mBoxSizing == StyleBoxSizing::Content) {
+            nsIFrame::IntrinsicISizeOffsetData offsets =
+              cellFrame->IntrinsicISizeOffsets();
+            colISize += offsets.hPadding + offsets.hBorder;
           }
-          colISize += boxSizingAdjust;
 
           pct /= float(colSpan);
           colFrame->AddPrefPercent(pct);
           pctTotal += pct;
         } else {
           // 'auto', '-moz-available', '-moz-fit-content', and 'calc()'
           // with percentages
           colISize = unassignedMarker;
--- a/layout/tables/nsTableRowFrame.cpp
+++ b/layout/tables/nsTableRowFrame.cpp
@@ -657,41 +657,28 @@ nsTableRowFrame::CalculateCellActualBSiz
       if (bsizeStyleCoord.CalcHasPercent()) {
         // Treat this like "auto"
         break;
       }
       // Fall through to the coord case
       MOZ_FALLTHROUGH;
     }
     case eStyleUnit_Coord: {
-      nscoord outsideBoxSizing = 0;
       // In quirks mode, table cell isize should be content-box, but bsize
       // should be border-box.
       // Because of this historic anomaly, we do not use quirk.css
       // (since we can't specify one value of box-sizing for isize and another
       // for bsize)
-      if (PresContext()->CompatibilityMode() != eCompatibility_NavQuirks) {
-        switch (position->mBoxSizing) {
-          case StyleBoxSizing::Content:
-            outsideBoxSizing =
-              aCellFrame->GetLogicalUsedBorderAndPadding(aWM).BStartEnd(aWM);
-            break;
-          case StyleBoxSizing::Padding:
-            outsideBoxSizing =
-              aCellFrame->GetLogicalUsedBorder(aWM).BStartEnd(aWM);
-            break;
-          case StyleBoxSizing::Border:
-            break;
-        }
+      specifiedBSize = nsRuleNode::ComputeCoordPercentCalc(bsizeStyleCoord, 0);
+      if (PresContext()->CompatibilityMode() != eCompatibility_NavQuirks &&
+          position->mBoxSizing == StyleBoxSizing::Content) {
+        specifiedBSize +=
+          aCellFrame->GetLogicalUsedBorderAndPadding(aWM).BStartEnd(aWM);
       }
 
-      specifiedBSize =
-        nsRuleNode::ComputeCoordPercentCalc(bsizeStyleCoord, 0) +
-        outsideBoxSizing;
-
       if (1 == rowSpan) {
         SetFixedBSize(specifiedBSize);
       }
       break;
     }
     case eStyleUnit_Percent: {
       if (1 == rowSpan) {
         SetPctBSize(bsizeStyleCoord.GetPercentValue());
--- a/layout/xul/nsResizerFrame.cpp
+++ b/layout/xul/nsResizerFrame.cpp
@@ -76,26 +76,18 @@ nsResizerFrame::HandleEvent(nsPresContex
           nsIFrame* frameToResize = contentToResize->GetPrimaryFrame();
           if (!frameToResize)
             break;
 
           // cache the content rectangle for the frame to resize
           // GetScreenRectInAppUnits returns the border box rectangle, so
           // adjust to get the desired content rectangle.
           nsRect rect = frameToResize->GetScreenRectInAppUnits();
-          switch (frameToResize->StylePosition()->mBoxSizing) {
-            case StyleBoxSizing::Content:
-              rect.Deflate(frameToResize->GetUsedPadding());
-              MOZ_FALLTHROUGH;
-            case StyleBoxSizing::Padding:
-              rect.Deflate(frameToResize->GetUsedBorder());
-              MOZ_FALLTHROUGH;
-            case StyleBoxSizing::Border:
-              // nothing
-              break;
+          if (frameToResize->StylePosition()->mBoxSizing == StyleBoxSizing::Content) {
+            rect.Deflate(frameToResize->GetUsedBorderAndPadding());
           }
 
           mMouseDownRect =
             LayoutDeviceIntRect::FromAppUnitsToNearest(rect, aPresContext->AppUnitsPerDevPixel());
           doDefault = false;
         }
         else {
           // If there is no window, then resizing isn't allowed.