| 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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 return; | 126 return; |
| 127 | 127 |
| 128 LocalFrame* frame = document()->frame(); | 128 LocalFrame* frame = document()->frame(); |
| 129 Settings* settings = frame->settings(); | 129 Settings* settings = frame->settings(); |
| 130 if (!frame->loader().client()->allowImage( | 130 if (!frame->loader().client()->allowImage( |
| 131 !settings || settings->imagesEnabled(), document()->url())) | 131 !settings || settings->imagesEnabled(), document()->url())) |
| 132 return; | 132 return; |
| 133 | 133 |
| 134 if (document()->cachedImage()) { | 134 if (document()->cachedImage()) { |
| 135 RELEASE_ASSERT(length <= std::numeric_limits<unsigned>::max()); | 135 RELEASE_ASSERT(length <= std::numeric_limits<unsigned>::max()); |
| 136 // If decoding has already failed, there's no point in sending additional da
ta to the ImageResource. | 136 // If decoding has already failed, there's no point in sending additional |
| 137 // data to the ImageResource. |
| 137 if (document()->cachedImage()->getStatus() != Resource::DecodeError) | 138 if (document()->cachedImage()->getStatus() != Resource::DecodeError) |
| 138 document()->cachedImage()->appendData(data, length); | 139 document()->cachedImage()->appendData(data, length); |
| 139 } | 140 } |
| 140 | 141 |
| 141 if (!isDetached()) | 142 if (!isDetached()) |
| 142 document()->imageUpdated(); | 143 document()->imageUpdated(); |
| 143 } | 144 } |
| 144 | 145 |
| 145 void ImageDocumentParser::finish() { | 146 void ImageDocumentParser::finish() { |
| 146 if (!isStopped() && document()->imageElement() && document()->cachedImage()) { | 147 if (!isStopped() && document()->imageElement() && document()->cachedImage()) { |
| 147 ImageResource* cachedImage = document()->cachedImage(); | 148 ImageResource* cachedImage = document()->cachedImage(); |
| 148 DocumentLoader* loader = document()->loader(); | 149 DocumentLoader* loader = document()->loader(); |
| 149 cachedImage->setResponse(loader->response()); | 150 cachedImage->setResponse(loader->response()); |
| 150 cachedImage->finish(loader->timing().responseEnd()); | 151 cachedImage->finish(loader->timing().responseEnd()); |
| 151 | 152 |
| 152 // Report the natural image size in the page title, regardless of zoom level
. | 153 // Report the natural image size in the page title, regardless of zoom |
| 153 // At a zoom level of 1 the image is guaranteed to have an integer size. | 154 // level. At a zoom level of 1 the image is guaranteed to have an integer |
| 155 // size. |
| 154 IntSize size = flooredIntSize( | 156 IntSize size = flooredIntSize( |
| 155 cachedImage->imageSize(LayoutObject::shouldRespectImageOrientation( | 157 cachedImage->imageSize(LayoutObject::shouldRespectImageOrientation( |
| 156 document()->imageElement()->layoutObject()), | 158 document()->imageElement()->layoutObject()), |
| 157 1.0f)); | 159 1.0f)); |
| 158 if (size.width()) { | 160 if (size.width()) { |
| 159 // Compute the title, we use the decoded filename of the resource, falling | 161 // Compute the title, we use the decoded filename of the resource, falling |
| 160 // back on the (decoded) hostname if there is no path. | 162 // back on the (decoded) hostname if there is no path. |
| 161 String fileName = | 163 String fileName = |
| 162 decodeURLEscapeSequences(document()->url().lastPathComponent()); | 164 decodeURLEscapeSequences(document()->url().lastPathComponent()); |
| 163 if (fileName.isEmpty()) | 165 if (fileName.isEmpty()) |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 return this->scale() >= 1; | 361 return this->scale() >= 1; |
| 360 } | 362 } |
| 361 | 363 |
| 362 void ImageDocument::windowSizeChanged() { | 364 void ImageDocument::windowSizeChanged() { |
| 363 if (!m_imageElement || !m_imageSizeIsKnown || | 365 if (!m_imageElement || !m_imageSizeIsKnown || |
| 364 m_imageElement->document() != this) | 366 m_imageElement->document() != this) |
| 365 return; | 367 return; |
| 366 | 368 |
| 367 if (m_shrinkToFitMode == Viewport) { | 369 if (m_shrinkToFitMode == Viewport) { |
| 368 // For huge images, minimum-scale=0.1 is still too big on small screens. | 370 // For huge images, minimum-scale=0.1 is still too big on small screens. |
| 369 // Set max-width so that the image will shrink to fit the width of the scree
n when | 371 // Set max-width so that the image will shrink to fit the width of the |
| 370 // the scale is minimum. | 372 // screen when the scale is minimum. Don't shrink height to fit because we |
| 371 // Don't shrink height to fit because we use width=device-width in viewport
meta tag, | 373 // use width=device-width in viewport meta tag, and expect a full-width |
| 372 // and expect a full-width reading mode for normal-width-huge-height images. | 374 // reading mode for normal-width-huge-height images. |
| 373 int viewportWidth = frame()->host()->visualViewport().size().width(); | 375 int viewportWidth = frame()->host()->visualViewport().size().width(); |
| 374 m_imageElement->setInlineStyleProperty(CSSPropertyMaxWidth, | 376 m_imageElement->setInlineStyleProperty(CSSPropertyMaxWidth, |
| 375 viewportWidth * 10, | 377 viewportWidth * 10, |
| 376 CSSPrimitiveValue::UnitType::Pixels); | 378 CSSPrimitiveValue::UnitType::Pixels); |
| 377 return; | 379 return; |
| 378 } | 380 } |
| 379 | 381 |
| 380 bool fitsInWindow = imageFitsInWindow(); | 382 bool fitsInWindow = imageFitsInWindow(); |
| 381 | 383 |
| 382 // If the image has been explicitly zoomed in, restore the cursor if the image
fits | 384 // If the image has been explicitly zoomed in, restore the cursor if the image |
| 383 // and set it to a zoom out cursor if the image doesn't fit | 385 // fits and set it to a zoom out cursor if the image doesn't fit |
| 384 if (!m_shouldShrinkImage) { | 386 if (!m_shouldShrinkImage) { |
| 385 if (fitsInWindow) | 387 if (fitsInWindow) |
| 386 m_imageElement->removeInlineStyleProperty(CSSPropertyCursor); | 388 m_imageElement->removeInlineStyleProperty(CSSPropertyCursor); |
| 387 else | 389 else |
| 388 m_imageElement->setInlineStyleProperty(CSSPropertyCursor, | 390 m_imageElement->setInlineStyleProperty(CSSPropertyCursor, |
| 389 CSSValueZoomOut); | 391 CSSValueZoomOut); |
| 390 return; | 392 return; |
| 391 } | 393 } |
| 392 | 394 |
| 393 if (m_didShrinkImage) { | 395 if (m_didShrinkImage) { |
| 394 // If the window has been resized so that the image fits, restore the image
size | 396 // If the window has been resized so that the image fits, restore the image |
| 395 // otherwise update the restored image size. | 397 // size otherwise update the restored image size. |
| 396 if (fitsInWindow) | 398 if (fitsInWindow) |
| 397 restoreImageSize(); | 399 restoreImageSize(); |
| 398 else | 400 else |
| 399 resizeImageToFit(); | 401 resizeImageToFit(); |
| 400 } else { | 402 } else { |
| 401 // If the image isn't resized but needs to be, then resize it. | 403 // If the image isn't resized but needs to be, then resize it. |
| 402 if (!fitsInWindow) { | 404 if (!fitsInWindow) { |
| 403 resizeImageToFit(); | 405 resizeImageToFit(); |
| 404 m_didShrinkImage = true; | 406 m_didShrinkImage = true; |
| 405 } | 407 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 } | 441 } |
| 440 | 442 |
| 441 bool ImageEventListener::operator==(const EventListener& listener) const { | 443 bool ImageEventListener::operator==(const EventListener& listener) const { |
| 442 if (const ImageEventListener* imageEventListener = | 444 if (const ImageEventListener* imageEventListener = |
| 443 ImageEventListener::cast(&listener)) | 445 ImageEventListener::cast(&listener)) |
| 444 return m_doc == imageEventListener->m_doc; | 446 return m_doc == imageEventListener->m_doc; |
| 445 return false; | 447 return false; |
| 446 } | 448 } |
| 447 | 449 |
| 448 } // namespace blink | 450 } // namespace blink |
| OLD | NEW |