Bug 1464113 Part 1: Make ImageShapeInfo tolerate shapes that are shifted left or above their margin rects. draft
authorBrad Werth <bwerth@mozilla.com>
Fri, 25 May 2018 15:12:02 -0700
changeset 800139 af3ea4f9dea580d5562f73f748cbf71113b9b760
parent 799792 bf4762f10b8d3076d6862e88ca61f90271291508
child 800140 86160534ffcb0b999dfb863f10c4486d4826b563
push id111282
push userbwerth@mozilla.com
push dateFri, 25 May 2018 23:19:27 +0000
bugs1464113
milestone62.0a1
Bug 1464113 Part 1: Make ImageShapeInfo tolerate shapes that are shifted left or above their margin rects. MozReview-Commit-ID: 9NuHsjQfLxP
layout/generic/nsFloatManager.cpp
--- a/layout/generic/nsFloatManager.cpp
+++ b/layout/generic/nsFloatManager.cpp
@@ -1925,19 +1925,16 @@ nsFloatManager::ImageShapeInfo::ImageSha
                                                 aAppUnitsPerDevPixel);
 
     // Allocate our distance field.  The distance field has to cover
     // the entire aMarginRect, since aShapeMargin could bleed into it,
     // beyond the content rect covered by aAlphaPixels. To make this work,
     // we calculate a dfOffset value which is the top left of the content
     // rect relative to the margin rect.
     nsPoint offsetPoint = aContentRect.TopLeft() - aMarginRect.TopLeft();
-    MOZ_ASSERT(offsetPoint.x >= 0 && offsetPoint.y >= 0,
-               "aContentRect should be within aMarginRect, which we need "
-               "for our math to make sense.");
     LayoutDeviceIntPoint dfOffset =
       LayoutDevicePixel::FromAppUnitsRounded(offsetPoint,
                                              aAppUnitsPerDevPixel);
 
     // Since our distance field is computed with a 5x5 neighborhood,
     // we need to expand our distance field by a further 4 pixels in
     // both axes, 2 on the leading edge and 2 on the trailing edge.
     // We call this edge area the "expanded region".
@@ -2009,20 +2006,20 @@ nsFloatManager::ImageShapeInfo::ImageSha
 
         // Handle our three cases, in order.
         if (col < kExpansionPerSide ||
             col >= wEx - kExpansionPerSide ||
             row < kExpansionPerSide ||
             row >= hEx - kExpansionPerSide) {
           // Case 1: Expanded pixel.
           df[index] = MAX_MARGIN_5X;
-        } else if (col >= (uint32_t)dfOffset.x &&
-                   col < (uint32_t)(dfOffset.x + w) &&
-                   row >= (uint32_t)dfOffset.y &&
-                   row < (uint32_t)(dfOffset.y + h) &&
+        } else if ((int32_t)col >= dfOffset.x &&
+                   (int32_t)col < (dfOffset.x + aImageSize.width) &&
+                   (int32_t)row >= dfOffset.y &&
+                   (int32_t)row < (dfOffset.y + aImageSize.height) &&
                    aAlphaPixels[col - dfOffset.x +
                                 (row - dfOffset.y) * aStride] > threshold) {
           // Case 2: Image pixel that is opaque.
           DebugOnly<uint32_t> alphaIndex = col - dfOffset.x +
                                            (row - dfOffset.y) * aStride;
           MOZ_ASSERT(alphaIndex < (aStride * h),
             "Our aAlphaPixels index should be in-bounds.");