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

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

Issue 2261663002: Disallow cast/implicit conversion from LayoutUnit to int/unsigned (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: - Created 4 years, 4 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
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"
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
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
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 setSpaceSize(LayoutSize(space.round(), spaceSize().height().toInt()));
235 LayoutUnit actualWidth = tileSize().width() + space; 235 LayoutUnit actualWidth = tileSize().width() + space;
236 setPhaseX(actualWidth ? LayoutUnit(roundf(actualWidth - fmodf((computedXPosi tion + extraOffset), actualWidth))) : LayoutUnit()); 236 setPhaseX(actualWidth ? LayoutUnit(roundf(actualWidth - fmodf((computedXPosi tion + extraOffset), actualWidth))) : LayoutUnit());
237 } 237 }
238 238
239 void BackgroundImageGeometry::setSpaceY(LayoutUnit space, LayoutUnit availableHe ight, LayoutUnit extraOffset) 239 void BackgroundImageGeometry::setSpaceY(LayoutUnit space, LayoutUnit availableHe ight, LayoutUnit extraOffset)
240 { 240 {
241 LayoutUnit computedYPosition = roundedMinimumValueForLength(Length(), availa bleHeight); 241 LayoutUnit computedYPosition = roundedMinimumValueForLength(Length(), availa bleHeight);
242 setSpaceSize(LayoutSize(spaceSize().width(), space.round())); 242 setSpaceSize(LayoutSize(spaceSize().width().toInt(), space.round()));
243 LayoutUnit actualHeight = tileSize().height() + space; 243 LayoutUnit actualHeight = tileSize().height() + space;
244 setPhaseY(actualHeight ? LayoutUnit(roundf(actualHeight - fmodf((computedYPo sition + extraOffset), actualHeight))) : LayoutUnit()); 244 setPhaseY(actualHeight ? LayoutUnit(roundf(actualHeight - fmodf((computedYPo sition + extraOffset), actualHeight))) : LayoutUnit());
245 } 245 }
246 246
247 void BackgroundImageGeometry::useFixedAttachment(const LayoutPoint& attachmentPo int) 247 void BackgroundImageGeometry::useFixedAttachment(const LayoutPoint& attachmentPo int)
248 { 248 {
249 LayoutPoint alignedPoint = attachmentPoint; 249 LayoutPoint alignedPoint = attachmentPoint;
250 m_phase.move(std::max(alignedPoint.x() - m_destRect.x(), LayoutUnit()), std: :max(alignedPoint.y() - m_destRect.y(), LayoutUnit())); 250 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))); 251 setPhase(LayoutPoint(roundedIntPoint(m_phase)));
252 } 252 }
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 useFixedAttachment(paintRect.location()); 415 useFixedAttachment(paintRect.location());
416 416
417 // Clip the final output rect to the paint rect 417 // Clip the final output rect to the paint rect
418 m_destRect.intersect(paintRect); 418 m_destRect.intersect(paintRect);
419 419
420 // Snap as-yet unsnapped values. 420 // Snap as-yet unsnapped values.
421 setDestRect(LayoutRect(pixelSnappedIntRect(m_destRect))); 421 setDestRect(LayoutRect(pixelSnappedIntRect(m_destRect)));
422 } 422 }
423 423
424 } // namespace blink 424 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/page/SpatialNavigation.cpp ('k') | third_party/WebKit/Source/core/paint/BoxPainter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698