Chromium Code Reviews| 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" |
| 11 #include "core/layout/compositing/CompositedLayerMapping.h" | 11 #include "core/layout/compositing/CompositedLayerMapping.h" |
| 12 #include "core/paint/PaintLayer.h" | 12 #include "core/paint/PaintLayer.h" |
| 13 #include "platform/LayoutUnit.h" | 13 #include "platform/LayoutUnit.h" |
| 14 #include "platform/geometry/LayoutRect.h" | 14 #include "platform/geometry/LayoutRect.h" |
| 15 | 15 |
| 16 namespace blink { | 16 namespace blink { |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 // Return the amount of space to leave between image tiles for the background-re peat: space property. | 20 // Return the amount of space to leave between image tiles for the background-re peat: space property. |
| 21 inline LayoutUnit getSpaceBetweenImageTiles(LayoutUnit areaSize, LayoutUnit tile Size) | 21 inline LayoutUnit getSpaceBetweenImageTiles(LayoutUnit areaSize, LayoutUnit tile Size) |
| 22 { | 22 { |
| 23 int numberOfTiles = areaSize / tileSize; | 23 int numberOfTiles = (areaSize / tileSize).toInt(); |
| 24 LayoutUnit space(-1); | 24 LayoutUnit space(-1); |
| 25 | 25 |
| 26 if (numberOfTiles > 1) { | 26 if (numberOfTiles > 1) { |
| 27 // Spec doesn't specify rounding, so use the same method as for backgrou nd-repeat: round. | 27 // Spec doesn't specify rounding, so use the same method as for backgrou nd-repeat: round. |
| 28 space = (areaSize - numberOfTiles * tileSize) / (numberOfTiles - 1); | 28 space = (areaSize - numberOfTiles * tileSize) / (numberOfTiles - 1); |
| 29 } | 29 } |
| 30 | 30 |
| 31 return space; | 31 return space; |
| 32 } | 32 } |
| 33 | 33 |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 154 size.width().fraction() == destination.width().fraction() ? snapSizeToPi xel(size.width(), destination.x()) : size.width().floor(), | 154 size.width().fraction() == destination.width().fraction() ? snapSizeToPi xel(size.width(), destination.x()) : size.width().floor(), |
| 155 size.height().fraction() == destination.height().fraction() ? snapSizeTo Pixel(size.height(), destination.y()) : size.height().floor()); | 155 size.height().fraction() == destination.height().fraction() ? snapSizeTo Pixel(size.height(), destination.y()) : size.height().floor()); |
| 156 return snappedSize; | 156 return snappedSize; |
| 157 } | 157 } |
| 158 | 158 |
| 159 } // anonymous namespace | 159 } // anonymous namespace |
| 160 | 160 |
| 161 void BackgroundImageGeometry::setNoRepeatX(LayoutUnit xOffset) | 161 void BackgroundImageGeometry::setNoRepeatX(LayoutUnit xOffset) |
| 162 { | 162 { |
| 163 int roundedOffset = roundToInt(xOffset); | 163 int roundedOffset = roundToInt(xOffset); |
| 164 m_destRect.move(std::max(roundedOffset, 0), LayoutUnit()); | 164 m_destRect.move(std::max(roundedOffset, 0), 0); |
| 165 setPhaseX(LayoutUnit(-std::min(roundedOffset, 0))); | 165 setPhaseX(LayoutUnit(-std::min(roundedOffset, 0))); |
| 166 m_destRect.setWidth(m_tileSize.width() + std::min(roundedOffset, 0)); | 166 m_destRect.setWidth(m_tileSize.width() + std::min(roundedOffset, 0)); |
| 167 setSpaceSize(LayoutSize(LayoutUnit(), spaceSize().height())); | 167 setSpaceSize(LayoutSize(LayoutUnit(), spaceSize().height())); |
| 168 } | 168 } |
| 169 | 169 |
| 170 void BackgroundImageGeometry::setNoRepeatY(LayoutUnit yOffset) | 170 void BackgroundImageGeometry::setNoRepeatY(LayoutUnit yOffset) |
| 171 { | 171 { |
| 172 int roundedOffset = roundToInt(yOffset); | 172 int roundedOffset = roundToInt(yOffset); |
| 173 m_destRect.move(LayoutUnit(), std::max(roundedOffset, 0)); | 173 m_destRect.move(0, std::max(roundedOffset, 0)); |
| 174 setPhaseY(LayoutUnit(-std::min(roundedOffset, 0))); | 174 setPhaseY(LayoutUnit(-std::min(roundedOffset, 0))); |
| 175 m_destRect.setHeight(m_tileSize.height() + std::min(roundedOffset, 0)); | 175 m_destRect.setHeight(m_tileSize.height() + std::min(roundedOffset, 0)); |
| 176 setSpaceSize(LayoutSize(spaceSize().width(), LayoutUnit())); | 176 setSpaceSize(LayoutSize(spaceSize().width(), LayoutUnit())); |
| 177 } | 177 } |
| 178 | 178 |
| 179 void BackgroundImageGeometry::setRepeatX( | 179 void BackgroundImageGeometry::setRepeatX( |
| 180 const FillLayer& fillLayer, | 180 const FillLayer& fillLayer, |
| 181 LayoutUnit unsnappedTileWidth, | 181 LayoutUnit unsnappedTileWidth, |
| 182 LayoutUnit snappedAvailableWidth, | 182 LayoutUnit snappedAvailableWidth, |
| 183 LayoutUnit unsnappedAvailableWidth, | 183 LayoutUnit unsnappedAvailableWidth, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 224 } | 224 } |
| 225 } else { | 225 } else { |
| 226 setPhaseY(LayoutUnit()); | 226 setPhaseY(LayoutUnit()); |
| 227 } | 227 } |
| 228 setSpaceSize(LayoutSize(spaceSize().width(), LayoutUnit())); | 228 setSpaceSize(LayoutSize(spaceSize().width(), LayoutUnit())); |
| 229 } | 229 } |
| 230 | 230 |
| 231 void BackgroundImageGeometry::setSpaceX(LayoutUnit space, LayoutUnit availableWi dth, LayoutUnit extraOffset) | 231 void BackgroundImageGeometry::setSpaceX(LayoutUnit space, LayoutUnit availableWi dth, LayoutUnit extraOffset) |
| 232 { | 232 { |
| 233 LayoutUnit computedXPosition = roundedMinimumValueForLength(Length(), availa bleWidth); | 233 LayoutUnit computedXPosition = roundedMinimumValueForLength(Length(), availa bleWidth); |
| 234 setSpaceSize(LayoutSize(space.round(), spaceSize().height())); | 234 // TODO(crbug.com/638981): Is the conversion to int intentional? |
|
Stephen Chennney
2016/08/22 17:46:10
Yes, definitely intentional.
Xianzhu
2016/08/22 18:14:37
Done.
| |
| 235 setSpaceSize(LayoutSize(space.round(), spaceSize().height().toInt())); | |
| 235 LayoutUnit actualWidth = tileSize().width() + space; | 236 LayoutUnit actualWidth = tileSize().width() + space; |
| 236 setPhaseX(actualWidth ? LayoutUnit(roundf(actualWidth - fmodf((computedXPosi tion + extraOffset), actualWidth))) : LayoutUnit()); | 237 setPhaseX(actualWidth ? LayoutUnit(roundf(actualWidth - fmodf((computedXPosi tion + extraOffset), actualWidth))) : LayoutUnit()); |
| 237 } | 238 } |
| 238 | 239 |
| 239 void BackgroundImageGeometry::setSpaceY(LayoutUnit space, LayoutUnit availableHe ight, LayoutUnit extraOffset) | 240 void BackgroundImageGeometry::setSpaceY(LayoutUnit space, LayoutUnit availableHe ight, LayoutUnit extraOffset) |
| 240 { | 241 { |
| 241 LayoutUnit computedYPosition = roundedMinimumValueForLength(Length(), availa bleHeight); | 242 LayoutUnit computedYPosition = roundedMinimumValueForLength(Length(), availa bleHeight); |
| 242 setSpaceSize(LayoutSize(spaceSize().width(), space.round())); | 243 // TODO(crbug.com/638981): Is the conversion to int intentional? |
|
Stephen Chennney
2016/08/22 17:46:10
Yes, definitely intentional.
Xianzhu
2016/08/22 18:14:37
Done.
| |
| 244 setSpaceSize(LayoutSize(spaceSize().width().toInt(), space.round())); | |
| 243 LayoutUnit actualHeight = tileSize().height() + space; | 245 LayoutUnit actualHeight = tileSize().height() + space; |
| 244 setPhaseY(actualHeight ? LayoutUnit(roundf(actualHeight - fmodf((computedYPo sition + extraOffset), actualHeight))) : LayoutUnit()); | 246 setPhaseY(actualHeight ? LayoutUnit(roundf(actualHeight - fmodf((computedYPo sition + extraOffset), actualHeight))) : LayoutUnit()); |
| 245 } | 247 } |
| 246 | 248 |
| 247 void BackgroundImageGeometry::useFixedAttachment(const LayoutPoint& attachmentPo int) | 249 void BackgroundImageGeometry::useFixedAttachment(const LayoutPoint& attachmentPo int) |
| 248 { | 250 { |
| 249 LayoutPoint alignedPoint = attachmentPoint; | 251 LayoutPoint alignedPoint = attachmentPoint; |
| 250 m_phase.move(std::max(alignedPoint.x() - m_destRect.x(), LayoutUnit()), std: :max(alignedPoint.y() - m_destRect.y(), LayoutUnit())); | 252 m_phase.move(std::max(alignedPoint.x() - m_destRect.x(), LayoutUnit()), std: :max(alignedPoint.y() - m_destRect.y(), LayoutUnit())); |
| 251 setPhase(LayoutPoint(roundedIntPoint(m_phase))); | 253 setPhase(LayoutPoint(roundedIntPoint(m_phase))); |
| 252 } | 254 } |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 415 useFixedAttachment(paintRect.location()); | 417 useFixedAttachment(paintRect.location()); |
| 416 | 418 |
| 417 // Clip the final output rect to the paint rect | 419 // Clip the final output rect to the paint rect |
| 418 m_destRect.intersect(paintRect); | 420 m_destRect.intersect(paintRect); |
| 419 | 421 |
| 420 // Snap as-yet unsnapped values. | 422 // Snap as-yet unsnapped values. |
| 421 setDestRect(LayoutRect(pixelSnappedIntRect(m_destRect))); | 423 setDestRect(LayoutRect(pixelSnappedIntRect(m_destRect))); |
| 422 } | 424 } |
| 423 | 425 |
| 424 } // namespace blink | 426 } // namespace blink |
| OLD | NEW |