Changeset 31389

Show
Ignore:
Timestamp:
2008-03-28 01:53:57 (8 months ago)
Author:
hyatt@apple.com
Message:

2008-03-28 David Hyatt <hyatt@apple.com>

Fix a bug where background-position truncates instead of rounding when it evaluates to fractional
pixel values. This matches other browsers.

Reviewed by maciej

Added fast/backgrounds/background-position-rounding.html

  • rendering/Length.h: (WebCore::Length::calcValue): (WebCore::Length::calcMinValue):
  • rendering/RenderBox.cpp: (WebCore::RenderBox::calculateBackgroundImageGeometry):
Location:
trunk/WebCore
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r31387 r31389  
     12008-03-28  David Hyatt  <hyatt@apple.com> 
     2 
     3        Fix a bug where background-position truncates instead of rounding when it evaluates to fractional 
     4        pixel values.  This matches other browsers. 
     5 
     6        Reviewed by maciej 
     7 
     8        Added fast/backgrounds/background-position-rounding.html 
     9 
     10        * rendering/Length.h: 
     11        (WebCore::Length::calcValue): 
     12        (WebCore::Length::calcMinValue): 
     13        * rendering/RenderBox.cpp: 
     14        (WebCore::RenderBox::calculateBackgroundImageGeometry): 
     15 
    1162008-03-27  Kevin Ollivier  <kevino@theolliviers.com> 
    217 
  • trunk/WebCore/rendering/Length.h

    r27330 r31389  
    104104 
    105105        // note: works only for certain types, returns undefinedLength otherwise 
    106         int calcValue(int maxValue) const 
     106        int calcValue(int maxValue, bool roundPercentages = false) const 
    107107        { 
    108108            switch (type()) { 
     
    110110                    return value(); 
    111111                case Percent: 
     112                    if (roundPercentages) 
     113                        return static_cast<int>(round(maxValue * percent())); 
    112114                    return maxValue * rawValue() / (100 * percentScaleFactor); 
    113115                case Auto: 
     
    118120        } 
    119121 
    120         int calcMinValue(int maxValue) const 
     122        int calcMinValue(int maxValue, bool roundPercentages = false) const 
    121123        { 
    122124            switch (type()) { 
     
    124126                    return value(); 
    125127                case Percent: 
     128                    if (roundPercentages) 
     129                        return static_cast<int>(round(maxValue * percent())); 
    126130                    return maxValue * rawValue() / (100 * percentScaleFactor); 
    127131                case Auto: 
  • trunk/WebCore/rendering/RenderBox.cpp

    r31313 r31389  
    578578    EBackgroundRepeat backgroundRepeat = bgLayer->backgroundRepeat(); 
    579579     
    580     int xPosition = bgLayer->backgroundXPosition().calcMinValue(pw - scaledImageWidth); 
     580    int xPosition = bgLayer->backgroundXPosition().calcMinValue(pw - scaledImageWidth, true); 
    581581    if (backgroundRepeat == REPEAT || backgroundRepeat == REPEAT_X) { 
    582582        cw = pw + left + right; 
     
    588588    } 
    589589 
    590     int yPosition = bgLayer->backgroundYPosition().calcMinValue(ph - scaledImageHeight); 
     590    int yPosition = bgLayer->backgroundYPosition().calcMinValue(ph - scaledImageHeight, true); 
    591591    if (backgroundRepeat == REPEAT || backgroundRepeat == REPEAT_Y) { 
    592592        ch = ph + top + bottom;