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

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

Issue 1780893004: Adjust the rounding methodology for tiled background phase (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed bad comment 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
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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 m_phase.setY(-std::min(yOffset, LayoutUnit())); 162 m_phase.setY(-std::min(yOffset, LayoutUnit()));
163 m_destRect.setHeight(m_tileSize.height() + std::min(yOffset, LayoutUnit())); 163 m_destRect.setHeight(m_tileSize.height() + std::min(yOffset, LayoutUnit()));
164 } 164 }
165 165
166 void BackgroundImageGeometry::useFixedAttachment(const LayoutPoint& attachmentPo int) 166 void BackgroundImageGeometry::useFixedAttachment(const LayoutPoint& attachmentPo int)
167 { 167 {
168 LayoutPoint alignedPoint = attachmentPoint; 168 LayoutPoint alignedPoint = attachmentPoint;
169 m_phase.move(std::max(alignedPoint.x() - m_destRect.x(), LayoutUnit()), std: :max(alignedPoint.y() - m_destRect.y(), LayoutUnit())); 169 m_phase.move(std::max(alignedPoint.x() - m_destRect.x(), LayoutUnit()), std: :max(alignedPoint.y() - m_destRect.y(), LayoutUnit()));
170 } 170 }
171 171
172 void BackgroundImageGeometry::clip(const LayoutRect& clipRect)
173 {
174 m_destRect.intersect(clipRect);
175 }
176
177 void BackgroundImageGeometry::pixelSnapGeometry()
178 {
179 setTileSize(applySubPixelHeuristicToImageSize(m_tileSize, m_destRect));
180 setImageContainerSize(applySubPixelHeuristicToImageSize(m_imageContainerSize , m_destRect));
181 setSpaceSize(LayoutSize(roundedIntSize(m_repeatSpacing)));
182 setDestRect(LayoutRect(pixelSnappedIntRect(m_destRect)));
183 setPhase(LayoutPoint(flooredIntPoint(m_phase)));
184 }
185
186 void BackgroundImageGeometry::calculate(const LayoutBoxModelObject& obj, const L ayoutBoxModelObject* paintContainer, 172 void BackgroundImageGeometry::calculate(const LayoutBoxModelObject& obj, const L ayoutBoxModelObject* paintContainer,
187 const GlobalPaintFlags globalPaintFlags, const FillLayer& fillLayer, const L ayoutRect& paintRect) 173 const GlobalPaintFlags globalPaintFlags, const FillLayer& fillLayer, const L ayoutRect& paintRect)
188 { 174 {
189 LayoutUnit left; 175 LayoutUnit left;
190 LayoutUnit top; 176 LayoutUnit top;
191 LayoutSize positioningAreaSize; 177 LayoutSize positioningAreaSize;
192 bool isLayoutView = obj.isLayoutView(); 178 bool isLayoutView = obj.isLayoutView();
193 const LayoutBox* rootBox = nullptr; 179 const LayoutBox* rootBox = nullptr;
194 if (isLayoutView) { 180 if (isLayoutView) {
195 // It is only possible reach here when root element has a box. 181 // It is only possible reach here when root element has a box.
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 if (paintContainer) 249 if (paintContainer)
264 viewportRect.moveBy(LayoutPoint(-paintContainer->localToAbsolute(Flo atPoint()))); 250 viewportRect.moveBy(LayoutPoint(-paintContainer->localToAbsolute(Flo atPoint())));
265 251
266 setDestRect(viewportRect); 252 setDestRect(viewportRect);
267 positioningAreaSize = destRect().size(); 253 positioningAreaSize = destRect().size();
268 } 254 }
269 255
270 LayoutSize fillTileSize(calculateFillTileSize(positioningBox, fillLayer, pos itioningAreaSize)); 256 LayoutSize fillTileSize(calculateFillTileSize(positioningBox, fillLayer, pos itioningAreaSize));
271 // It's necessary to apply the heuristic here prior to any further calculati ons to avoid 257 // It's necessary to apply the heuristic here prior to any further calculati ons to avoid
272 // incorrectly using sub-pixel values that won't be present in the painted t ile. 258 // incorrectly using sub-pixel values that won't be present in the painted t ile.
273 fillTileSize = applySubPixelHeuristicToImageSize(fillTileSize, m_destRect); 259 setTileSize(applySubPixelHeuristicToImageSize(fillTileSize, m_destRect));
274 setTileSize(fillTileSize);
275 setImageContainerSize(fillTileSize);
276 260
277 EFillRepeat backgroundRepeatX = fillLayer.repeatX(); 261 EFillRepeat backgroundRepeatX = fillLayer.repeatX();
278 EFillRepeat backgroundRepeatY = fillLayer.repeatY(); 262 EFillRepeat backgroundRepeatY = fillLayer.repeatY();
279 positioningAreaSize = LayoutSize(snapSizeToPixel(positioningAreaSize.width() , m_destRect.x()), snapSizeToPixel(positioningAreaSize.height(), m_destRect.y()) ); 263 positioningAreaSize = LayoutSize(snapSizeToPixel(positioningAreaSize.width() , m_destRect.x()), snapSizeToPixel(positioningAreaSize.height(), m_destRect.y()) );
280 LayoutUnit availableWidth = positioningAreaSize.width() - tileSize().width() ; 264 LayoutUnit availableWidth = positioningAreaSize.width() - tileSize().width() ;
281 LayoutUnit availableHeight = positioningAreaSize.height() - tileSize().heigh t(); 265 LayoutUnit availableHeight = positioningAreaSize.height() - tileSize().heigh t();
282 266
283 LayoutUnit computedXPosition = roundedMinimumValueForLength(fillLayer.xPosit ion(), availableWidth); 267 LayoutUnit computedXPosition = roundedMinimumValueForLength(fillLayer.xPosit ion(), availableWidth);
284 if (backgroundRepeatX == RoundFill && positioningAreaSize.width() > LayoutUn it() && fillTileSize.width() > LayoutUnit()) { 268 if (backgroundRepeatX == RoundFill && positioningAreaSize.width() > LayoutUn it() && fillTileSize.width() > LayoutUnit()) {
285 int nrTiles = std::max(1, roundToInt(positioningAreaSize.width() / fillT ileSize.width())); 269 int nrTiles = std::max(1, roundToInt(positioningAreaSize.width() / fillT ileSize.width()));
286 270
287 fillTileSize.setWidth(positioningAreaSize.width() / nrTiles); 271 fillTileSize.setWidth(positioningAreaSize.width() / nrTiles);
288 272
289 // Maintain aspect ratio if background-size: auto is set 273 // Maintain aspect ratio if background-size: auto is set
290 if (fillLayer.size().size.height().isAuto() && backgroundRepeatY != Roun dFill) { 274 if (fillLayer.size().size.height().isAuto() && backgroundRepeatY != Roun dFill) {
291 fillTileSize.setHeight(fillTileSize.height() * positioningAreaSize.w idth() / (nrTiles * fillTileSize.width())); 275 fillTileSize.setHeight(fillTileSize.height() * positioningAreaSize.w idth() / (nrTiles * fillTileSize.width()));
292 } 276 }
293 277 setTileSize(applySubPixelHeuristicToImageSize(fillTileSize, m_destRect)) ;
294 setTileSize(fillTileSize);
295 setImageContainerSize(fillTileSize);
296 setPhaseX(tileSize().width() ? LayoutUnit(tileSize().width() - fmodf((co mputedXPosition + left), tileSize().width())) 278 setPhaseX(tileSize().width() ? LayoutUnit(tileSize().width() - fmodf((co mputedXPosition + left), tileSize().width()))
297 : LayoutUnit()); 279 : LayoutUnit());
298 setSpaceSize(LayoutSize()); 280 setSpaceSize(LayoutSize());
299 } 281 }
300 282
301 LayoutUnit computedYPosition = roundedMinimumValueForLength(fillLayer.yPosit ion(), availableHeight); 283 LayoutUnit computedYPosition = roundedMinimumValueForLength(fillLayer.yPosit ion(), availableHeight);
302 if (backgroundRepeatY == RoundFill && positioningAreaSize.height() > LayoutU nit() && fillTileSize.height() > LayoutUnit()) { 284 if (backgroundRepeatY == RoundFill && positioningAreaSize.height() > LayoutU nit() && fillTileSize.height() > LayoutUnit()) {
303 int nrTiles = std::max(1, roundToInt(positioningAreaSize.height() / fill TileSize.height())); 285 int nrTiles = std::max(1, roundToInt(positioningAreaSize.height() / fill TileSize.height()));
304 286
305 fillTileSize.setHeight(positioningAreaSize.height() / nrTiles); 287 fillTileSize.setHeight(positioningAreaSize.height() / nrTiles);
306 288
307 // Maintain aspect ratio if background-size: auto is set 289 // Maintain aspect ratio if background-size: auto is set
308 if (fillLayer.size().size.width().isAuto() && backgroundRepeatX != Round Fill) { 290 if (fillLayer.size().size.width().isAuto() && backgroundRepeatX != Round Fill) {
309 fillTileSize.setWidth(fillTileSize.width() * positioningAreaSize.hei ght() / (nrTiles * fillTileSize.height())); 291 fillTileSize.setWidth(fillTileSize.width() * positioningAreaSize.hei ght() / (nrTiles * fillTileSize.height()));
310 } 292 }
311 293 setTileSize(applySubPixelHeuristicToImageSize(fillTileSize, m_destRect)) ;
312 setTileSize(fillTileSize);
313 setImageContainerSize(fillTileSize);
314 setPhaseY(tileSize().height() ? LayoutUnit(tileSize().height() - fmodf(( computedYPosition + top), tileSize().height())) 294 setPhaseY(tileSize().height() ? LayoutUnit(tileSize().height() - fmodf(( computedYPosition + top), tileSize().height()))
315 : LayoutUnit()); 295 : LayoutUnit());
316 setSpaceSize(LayoutSize()); 296 setSpaceSize(LayoutSize());
317 } 297 }
318 298
319 if (backgroundRepeatX == RepeatFill) { 299 if (backgroundRepeatX == RepeatFill) {
320 LayoutUnit xOffset = fillLayer.backgroundXOrigin() == RightEdge ? availa bleWidth - computedXPosition : computedXPosition; 300 LayoutUnit xOffset = fillLayer.backgroundXOrigin() == RightEdge ? availa bleWidth - computedXPosition : computedXPosition;
321 setPhaseX(tileSize().width() ? LayoutUnit(tileSize().width() - fmodf((xO ffset + left), tileSize().width())) 301 setPhaseX(tileSize().width() ? LayoutUnit(tileSize().width() - fmodf((xO ffset + left), tileSize().width()))
322 : LayoutUnit()); 302 : LayoutUnit());
323 setSpaceSize(LayoutSize()); 303 setSpaceSize(LayoutSize());
324 } else if (backgroundRepeatX == SpaceFill && fillTileSize.width() > LayoutUn it()) { 304 } else if (backgroundRepeatX == SpaceFill && fillTileSize.width() > LayoutUn it()) {
325 LayoutUnit space = getSpaceBetweenImageTiles(positioningAreaSize.width() , tileSize().width()); 305 LayoutUnit space = getSpaceBetweenImageTiles(positioningAreaSize.width() , tileSize().width());
326 LayoutUnit actualWidth = tileSize().width() + space; 306 LayoutUnit actualWidth = tileSize().width() + space;
327 307
328 if (space >= LayoutUnit()) { 308 if (space >= LayoutUnit()) {
329 computedXPosition = roundedMinimumValueForLength(Length(), available Width); 309 computedXPosition = roundedMinimumValueForLength(Length(), available Width);
330 setSpaceSize(LayoutSize(space, LayoutUnit())); 310 setSpaceSize(LayoutSize(space.round(), LayoutUnit()));
331 setPhaseX(actualWidth ? LayoutUnit(actualWidth - fmodf((computedXPos ition + left), actualWidth)) : LayoutUnit()); 311 setPhaseX(actualWidth ? LayoutUnit(actualWidth - fmodf((computedXPos ition + left), actualWidth)) : LayoutUnit());
332 } else { 312 } else {
333 backgroundRepeatX = NoRepeatFill; 313 backgroundRepeatX = NoRepeatFill;
334 } 314 }
335 } 315 }
336 if (backgroundRepeatX == NoRepeatFill) { 316 if (backgroundRepeatX == NoRepeatFill) {
337 LayoutUnit xOffset = fillLayer.backgroundXOrigin() == RightEdge ? availa bleWidth - computedXPosition : computedXPosition; 317 LayoutUnit xOffset = fillLayer.backgroundXOrigin() == RightEdge ? availa bleWidth - computedXPosition : computedXPosition;
338 setNoRepeatX(left + xOffset); 318 setNoRepeatX(left + xOffset);
339 setSpaceSize(LayoutSize(LayoutUnit(), spaceSize().height())); 319 setSpaceSize(LayoutSize(LayoutUnit(), spaceSize().height()));
340 } 320 }
341 321
342 if (backgroundRepeatY == RepeatFill) { 322 if (backgroundRepeatY == RepeatFill) {
343 LayoutUnit yOffset = fillLayer.backgroundYOrigin() == BottomEdge ? avail ableHeight - computedYPosition : computedYPosition; 323 LayoutUnit yOffset = fillLayer.backgroundYOrigin() == BottomEdge ? avail ableHeight - computedYPosition : computedYPosition;
344 setPhaseY(tileSize().height() ? LayoutUnit(tileSize().height() - fmodf(( yOffset + top), tileSize().height())) 324 setPhaseY(tileSize().height() ? LayoutUnit(tileSize().height() - fmodf(( yOffset + top), tileSize().height()))
345 : LayoutUnit()); 325 : LayoutUnit());
346 setSpaceSize(LayoutSize(spaceSize().width(), LayoutUnit())); 326 setSpaceSize(LayoutSize(spaceSize().width(), LayoutUnit()));
347 } else if (backgroundRepeatY == SpaceFill && fillTileSize.height() > LayoutU nit()) { 327 } else if (backgroundRepeatY == SpaceFill && fillTileSize.height() > LayoutU nit()) {
348 LayoutUnit space = getSpaceBetweenImageTiles(positioningAreaSize.height( ), tileSize().height()); 328 LayoutUnit space = getSpaceBetweenImageTiles(positioningAreaSize.height( ), tileSize().height());
349 LayoutUnit actualHeight = tileSize().height() + space; 329 LayoutUnit actualHeight = tileSize().height() + space;
350 330
351 if (space >= LayoutUnit()) { 331 if (space >= LayoutUnit()) {
352 computedYPosition = roundedMinimumValueForLength(Length(), available Height); 332 computedYPosition = roundedMinimumValueForLength(Length(), available Height);
353 setSpaceSize(LayoutSize(spaceSize().width(), space)); 333 setSpaceSize(LayoutSize(spaceSize().width(), space.round()));
354 setPhaseY(actualHeight ? LayoutUnit(actualHeight - fmodf((computedYP osition + top), actualHeight)) : LayoutUnit()); 334 setPhaseY(actualHeight ? LayoutUnit(actualHeight - fmodf((computedYP osition + top), actualHeight)) : LayoutUnit());
355 } else { 335 } else {
356 backgroundRepeatY = NoRepeatFill; 336 backgroundRepeatY = NoRepeatFill;
357 } 337 }
358 } 338 }
359 if (backgroundRepeatY == NoRepeatFill) { 339 if (backgroundRepeatY == NoRepeatFill) {
360 LayoutUnit yOffset = fillLayer.backgroundYOrigin() == BottomEdge ? avail ableHeight - computedYPosition : computedYPosition; 340 LayoutUnit yOffset = fillLayer.backgroundYOrigin() == BottomEdge ? avail ableHeight - computedYPosition : computedYPosition;
361 setNoRepeatY(top + yOffset); 341 setNoRepeatY(top + yOffset);
362 setSpaceSize(LayoutSize(spaceSize().width(), LayoutUnit())); 342 setSpaceSize(LayoutSize(spaceSize().width(), LayoutUnit()));
363 } 343 }
364 344
365 if (fixedAttachment) 345 if (fixedAttachment)
366 useFixedAttachment(paintRect.location()); 346 useFixedAttachment(paintRect.location());
367 347
368 clip(paintRect); 348 // Clip the final output rect to the paint rect
369 pixelSnapGeometry(); 349 m_destRect.intersect(paintRect);
350
351 // Snap as-yet unsnapped values.
352 setPhase(LayoutPoint(roundedIntPoint(m_phase)));
353 setDestRect(LayoutRect(pixelSnappedIntRect(m_destRect)));
354
370 } 355 }
371 356
372 } // namespace blink 357 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/paint/BackgroundImageGeometry.h ('k') | third_party/WebKit/Source/core/paint/BoxPainter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698