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 767052 73d56b6e75bc2c0b3cebc7de0bd43946fe1afaa8
parent 767051 c9623fe3361a19800d1d61bc6f5ef3d728a76a0b
push id102494
push userbwerth@mozilla.com
push dateTue, 13 Mar 2018 20:51:39 +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,
     const LogicalRect& aShapeBoxRect,
@@ -1495,20 +1496,24 @@ nsFloatManager::FloatInfo::FloatInfo(nsI
         // Image is not ready, or fails to load, etc.
         return;
       }
 
       break;
     }
 
     case StyleShapeSourceType::Box: {
+      nscoord shapeMargin =
+        ::ResolveToDefiniteSize(mFrame->StyleDisplay()->mShapeMargin,
+                                aContainerSize.width);
       // 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 =
         ::ResolveToDefiniteSize(mFrame->StyleDisplay()->mShapeMargin,
@@ -1661,30 +1666,36 @@ 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);
 
   nscoord physicalRadii[8];
   bool hasRadii = aFrame->GetShapeBoxBorderRadii(physicalRadii);
-  if (!hasRadii) {
+  if (!hasRadii && aShapeMargin <= 0) {
     return MakeUnique<RoundedBoxShapeInfo>(logicalShapeBoxRect,
                                            UniquePtr<nscoord[]>());
   }
 
+  // Add aShapeMargin to each of the radii.
+  for (int32_t i = 0; i < 8; ++i) {
+    physicalRadii[i] += aShapeMargin;
+  }
+
   return MakeUnique<RoundedBoxShapeInfo>(logicalShapeBoxRect,
                                          ConvertToFloatLogical(physicalRadii,
                                                                aWM));
 }
 
 /* static */ UniquePtr<nsFloatManager::ShapeInfo>
 nsFloatManager::ShapeInfo::CreateBasicShape(
   const UniquePtr<StyleBasicShape>& aBasicShape,