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 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 | 404 |
405 void BackgroundImageGeometry::calculate( | 405 void BackgroundImageGeometry::calculate( |
406 const LayoutBoxModelObject& obj, | 406 const LayoutBoxModelObject& obj, |
407 const LayoutObject* backgroundObject, | 407 const LayoutObject* backgroundObject, |
408 const LayoutBoxModelObject* paintContainer, | 408 const LayoutBoxModelObject* paintContainer, |
409 const GlobalPaintFlags globalPaintFlags, | 409 const GlobalPaintFlags globalPaintFlags, |
410 const FillLayer& fillLayer, | 410 const FillLayer& fillLayer, |
411 const LayoutRect& paintRect) { | 411 const LayoutRect& paintRect) { |
412 LayoutUnit left; | 412 LayoutUnit left; |
413 LayoutUnit top; | 413 LayoutUnit top; |
414 LayoutSize positioningAreaSize; | 414 LayoutRect positioningArea; |
415 bool isLayoutView = obj.isLayoutView(); | 415 bool isLayoutView = obj.isLayoutView(); |
416 const LayoutBox* rootBox = nullptr; | 416 const LayoutBox* rootBox = nullptr; |
417 if (isLayoutView) { | 417 if (isLayoutView) { |
418 // It is only possible reach here when root element has a box. | 418 // It is only possible reach here when root element has a box. |
419 Element* documentElement = obj.document().documentElement(); | 419 Element* documentElement = obj.document().documentElement(); |
420 DCHECK(documentElement); | 420 DCHECK(documentElement); |
421 DCHECK(documentElement->layoutObject()); | 421 DCHECK(documentElement->layoutObject()); |
422 DCHECK(documentElement->layoutObject()->isBox()); | 422 DCHECK(documentElement->layoutObject()->isBox()); |
423 rootBox = toLayoutBox(documentElement->layoutObject()); | 423 rootBox = toLayoutBox(documentElement->layoutObject()); |
424 } | 424 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 right += positioningBox.paddingRight(); | 466 right += positioningBox.paddingRight(); |
467 top += positioningBox.paddingTop(); | 467 top += positioningBox.paddingTop(); |
468 bottom += positioningBox.paddingBottom(); | 468 bottom += positioningBox.paddingBottom(); |
469 } | 469 } |
470 } | 470 } |
471 | 471 |
472 if (isLayoutView) { | 472 if (isLayoutView) { |
473 // The background of the box generated by the root element covers the | 473 // The background of the box generated by the root element covers the |
474 // entire canvas and will be painted by the view object, but the we should | 474 // entire canvas and will be painted by the view object, but the we should |
475 // still use the root element box for positioning. | 475 // still use the root element box for positioning. |
476 positioningAreaSize = | 476 positioningArea.setSize(rootBox->size()); |
477 rootBox->size() - LayoutSize(left + right, top + bottom); | 477 positioningArea.contractEdges(top, right, bottom, left); |
| 478 |
478 // The input paint rect is specified in root element local coordinate | 479 // The input paint rect is specified in root element local coordinate |
479 // (i.e. a transform is applied on the context for painting), and is | 480 // (i.e. a transform is applied on the context for painting), and is |
480 // expanded to cover the whole canvas. Since left/top is relative to the | 481 // expanded to cover the whole canvas. Since left/top is relative to the |
481 // paint rect, we need to offset them back. | 482 // paint rect, we need to offset them back. |
482 left -= paintRect.x(); | 483 left -= paintRect.x(); |
483 top -= paintRect.y(); | 484 top -= paintRect.y(); |
484 } else { | 485 } else { |
485 positioningAreaSize = | 486 if (cellUsingContainerBackground) { |
486 (cellUsingContainerBackground | 487 positioningArea.setSize(getBackgroundObjectDimensions( |
487 ? getBackgroundObjectDimensions(toLayoutTableCell(obj), | 488 toLayoutTableCell(obj), toLayoutBox(positioningBox))); |
488 toLayoutBox(positioningBox)) | 489 } else { |
489 : paintRect.size()) - | 490 positioningArea = paintRect; |
490 LayoutSize(left + right, top + bottom); | 491 } |
| 492 |
| 493 positioningArea.contractEdges(top, right, bottom, left); |
491 } | 494 } |
492 } else { | 495 } else { |
493 setHasNonLocalGeometry(); | 496 setHasNonLocalGeometry(); |
494 | 497 |
495 LayoutRect viewportRect = obj.viewRect(); | 498 LayoutRect viewportRect = obj.viewRect(); |
496 if (fixedBackgroundPaintsInLocalCoordinates(obj, globalPaintFlags)) { | 499 if (fixedBackgroundPaintsInLocalCoordinates(obj, globalPaintFlags)) { |
497 viewportRect.setLocation(LayoutPoint()); | 500 viewportRect.setLocation(LayoutPoint()); |
498 } else { | 501 } else { |
499 if (FrameView* frameView = obj.view()->frameView()) | 502 if (FrameView* frameView = obj.view()->frameView()) |
500 viewportRect.setLocation(IntPoint(frameView->scrollOffsetInt())); | 503 viewportRect.setLocation(IntPoint(frameView->scrollOffsetInt())); |
501 // Compensate the translations created by ScrollRecorders. | 504 // Compensate the translations created by ScrollRecorders. |
502 // TODO(trchen): Fix this for SP phase 2. crbug.com/529963. | 505 // TODO(trchen): Fix this for SP phase 2. crbug.com/529963. |
503 viewportRect.moveBy( | 506 viewportRect.moveBy( |
504 accumulatedScrollOffsetForFixedBackground(obj, paintContainer)); | 507 accumulatedScrollOffsetForFixedBackground(obj, paintContainer)); |
505 } | 508 } |
506 | 509 |
507 if (paintContainer) | 510 if (paintContainer) |
508 viewportRect.moveBy( | 511 viewportRect.moveBy( |
509 LayoutPoint(-paintContainer->localToAbsolute(FloatPoint()))); | 512 LayoutPoint(-paintContainer->localToAbsolute(FloatPoint()))); |
510 | 513 |
511 setDestRect(viewportRect); | 514 setDestRect(viewportRect); |
512 positioningAreaSize = destRect().size(); | 515 positioningArea = viewportRect; |
513 } | 516 } |
514 | 517 |
515 LayoutSize fillTileSize( | 518 LayoutSize fillTileSize( |
516 calculateFillTileSize(positioningBox, fillLayer, positioningAreaSize)); | 519 calculateFillTileSize(positioningBox, fillLayer, positioningArea.size())); |
517 // It's necessary to apply the heuristic here prior to any further | 520 // It's necessary to apply the heuristic here prior to any further |
518 // calculations to avoid incorrectly using sub-pixel values that won't be | 521 // calculations to avoid incorrectly using sub-pixel values that won't be |
519 // present in the painted tile. | 522 // present in the painted tile. |
520 setTileSize(applySubPixelHeuristicToImageSize(fillTileSize, m_destRect)); | 523 setTileSize(applySubPixelHeuristicToImageSize(fillTileSize, m_destRect)); |
521 | 524 |
522 EFillRepeat backgroundRepeatX = fillLayer.repeatX(); | 525 EFillRepeat backgroundRepeatX = fillLayer.repeatX(); |
523 EFillRepeat backgroundRepeatY = fillLayer.repeatY(); | 526 EFillRepeat backgroundRepeatY = fillLayer.repeatY(); |
524 LayoutUnit unsnappedAvailableWidth = | 527 LayoutUnit unsnappedAvailableWidth = |
525 positioningAreaSize.width() - fillTileSize.width(); | 528 positioningArea.width() - fillTileSize.width(); |
526 LayoutUnit unsnappedAvailableHeight = | 529 LayoutUnit unsnappedAvailableHeight = |
527 positioningAreaSize.height() - fillTileSize.height(); | 530 positioningArea.height() - fillTileSize.height(); |
528 positioningAreaSize = | 531 LayoutSize positioningAreaSize = |
529 LayoutSize(snapSizeToPixel(positioningAreaSize.width(), m_destRect.x()), | 532 LayoutSize(snapSizeToPixel(positioningArea.width(), m_destRect.x()), |
530 snapSizeToPixel(positioningAreaSize.height(), m_destRect.y())); | 533 snapSizeToPixel(positioningArea.height(), m_destRect.y())); |
531 LayoutUnit availableWidth = positioningAreaSize.width() - tileSize().width(); | 534 LayoutUnit availableWidth = positioningAreaSize.width() - tileSize().width(); |
532 LayoutUnit availableHeight = | 535 LayoutUnit availableHeight = |
533 positioningAreaSize.height() - tileSize().height(); | 536 positioningAreaSize.height() - tileSize().height(); |
534 | 537 |
535 LayoutUnit computedXPosition = | 538 LayoutUnit computedXPosition = |
536 roundedMinimumValueForLength(fillLayer.xPosition(), availableWidth) - | 539 roundedMinimumValueForLength(fillLayer.xPosition(), availableWidth) - |
537 offsetInBackground.x(); | 540 offsetInBackground.x(); |
538 if (backgroundRepeatX == RoundFill && | 541 if (backgroundRepeatX == RoundFill && |
539 positioningAreaSize.width() > LayoutUnit() && | 542 positioningAreaSize.width() > LayoutUnit() && |
540 fillTileSize.width() > LayoutUnit()) { | 543 fillTileSize.width() > LayoutUnit()) { |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
631 useFixedAttachment(paintRect.location()); | 634 useFixedAttachment(paintRect.location()); |
632 | 635 |
633 // Clip the final output rect to the paint rect | 636 // Clip the final output rect to the paint rect |
634 m_destRect.intersect(paintRect); | 637 m_destRect.intersect(paintRect); |
635 | 638 |
636 // Snap as-yet unsnapped values. | 639 // Snap as-yet unsnapped values. |
637 setDestRect(LayoutRect(pixelSnappedIntRect(m_destRect))); | 640 setDestRect(LayoutRect(pixelSnappedIntRect(m_destRect))); |
638 } | 641 } |
639 | 642 |
640 } // namespace blink | 643 } // namespace blink |
OLD | NEW |