Bug 1265342 Part 7: Implement shape-margin for shape-outside: shape-box. draft
authorBrad Werth <bwerth@mozilla.com>
Mon, 26 Feb 2018 14:47:31 -0800
changeset 787956 52390d12e68722ea260604bdeb4337fb2f6df47b
parent 787955 cd2ea0ddb67a5d4efcbbca0aa83544c82631ed3e
child 787957 1367373ee4ef67454bd8bd7bc95940c793899c55
push id107854
push userbwerth@mozilla.com
push dateWed, 25 Apr 2018 18:14:35 +0000
bugs1265342
milestone61.0a1
Bug 1265342 Part 7: Implement shape-margin for shape-outside: shape-box. 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,