Bug 1265342 Part 7: Implement shape-margin for shape-outside: shape-box. r=dholbert
☠☠ backed out by 723a9f786923 ☠ ☠
authorBrad Werth <bwerth@mozilla.com>
Mon, 26 Feb 2018 14:47:31 -0800
changeset 471525 0791ff3d91947249711a0d880582003d5cec7b13
parent 471524 7109288f10b3e516bf891f6f72c5c711cd993d40
child 471526 a90aa063b2fd736680ebf86a00bc2a3fc5648754
push id1728
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:12:27 +0000
treeherdermozilla-release@c296fde26f5f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert
bugs1265342
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1265342 Part 7: Implement shape-margin for shape-outside: shape-box. r=dholbert MozReview-Commit-ID: 67vq9Gcr8qJ
layout/generic/nsFloatManager.cpp
--- a/layout/generic/nsFloatManager.cpp
+++ b/layout/generic/nsFloatManager.cpp
@@ -548,16 +548,17 @@ public:
                                       const nsSize& aContainerSize)
   {
     return nsRect(aRect.LineLeft(aWM, aContainerSize), aRect.BStart(aWM),
                   aRect.ISize(aWM), aRect.BSize(aWM));
   }
 
   static UniquePtr<ShapeInfo> CreateShapeBox(
     nsIFrame* const aFrame,
+    nscoord aShapeMargin,
     const LogicalRect& aShapeBoxRect,
     WritingMode aWM,
     const nsSize& aContainerSize);
 
   static UniquePtr<ShapeInfo> CreateBasicShape(
     const UniquePtr<StyleBasicShape>& aBasicShape,
     nscoord aShapeMargin,
     nsIFrame* const aFrame,
@@ -1949,30 +1950,33 @@ nsFloatManager::FloatInfo::FloatInfo(nsI
     // margin box.
 
     // https://drafts.csswg.org/css-shapes/#relation-to-box-model-and-float-behavior
     return;
   }
 
   const StyleShapeSource& shapeOutside = mFrame->StyleDisplay()->mShapeOutside;
 
+  nscoord shapeMargin = (shapeOutside.GetType() == StyleShapeSourceType::None)
+   ? 0
+   : nsLayoutUtils::ResolveToLength<true>(
+       mFrame->StyleDisplay()->mShapeMargin,
+       LogicalSize(aWM, aContainerSize).ISize(aWM));
+
   switch (shapeOutside.GetType()) {
     case StyleShapeSourceType::None:
       // No need to create shape info.
       return;
 
     case StyleShapeSourceType::URL:
       MOZ_ASSERT_UNREACHABLE("shape-outside doesn't have URL source type!");
       return;
 
     case StyleShapeSourceType::Image: {
       float shapeImageThreshold = mFrame->StyleDisplay()->mShapeImageThreshold;
-      nscoord shapeMargin = nsLayoutUtils::ResolveToLength<true>(
-        mFrame->StyleDisplay()->mShapeMargin,
-        LogicalSize(aWM, aContainerSize).ISize(aWM));
       mShapeInfo = ShapeInfo::CreateImageShape(shapeOutside.GetShapeImage(),
                                                shapeImageThreshold,
                                                shapeMargin,
                                                mFrame,
                                                aMarginRect,
                                                aWM,
                                                aContainerSize);
       if (!mShapeInfo) {
@@ -1982,26 +1986,24 @@ nsFloatManager::FloatInfo::FloatInfo(nsI
 
       break;
     }
 
     case StyleShapeSourceType::Box: {
       // Initialize <shape-box>'s reference rect.
       LogicalRect shapeBoxRect =
         ShapeInfo::ComputeShapeBoxRect(shapeOutside, mFrame, aMarginRect, aWM);
-      mShapeInfo = ShapeInfo::CreateShapeBox(mFrame, shapeBoxRect, aWM,
+      mShapeInfo = ShapeInfo::CreateShapeBox(mFrame, shapeMargin,
+                                             shapeBoxRect, aWM,
                                              aContainerSize);
       break;
     }
 
     case StyleShapeSourceType::Shape: {
       const UniquePtr<StyleBasicShape>& basicShape = shapeOutside.GetBasicShape();
-      nscoord shapeMargin = nsLayoutUtils::ResolveToLength<true>(
-        mFrame->StyleDisplay()->mShapeMargin,
-        LogicalSize(aWM, aContainerSize).ISize(aWM));
       // Initialize <shape-box>'s reference rect.
       LogicalRect shapeBoxRect =
         ShapeInfo::ComputeShapeBoxRect(shapeOutside, mFrame, aMarginRect, aWM);
       mShapeInfo = ShapeInfo::CreateBasicShape(basicShape, shapeMargin, mFrame,
                                                shapeBoxRect, aWM,
                                                aContainerSize);
       break;
     }
@@ -2145,30 +2147,39 @@ nsFloatManager::ShapeInfo::ComputeShapeB
   }
 
   return rect;
 }
 
 /* static */ UniquePtr<nsFloatManager::ShapeInfo>
 nsFloatManager::ShapeInfo::CreateShapeBox(
   nsIFrame* const aFrame,
+  nscoord aShapeMargin,
   const LogicalRect& aShapeBoxRect,
   WritingMode aWM,
   const nsSize& aContainerSize)
 {
   nsRect logicalShapeBoxRect
     = ConvertToFloatLogical(aShapeBoxRect, aWM, aContainerSize);
 
+  // Inflate logicalShapeBoxRect by aShapeMargin.
+  logicalShapeBoxRect.Inflate(aShapeMargin);
+
   nscoord physicalRadii[8];
   bool hasRadii = aFrame->GetShapeBoxBorderRadii(physicalRadii);
   if (!hasRadii) {
     return MakeUnique<RoundedBoxShapeInfo>(logicalShapeBoxRect,
                                            UniquePtr<nscoord[]>());
   }
 
+  // Add aShapeMargin to each of the radii.
+  for (nscoord& r : physicalRadii) {
+    r += aShapeMargin;
+  }
+
   return MakeUnique<RoundedBoxShapeInfo>(logicalShapeBoxRect,
                                          ConvertToFloatLogical(physicalRadii,
                                                                aWM));
 }
 
 /* static */ UniquePtr<nsFloatManager::ShapeInfo>
 nsFloatManager::ShapeInfo::CreateBasicShape(
   const UniquePtr<StyleBasicShape>& aBasicShape,