Changeset 66776 in webkit


Ignore:
Timestamp:
Sep 3, 2010 4:04:12 PM (14 years ago)
Author:
commit-queue@webkit.org
Message:

2010-09-03 Peter Kasting <pkasting@google.com>

Reviewed by Simon Fraser.

Report correct (unzoomed) image sizes for zoomed images.
https://bugs.webkit.org/show_bug.cgi?id=42089

  • fast/images/resources/oval.png: Added.
  • fast/images/zoomed-img-size-expected.txt: Added.
  • fast/images/zoomed-img-size.html: Added.

2010-09-03 Peter Kasting <pkasting@google.com>

Reviewed by Simon Fraser.

Report correct (unzoomed) image sizes for zoomed images.
https://bugs.webkit.org/show_bug.cgi?id=42089

Test: fast/images/zoomed-img-size.html

  • css/CSSPrimitiveValue.cpp: Factor rounding code out to a templatized function so it can be shared. (WebCore::CSSPrimitiveValue::computeLengthInt): (WebCore::CSSPrimitiveValue::computeLengthIntForLength): (WebCore::CSSPrimitiveValue::computeLengthShort):
  • css/CSSPrimitiveValue.h: Factor rounding code out to a templatized function so it can be shared. (WebCore::roundForImpreciseConversion):
  • html/HTMLImageElement.cpp: Report unzoomed size to script that queries an image's width or height. (WebCore::HTMLImageElement::width): (WebCore::HTMLImageElement::height):
  • loader/ImageDocument.cpp: Report unzoomed size in the page title when viewing a standalone image. (WebCore::ImageDocumentParser::finish):
  • rendering/RenderObject.h: Use shared rounding code from CSSPrimitiveValue to compensate for inexactness in zoomed sizes. (WebCore::adjustForAbsoluteZoom):
Location:
trunk
Files:
3 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r66775 r66776  
     12010-09-03  Peter Kasting  <pkasting@google.com>
     2
     3        Reviewed by Simon Fraser.
     4
     5        Report correct (unzoomed) image sizes for zoomed images.
     6        https://bugs.webkit.org/show_bug.cgi?id=42089
     7
     8        * fast/images/resources/oval.png: Added.
     9        * fast/images/zoomed-img-size-expected.txt: Added.
     10        * fast/images/zoomed-img-size.html: Added.
     11
    1122010-09-03  Zhenyao Mo  <zmo@google.com>
    213
  • trunk/WebCore/ChangeLog

    r66774 r66776  
     12010-09-03  Peter Kasting  <pkasting@google.com>
     2
     3        Reviewed by Simon Fraser.
     4
     5        Report correct (unzoomed) image sizes for zoomed images.
     6        https://bugs.webkit.org/show_bug.cgi?id=42089
     7
     8        Test: fast/images/zoomed-img-size.html
     9
     10        * css/CSSPrimitiveValue.cpp: Factor rounding code out to a templatized function so it can be shared.
     11        (WebCore::CSSPrimitiveValue::computeLengthInt):
     12        (WebCore::CSSPrimitiveValue::computeLengthIntForLength):
     13        (WebCore::CSSPrimitiveValue::computeLengthShort):
     14        * css/CSSPrimitiveValue.h: Factor rounding code out to a templatized function so it can be shared.
     15        (WebCore::roundForImpreciseConversion):
     16        * html/HTMLImageElement.cpp: Report unzoomed size to script that queries an image's width or height.
     17        (WebCore::HTMLImageElement::width):
     18        (WebCore::HTMLImageElement::height):
     19        * loader/ImageDocument.cpp: Report unzoomed size in the page title when viewing a standalone image.
     20        (WebCore::ImageDocumentParser::finish):
     21        * rendering/RenderObject.h: Use shared rounding code from CSSPrimitiveValue to compensate for inexactness in zoomed sizes.
     22        (WebCore::adjustForAbsoluteZoom):
     23
    1242010-09-03  Sheriff Bot  <webkit.review.bot@gmail.com>
    225
  • trunk/WebCore/css/CSSPrimitiveValue.cpp

    r66615 r66776  
    306306int CSSPrimitiveValue::computeLengthInt(RenderStyle* style, RenderStyle* rootStyle)
    307307{
    308     double result = computeLengthDouble(style, rootStyle);
    309 
    310     // This conversion is imprecise, often resulting in values of, e.g., 44.99998.  We
    311     // need to go ahead and round if we're really close to the next integer value.
    312     result += result < 0 ? -0.01 : +0.01;
    313 
    314     if (result > INT_MAX || result < INT_MIN)
    315         return 0;
    316     return static_cast<int>(result);
     308    return roundForImpreciseConversion<int, INT_MAX, INT_MIN>(computeLengthDouble(style, rootStyle));
    317309}
    318310
    319311int CSSPrimitiveValue::computeLengthInt(RenderStyle* style, RenderStyle* rootStyle, double multiplier)
    320312{
    321     double result = computeLengthDouble(style, rootStyle, multiplier);
    322 
    323     // This conversion is imprecise, often resulting in values of, e.g., 44.99998.  We
    324     // need to go ahead and round if we're really close to the next integer value.
    325     result += result < 0 ? -0.01 : +0.01;
    326 
    327     if (result > INT_MAX || result < INT_MIN)
    328         return 0;
    329     return static_cast<int>(result);
    330 }
    331 
    332 // Lengths expect an int that is only 28-bits, so we have to check for a different overflow.
     313    return roundForImpreciseConversion<int, INT_MAX, INT_MIN>(computeLengthDouble(style, rootStyle, multiplier));
     314}
     315
     316// Lengths expect an int that is only 28-bits, so we have to check for a
     317// different overflow.
    333318int CSSPrimitiveValue::computeLengthIntForLength(RenderStyle* style, RenderStyle* rootStyle)
    334319{
    335     double result = computeLengthDouble(style, rootStyle);
    336 
    337     // This conversion is imprecise, often resulting in values of, e.g., 44.99998.  We
    338     // need to go ahead and round if we're really close to the next integer value.
    339     result += result < 0 ? -0.01 : +0.01;
    340 
    341     if (result > intMaxForLength || result < intMinForLength)
    342         return 0;
    343     return static_cast<int>(result);
    344 }
    345 
    346 // Lengths expect an int that is only 28-bits, so we have to check for a different overflow.
     320    return roundForImpreciseConversion<int, intMaxForLength, intMinForLength>(computeLengthDouble(style, rootStyle));
     321}
     322
    347323int CSSPrimitiveValue::computeLengthIntForLength(RenderStyle* style, RenderStyle* rootStyle, double multiplier)
    348324{
    349     double result = computeLengthDouble(style, rootStyle, multiplier);
    350 
    351     // This conversion is imprecise, often resulting in values of, e.g., 44.99998.  We
    352     // need to go ahead and round if we're really close to the next integer value.
    353     result += result < 0 ? -0.01 : +0.01;
    354 
    355     if (result > intMaxForLength || result < intMinForLength)
    356         return 0;
    357     return static_cast<int>(result);
     325    return roundForImpreciseConversion<int, intMaxForLength, intMinForLength>(computeLengthDouble(style, rootStyle, multiplier));
    358326}
    359327
    360328short CSSPrimitiveValue::computeLengthShort(RenderStyle* style, RenderStyle* rootStyle)
    361329{
    362     double result = computeLengthDouble(style, rootStyle);
    363 
    364     // This conversion is imprecise, often resulting in values of, e.g., 44.99998.  We
    365     // need to go ahead and round if we're really close to the next integer value.
    366     result += result < 0 ? -0.01 : +0.01;
    367 
    368     if (result > SHRT_MAX || result < SHRT_MIN)
    369         return 0;
    370     return static_cast<short>(result);
     330    return roundForImpreciseConversion<short, SHRT_MAX, SHRT_MIN>(computeLengthDouble(style, rootStyle));
    371331}
    372332
    373333short CSSPrimitiveValue::computeLengthShort(RenderStyle* style, RenderStyle* rootStyle, double multiplier)
    374334{
    375     double result = computeLengthDouble(style, rootStyle, multiplier);
    376 
    377     // This conversion is imprecise, often resulting in values of, e.g., 44.99998.  We
    378     // need to go ahead and round if we're really close to the next integer value.
    379     result += result < 0 ? -0.01 : +0.01;
    380 
    381     if (result > SHRT_MAX || result < SHRT_MIN)
    382         return 0;
    383     return static_cast<short>(result);
     335    return roundForImpreciseConversion<short, SHRT_MAX, SHRT_MIN>(computeLengthDouble(style, rootStyle, multiplier));
    384336}
    385337
  • trunk/WebCore/css/CSSPrimitiveValue.h

    r65021 r66776  
    3838
    3939struct Length;
     40
     41template<typename T, T max, T min> inline T roundForImpreciseConversion(double value)
     42{
     43    // Dimension calculations are imprecise, often resulting in values of e.g.
     44    // 44.99998.  We need to go ahead and round if we're really close to the
     45    // next integer value.
     46    value += (value < 0) ? -0.01 : +0.01;
     47    return ((value > max) || (value < min)) ? 0 : static_cast<T>(value);
     48}
    4049
    4150class CSSPrimitiveValue : public CSSValue {
  • trunk/WebCore/html/HTMLImageElement.cpp

    r66223 r66776  
    268268
    269269        // if the image is available, use its width
    270         if (m_imageLoader.image()) {
    271             float zoomFactor = document()->view() ? document()->view()->pageZoomFactor() : 1.0f;
    272             return m_imageLoader.image()->imageSize(zoomFactor).width();
    273         }
     270        if (m_imageLoader.image())
     271            return m_imageLoader.image()->imageSize(1.0f).width();
    274272    }
    275273
     
    279277        document()->updateLayout();
    280278
    281     return renderBox() ? renderBox()->contentWidth() : 0;
     279    RenderBox* box = renderBox();
     280    return box ? adjustForAbsoluteZoom(box->contentWidth(), box) : 0;
    282281}
    283282
     
    292291
    293292        // if the image is available, use its height
    294         if (m_imageLoader.image()) {
    295             float zoomFactor = document()->view() ? document()->view()->pageZoomFactor() : 1.0f;
    296             return m_imageLoader.image()->imageSize(zoomFactor).height();
    297         }
     293        if (m_imageLoader.image())
     294            return m_imageLoader.image()->imageSize(1.0f).height();
    298295    }
    299296
     
    303300        document()->updateLayout();
    304301
    305     return renderBox() ? renderBox()->contentHeight() : 0;
     302    RenderBox* box = renderBox();
     303    return box ? adjustForAbsoluteZoom(box->contentHeight(), box) : 0;
    306304}
    307305
  • trunk/WebCore/loader/ImageDocument.cpp

    r66670 r66776  
    153153        cachedImage->setResponse(document()->frame()->loader()->documentLoader()->response());
    154154
    155         IntSize size = cachedImage->imageSize(pageZoomFactor(document()));
     155        // Report the natural image size in the page title, regardless of zoom
     156        // level.
     157        IntSize size = cachedImage->imageSize(1.0f);
    156158        if (size.width()) {
    157159            // Compute the title, we use the decoded filename of the resource, falling
  • trunk/WebCore/rendering/RenderObject.h

    r66598 r66776  
    2929#include "AffineTransform.h"
    3030#include "CachedResourceClient.h"
     31#include "CSSPrimitiveValue.h"
    3132#include "Document.h"
    3233#include "Element.h"
     
    987988inline int adjustForAbsoluteZoom(int value, RenderObject* renderer)
    988989{
    989     float zoomFactor = renderer->style()->effectiveZoom();
     990    double zoomFactor = renderer->style()->effectiveZoom();
    990991    if (zoomFactor == 1)
    991992        return value;
     
    993994    if (zoomFactor > 1)
    994995        value++;
    995     return static_cast<int>(value / zoomFactor);
     996
     997    return roundForImpreciseConversion<int, INT_MAX, INT_MIN>(value / zoomFactor);
    996998}
    997999
Note: See TracChangeset for help on using the changeset viewer.