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

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: Snap as we go 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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 LayoutUnit computedXPosition = roundedMinimumValueForLength(fillLayer.xPosit ion(), availableWidth); 269 LayoutUnit computedXPosition = roundedMinimumValueForLength(fillLayer.xPosit ion(), availableWidth);
284 if (backgroundRepeatX == RoundFill && positioningAreaSize.width() > LayoutUn it() && fillTileSize.width() > LayoutUnit()) { 270 if (backgroundRepeatX == RoundFill && positioningAreaSize.width() > LayoutUn it() && fillTileSize.width() > LayoutUnit()) {
285 int nrTiles = std::max(1, roundToInt(positioningAreaSize.width() / fillT ileSize.width())); 271 int nrTiles = std::max(1, roundToInt(positioningAreaSize.width() / fillT ileSize.width()));
286 272
287 fillTileSize.setWidth(positioningAreaSize.width() / nrTiles); 273 fillTileSize.setWidth(positioningAreaSize.width() / nrTiles);
288 274
289 // Maintain aspect ratio if background-size: auto is set 275 // Maintain aspect ratio if background-size: auto is set
290 if (fillLayer.size().size.height().isAuto() && backgroundRepeatY != Roun dFill) { 276 if (fillLayer.size().size.height().isAuto() && backgroundRepeatY != Roun dFill) {
291 fillTileSize.setHeight(fillTileSize.height() * positioningAreaSize.w idth() / (nrTiles * fillTileSize.width())); 277 fillTileSize.setHeight(fillTileSize.height() * positioningAreaSize.w idth() / (nrTiles * fillTileSize.width()));
292 } 278 }
293 279 fillTileSize = applySubPixelHeuristicToImageSize(fillTileSize, m_destRec t);
294 setTileSize(fillTileSize); 280 setTileSize(fillTileSize);
295 setImageContainerSize(fillTileSize); 281 setImageContainerSize(fillTileSize);
296 setPhaseX(tileSize().width() ? LayoutUnit(tileSize().width() - fmodf((co mputedXPosition + left), tileSize().width())) 282 setPhaseX(tileSize().width() ? LayoutUnit(tileSize().width() - fmodf((co mputedXPosition + left), tileSize().width()))
297 : LayoutUnit()); 283 : LayoutUnit());
298 setSpaceSize(LayoutSize()); 284 setSpaceSize(LayoutSize());
299 } 285 }
300 286
301 LayoutUnit computedYPosition = roundedMinimumValueForLength(fillLayer.yPosit ion(), availableHeight); 287 LayoutUnit computedYPosition = roundedMinimumValueForLength(fillLayer.yPosit ion(), availableHeight);
302 if (backgroundRepeatY == RoundFill && positioningAreaSize.height() > LayoutU nit() && fillTileSize.height() > LayoutUnit()) { 288 if (backgroundRepeatY == RoundFill && positioningAreaSize.height() > LayoutU nit() && fillTileSize.height() > LayoutUnit()) {
303 int nrTiles = std::max(1, roundToInt(positioningAreaSize.height() / fill TileSize.height())); 289 int nrTiles = std::max(1, roundToInt(positioningAreaSize.height() / fill TileSize.height()));
304 290
305 fillTileSize.setHeight(positioningAreaSize.height() / nrTiles); 291 fillTileSize.setHeight(positioningAreaSize.height() / nrTiles);
306 292
307 // Maintain aspect ratio if background-size: auto is set 293 // Maintain aspect ratio if background-size: auto is set
308 if (fillLayer.size().size.width().isAuto() && backgroundRepeatX != Round Fill) { 294 if (fillLayer.size().size.width().isAuto() && backgroundRepeatX != Round Fill) {
309 fillTileSize.setWidth(fillTileSize.width() * positioningAreaSize.hei ght() / (nrTiles * fillTileSize.height())); 295 fillTileSize.setWidth(fillTileSize.width() * positioningAreaSize.hei ght() / (nrTiles * fillTileSize.height()));
310 } 296 }
311 297
298 fillTileSize = applySubPixelHeuristicToImageSize(fillTileSize, m_destRec t);
312 setTileSize(fillTileSize); 299 setTileSize(fillTileSize);
313 setImageContainerSize(fillTileSize); 300 setImageContainerSize(fillTileSize);
314 setPhaseY(tileSize().height() ? LayoutUnit(tileSize().height() - fmodf(( computedYPosition + top), tileSize().height())) 301 setPhaseY(tileSize().height() ? LayoutUnit(tileSize().height() - fmodf(( computedYPosition + top), tileSize().height()))
315 : LayoutUnit()); 302 : LayoutUnit());
316 setSpaceSize(LayoutSize()); 303 setSpaceSize(LayoutSize());
317 } 304 }
318 305
319 if (backgroundRepeatX == RepeatFill) { 306 if (backgroundRepeatX == RepeatFill) {
320 LayoutUnit xOffset = fillLayer.backgroundXOrigin() == RightEdge ? availa bleWidth - computedXPosition : computedXPosition; 307 LayoutUnit xOffset = fillLayer.backgroundXOrigin() == RightEdge ? availa bleWidth - computedXPosition : computedXPosition;
321 setPhaseX(tileSize().width() ? LayoutUnit(tileSize().width() - fmodf((xO ffset + left), tileSize().width())) 308 setPhaseX(tileSize().width() ? LayoutUnit(tileSize().width() - fmodf((xO ffset + left), tileSize().width()))
322 : LayoutUnit()); 309 : LayoutUnit());
323 setSpaceSize(LayoutSize()); 310 setSpaceSize(LayoutSize());
324 } else if (backgroundRepeatX == SpaceFill && fillTileSize.width() > LayoutUn it()) { 311 } else if (backgroundRepeatX == SpaceFill && fillTileSize.width() > LayoutUn it()) {
325 LayoutUnit space = getSpaceBetweenImageTiles(positioningAreaSize.width() , tileSize().width()); 312 LayoutUnit space = getSpaceBetweenImageTiles(positioningAreaSize.width() , tileSize().width());
326 LayoutUnit actualWidth = tileSize().width() + space; 313 LayoutUnit actualWidth = tileSize().width() + space;
327 314
328 if (space >= LayoutUnit()) { 315 if (space >= LayoutUnit()) {
329 computedXPosition = roundedMinimumValueForLength(Length(), available Width); 316 computedXPosition = roundedMinimumValueForLength(Length(), available Width);
330 setSpaceSize(LayoutSize(space, LayoutUnit())); 317 setSpaceSize(LayoutSize(space.round(), LayoutUnit()));
331 setPhaseX(actualWidth ? LayoutUnit(actualWidth - fmodf((computedXPos ition + left), actualWidth)) : LayoutUnit()); 318 setPhaseX(actualWidth ? LayoutUnit(actualWidth - fmodf((computedXPos ition + left), actualWidth)) : LayoutUnit());
332 } else { 319 } else {
333 backgroundRepeatX = NoRepeatFill; 320 backgroundRepeatX = NoRepeatFill;
334 } 321 }
335 } 322 }
336 if (backgroundRepeatX == NoRepeatFill) { 323 if (backgroundRepeatX == NoRepeatFill) {
337 LayoutUnit xOffset = fillLayer.backgroundXOrigin() == RightEdge ? availa bleWidth - computedXPosition : computedXPosition; 324 LayoutUnit xOffset = fillLayer.backgroundXOrigin() == RightEdge ? availa bleWidth - computedXPosition : computedXPosition;
338 setNoRepeatX(left + xOffset); 325 setNoRepeatX(left + xOffset);
339 setSpaceSize(LayoutSize(LayoutUnit(), spaceSize().height())); 326 setSpaceSize(LayoutSize(LayoutUnit(), spaceSize().height()));
340 } 327 }
341 328
342 if (backgroundRepeatY == RepeatFill) { 329 if (backgroundRepeatY == RepeatFill) {
343 LayoutUnit yOffset = fillLayer.backgroundYOrigin() == BottomEdge ? avail ableHeight - computedYPosition : computedYPosition; 330 LayoutUnit yOffset = fillLayer.backgroundYOrigin() == BottomEdge ? avail ableHeight - computedYPosition : computedYPosition;
344 setPhaseY(tileSize().height() ? LayoutUnit(tileSize().height() - fmodf(( yOffset + top), tileSize().height())) 331 setPhaseY(tileSize().height() ? LayoutUnit(tileSize().height() - fmodf(( yOffset + top), tileSize().height()))
345 : LayoutUnit()); 332 : LayoutUnit());
346 setSpaceSize(LayoutSize(spaceSize().width(), LayoutUnit())); 333 setSpaceSize(LayoutSize(spaceSize().width(), LayoutUnit()));
347 } else if (backgroundRepeatY == SpaceFill && fillTileSize.height() > LayoutU nit()) { 334 } else if (backgroundRepeatY == SpaceFill && fillTileSize.height() > LayoutU nit()) {
348 LayoutUnit space = getSpaceBetweenImageTiles(positioningAreaSize.height( ), tileSize().height()); 335 LayoutUnit space = getSpaceBetweenImageTiles(positioningAreaSize.height( ), tileSize().height());
349 LayoutUnit actualHeight = tileSize().height() + space; 336 LayoutUnit actualHeight = tileSize().height() + space;
350 337
351 if (space >= LayoutUnit()) { 338 if (space >= LayoutUnit()) {
352 computedYPosition = roundedMinimumValueForLength(Length(), available Height); 339 computedYPosition = roundedMinimumValueForLength(Length(), available Height);
353 setSpaceSize(LayoutSize(spaceSize().width(), space)); 340 setSpaceSize(LayoutSize(spaceSize().width(), space.round()));
354 setPhaseY(actualHeight ? LayoutUnit(actualHeight - fmodf((computedYP osition + top), actualHeight)) : LayoutUnit()); 341 setPhaseY(actualHeight ? LayoutUnit(actualHeight - fmodf((computedYP osition + top), actualHeight)) : LayoutUnit());
355 } else { 342 } else {
356 backgroundRepeatY = NoRepeatFill; 343 backgroundRepeatY = NoRepeatFill;
357 } 344 }
358 } 345 }
359 if (backgroundRepeatY == NoRepeatFill) { 346 if (backgroundRepeatY == NoRepeatFill) {
360 LayoutUnit yOffset = fillLayer.backgroundYOrigin() == BottomEdge ? avail ableHeight - computedYPosition : computedYPosition; 347 LayoutUnit yOffset = fillLayer.backgroundYOrigin() == BottomEdge ? avail ableHeight - computedYPosition : computedYPosition;
361 setNoRepeatY(top + yOffset); 348 setNoRepeatY(top + yOffset);
362 setSpaceSize(LayoutSize(spaceSize().width(), LayoutUnit())); 349 setSpaceSize(LayoutSize(spaceSize().width(), LayoutUnit()));
363 } 350 }
364 351
365 if (fixedAttachment) 352 if (fixedAttachment)
366 useFixedAttachment(paintRect.location()); 353 useFixedAttachment(paintRect.location());
367 354
368 clip(paintRect); 355 // Clip the final output rect to the paint rect
369 pixelSnapGeometry(); 356 m_destRect.intersect(paintRect);
357
358 // Snap as-yet unsnapped values.
359 setPhase(LayoutPoint(roundedIntPoint(m_phase)));
360 setDestRect(LayoutRect(pixelSnappedIntRect(m_destRect)));
361
370 } 362 }
371 363
372 } // namespace blink 364 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698