Changeset 66776 in webkit
- Timestamp:
- Sep 3, 2010 4:04:12 PM (14 years ago)
- Location:
- trunk
- Files:
-
- 3 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r66775 r66776 1 2010-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 1 12 2010-09-03 Zhenyao Mo <zmo@google.com> 2 13 -
trunk/WebCore/ChangeLog
r66774 r66776 1 2010-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 1 24 2010-09-03 Sheriff Bot <webkit.review.bot@gmail.com> 2 25 -
trunk/WebCore/css/CSSPrimitiveValue.cpp
r66615 r66776 306 306 int CSSPrimitiveValue::computeLengthInt(RenderStyle* style, RenderStyle* rootStyle) 307 307 { 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)); 317 309 } 318 310 319 311 int CSSPrimitiveValue::computeLengthInt(RenderStyle* style, RenderStyle* rootStyle, double multiplier) 320 312 { 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. 333 318 int CSSPrimitiveValue::computeLengthIntForLength(RenderStyle* style, RenderStyle* rootStyle) 334 319 { 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 347 323 int CSSPrimitiveValue::computeLengthIntForLength(RenderStyle* style, RenderStyle* rootStyle, double multiplier) 348 324 { 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)); 358 326 } 359 327 360 328 short CSSPrimitiveValue::computeLengthShort(RenderStyle* style, RenderStyle* rootStyle) 361 329 { 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)); 371 331 } 372 332 373 333 short CSSPrimitiveValue::computeLengthShort(RenderStyle* style, RenderStyle* rootStyle, double multiplier) 374 334 { 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)); 384 336 } 385 337 -
trunk/WebCore/css/CSSPrimitiveValue.h
r65021 r66776 38 38 39 39 struct Length; 40 41 template<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 } 40 49 41 50 class CSSPrimitiveValue : public CSSValue { -
trunk/WebCore/html/HTMLImageElement.cpp
r66223 r66776 268 268 269 269 // 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(); 274 272 } 275 273 … … 279 277 document()->updateLayout(); 280 278 281 return renderBox() ? renderBox()->contentWidth() : 0; 279 RenderBox* box = renderBox(); 280 return box ? adjustForAbsoluteZoom(box->contentWidth(), box) : 0; 282 281 } 283 282 … … 292 291 293 292 // 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(); 298 295 } 299 296 … … 303 300 document()->updateLayout(); 304 301 305 return renderBox() ? renderBox()->contentHeight() : 0; 302 RenderBox* box = renderBox(); 303 return box ? adjustForAbsoluteZoom(box->contentHeight(), box) : 0; 306 304 } 307 305 -
trunk/WebCore/loader/ImageDocument.cpp
r66670 r66776 153 153 cachedImage->setResponse(document()->frame()->loader()->documentLoader()->response()); 154 154 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); 156 158 if (size.width()) { 157 159 // Compute the title, we use the decoded filename of the resource, falling -
trunk/WebCore/rendering/RenderObject.h
r66598 r66776 29 29 #include "AffineTransform.h" 30 30 #include "CachedResourceClient.h" 31 #include "CSSPrimitiveValue.h" 31 32 #include "Document.h" 32 33 #include "Element.h" … … 987 988 inline int adjustForAbsoluteZoom(int value, RenderObject* renderer) 988 989 { 989 floatzoomFactor = renderer->style()->effectiveZoom();990 double zoomFactor = renderer->style()->effectiveZoom(); 990 991 if (zoomFactor == 1) 991 992 return value; … … 993 994 if (zoomFactor > 1) 994 995 value++; 995 return static_cast<int>(value / zoomFactor); 996 997 return roundForImpreciseConversion<int, INT_MAX, INT_MIN>(value / zoomFactor); 996 998 } 997 999
Note: See TracChangeset
for help on using the changeset viewer.