OLD | NEW |
---|---|
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 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 positioningArea.setSize(rootBox->size()); | 484 positioningArea.setSize(rootBox->size()); |
Stephen Chennney
2017/02/13 20:24:00
Do we have a test case that hits this code path? T
| |
485 positioningArea.contractEdges(top, right, bottom, left); | 485 positioningArea.contractEdges(top, right, bottom, left); |
486 | 486 |
487 // The input paint rect is specified in root element local coordinate | 487 // The input paint rect is specified in root element local coordinate |
488 // (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 |
489 // 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 |
490 // paint rect, we need to offset them back. | 490 // paint rect, we need to offset them back. |
491 left -= paintRect.x(); | 491 left -= paintRect.x(); |
492 top -= paintRect.y(); | 492 top -= paintRect.y(); |
493 } else { | 493 } else { |
494 if (cellUsingContainerBackground) { | 494 if (cellUsingContainerBackground) { |
(...skipping 26 matching lines...) Expand all Loading... | |
521 | 521 |
522 setDestRect(viewportRect); | 522 setDestRect(viewportRect); |
523 positioningArea = viewportRect; | 523 positioningArea = viewportRect; |
524 } | 524 } |
525 | 525 |
526 LayoutSize fillTileSize( | 526 LayoutSize fillTileSize( |
527 calculateFillTileSize(positioningBox, fillLayer, positioningArea.size())); | 527 calculateFillTileSize(positioningBox, fillLayer, positioningArea.size())); |
528 // 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 |
529 // 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 |
530 // present in the painted tile. | 530 // present in the painted tile. |
531 setTileSize(applySubPixelHeuristicToImageSize(fillTileSize, m_destRect)); | 531 setTileSize(applySubPixelHeuristicToImageSize(fillTileSize, positioningArea)); |
532 | 532 |
533 EFillRepeat backgroundRepeatX = fillLayer.repeatX(); | 533 EFillRepeat backgroundRepeatX = fillLayer.repeatX(); |
534 EFillRepeat backgroundRepeatY = fillLayer.repeatY(); | 534 EFillRepeat backgroundRepeatY = fillLayer.repeatY(); |
535 LayoutUnit unsnappedAvailableWidth = | 535 LayoutUnit unsnappedAvailableWidth = |
536 positioningArea.width() - fillTileSize.width(); | 536 positioningArea.width() - fillTileSize.width(); |
537 LayoutUnit unsnappedAvailableHeight = | 537 LayoutUnit unsnappedAvailableHeight = |
538 positioningArea.height() - fillTileSize.height(); | 538 positioningArea.height() - fillTileSize.height(); |
539 LayoutSize positioningAreaSize(positioningArea.pixelSnappedSize()); | 539 LayoutSize positioningAreaSize(positioningArea.pixelSnappedSize()); |
540 LayoutUnit availableWidth = positioningAreaSize.width() - tileSize().width(); | 540 LayoutUnit availableWidth = positioningAreaSize.width() - tileSize().width(); |
541 LayoutUnit availableHeight = | 541 LayoutUnit availableHeight = |
(...skipping 10 matching lines...) Expand all Loading... | |
552 LayoutUnit roundedWidth = positioningAreaSize.width() / nrTiles; | 552 LayoutUnit roundedWidth = positioningAreaSize.width() / nrTiles; |
553 | 553 |
554 // Maintain aspect ratio if background-size: auto is set | 554 // Maintain aspect ratio if background-size: auto is set |
555 if (fillLayer.size().size.height().isAuto() && | 555 if (fillLayer.size().size.height().isAuto() && |
556 backgroundRepeatY != RoundFill) { | 556 backgroundRepeatY != RoundFill) { |
557 fillTileSize.setHeight(fillTileSize.height() * roundedWidth / | 557 fillTileSize.setHeight(fillTileSize.height() * roundedWidth / |
558 fillTileSize.width()); | 558 fillTileSize.width()); |
559 } | 559 } |
560 fillTileSize.setWidth(roundedWidth); | 560 fillTileSize.setWidth(roundedWidth); |
561 | 561 |
562 setTileSize(applySubPixelHeuristicToImageSize(fillTileSize, m_destRect)); | 562 setTileSize( |
563 applySubPixelHeuristicToImageSize(fillTileSize, positioningArea)); | |
563 setPhaseX(tileSize().width() | 564 setPhaseX(tileSize().width() |
564 ? LayoutUnit(roundf( | 565 ? LayoutUnit(roundf( |
565 tileSize().width() - | 566 tileSize().width() - |
566 fmodf((computedXPosition + left), tileSize().width()))) | 567 fmodf((computedXPosition + left), tileSize().width()))) |
567 : LayoutUnit()); | 568 : LayoutUnit()); |
568 setSpaceSize(LayoutSize()); | 569 setSpaceSize(LayoutSize()); |
569 } | 570 } |
570 | 571 |
571 LayoutUnit computedYPosition = | 572 LayoutUnit computedYPosition = |
572 roundedMinimumValueForLength(fillLayer.yPosition(), availableHeight) - | 573 roundedMinimumValueForLength(fillLayer.yPosition(), availableHeight) - |
573 offsetInBackground.y(); | 574 offsetInBackground.y(); |
574 if (backgroundRepeatY == RoundFill && | 575 if (backgroundRepeatY == RoundFill && |
575 positioningAreaSize.height() > LayoutUnit() && | 576 positioningAreaSize.height() > LayoutUnit() && |
576 fillTileSize.height() > LayoutUnit()) { | 577 fillTileSize.height() > LayoutUnit()) { |
577 int nrTiles = std::max( | 578 int nrTiles = std::max( |
578 1, roundToInt(positioningAreaSize.height() / fillTileSize.height())); | 579 1, roundToInt(positioningAreaSize.height() / fillTileSize.height())); |
579 LayoutUnit roundedHeight = positioningAreaSize.height() / nrTiles; | 580 LayoutUnit roundedHeight = positioningAreaSize.height() / nrTiles; |
580 // Maintain aspect ratio if background-size: auto is set | 581 // Maintain aspect ratio if background-size: auto is set |
581 if (fillLayer.size().size.width().isAuto() && | 582 if (fillLayer.size().size.width().isAuto() && |
582 backgroundRepeatX != RoundFill) { | 583 backgroundRepeatX != RoundFill) { |
583 fillTileSize.setWidth(fillTileSize.width() * roundedHeight / | 584 fillTileSize.setWidth(fillTileSize.width() * roundedHeight / |
584 fillTileSize.height()); | 585 fillTileSize.height()); |
585 } | 586 } |
586 fillTileSize.setHeight(roundedHeight); | 587 fillTileSize.setHeight(roundedHeight); |
587 | 588 |
588 setTileSize(applySubPixelHeuristicToImageSize(fillTileSize, m_destRect)); | 589 setTileSize( |
590 applySubPixelHeuristicToImageSize(fillTileSize, positioningArea)); | |
589 setPhaseY(tileSize().height() | 591 setPhaseY(tileSize().height() |
590 ? LayoutUnit(roundf( | 592 ? LayoutUnit(roundf( |
591 tileSize().height() - | 593 tileSize().height() - |
592 fmodf((computedYPosition + top), tileSize().height()))) | 594 fmodf((computedYPosition + top), tileSize().height()))) |
593 : LayoutUnit()); | 595 : LayoutUnit()); |
594 setSpaceSize(LayoutSize()); | 596 setSpaceSize(LayoutSize()); |
595 } | 597 } |
596 | 598 |
597 if (backgroundRepeatX == RepeatFill) { | 599 if (backgroundRepeatX == RepeatFill) { |
598 setRepeatX(fillLayer, fillTileSize.width(), availableWidth, | 600 setRepeatX(fillLayer, fillTileSize.width(), availableWidth, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
640 useFixedAttachment(paintRect.location()); | 642 useFixedAttachment(paintRect.location()); |
641 | 643 |
642 // Clip the final output rect to the paint rect | 644 // Clip the final output rect to the paint rect |
643 m_destRect.intersect(paintRect); | 645 m_destRect.intersect(paintRect); |
644 | 646 |
645 // Snap as-yet unsnapped values. | 647 // Snap as-yet unsnapped values. |
646 setDestRect(LayoutRect(pixelSnappedIntRect(m_destRect))); | 648 setDestRect(LayoutRect(pixelSnappedIntRect(m_destRect))); |
647 } | 649 } |
648 | 650 |
649 } // namespace blink | 651 } // namespace blink |
OLD | NEW |