Bug 1469000: Fix image to layout transform for invalidation. r?mattwoodrow draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Tue, 19 Jun 2018 17:51:53 +0200
changeset 808455 9512c19d26b3aa215b826074db3ddd60e20543ca
parent 808454 801934c047e169b84633232b59b4f8826b30ba6c
push id113390
push userbmo:emilio@crisal.io
push dateTue, 19 Jun 2018 16:01:28 +0000
reviewersmattwoodrow
bugs1469000
milestone62.0a1
Bug 1469000: Fix image to layout transform for invalidation. r?mattwoodrow When computing image to layout transforms for invalidation, use the actual intrinsic size of the source image, instead of the layout intrinsic size, which may be scaled by ResponsiveImageSelector. I have absolutely no idea how to write a test for this, suggestions welcome. MozReview-Commit-ID: LP6C9fSvMi2
layout/generic/nsImageFrame.cpp
--- a/layout/generic/nsImageFrame.cpp
+++ b/layout/generic/nsImageFrame.cpp
@@ -379,35 +379,32 @@ nsImageFrame::GetSourceToDestTransform(n
   nsRect destRect = nsLayoutUtils::ComputeObjectDestRect(constraintRect,
                                                          mIntrinsicSize,
                                                          mIntrinsicRatio,
                                                          StylePosition());
   // Set the translation components, based on destRect
   // XXXbz does this introduce rounding errors because of the cast to
   // float?  Should we just manually add that stuff in every time
   // instead?
-  aTransform.SetToTranslate(float(destRect.x),
-                            float(destRect.y));
+  aTransform.SetToTranslate(float(destRect.x), float(destRect.y));
+
 
-  // Set the scale factors, based on destRect and intrinsic size.
-  if (mIntrinsicSize.width.GetUnit() == eStyleUnit_Coord &&
-      mIntrinsicSize.width.GetCoordValue() != 0 &&
-      mIntrinsicSize.height.GetUnit() == eStyleUnit_Coord &&
-      mIntrinsicSize.height.GetCoordValue() != 0 &&
-      mIntrinsicSize.width.GetCoordValue() != destRect.width &&
-      mIntrinsicSize.height.GetCoordValue() != destRect.height) {
-
-    aTransform.SetScale(float(destRect.width)  /
-                        float(mIntrinsicSize.width.GetCoordValue()),
-                        float(destRect.height) /
-                        float(mIntrinsicSize.height.GetCoordValue()));
-    return true;
+  // NOTE(emilio): This intrinsicSize is not the same as the layout intrinsic
+  // size (mIntrinsicSize), which can be scaled due to ResponsiveImageSelector,
+  // see ScaleIntrinsicSizeForDensity.
+  nsSize intrinsicSize;
+  if (!mImage ||
+      !NS_SUCCEEDED(mImage->GetIntrinsicSize(&intrinsicSize)) ||
+      intrinsicSize.IsEmpty()) {
+    return false;
   }
 
-  return false;
+  aTransform.SetScale(float(destRect.width)  / float(intrinsicSize.width),
+                      float(destRect.height) / float(intrinsicSize.height));
+  return true;
 }
 
 // This function checks whether the given request is the current request for our
 // mContent.
 bool
 nsImageFrame::IsPendingLoad(imgIRequest* aRequest) const
 {
   // Default to pending load in case of errors