Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(677)

Unified Diff: third_party/WebKit/Source/core/paint/BackgroundImageGeometry.cpp

Issue 1823593003: Fix for lack of cover with background-size: cover (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2661
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/LayoutTests/fast/backgrounds/background-cover-rounding-expected.html ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/paint/BackgroundImageGeometry.cpp
diff --git a/third_party/WebKit/Source/core/paint/BackgroundImageGeometry.cpp b/third_party/WebKit/Source/core/paint/BackgroundImageGeometry.cpp
index 5de58bf6baff7f948809727fb61ab65e331606cb..933fba27dd073c50d4ce315aca6f68eddb0b6be8 100644
--- a/third_party/WebKit/Source/core/paint/BackgroundImageGeometry.cpp
+++ b/third_party/WebKit/Source/core/paint/BackgroundImageGeometry.cpp
@@ -110,9 +110,18 @@ LayoutSize calculateFillTileSize(const LayoutBoxModelObject& obj, const FillLaye
? positioningAreaSize.width().toFloat() / imageIntrinsicSize.width() : 1.0f;
float verticalScaleFactor = imageIntrinsicSize.height()
? positioningAreaSize.height().toFloat() / imageIntrinsicSize.height() : 1.0f;
- float scaleFactor = type == Contain ? std::min(horizontalScaleFactor, verticalScaleFactor) : std::max(horizontalScaleFactor, verticalScaleFactor);
- return LayoutSize(std::max(1.0f, imageIntrinsicSize.width() * scaleFactor),
- std::max(1.0f, imageIntrinsicSize.height() * scaleFactor));
+ // Force the dimension that determines the size to exactly match the
+ // positioningAreaSize in that dimension, so that rounding of floating point
+ // approximation to LayoutUnit do not shrink the image to smaller than the
+ // positioningAreaSize.
+ if (type == Contain) {
+ if (horizontalScaleFactor < verticalScaleFactor)
+ return LayoutSize(positioningAreaSize.width(), LayoutUnit(std::max(1.0f, imageIntrinsicSize.height() * horizontalScaleFactor)));
+ return LayoutSize(LayoutUnit(std::max(1.0f, imageIntrinsicSize.width() * verticalScaleFactor)), positioningAreaSize.height());
+ }
+ if (horizontalScaleFactor > verticalScaleFactor)
+ return LayoutSize(positioningAreaSize.width(), LayoutUnit(std::max(1.0f, imageIntrinsicSize.height() * horizontalScaleFactor)));
+ return LayoutSize(LayoutUnit(std::max(1.0f, imageIntrinsicSize.width() * verticalScaleFactor)), positioningAreaSize.height());
}
}
« no previous file with comments | « third_party/WebKit/LayoutTests/fast/backgrounds/background-cover-rounding-expected.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698