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

Side by Side Diff: third_party/WebKit/Source/core/paint/BackgroundImageGeometry.cpp

Issue 1811943003: Fix for lack of cover with background-size: cover (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/paint/BackgroundImageGeometry.h" 5 #include "core/paint/BackgroundImageGeometry.h"
6 6
7 #include "core/frame/FrameView.h" 7 #include "core/frame/FrameView.h"
8 #include "core/layout/LayoutBox.h" 8 #include "core/layout/LayoutBox.h"
9 #include "core/layout/LayoutBoxModelObject.h" 9 #include "core/layout/LayoutBoxModelObject.h"
10 #include "core/layout/LayoutView.h" 10 #include "core/layout/LayoutView.h"
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 102
103 // If the image has neither an intrinsic width nor an intrinsic height, its size is determined as for 'contain'. 103 // If the image has neither an intrinsic width nor an intrinsic height, its size is determined as for 'contain'.
104 type = Contain; 104 type = Contain;
105 } 105 }
106 case Contain: 106 case Contain:
107 case Cover: { 107 case Cover: {
108 float horizontalScaleFactor = imageIntrinsicSize.width() 108 float horizontalScaleFactor = imageIntrinsicSize.width()
109 ? positioningAreaSize.width().toFloat() / imageIntrinsicSize.width() : 1.0f; 109 ? positioningAreaSize.width().toFloat() / imageIntrinsicSize.width() : 1.0f;
110 float verticalScaleFactor = imageIntrinsicSize.height() 110 float verticalScaleFactor = imageIntrinsicSize.height()
111 ? positioningAreaSize.height().toFloat() / imageIntrinsicSize.height () : 1.0f; 111 ? positioningAreaSize.height().toFloat() / imageIntrinsicSize.height () : 1.0f;
112 float scaleFactor = type == Contain ? std::min(horizontalScaleFactor, ve rticalScaleFactor) : std::max(horizontalScaleFactor, verticalScaleFactor); 112 // Force the dimension that determines the size to exactly match the
113 return LayoutSize(std::max(1.0f, imageIntrinsicSize.width() * scaleFacto r), 113 // positioningAreaSize in that dimension, so that rounding of floating p oint
114 std::max(1.0f, imageIntrinsicSize.height() * scaleFactor)); 114 // approximation to LayoutUnit do not shrink the image to smaller than t he
115 // positioningAreaSize.
Stephen Chennney 2016/03/17 19:46:29 Following the style guide makes the following code
116 if (type == Contain) {
117 if (horizontalScaleFactor < verticalScaleFactor)
118 return LayoutSize(positioningAreaSize.width(), LayoutUnit(std::m ax(1.0f, imageIntrinsicSize.height() * horizontalScaleFactor)));
119 return LayoutSize(LayoutUnit(std::max(1.0f, imageIntrinsicSize.width () * verticalScaleFactor)), positioningAreaSize.height());
120 }
121 if (horizontalScaleFactor > verticalScaleFactor)
122 return LayoutSize(positioningAreaSize.width(), LayoutUnit(std::max(1 .0f, imageIntrinsicSize.height() * horizontalScaleFactor)));
123 return LayoutSize(LayoutUnit(std::max(1.0f, imageIntrinsicSize.width() * verticalScaleFactor)), positioningAreaSize.height());
115 } 124 }
116 } 125 }
117 126
118 ASSERT_NOT_REACHED(); 127 ASSERT_NOT_REACHED();
119 return LayoutSize(); 128 return LayoutSize();
120 } 129 }
121 130
122 IntPoint accumulatedScrollOffsetForFixedBackground(const LayoutBoxModelObject& o bject, const LayoutBoxModelObject* container) 131 IntPoint accumulatedScrollOffsetForFixedBackground(const LayoutBoxModelObject& o bject, const LayoutBoxModelObject* container)
123 { 132 {
124 IntPoint result; 133 IntPoint result;
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 // Clip the final output rect to the paint rect 357 // Clip the final output rect to the paint rect
349 m_destRect.intersect(paintRect); 358 m_destRect.intersect(paintRect);
350 359
351 // Snap as-yet unsnapped values. 360 // Snap as-yet unsnapped values.
352 setPhase(LayoutPoint(roundedIntPoint(m_phase))); 361 setPhase(LayoutPoint(roundedIntPoint(m_phase)));
353 setDestRect(LayoutRect(pixelSnappedIntRect(m_destRect))); 362 setDestRect(LayoutRect(pixelSnappedIntRect(m_destRect)));
354 363
355 } 364 }
356 365
357 } // namespace blink 366 } // namespace blink
OLDNEW
« 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