Bug 1265342 Part 7: Implement shape-margin for shape-outside: shape-box. r=dholbert
authorBrad Werth <bwerth@mozilla.com>
Mon, 26 Feb 2018 14:47:31 -0800
changeset 469098 0cb6c9f7c6dbf71e5143b901de1dd3aa128f949d
parent 469097 93dacd65e0093ba69fc376f0859a54be4e325388
child 469099 581d1a27f4eff370799aef05a2375d69f423f4b7
push id9165
push userasasaki@mozilla.com
push dateThu, 26 Apr 2018 21:04:54 +0000
treeherdermozilla-beta@064c3804de2e [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,