| 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/LayoutTableCell.h" | 10 #include "core/layout/LayoutTableCell.h" |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 if (!imageIntrinsicSize.isEmpty()) | 115 if (!imageIntrinsicSize.isEmpty()) |
| 116 return imageIntrinsicSize; | 116 return imageIntrinsicSize; |
| 117 | 117 |
| 118 // If the image has neither an intrinsic width nor an intrinsic height, | 118 // If the image has neither an intrinsic width nor an intrinsic height, |
| 119 // its size is determined as for 'contain'. | 119 // its size is determined as for 'contain'. |
| 120 type = Contain; | 120 type = Contain; |
| 121 } | 121 } |
| 122 case Contain: | 122 case Contain: |
| 123 case Cover: { | 123 case Cover: { |
| 124 float horizontalScaleFactor = | 124 float horizontalScaleFactor = |
| 125 imageIntrinsicSize.width() | 125 imageIntrinsicSize.width() ? positioningAreaSize.width().toFloat() / |
| 126 ? positioningAreaSize.width().toFloat() / | 126 imageIntrinsicSize.width() |
| 127 imageIntrinsicSize.width() | 127 : 1.0f; |
| 128 : 1.0f; | |
| 129 float verticalScaleFactor = imageIntrinsicSize.height() | 128 float verticalScaleFactor = imageIntrinsicSize.height() |
| 130 ? positioningAreaSize.height().toFloat() / | 129 ? positioningAreaSize.height().toFloat() / |
| 131 imageIntrinsicSize.height() | 130 imageIntrinsicSize.height() |
| 132 : 1.0f; | 131 : 1.0f; |
| 133 // Force the dimension that determines the size to exactly match the | 132 // Force the dimension that determines the size to exactly match the |
| 134 // positioningAreaSize in that dimension, so that rounding of floating | 133 // positioningAreaSize in that dimension, so that rounding of floating |
| 135 // point approximation to LayoutUnit do not shrink the image to smaller | 134 // point approximation to LayoutUnit do not shrink the image to smaller |
| 136 // than the positioningAreaSize. | 135 // than the positioningAreaSize. |
| 137 if (type == Contain) { | 136 if (type == Contain) { |
| 138 if (horizontalScaleFactor < verticalScaleFactor) | 137 if (horizontalScaleFactor < verticalScaleFactor) |
| 139 return LayoutSize( | 138 return LayoutSize( |
| 140 positioningAreaSize.width(), | 139 positioningAreaSize.width(), |
| 141 LayoutUnit(std::max( | 140 LayoutUnit(std::max( |
| 142 1.0f, imageIntrinsicSize.height() * horizontalScaleFactor))); | 141 1.0f, imageIntrinsicSize.height() * horizontalScaleFactor))); |
| 143 return LayoutSize(LayoutUnit(std::max(1.0f, imageIntrinsicSize.width() * | 142 return LayoutSize( |
| 144 verticalScaleFactor)), | 143 LayoutUnit(std::max( |
| 145 positioningAreaSize.height()); | 144 1.0f, imageIntrinsicSize.width() * verticalScaleFactor)), |
| 145 positioningAreaSize.height()); |
| 146 } | 146 } |
| 147 if (horizontalScaleFactor > verticalScaleFactor) | 147 if (horizontalScaleFactor > verticalScaleFactor) |
| 148 return LayoutSize( | 148 return LayoutSize( |
| 149 positioningAreaSize.width(), | 149 positioningAreaSize.width(), |
| 150 LayoutUnit(std::max( | 150 LayoutUnit(std::max( |
| 151 1.0f, imageIntrinsicSize.height() * horizontalScaleFactor))); | 151 1.0f, imageIntrinsicSize.height() * horizontalScaleFactor))); |
| 152 return LayoutSize(LayoutUnit(std::max(1.0f, imageIntrinsicSize.width() * | 152 return LayoutSize( |
| 153 verticalScaleFactor)), | 153 LayoutUnit( |
| 154 positioningAreaSize.height()); | 154 std::max(1.0f, imageIntrinsicSize.width() * verticalScaleFactor)), |
| 155 positioningAreaSize.height()); |
| 155 } | 156 } |
| 156 } | 157 } |
| 157 | 158 |
| 158 NOTREACHED(); | 159 NOTREACHED(); |
| 159 return LayoutSize(); | 160 return LayoutSize(); |
| 160 } | 161 } |
| 161 | 162 |
| 162 IntPoint accumulatedScrollOffsetForFixedBackground( | 163 IntPoint accumulatedScrollOffsetForFixedBackground( |
| 163 const LayoutBoxModelObject& object, | 164 const LayoutBoxModelObject& object, |
| 164 const LayoutBoxModelObject* container) { | 165 const LayoutBoxModelObject* container) { |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 return cell.location() - borderSpacing; | 352 return cell.location() - borderSpacing; |
| 352 if (positioningBox.isTableRow()) { | 353 if (positioningBox.isTableRow()) { |
| 353 return LayoutPoint(cell.location().x(), LayoutUnit()) - | 354 return LayoutPoint(cell.location().x(), LayoutUnit()) - |
| 354 LayoutSize(borderSpacing.width(), LayoutUnit()); | 355 LayoutSize(borderSpacing.width(), LayoutUnit()); |
| 355 } | 356 } |
| 356 | 357 |
| 357 LayoutRect sectionsRect(LayoutPoint(), cell.table()->size()); | 358 LayoutRect sectionsRect(LayoutPoint(), cell.table()->size()); |
| 358 cell.table()->subtractCaptionRect(sectionsRect); | 359 cell.table()->subtractCaptionRect(sectionsRect); |
| 359 LayoutUnit heightOfCaptions = | 360 LayoutUnit heightOfCaptions = |
| 360 cell.table()->size().height() - sectionsRect.height(); | 361 cell.table()->size().height() - sectionsRect.height(); |
| 361 LayoutPoint offsetInBackground = LayoutPoint( | 362 LayoutPoint offsetInBackground = |
| 362 LayoutUnit(), (cell.section()->location().y() - | 363 LayoutPoint(LayoutUnit(), |
| 363 cell.table()->borderBefore() - heightOfCaptions) + | 364 (cell.section()->location().y() - |
| 364 cell.location().y()); | 365 cell.table()->borderBefore() - heightOfCaptions) + |
| 366 cell.location().y()); |
| 365 | 367 |
| 366 DCHECK(positioningBox.isLayoutTableCol()); | 368 DCHECK(positioningBox.isLayoutTableCol()); |
| 367 if (toLayoutTableCol(positioningBox).isTableColumn()) { | 369 if (toLayoutTableCol(positioningBox).isTableColumn()) { |
| 368 return offsetInBackground - | 370 return offsetInBackground - |
| 369 LayoutSize(LayoutUnit(), borderSpacing.height()); | 371 LayoutSize(LayoutUnit(), borderSpacing.height()); |
| 370 } | 372 } |
| 371 | 373 |
| 372 DCHECK(toLayoutTableCol(positioningBox).isTableColumnGroup()); | 374 DCHECK(toLayoutTableCol(positioningBox).isTableColumnGroup()); |
| 373 LayoutUnit offset = offsetInBackground.x(); | 375 LayoutUnit offset = offsetInBackground.x(); |
| 374 expandToTableColumnGroup(cell, toLayoutTableCol(positioningBox), offset, | 376 expandToTableColumnGroup(cell, toLayoutTableCol(positioningBox), offset, |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 639 useFixedAttachment(paintRect.location()); | 641 useFixedAttachment(paintRect.location()); |
| 640 | 642 |
| 641 // Clip the final output rect to the paint rect | 643 // Clip the final output rect to the paint rect |
| 642 m_destRect.intersect(paintRect); | 644 m_destRect.intersect(paintRect); |
| 643 | 645 |
| 644 // Snap as-yet unsnapped values. | 646 // Snap as-yet unsnapped values. |
| 645 setDestRect(LayoutRect(pixelSnappedIntRect(m_destRect))); | 647 setDestRect(LayoutRect(pixelSnappedIntRect(m_destRect))); |
| 646 } | 648 } |
| 647 | 649 |
| 648 } // namespace blink | 650 } // namespace blink |
| OLD | NEW |