Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(956)

Unified Diff: Source/core/html/ImageDocument.cpp

Issue 136823005: Fix distorted image issue when open some images in a new browser window. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink@master
Patch Set: not plumb knowledge to ImageResource Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« Source/core/fetch/ImageResource.cpp ('K') | « Source/core/html/ImageDocument.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/html/ImageDocument.cpp
diff --git a/Source/core/html/ImageDocument.cpp b/Source/core/html/ImageDocument.cpp
index d5d8eb2d399b021118858d7581e75f739f110525..66414d4d6fd450b9a77cb58eec91f2d947ac511f 100644
--- a/Source/core/html/ImageDocument.cpp
+++ b/Source/core/html/ImageDocument.cpp
@@ -142,7 +142,7 @@ void ImageDocumentParser::finish()
// Report the natural image size in the page title, regardless of zoom level.
// At a zoom level of 1 the image is guaranteed to have an integer size.
- IntSize size = flooredIntSize(cachedImage->imageSizeForRenderer(document()->imageElement()->renderer(), 1.0f));
+ IntSize size = flooredIntSize(document()->cachedImageSize(1.0f));
if (size.width()) {
// Compute the title, we use the decoded filename of the resource, falling
// back on the (decoded) hostname if there is no path.
@@ -221,7 +221,7 @@ float ImageDocument::scale() const
if (!view)
return 1;
- LayoutSize imageSize = m_imageElement->cachedImage()->imageSizeForRenderer(m_imageElement->renderer(), pageZoomFactor(this));
+ LayoutSize imageSize = cachedImageSize(pageZoomFactor(this));
LayoutSize windowSize = LayoutSize(view->width(), view->height());
float widthScale = (float)windowSize.width() / imageSize.width();
@@ -235,7 +235,7 @@ void ImageDocument::resizeImageToFit()
if (!m_imageElement || m_imageElement->document() != this || pageZoomFactor(this) > 1)
return;
- LayoutSize imageSize = m_imageElement->cachedImage()->imageSizeForRenderer(m_imageElement->renderer(), pageZoomFactor(this));
+ LayoutSize imageSize = cachedImageSize(pageZoomFactor(this));
float scale = this->scale();
m_imageElement->setWidth(static_cast<int>(imageSize.width() * scale));
@@ -274,7 +274,7 @@ void ImageDocument::imageUpdated()
if (m_imageSizeIsKnown)
return;
- if (m_imageElement->cachedImage()->imageSizeForRenderer(m_imageElement->renderer(), pageZoomFactor(this)).isEmpty())
+ if (cachedImageSize(pageZoomFactor(this)).isEmpty())
return;
m_imageSizeIsKnown = true;
@@ -290,7 +290,7 @@ void ImageDocument::restoreImageSize()
if (!m_imageElement || !m_imageSizeIsKnown || m_imageElement->document() != this || pageZoomFactor(this) < 1)
return;
- LayoutSize imageSize = m_imageElement->cachedImage()->imageSizeForRenderer(m_imageElement->renderer(), 1.0f);
+ LayoutSize imageSize = cachedImageSize(1.0f);
m_imageElement->setWidth(imageSize.width());
m_imageElement->setHeight(imageSize.height());
@@ -311,7 +311,7 @@ bool ImageDocument::imageFitsInWindow() const
if (!view)
return true;
- LayoutSize imageSize = m_imageElement->cachedImage()->imageSizeForRenderer(m_imageElement->renderer(), pageZoomFactor(this));
+ LayoutSize imageSize = cachedImageSize(pageZoomFactor(this));
LayoutSize windowSize = LayoutSize(view->width(), view->height());
return imageSize.width() <= windowSize.width() && imageSize.height() <= windowSize.height();
@@ -369,6 +369,18 @@ void ImageDocument::dispose()
HTMLDocument::dispose();
}
+LayoutSize ImageDocument::cachedImageSize(float zoomFactor) const
+{
+ if (!m_imageElement)
+ return LayoutSize();
+
+ ImageResource* imageResource = m_imageElement->cachedImage();
+ if (!m_imageElement->renderer() && imageResource->hasImage() && imageResource->image()->isBitmapImage())
+ return imageResource->bitmapImageSizeRespectingOrientation(zoomFactor);
+
+ return imageResource->imageSizeForRenderer(m_imageElement->renderer(), zoomFactor);
abarth-chromium 2014/02/15 18:58:33 Won't this still be broken for non-bitmap images?
+}
+
// --------
void ImageEventListener::handleEvent(ExecutionContext*, Event* event)
« Source/core/fetch/ImageResource.cpp ('K') | « Source/core/html/ImageDocument.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698