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

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

Issue 2690053002: Calculate positioningArea and not just size, for tiling background. (Closed)
Patch Set: Created 3 years, 10 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 | « no previous file | 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/LayoutTableCell.h" 10 #include "core/layout/LayoutTableCell.h"
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 412
413 void BackgroundImageGeometry::calculate( 413 void BackgroundImageGeometry::calculate(
414 const LayoutBoxModelObject& obj, 414 const LayoutBoxModelObject& obj,
415 const LayoutObject* backgroundObject, 415 const LayoutObject* backgroundObject,
416 const LayoutBoxModelObject* paintContainer, 416 const LayoutBoxModelObject* paintContainer,
417 const GlobalPaintFlags globalPaintFlags, 417 const GlobalPaintFlags globalPaintFlags,
418 const FillLayer& fillLayer, 418 const FillLayer& fillLayer,
419 const LayoutRect& paintRect) { 419 const LayoutRect& paintRect) {
420 LayoutUnit left; 420 LayoutUnit left;
421 LayoutUnit top; 421 LayoutUnit top;
422 LayoutSize positioningAreaSize; 422 LayoutRect positioningArea;
423 bool isLayoutView = obj.isLayoutView(); 423 bool isLayoutView = obj.isLayoutView();
424 const LayoutBox* rootBox = nullptr; 424 const LayoutBox* rootBox = nullptr;
425 if (isLayoutView) { 425 if (isLayoutView) {
426 // It is only possible reach here when root element has a box. 426 // It is only possible reach here when root element has a box.
427 Element* documentElement = obj.document().documentElement(); 427 Element* documentElement = obj.document().documentElement();
428 DCHECK(documentElement); 428 DCHECK(documentElement);
429 DCHECK(documentElement->layoutObject()); 429 DCHECK(documentElement->layoutObject());
430 DCHECK(documentElement->layoutObject()->isBox()); 430 DCHECK(documentElement->layoutObject()->isBox());
431 rootBox = toLayoutBox(documentElement->layoutObject()); 431 rootBox = toLayoutBox(documentElement->layoutObject());
432 } 432 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 right += positioningBox.paddingRight(); 474 right += positioningBox.paddingRight();
475 top += positioningBox.paddingTop(); 475 top += positioningBox.paddingTop();
476 bottom += positioningBox.paddingBottom(); 476 bottom += positioningBox.paddingBottom();
477 } 477 }
478 } 478 }
479 479
480 if (isLayoutView) { 480 if (isLayoutView) {
481 // The background of the box generated by the root element covers the 481 // The background of the box generated by the root element covers the
482 // entire canvas and will be painted by the view object, but the we should 482 // entire canvas and will be painted by the view object, but the we should
483 // still use the root element box for positioning. 483 // still use the root element box for positioning.
484 positioningAreaSize = 484 positioningArea.setSize(rootBox->size());
485 rootBox->size() - LayoutSize(left + right, top + bottom); 485 positioningArea.contractEdges(top, right, bottom, left);
486
486 // The input paint rect is specified in root element local coordinate 487 // The input paint rect is specified in root element local coordinate
487 // (i.e. a transform is applied on the context for painting), and is 488 // (i.e. a transform is applied on the context for painting), and is
488 // expanded to cover the whole canvas. Since left/top is relative to the 489 // expanded to cover the whole canvas. Since left/top is relative to the
489 // paint rect, we need to offset them back. 490 // paint rect, we need to offset them back.
490 left -= paintRect.x(); 491 left -= paintRect.x();
491 top -= paintRect.y(); 492 top -= paintRect.y();
492 } else { 493 } else {
493 positioningAreaSize = 494 if (cellUsingContainerBackground) {
494 (cellUsingContainerBackground 495 positioningArea.setSize(getBackgroundObjectDimensions(
495 ? getBackgroundObjectDimensions(toLayoutTableCell(obj), 496 toLayoutTableCell(obj), toLayoutBox(positioningBox)));
496 toLayoutBox(positioningBox)) 497 } else {
497 : paintRect.size()) - 498 positioningArea = paintRect;
498 LayoutSize(left + right, top + bottom); 499 }
500
501 positioningArea.contractEdges(top, right, bottom, left);
499 } 502 }
500 } else { 503 } else {
501 setHasNonLocalGeometry(); 504 setHasNonLocalGeometry();
502 505
503 LayoutRect viewportRect = obj.viewRect(); 506 LayoutRect viewportRect = obj.viewRect();
504 if (fixedBackgroundPaintsInLocalCoordinates(obj, globalPaintFlags)) { 507 if (fixedBackgroundPaintsInLocalCoordinates(obj, globalPaintFlags)) {
505 viewportRect.setLocation(LayoutPoint()); 508 viewportRect.setLocation(LayoutPoint());
506 } else { 509 } else {
507 if (FrameView* frameView = obj.view()->frameView()) 510 if (FrameView* frameView = obj.view()->frameView())
508 viewportRect.setLocation(IntPoint(frameView->scrollOffsetInt())); 511 viewportRect.setLocation(IntPoint(frameView->scrollOffsetInt()));
509 // Compensate the translations created by ScrollRecorders. 512 // Compensate the translations created by ScrollRecorders.
510 // TODO(trchen): Fix this for SP phase 2. crbug.com/529963. 513 // TODO(trchen): Fix this for SP phase 2. crbug.com/529963.
511 viewportRect.moveBy( 514 viewportRect.moveBy(
512 accumulatedScrollOffsetForFixedBackground(obj, paintContainer)); 515 accumulatedScrollOffsetForFixedBackground(obj, paintContainer));
513 } 516 }
514 517
515 if (paintContainer) 518 if (paintContainer)
516 viewportRect.moveBy( 519 viewportRect.moveBy(
517 LayoutPoint(-paintContainer->localToAbsolute(FloatPoint()))); 520 LayoutPoint(-paintContainer->localToAbsolute(FloatPoint())));
518 521
519 setDestRect(viewportRect); 522 setDestRect(viewportRect);
520 positioningAreaSize = destRect().size(); 523 positioningArea = viewportRect;
521 } 524 }
522 525
523 LayoutSize fillTileSize( 526 LayoutSize fillTileSize(
524 calculateFillTileSize(positioningBox, fillLayer, positioningAreaSize)); 527 calculateFillTileSize(positioningBox, fillLayer, positioningArea.size()));
525 // It's necessary to apply the heuristic here prior to any further 528 // It's necessary to apply the heuristic here prior to any further
526 // calculations to avoid incorrectly using sub-pixel values that won't be 529 // calculations to avoid incorrectly using sub-pixel values that won't be
527 // present in the painted tile. 530 // present in the painted tile.
528 setTileSize(applySubPixelHeuristicToImageSize(fillTileSize, m_destRect)); 531 setTileSize(applySubPixelHeuristicToImageSize(fillTileSize, m_destRect));
529 532
530 EFillRepeat backgroundRepeatX = fillLayer.repeatX(); 533 EFillRepeat backgroundRepeatX = fillLayer.repeatX();
531 EFillRepeat backgroundRepeatY = fillLayer.repeatY(); 534 EFillRepeat backgroundRepeatY = fillLayer.repeatY();
532 LayoutUnit unsnappedAvailableWidth = 535 LayoutUnit unsnappedAvailableWidth =
533 positioningAreaSize.width() - fillTileSize.width(); 536 positioningArea.width() - fillTileSize.width();
534 LayoutUnit unsnappedAvailableHeight = 537 LayoutUnit unsnappedAvailableHeight =
535 positioningAreaSize.height() - fillTileSize.height(); 538 positioningArea.height() - fillTileSize.height();
536 positioningAreaSize = 539 LayoutSize positioningAreaSize(positioningArea.pixelSnappedSize());
Stephen Chennney 2017/03/01 14:48:29 This is a subtle change that might change snapping
Karl Øygard 2017/03/03 15:00:07 Good catch, this does not belong here. Thanks!
537 LayoutSize(snapSizeToPixel(positioningAreaSize.width(), m_destRect.x()),
538 snapSizeToPixel(positioningAreaSize.height(), m_destRect.y()));
539 LayoutUnit availableWidth = positioningAreaSize.width() - tileSize().width(); 540 LayoutUnit availableWidth = positioningAreaSize.width() - tileSize().width();
540 LayoutUnit availableHeight = 541 LayoutUnit availableHeight =
541 positioningAreaSize.height() - tileSize().height(); 542 positioningAreaSize.height() - tileSize().height();
542 543
543 LayoutUnit computedXPosition = 544 LayoutUnit computedXPosition =
544 roundedMinimumValueForLength(fillLayer.xPosition(), availableWidth) - 545 roundedMinimumValueForLength(fillLayer.xPosition(), availableWidth) -
545 offsetInBackground.x(); 546 offsetInBackground.x();
546 if (backgroundRepeatX == RoundFill && 547 if (backgroundRepeatX == RoundFill &&
547 positioningAreaSize.width() > LayoutUnit() && 548 positioningAreaSize.width() > LayoutUnit() &&
548 fillTileSize.width() > LayoutUnit()) { 549 fillTileSize.width() > LayoutUnit()) {
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 useFixedAttachment(paintRect.location()); 640 useFixedAttachment(paintRect.location());
640 641
641 // Clip the final output rect to the paint rect 642 // Clip the final output rect to the paint rect
642 m_destRect.intersect(paintRect); 643 m_destRect.intersect(paintRect);
643 644
644 // Snap as-yet unsnapped values. 645 // Snap as-yet unsnapped values.
645 setDestRect(LayoutRect(pixelSnappedIntRect(m_destRect))); 646 setDestRect(LayoutRect(pixelSnappedIntRect(m_destRect)));
646 } 647 }
647 648
648 } // namespace blink 649 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698