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

Side by Side Diff: Source/core/html/ImageDocument.cpp

Issue 1343493002: Fix progressive rendering of image documents (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 3 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | Source/web/tests/DocumentLoadingRenderingTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 LocalFrame* frame = document()->frame(); 139 LocalFrame* frame = document()->frame();
140 Settings* settings = frame->settings(); 140 Settings* settings = frame->settings();
141 if (!frame->loader().client()->allowImage(!settings || settings->imagesEnabl ed(), document()->url())) 141 if (!frame->loader().client()->allowImage(!settings || settings->imagesEnabl ed(), document()->url()))
142 return; 142 return;
143 143
144 if (document()->cachedImage()) { 144 if (document()->cachedImage()) {
145 RELEASE_ASSERT(length <= std::numeric_limits<unsigned>::max()); 145 RELEASE_ASSERT(length <= std::numeric_limits<unsigned>::max());
146 document()->cachedImage()->appendData(data, length); 146 document()->cachedImage()->appendData(data, length);
147 } 147 }
148 148
149 if (!document()) 149 // TODO(esprehn): These null checks on Document don't make sense, document()
150 return; 150 // will ASSERT if it was null. Do these want to check isDetached() ?
151 151 if (document())
152 // Make sure the image layoutObject gets created because we need the layoutO bject 152 document()->imageUpdated();
153 // to read the aspect ratio. See crbug.com/320244
154 document()->updateLayoutTreeIfNeeded();
155 document()->imageUpdated();
156 } 153 }
157 154
158 void ImageDocumentParser::finish() 155 void ImageDocumentParser::finish()
159 { 156 {
160 if (!isStopped() && document()->imageElement() && document()->cachedImage()) { 157 if (!isStopped() && document()->imageElement() && document()->cachedImage()) {
161 ImageResource* cachedImage = document()->cachedImage(); 158 ImageResource* cachedImage = document()->cachedImage();
162 cachedImage->finish(); 159 cachedImage->finish();
163 cachedImage->setResponse(document()->frame()->loader().documentLoader()- >response()); 160 cachedImage->setResponse(document()->frame()->loader().documentLoader()- >response());
164 161
165 // Report the natural image size in the page title, regardless of zoom l evel. 162 // Report the natural image size in the page title, regardless of zoom l evel.
166 // At a zoom level of 1 the image is guaranteed to have an integer size. 163 // At a zoom level of 1 the image is guaranteed to have an integer size.
167 IntSize size = flooredIntSize(cachedImage->imageSizeForLayoutObject(docu ment()->imageElement()->layoutObject(), 1.0f)); 164 IntSize size = flooredIntSize(cachedImage->imageSizeForLayoutObject(docu ment()->imageElement()->layoutObject(), 1.0f));
168 if (size.width()) { 165 if (size.width()) {
169 // Compute the title, we use the decoded filename of the resource, f alling 166 // Compute the title, we use the decoded filename of the resource, f alling
170 // back on the (decoded) hostname if there is no path. 167 // back on the (decoded) hostname if there is no path.
171 String fileName = decodeURLEscapeSequences(document()->url().lastPat hComponent()); 168 String fileName = decodeURLEscapeSequences(document()->url().lastPat hComponent());
172 if (fileName.isEmpty()) 169 if (fileName.isEmpty())
173 fileName = document()->url().host(); 170 fileName = document()->url().host();
174 document()->setTitle(imageTitle(fileName, size)); 171 document()->setTitle(imageTitle(fileName, size));
175 } 172 }
176 173
177 document()->imageUpdated(); 174 document()->imageUpdated();
178 } 175 }
179 176
177 // TODO(esprehn): These null checks on Document don't make sense, document()
178 // will ASSERT if it was null. Do these want to check isDetached() ?
180 if (document()) 179 if (document())
181 document()->finishedParsing(); 180 document()->finishedParsing();
182 } 181 }
183 182
184 // -------- 183 // --------
185 184
186 ImageDocument::ImageDocument(const DocumentInit& initializer) 185 ImageDocument::ImageDocument(const DocumentInit& initializer)
187 : HTMLDocument(initializer, ImageDocumentClass) 186 : HTMLDocument(initializer, ImageDocumentClass)
188 , m_imageElement(nullptr) 187 , m_imageElement(nullptr)
189 , m_imageSizeIsKnown(false) 188 , m_imageSizeIsKnown(false)
(...skipping 28 matching lines...) Expand all
218 217
219 RefPtrWillBeRawPtr<HTMLHeadElement> head = HTMLHeadElement::create(*this); 218 RefPtrWillBeRawPtr<HTMLHeadElement> head = HTMLHeadElement::create(*this);
220 RefPtrWillBeRawPtr<HTMLMetaElement> meta = HTMLMetaElement::create(*this); 219 RefPtrWillBeRawPtr<HTMLMetaElement> meta = HTMLMetaElement::create(*this);
221 meta->setAttribute(nameAttr, "viewport"); 220 meta->setAttribute(nameAttr, "viewport");
222 meta->setAttribute(contentAttr, "width=device-width, minimum-scale=0.1"); 221 meta->setAttribute(contentAttr, "width=device-width, minimum-scale=0.1");
223 head->appendChild(meta); 222 head->appendChild(meta);
224 223
225 RefPtrWillBeRawPtr<HTMLBodyElement> body = HTMLBodyElement::create(*this); 224 RefPtrWillBeRawPtr<HTMLBodyElement> body = HTMLBodyElement::create(*this);
226 body->setAttribute(styleAttr, "margin: 0px;"); 225 body->setAttribute(styleAttr, "margin: 0px;");
227 226
227 if (frame())
228 frame()->loader().client()->dispatchWillInsertBody();
229
228 m_imageElement = HTMLImageElement::create(*this); 230 m_imageElement = HTMLImageElement::create(*this);
229 m_imageElement->setAttribute(styleAttr, "-webkit-user-select: none"); 231 m_imageElement->setAttribute(styleAttr, "-webkit-user-select: none");
230 // If the image is multipart, we neglect to mention to the HTMLImageElement that it's in an 232 // If the image is multipart, we neglect to mention to the HTMLImageElement that it's in an
231 // ImageDocument, so that it requests the image normally. 233 // ImageDocument, so that it requests the image normally.
232 if (!loadingMultipartContent) 234 if (!loadingMultipartContent)
233 m_imageElement->setLoadingImageDocument(); 235 m_imageElement->setLoadingImageDocument();
234 m_imageElement->setSrc(url().string()); 236 m_imageElement->setSrc(url().string());
235 body->appendChild(m_imageElement.get()); 237 body->appendChild(m_imageElement.get());
236 238
237 if (shouldShrinkToFit()) { 239 if (shouldShrinkToFit()) {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 } 310 }
309 } 311 }
310 312
311 void ImageDocument::imageUpdated() 313 void ImageDocument::imageUpdated()
312 { 314 {
313 ASSERT(m_imageElement); 315 ASSERT(m_imageElement);
314 316
315 if (m_imageSizeIsKnown) 317 if (m_imageSizeIsKnown)
316 return; 318 return;
317 319
320 updateLayoutTreeIfNeeded();
318 if (!m_imageElement->cachedImage() || m_imageElement->cachedImage()->imageSi zeForLayoutObject(m_imageElement->layoutObject(), pageZoomFactor(this)).isEmpty( )) 321 if (!m_imageElement->cachedImage() || m_imageElement->cachedImage()->imageSi zeForLayoutObject(m_imageElement->layoutObject(), pageZoomFactor(this)).isEmpty( ))
319 return; 322 return;
320 323
321 m_imageSizeIsKnown = true; 324 m_imageSizeIsKnown = true;
322 325
323 if (shouldShrinkToFit()) { 326 if (shouldShrinkToFit()) {
324 // Force resizing of the image 327 // Force resizing of the image
325 windowSizeChanged(ScaleOnlyUnzoomedDocument); 328 windowSizeChanged(ScaleOnlyUnzoomedDocument);
326 } 329 }
327
328 // Update layout as soon as image size is known. This enables large image fi les to render progressively or to animate.
329 updateLayout();
330 } 330 }
331 331
332 void ImageDocument::restoreImageSize(ScaleType type) 332 void ImageDocument::restoreImageSize(ScaleType type)
333 { 333 {
334 ASSERT(m_shrinkToFitMode == Desktop); 334 ASSERT(m_shrinkToFitMode == Desktop);
335 335
336 if (!m_imageElement || !m_imageSizeIsKnown || m_imageElement->document() != this || (pageZoomFactor(this) < 1 && type == ScaleOnlyUnzoomedDocument)) 336 if (!m_imageElement || !m_imageSizeIsKnown || m_imageElement->document() != this || (pageZoomFactor(this) < 1 && type == ScaleOnlyUnzoomedDocument))
337 return; 337 return;
338 338
339 ASSERT(m_imageElement->cachedImage()); 339 ASSERT(m_imageElement->cachedImage());
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 } 452 }
453 453
454 bool ImageEventListener::operator==(const EventListener& listener) 454 bool ImageEventListener::operator==(const EventListener& listener)
455 { 455 {
456 if (const ImageEventListener* imageEventListener = ImageEventListener::cast( &listener)) 456 if (const ImageEventListener* imageEventListener = ImageEventListener::cast( &listener))
457 return m_doc == imageEventListener->m_doc; 457 return m_doc == imageEventListener->m_doc;
458 return false; 458 return false;
459 } 459 }
460 460
461 } 461 }
OLDNEW
« no previous file with comments | « no previous file | Source/web/tests/DocumentLoadingRenderingTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698