| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006, 2007, 2008, 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008, 2010 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 { | 156 { |
| 157 if (!isStopped() && document()->imageElement() && document()->cachedImage())
{ | 157 if (!isStopped() && document()->imageElement() && document()->cachedImage())
{ |
| 158 ImageResource* cachedImage = document()->cachedImage(); | 158 ImageResource* cachedImage = document()->cachedImage(); |
| 159 DocumentLoader* loader = document()->loader(); | 159 DocumentLoader* loader = document()->loader(); |
| 160 cachedImage->setResponse(loader->response()); | 160 cachedImage->setResponse(loader->response()); |
| 161 cachedImage->setLoadFinishTime(loader->timing().responseEnd()); | 161 cachedImage->setLoadFinishTime(loader->timing().responseEnd()); |
| 162 cachedImage->finish(); | 162 cachedImage->finish(); |
| 163 | 163 |
| 164 // Report the natural image size in the page title, regardless of zoom l
evel. | 164 // Report the natural image size in the page title, regardless of zoom l
evel. |
| 165 // At a zoom level of 1 the image is guaranteed to have an integer size. | 165 // At a zoom level of 1 the image is guaranteed to have an integer size. |
| 166 IntSize size = flooredIntSize(cachedImage->imageSize(LayoutObject::shoul
dRespectImageOrientation(document()->imageElement()->layoutObject()), 1.0f)); | 166 IntSize size = flooredIntSize(cachedImage->defaultConcreteObjectSize(Lay
outObject::shouldRespectImageOrientation(document()->imageElement()->layoutObjec
t()), 1.0f)); |
| 167 if (size.width()) { | 167 if (size.width()) { |
| 168 // Compute the title, we use the decoded filename of the resource, f
alling | 168 // Compute the title, we use the decoded filename of the resource, f
alling |
| 169 // back on the (decoded) hostname if there is no path. | 169 // back on the (decoded) hostname if there is no path. |
| 170 String fileName = decodeURLEscapeSequences(document()->url().lastPat
hComponent()); | 170 String fileName = decodeURLEscapeSequences(document()->url().lastPat
hComponent()); |
| 171 if (fileName.isEmpty()) | 171 if (fileName.isEmpty()) |
| 172 fileName = document()->url().host(); | 172 fileName = document()->url().host(); |
| 173 document()->setTitle(imageTitle(fileName, size)); | 173 document()->setTitle(imageTitle(fileName, size)); |
| 174 } | 174 } |
| 175 | 175 |
| 176 document()->imageUpdated(); | 176 document()->imageUpdated(); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 float ImageDocument::scale() const | 256 float ImageDocument::scale() const |
| 257 { | 257 { |
| 258 if (!m_imageElement || m_imageElement->document() != this) | 258 if (!m_imageElement || m_imageElement->document() != this) |
| 259 return 1.0f; | 259 return 1.0f; |
| 260 | 260 |
| 261 FrameView* view = frame()->view(); | 261 FrameView* view = frame()->view(); |
| 262 if (!view) | 262 if (!view) |
| 263 return 1; | 263 return 1; |
| 264 | 264 |
| 265 ASSERT(m_imageElement->cachedImage()); | 265 ASSERT(m_imageElement->cachedImage()); |
| 266 LayoutSize imageSize = m_imageElement->cachedImage()->imageSize(LayoutObject
::shouldRespectImageOrientation(m_imageElement->layoutObject()), pageZoomFactor(
this)); | 266 LayoutSize imageSize = m_imageElement->cachedImage()->defaultConcreteObjectS
ize(LayoutObject::shouldRespectImageOrientation(m_imageElement->layoutObject()),
pageZoomFactor(this)); |
| 267 LayoutSize windowSize = LayoutSize(view->width(), view->height()); | 267 LayoutSize windowSize = LayoutSize(view->width(), view->height()); |
| 268 | 268 |
| 269 float widthScale = windowSize.width().toFloat() / imageSize.width().toFloat(
); | 269 float widthScale = windowSize.width().toFloat() / imageSize.width().toFloat(
); |
| 270 float heightScale = windowSize.height().toFloat() / imageSize.height().toFlo
at(); | 270 float heightScale = windowSize.height().toFloat() / imageSize.height().toFlo
at(); |
| 271 | 271 |
| 272 return min(widthScale, heightScale); | 272 return min(widthScale, heightScale); |
| 273 } | 273 } |
| 274 | 274 |
| 275 void ImageDocument::resizeImageToFit(ScaleType type) | 275 void ImageDocument::resizeImageToFit(ScaleType type) |
| 276 { | 276 { |
| 277 if (!m_imageElement || m_imageElement->document() != this || (pageZoomFactor
(this) > 1 && type == ScaleOnlyUnzoomedDocument)) | 277 if (!m_imageElement || m_imageElement->document() != this || (pageZoomFactor
(this) > 1 && type == ScaleOnlyUnzoomedDocument)) |
| 278 return; | 278 return; |
| 279 | 279 |
| 280 ASSERT(m_imageElement->cachedImage()); | 280 ASSERT(m_imageElement->cachedImage()); |
| 281 LayoutSize imageSize = m_imageElement->cachedImage()->imageSize(LayoutObject
::shouldRespectImageOrientation(m_imageElement->layoutObject()), pageZoomFactor(
this)); | 281 LayoutSize imageSize = m_imageElement->cachedImage()->defaultConcreteObjectS
ize(LayoutObject::shouldRespectImageOrientation(m_imageElement->layoutObject()),
pageZoomFactor(this)); |
| 282 | 282 |
| 283 float scale = this->scale(); | 283 float scale = this->scale(); |
| 284 m_imageElement->setWidth(static_cast<int>(imageSize.width() * scale)); | 284 m_imageElement->setWidth(static_cast<int>(imageSize.width() * scale)); |
| 285 m_imageElement->setHeight(static_cast<int>(imageSize.height() * scale)); | 285 m_imageElement->setHeight(static_cast<int>(imageSize.height() * scale)); |
| 286 | 286 |
| 287 m_imageElement->setInlineStyleProperty(CSSPropertyCursor, CSSValueZoomIn); | 287 m_imageElement->setInlineStyleProperty(CSSPropertyCursor, CSSValueZoomIn); |
| 288 } | 288 } |
| 289 | 289 |
| 290 void ImageDocument::imageClicked(int x, int y) | 290 void ImageDocument::imageClicked(int x, int y) |
| 291 { | 291 { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 313 } | 313 } |
| 314 | 314 |
| 315 void ImageDocument::imageUpdated() | 315 void ImageDocument::imageUpdated() |
| 316 { | 316 { |
| 317 ASSERT(m_imageElement); | 317 ASSERT(m_imageElement); |
| 318 | 318 |
| 319 if (m_imageSizeIsKnown) | 319 if (m_imageSizeIsKnown) |
| 320 return; | 320 return; |
| 321 | 321 |
| 322 updateLayoutTreeIfNeeded(); | 322 updateLayoutTreeIfNeeded(); |
| 323 if (!m_imageElement->cachedImage() || m_imageElement->cachedImage()->imageSi
ze(LayoutObject::shouldRespectImageOrientation(m_imageElement->layoutObject()),
pageZoomFactor(this)).isEmpty()) | 323 if (!m_imageElement->cachedImage() || m_imageElement->cachedImage()->default
ConcreteObjectSize(LayoutObject::shouldRespectImageOrientation(m_imageElement->l
ayoutObject()), pageZoomFactor(this)).isEmpty()) |
| 324 return; | 324 return; |
| 325 | 325 |
| 326 m_imageSizeIsKnown = true; | 326 m_imageSizeIsKnown = true; |
| 327 | 327 |
| 328 if (shouldShrinkToFit()) { | 328 if (shouldShrinkToFit()) { |
| 329 // Force resizing of the image | 329 // Force resizing of the image |
| 330 windowSizeChanged(ScaleOnlyUnzoomedDocument); | 330 windowSizeChanged(ScaleOnlyUnzoomedDocument); |
| 331 } | 331 } |
| 332 } | 332 } |
| 333 | 333 |
| 334 void ImageDocument::restoreImageSize(ScaleType type) | 334 void ImageDocument::restoreImageSize(ScaleType type) |
| 335 { | 335 { |
| 336 ASSERT(m_shrinkToFitMode == Desktop); | 336 ASSERT(m_shrinkToFitMode == Desktop); |
| 337 | 337 |
| 338 if (!m_imageElement || !m_imageSizeIsKnown || m_imageElement->document() !=
this || (pageZoomFactor(this) < 1 && type == ScaleOnlyUnzoomedDocument)) | 338 if (!m_imageElement || !m_imageSizeIsKnown || m_imageElement->document() !=
this || (pageZoomFactor(this) < 1 && type == ScaleOnlyUnzoomedDocument)) |
| 339 return; | 339 return; |
| 340 | 340 |
| 341 ASSERT(m_imageElement->cachedImage()); | 341 ASSERT(m_imageElement->cachedImage()); |
| 342 LayoutSize imageSize = m_imageElement->cachedImage()->imageSize(LayoutObject
::shouldRespectImageOrientation(m_imageElement->layoutObject()), 1.0f); | 342 LayoutSize imageSize = m_imageElement->cachedImage()->defaultConcreteObjectS
ize(LayoutObject::shouldRespectImageOrientation(m_imageElement->layoutObject()),
1.0f); |
| 343 m_imageElement->setWidth(imageSize.width()); | 343 m_imageElement->setWidth(imageSize.width()); |
| 344 m_imageElement->setHeight(imageSize.height()); | 344 m_imageElement->setHeight(imageSize.height()); |
| 345 | 345 |
| 346 if (imageFitsInWindow()) | 346 if (imageFitsInWindow()) |
| 347 m_imageElement->removeInlineStyleProperty(CSSPropertyCursor); | 347 m_imageElement->removeInlineStyleProperty(CSSPropertyCursor); |
| 348 else | 348 else |
| 349 m_imageElement->setInlineStyleProperty(CSSPropertyCursor, CSSValueZoomOu
t); | 349 m_imageElement->setInlineStyleProperty(CSSPropertyCursor, CSSValueZoomOu
t); |
| 350 | 350 |
| 351 m_didShrinkImage = false; | 351 m_didShrinkImage = false; |
| 352 } | 352 } |
| 353 | 353 |
| 354 bool ImageDocument::imageFitsInWindow() const | 354 bool ImageDocument::imageFitsInWindow() const |
| 355 { | 355 { |
| 356 ASSERT(m_shrinkToFitMode == Desktop); | 356 ASSERT(m_shrinkToFitMode == Desktop); |
| 357 | 357 |
| 358 if (!m_imageElement || m_imageElement->document() != this) | 358 if (!m_imageElement || m_imageElement->document() != this) |
| 359 return true; | 359 return true; |
| 360 | 360 |
| 361 FrameView* view = frame()->view(); | 361 FrameView* view = frame()->view(); |
| 362 if (!view) | 362 if (!view) |
| 363 return true; | 363 return true; |
| 364 | 364 |
| 365 ASSERT(m_imageElement->cachedImage()); | 365 ASSERT(m_imageElement->cachedImage()); |
| 366 LayoutSize imageSize = m_imageElement->cachedImage()->imageSize(LayoutObject
::shouldRespectImageOrientation(m_imageElement->layoutObject()), pageZoomFactor(
this)); | 366 LayoutSize imageSize = m_imageElement->cachedImage()->defaultConcreteObjectS
ize(LayoutObject::shouldRespectImageOrientation(m_imageElement->layoutObject()),
pageZoomFactor(this)); |
| 367 LayoutSize windowSize = LayoutSize(view->width(), view->height()); | 367 LayoutSize windowSize = LayoutSize(view->width(), view->height()); |
| 368 | 368 |
| 369 return imageSize.width() <= windowSize.width() && imageSize.height() <= wind
owSize.height(); | 369 return imageSize.width() <= windowSize.width() && imageSize.height() <= wind
owSize.height(); |
| 370 } | 370 } |
| 371 | 371 |
| 372 void ImageDocument::windowSizeChanged(ScaleType type) | 372 void ImageDocument::windowSizeChanged(ScaleType type) |
| 373 { | 373 { |
| 374 if (!m_imageElement || !m_imageSizeIsKnown || m_imageElement->document() !=
this) | 374 if (!m_imageElement || !m_imageSizeIsKnown || m_imageElement->document() !=
this) |
| 375 return; | 375 return; |
| 376 | 376 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 } | 454 } |
| 455 | 455 |
| 456 bool ImageEventListener::operator==(const EventListener& listener) const | 456 bool ImageEventListener::operator==(const EventListener& listener) const |
| 457 { | 457 { |
| 458 if (const ImageEventListener* imageEventListener = ImageEventListener::cast(
&listener)) | 458 if (const ImageEventListener* imageEventListener = ImageEventListener::cast(
&listener)) |
| 459 return m_doc == imageEventListener->m_doc; | 459 return m_doc == imageEventListener->m_doc; |
| 460 return false; | 460 return false; |
| 461 } | 461 } |
| 462 | 462 |
| 463 } // namespace blink | 463 } // namespace blink |
| OLD | NEW |