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

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

Issue 2130523002: Fix aspect ratio for rounded background image size (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove new tests; we already have coverage Created 4 years, 5 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
« no previous file with comments | « third_party/WebKit/LayoutTests/fast/backgrounds/background-repeat-with-background-color.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 EFillRepeat backgroundRepeatY = fillLayer.repeatY(); 347 EFillRepeat backgroundRepeatY = fillLayer.repeatY();
348 LayoutUnit unsnappedAvailableWidth = positioningAreaSize.width() - fillTileS ize.width(); 348 LayoutUnit unsnappedAvailableWidth = positioningAreaSize.width() - fillTileS ize.width();
349 LayoutUnit unsnappedAvailableHeight = positioningAreaSize.height() - fillTil eSize.height(); 349 LayoutUnit unsnappedAvailableHeight = positioningAreaSize.height() - fillTil eSize.height();
350 positioningAreaSize = LayoutSize(snapSizeToPixel(positioningAreaSize.width() , m_destRect.x()), snapSizeToPixel(positioningAreaSize.height(), m_destRect.y()) ); 350 positioningAreaSize = LayoutSize(snapSizeToPixel(positioningAreaSize.width() , m_destRect.x()), snapSizeToPixel(positioningAreaSize.height(), m_destRect.y()) );
351 LayoutUnit availableWidth = positioningAreaSize.width() - tileSize().width() ; 351 LayoutUnit availableWidth = positioningAreaSize.width() - tileSize().width() ;
352 LayoutUnit availableHeight = positioningAreaSize.height() - tileSize().heigh t(); 352 LayoutUnit availableHeight = positioningAreaSize.height() - tileSize().heigh t();
353 353
354 LayoutUnit computedXPosition = roundedMinimumValueForLength(fillLayer.xPosit ion(), availableWidth); 354 LayoutUnit computedXPosition = roundedMinimumValueForLength(fillLayer.xPosit ion(), availableWidth);
355 if (backgroundRepeatX == RoundFill && positioningAreaSize.width() > LayoutUn it() && fillTileSize.width() > LayoutUnit()) { 355 if (backgroundRepeatX == RoundFill && positioningAreaSize.width() > LayoutUn it() && fillTileSize.width() > LayoutUnit()) {
356 int nrTiles = std::max(1, roundToInt(positioningAreaSize.width() / fillT ileSize.width())); 356 int nrTiles = std::max(1, roundToInt(positioningAreaSize.width() / fillT ileSize.width()));
357 357 LayoutUnit roundedWidth = positioningAreaSize.width() / nrTiles;
358 fillTileSize.setWidth(positioningAreaSize.width() / nrTiles);
359 358
360 // Maintain aspect ratio if background-size: auto is set 359 // Maintain aspect ratio if background-size: auto is set
361 if (fillLayer.size().size.height().isAuto() && backgroundRepeatY != Roun dFill) { 360 if (fillLayer.size().size.height().isAuto() && backgroundRepeatY != Roun dFill) {
362 fillTileSize.setHeight(fillTileSize.height() * positioningAreaSize.w idth() / (nrTiles * fillTileSize.width())); 361 fillTileSize.setHeight(fillTileSize.height() * roundedWidth / fillTi leSize.width());
363 } 362 }
363 fillTileSize.setWidth(roundedWidth);
364
364 setTileSize(applySubPixelHeuristicToImageSize(fillTileSize, m_destRect)) ; 365 setTileSize(applySubPixelHeuristicToImageSize(fillTileSize, m_destRect)) ;
365 setPhaseX(tileSize().width() 366 setPhaseX(tileSize().width()
366 ? LayoutUnit(roundf(tileSize().width() - fmodf((computedXPosition + left), tileSize().width()))) 367 ? LayoutUnit(roundf(tileSize().width() - fmodf((computedXPosition + left), tileSize().width())))
367 : LayoutUnit()); 368 : LayoutUnit());
368 setSpaceSize(LayoutSize()); 369 setSpaceSize(LayoutSize());
369 } 370 }
370 371
371 LayoutUnit computedYPosition = roundedMinimumValueForLength(fillLayer.yPosit ion(), availableHeight); 372 LayoutUnit computedYPosition = roundedMinimumValueForLength(fillLayer.yPosit ion(), availableHeight);
372 if (backgroundRepeatY == RoundFill && positioningAreaSize.height() > LayoutU nit() && fillTileSize.height() > LayoutUnit()) { 373 if (backgroundRepeatY == RoundFill && positioningAreaSize.height() > LayoutU nit() && fillTileSize.height() > LayoutUnit()) {
373 int nrTiles = std::max(1, roundToInt(positioningAreaSize.height() / fill TileSize.height())); 374 int nrTiles = std::max(1, roundToInt(positioningAreaSize.height() / fill TileSize.height()));
374 375 LayoutUnit roundedHeight = positioningAreaSize.height() / nrTiles;
375 fillTileSize.setHeight(positioningAreaSize.height() / nrTiles);
376
377 // Maintain aspect ratio if background-size: auto is set 376 // Maintain aspect ratio if background-size: auto is set
378 if (fillLayer.size().size.width().isAuto() && backgroundRepeatX != Round Fill) { 377 if (fillLayer.size().size.width().isAuto() && backgroundRepeatX != Round Fill) {
379 fillTileSize.setWidth(fillTileSize.width() * positioningAreaSize.hei ght() / (nrTiles * fillTileSize.height())); 378 fillTileSize.setWidth(fillTileSize.width() * roundedHeight / fillTil eSize.height());
380 } 379 }
380 fillTileSize.setHeight(roundedHeight);
381
381 setTileSize(applySubPixelHeuristicToImageSize(fillTileSize, m_destRect)) ; 382 setTileSize(applySubPixelHeuristicToImageSize(fillTileSize, m_destRect)) ;
382 setPhaseY(tileSize().height() 383 setPhaseY(tileSize().height()
383 ? LayoutUnit(roundf(tileSize().height() - fmodf((computedYPosition + top), tileSize().height()))) 384 ? LayoutUnit(roundf(tileSize().height() - fmodf((computedYPosition + top), tileSize().height())))
384 : LayoutUnit()); 385 : LayoutUnit());
385 setSpaceSize(LayoutSize()); 386 setSpaceSize(LayoutSize());
386 } 387 }
387 388
388 if (backgroundRepeatX == RepeatFill) { 389 if (backgroundRepeatX == RepeatFill) {
389 setRepeatX(fillLayer, fillTileSize.width(), availableWidth, unsnappedAva ilableWidth, left); 390 setRepeatX(fillLayer, fillTileSize.width(), availableWidth, unsnappedAva ilableWidth, left);
390 } else if (backgroundRepeatX == SpaceFill && tileSize().width() > LayoutUnit ()) { 391 } else if (backgroundRepeatX == SpaceFill && tileSize().width() > LayoutUnit ()) {
(...skipping 28 matching lines...) Expand all
419 // Clip the final output rect to the paint rect 420 // Clip the final output rect to the paint rect
420 m_destRect.intersect(paintRect); 421 m_destRect.intersect(paintRect);
421 422
422 // Snap as-yet unsnapped values. 423 // Snap as-yet unsnapped values.
423 DCHECK(m_phase == LayoutPoint(roundedIntPoint(m_phase))); 424 DCHECK(m_phase == LayoutPoint(roundedIntPoint(m_phase)));
424 setDestRect(LayoutRect(pixelSnappedIntRect(m_destRect))); 425 setDestRect(LayoutRect(pixelSnappedIntRect(m_destRect)));
425 426
426 } 427 }
427 428
428 } // namespace blink 429 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/fast/backgrounds/background-repeat-with-background-color.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698