Bug 1275966 - Part 1. Fix wrong rendering of background-repeat:space. r=mstange
authorEthan Lin <ethlin@mozilla.com>
Sat, 28 May 2016 06:23:00 +0200
changeset 340724 25fb10028068d558a7869fb9b71d0097b4f9e8e5
parent 340723 830cccc16bd90dc0c2277247026c2a665c794cee
child 340725 005a02a60fbd9e61026054cc9f5a3a3a09cbabec
push id1183
push userraliiev@mozilla.com
push dateMon, 05 Sep 2016 20:01:49 +0000
treeherdermozilla-release@3148731bed45 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange
bugs1275966
milestone49.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 1275966 - Part 1. Fix wrong rendering of background-repeat:space. r=mstange
layout/base/nsCSSRendering.cpp
--- a/layout/base/nsCSSRendering.cpp
+++ b/layout/base/nsCSSRendering.cpp
@@ -3322,25 +3322,29 @@ ComputeDrawnSizeForBackground(const CSSS
 
   return imageSize;
 }
 
 /* ComputeSpacedRepeatSize
  * aImageDimension: the image width/height
  * aAvailableSpace: the background positioning area width/height
  * aRepeatSize: the image size plus gap size of app units for use as spacing
+ * aRepeat: determine whether the image is repeated
  */
 static nscoord
 ComputeSpacedRepeatSize(nscoord aImageDimension,
-                        nscoord aAvailableSpace) {
+                        nscoord aAvailableSpace,
+                        bool& aRepeat) {
   float ratio = aAvailableSpace / aImageDimension;
 
   if (ratio < 2.0f) { // If you can't repeat at least twice, then don't repeat.
+    aRepeat = false;
     return aImageDimension;
   } else {
+    aRepeat = true;
     return (aAvailableSpace - aImageDimension) / (NSToIntFloor(ratio) - 1);
   }
 }
 
 nsBackgroundLayerState
 nsCSSRendering::PrepareImageLayer(nsPresContext* aPresContext,
                                   nsIFrame* aForFrame,
                                   uint32_t aFlags,
@@ -3484,30 +3488,34 @@ nsCSSRendering::PrepareImageLayer(nsPres
 
   // Compute the position of the background now that the background's size is
   // determined.
   nsImageRenderer::ComputeObjectAnchorPoint(aLayer.mPosition,
                                             bgPositionSize, imageSize,
                                             &imageTopLeft, &state.mAnchor);
   state.mRepeatSize = imageSize;
   if (repeatX == NS_STYLE_IMAGELAYER_REPEAT_SPACE) {
+    bool isRepeat;
     state.mRepeatSize.width = ComputeSpacedRepeatSize(imageSize.width,
-                                                      bgPositionSize.width);
-    if (state.mRepeatSize.width > imageSize.width) {
+                                                      bgPositionSize.width,
+                                                      isRepeat);
+    if (isRepeat) {
       imageTopLeft.x = 0;
       state.mAnchor.x = 0;
     } else {
       repeatX = NS_STYLE_IMAGELAYER_REPEAT_NO_REPEAT;
     }
   }
 
   if (repeatY == NS_STYLE_IMAGELAYER_REPEAT_SPACE) {
+    bool isRepeat;
     state.mRepeatSize.height = ComputeSpacedRepeatSize(imageSize.height,
-                                                       bgPositionSize.height);
-    if (state.mRepeatSize.height > imageSize.height) {
+                                                       bgPositionSize.height,
+                                                       isRepeat);
+    if (isRepeat) {
       imageTopLeft.y = 0;
       state.mAnchor.y = 0;
     } else {
       repeatY = NS_STYLE_IMAGELAYER_REPEAT_NO_REPEAT;
     }
   }
 
   imageTopLeft += bgPositioningArea.TopLeft();