| OLD | NEW |
| 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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 | 103 |
| 104 // If the image has neither an intrinsic width nor an intrinsic height,
its size is determined as for 'contain'. | 104 // If the image has neither an intrinsic width nor an intrinsic height,
its size is determined as for 'contain'. |
| 105 type = Contain; | 105 type = Contain; |
| 106 } | 106 } |
| 107 case Contain: | 107 case Contain: |
| 108 case Cover: { | 108 case Cover: { |
| 109 float horizontalScaleFactor = imageIntrinsicSize.width() | 109 float horizontalScaleFactor = imageIntrinsicSize.width() |
| 110 ? positioningAreaSize.width().toFloat() / imageIntrinsicSize.width()
: 1.0f; | 110 ? positioningAreaSize.width().toFloat() / imageIntrinsicSize.width()
: 1.0f; |
| 111 float verticalScaleFactor = imageIntrinsicSize.height() | 111 float verticalScaleFactor = imageIntrinsicSize.height() |
| 112 ? positioningAreaSize.height().toFloat() / imageIntrinsicSize.height
() : 1.0f; | 112 ? positioningAreaSize.height().toFloat() / imageIntrinsicSize.height
() : 1.0f; |
| 113 float scaleFactor = type == Contain ? std::min(horizontalScaleFactor, ve
rticalScaleFactor) : std::max(horizontalScaleFactor, verticalScaleFactor); | 113 // Force the dimension that determines the size to exactly match the |
| 114 return LayoutSize(std::max(1.0f, imageIntrinsicSize.width() * scaleFacto
r), | 114 // positioningAreaSize in that dimension, so that rounding of floating p
oint |
| 115 std::max(1.0f, imageIntrinsicSize.height() * scaleFactor)); | 115 // approximation to LayoutUnit do not shrink the image to smaller than t
he |
| 116 // positioningAreaSize. |
| 117 if (type == Contain) { |
| 118 if (horizontalScaleFactor < verticalScaleFactor) |
| 119 return LayoutSize(positioningAreaSize.width(), LayoutUnit(std::m
ax(1.0f, imageIntrinsicSize.height() * horizontalScaleFactor))); |
| 120 return LayoutSize(LayoutUnit(std::max(1.0f, imageIntrinsicSize.width
() * verticalScaleFactor)), positioningAreaSize.height()); |
| 121 } |
| 122 if (horizontalScaleFactor > verticalScaleFactor) |
| 123 return LayoutSize(positioningAreaSize.width(), LayoutUnit(std::max(1
.0f, imageIntrinsicSize.height() * horizontalScaleFactor))); |
| 124 return LayoutSize(LayoutUnit(std::max(1.0f, imageIntrinsicSize.width() *
verticalScaleFactor)), positioningAreaSize.height()); |
| 116 } | 125 } |
| 117 } | 126 } |
| 118 | 127 |
| 119 ASSERT_NOT_REACHED(); | 128 ASSERT_NOT_REACHED(); |
| 120 return LayoutSize(); | 129 return LayoutSize(); |
| 121 } | 130 } |
| 122 | 131 |
| 123 IntPoint accumulatedScrollOffsetForFixedBackground(const LayoutBoxModelObject& o
bject, const LayoutBoxModelObject* container) | 132 IntPoint accumulatedScrollOffsetForFixedBackground(const LayoutBoxModelObject& o
bject, const LayoutBoxModelObject* container) |
| 124 { | 133 { |
| 125 IntPoint result; | 134 IntPoint result; |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 } | 373 } |
| 365 | 374 |
| 366 if (fixedAttachment) | 375 if (fixedAttachment) |
| 367 useFixedAttachment(paintRect.location()); | 376 useFixedAttachment(paintRect.location()); |
| 368 | 377 |
| 369 clip(paintRect); | 378 clip(paintRect); |
| 370 pixelSnapGeometry(); | 379 pixelSnapGeometry(); |
| 371 } | 380 } |
| 372 | 381 |
| 373 } // namespace blink | 382 } // namespace blink |
| OLD | NEW |