Changeset 47674 in webkit
- Timestamp:
- Aug 22, 2009, 9:32:53 AM (16 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r47673 r47674 1 2009-08-21 Dan Bernstein <mitz@apple.com> 2 3 Reviewed by Darin Adler. 4 5 Clean up fill image geometry calculation 6 https://bugs.webkit.org/show_bug.cgi?id=28652 7 8 * rendering/RenderBoxModelObject.cpp: 9 (WebCore::RenderBoxModelObject::calculateFillTileSize): Renamed 10 calculateBackgroundSize() to this. Replaced separate scaledWidth and 11 scaledHeight parameters with a single scaledSize parameter. Renamed 12 parameters and local variables. 13 (WebCore::RenderBoxModelObject::calculateBackgroundImageGeometry): Changed 14 to use CSS3 Backgrounds and Borders terminology in comments and 15 local variable names. Renamed, clarified and consolidated some local 16 variables. 17 * rendering/RenderBoxModelObject.h: Made calculateFillTileSize() private. 18 1 19 2009-08-22 Chris Marrin <cmarrin@apple.com> 2 20 -
trunk/WebCore/rendering/RenderBoxModelObject.cpp
r47650 r47674 494 494 } 495 495 496 IntSize RenderBoxModelObject::calculate BackgroundSize(const FillLayer* bgLayer, int scaledWidth, int scaledHeight) const497 { 498 StyleImage* bg = bgLayer->image();499 bg->setImageContainerSize(IntSize(scaledWidth, scaledHeight)); // Use the box established by background-origin.500 501 EFillSizeType type = bgLayer->size().type;496 IntSize RenderBoxModelObject::calculateFillTileSize(const FillLayer* fillLayer, IntSize positioningAreaSize) const 497 { 498 StyleImage* image = fillLayer->image(); 499 image->setImageContainerSize(positioningAreaSize); // Use the box established by background-origin. 500 501 EFillSizeType type = fillLayer->size().type; 502 502 503 503 switch (type) { 504 504 case SizeLength: { 505 int w = scaledWidth;506 int h = scaledHeight;507 Length bgWidth = bgLayer->size().size.width();508 Length bgHeight = bgLayer->size().size.height();509 510 if ( bgWidth.isFixed())511 w = bgWidth.value();512 else if ( bgWidth.isPercent())513 w = bgWidth.calcValue(scaledWidth);505 int w = positioningAreaSize.width(); 506 int h = positioningAreaSize.height(); 507 Length layerWidth = fillLayer->size().size.width(); 508 Length layerHeight = fillLayer->size().size.height(); 509 510 if (layerWidth.isFixed()) 511 w = layerWidth.value(); 512 else if (layerWidth.isPercent()) 513 w = layerWidth.calcValue(positioningAreaSize.width()); 514 514 515 if ( bgHeight.isFixed())516 h = bgHeight.value();517 else if ( bgHeight.isPercent())518 h = bgHeight.calcValue(scaledHeight);515 if (layerHeight.isFixed()) 516 h = layerHeight.value(); 517 else if (layerHeight.isPercent()) 518 h = layerHeight.calcValue(positioningAreaSize.height()); 519 519 520 520 // If one of the values is auto we have to use the appropriate 521 521 // scale to maintain our aspect ratio. 522 if ( bgWidth.isAuto() && !bgHeight.isAuto())523 w = bg->imageSize(this, style()->effectiveZoom()).width() * h / bg->imageSize(this, style()->effectiveZoom()).height();524 else if (! bgWidth.isAuto() && bgHeight.isAuto())525 h = bg->imageSize(this, style()->effectiveZoom()).height() * w / bg->imageSize(this, style()->effectiveZoom()).width();526 else if ( bgWidth.isAuto() && bgHeight.isAuto()) {522 if (layerWidth.isAuto() && !layerHeight.isAuto()) 523 w = image->imageSize(this, style()->effectiveZoom()).width() * h / image->imageSize(this, style()->effectiveZoom()).height(); 524 else if (!layerWidth.isAuto() && layerHeight.isAuto()) 525 h = image->imageSize(this, style()->effectiveZoom()).height() * w / image->imageSize(this, style()->effectiveZoom()).width(); 526 else if (layerWidth.isAuto() && layerHeight.isAuto()) { 527 527 // If both width and height are auto, we just want to use the image's 528 528 // intrinsic size. 529 w = bg->imageSize(this, style()->effectiveZoom()).width();530 h = bg->imageSize(this, style()->effectiveZoom()).height();529 w = image->imageSize(this, style()->effectiveZoom()).width(); 530 h = image->imageSize(this, style()->effectiveZoom()).height(); 531 531 } 532 532 … … 535 535 case Contain: 536 536 case Cover: { 537 IntSize imageIntrinsicSize = bg->imageSize(this, 1);538 float horizontalScaleFactor = static_cast<float>( scaledWidth) / imageIntrinsicSize.width();539 float verticalScaleFactor = static_cast<float>( scaledHeight) / imageIntrinsicSize.height();537 IntSize imageIntrinsicSize = image->imageSize(this, 1); 538 float horizontalScaleFactor = static_cast<float>(positioningAreaSize.width()) / imageIntrinsicSize.width(); 539 float verticalScaleFactor = static_cast<float>(positioningAreaSize.height()) / imageIntrinsicSize.height(); 540 540 float scaleFactor = type == Contain ? min(horizontalScaleFactor, verticalScaleFactor) : max(horizontalScaleFactor, verticalScaleFactor); 541 541 … … 546 546 break; 547 547 } 548 return bg->imageSize(this, style()->effectiveZoom());549 } 550 551 void RenderBoxModelObject::calculateBackgroundImageGeometry(const FillLayer* bgLayer, int tx, int ty, int w, int h,548 return image->imageSize(this, style()->effectiveZoom()); 549 } 550 551 void RenderBoxModelObject::calculateBackgroundImageGeometry(const FillLayer* fillLayer, int tx, int ty, int w, int h, 552 552 IntRect& destRect, IntPoint& phase, IntSize& tileSize) 553 553 { 554 int pw;555 int ph;556 554 int left = 0; 557 int right = 0;558 555 int top = 0; 559 int bottom = 0; 560 int cx; 561 int cy; 562 int rw = 0; 563 int rh = 0; 564 565 // CSS2 chapter 14.2.1 566 bool fixedAttachment = bgLayer->attachment() == FixedBackgroundAttachment; 556 IntSize positioningAreaSize; 557 558 // Determine the background positioning area and set destRect to the background painting area. 559 // destRect will be adjusted later if the background is non-repeating. 560 bool fixedAttachment = fillLayer->attachment() == FixedBackgroundAttachment; 567 561 if (!fixedAttachment) { 568 // Scroll and Local 569 if (bgLayer->origin() != BorderFillBox) { 562 destRect = IntRect(tx, ty, w, h); 563 564 int right = 0; 565 int bottom = 0; 566 // Scroll and Local. 567 if (fillLayer->origin() != BorderFillBox) { 570 568 left = borderLeft(); 571 569 right = borderRight(); 572 570 top = borderTop(); 573 571 bottom = borderBottom(); 574 if ( bgLayer->origin() == ContentFillBox) {572 if (fillLayer->origin() == ContentFillBox) { 575 573 left += paddingLeft(); 576 574 right += paddingRight(); … … 579 577 } 580 578 } 581 579 582 580 // The background of the box generated by the root element covers the entire canvas including 583 // its margins. Since those were added in already, we have to factor them out when computing the584 // box used by background-origin/size/position.581 // its margins. Since those were added in already, we have to factor them out when computing 582 // the background positioning area. 585 583 if (isRoot()) { 586 rw = toRenderBox(this)->width() - left - right; 587 rh = toRenderBox(this)->height() - top - bottom; 584 positioningAreaSize = IntSize(toRenderBox(this)->width() - left - right, toRenderBox(this)->height() - top - bottom); 588 585 left += marginLeft(); 589 right += marginRight();590 586 top += marginTop(); 591 bottom += marginBottom(); 592 } 593 cx = tx; 594 cy = ty; 595 pw = w - left - right; 596 ph = h - top - bottom; 587 } else 588 positioningAreaSize = IntSize(w - left - right, h - top - bottom); 597 589 } else { 598 // Fixed background attachment. 599 IntRect vr = viewRect(); 600 cx = vr.x(); 601 cy = vr.y(); 602 pw = vr.width(); 603 ph = vr.height(); 604 } 605 606 int sx = 0; 607 int sy = 0; 608 int cw; 609 int ch; 610 611 IntSize scaledImageSize; 612 if (isRoot() && !fixedAttachment) 613 scaledImageSize = calculateBackgroundSize(bgLayer, rw, rh); 614 else 615 scaledImageSize = calculateBackgroundSize(bgLayer, pw, ph); 616 617 int scaledImageWidth = scaledImageSize.width(); 618 int scaledImageHeight = scaledImageSize.height(); 619 620 EFillRepeat backgroundRepeat = bgLayer->repeat(); 621 622 int xPosition; 623 if (isRoot() && !fixedAttachment) 624 xPosition = bgLayer->xPosition().calcMinValue(rw - scaledImageWidth, true); 625 else 626 xPosition = bgLayer->xPosition().calcMinValue(pw - scaledImageWidth, true); 627 if (backgroundRepeat == RepeatFill || backgroundRepeat == RepeatXFill) { 628 cw = pw + left + right; 629 sx = scaledImageWidth ? scaledImageWidth - (xPosition + left) % scaledImageWidth : 0; 630 } else { 631 cx += max(xPosition + left, 0); 632 sx = -min(xPosition + left, 0); 633 cw = scaledImageWidth + min(xPosition + left, 0); 634 } 635 636 int yPosition; 637 if (isRoot() && !fixedAttachment) 638 yPosition = bgLayer->yPosition().calcMinValue(rh - scaledImageHeight, true); 639 else 640 yPosition = bgLayer->yPosition().calcMinValue(ph - scaledImageHeight, true); 641 if (backgroundRepeat == RepeatFill || backgroundRepeat == RepeatYFill) { 642 ch = ph + top + bottom; 643 sy = scaledImageHeight ? scaledImageHeight - (yPosition + top) % scaledImageHeight : 0; 644 } else { 645 cy += max(yPosition + top, 0); 646 sy = -min(yPosition + top, 0); 647 ch = scaledImageHeight + min(yPosition + top, 0); 648 } 649 650 if (fixedAttachment) { 651 sx += max(tx - cx, 0); 652 sy += max(ty - cy, 0); 653 } 654 655 destRect = IntRect(cx, cy, cw, ch); 590 destRect = viewRect(); 591 positioningAreaSize = destRect.size(); 592 } 593 594 tileSize = calculateFillTileSize(fillLayer, positioningAreaSize); 595 596 EFillRepeat backgroundRepeat = fillLayer->repeat(); 597 598 int xPosition = fillLayer->xPosition().calcMinValue(positioningAreaSize.width() - tileSize.width(), true); 599 if (backgroundRepeat == RepeatFill || backgroundRepeat == RepeatXFill) 600 phase.setX(tileSize.width() ? tileSize.width() - (xPosition + left) % tileSize.width() : 0); 601 else { 602 destRect.move(max(xPosition + left, 0), 0); 603 phase.setX(-min(xPosition + left, 0)); 604 destRect.setWidth(tileSize.width() + min(xPosition + left, 0)); 605 } 606 607 int yPosition = fillLayer->yPosition().calcMinValue(positioningAreaSize.height() - tileSize.height(), true); 608 if (backgroundRepeat == RepeatFill || backgroundRepeat == RepeatYFill) 609 phase.setY(tileSize.height() ? tileSize.height() - (yPosition + top) % tileSize.height() : 0); 610 else { 611 destRect.move(0, max(yPosition + top, 0)); 612 phase.setY(-min(yPosition + top, 0)); 613 destRect.setHeight(tileSize.height() + min(yPosition + top, 0)); 614 } 615 616 if (fixedAttachment) 617 phase.move(max(tx - destRect.x(), 0), max(ty - destRect.y(), 0)); 618 656 619 destRect.intersect(IntRect(tx, ty, w, h)); 657 phase = IntPoint(sx, sy);658 tileSize = IntSize(scaledImageWidth, scaledImageHeight);659 620 } 660 621 -
trunk/WebCore/rendering/RenderBoxModelObject.h
r46647 r47674 101 101 protected: 102 102 void calculateBackgroundImageGeometry(const FillLayer*, int tx, int ty, int w, int h, IntRect& destRect, IntPoint& phase, IntSize& tileSize); 103 IntSize calculateBackgroundSize(const FillLayer*, int scaledWidth, int scaledHeight) const;104 103 105 104 private: 106 105 virtual bool isBoxModelObject() const { return true; } 106 107 IntSize calculateFillTileSize(const FillLayer*, IntSize scaledSize) const; 108 107 109 friend class RenderView; 108 110
Note:
See TracChangeset
for help on using the changeset viewer.