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

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

Issue 2469873002: [ImageResource 4] Split ImageResource into Resource and Image parts (Closed)
Patch Set: style Created 4 years 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
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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 void ImageDocumentParser::appendBytes(const char* data, size_t length) { 141 void ImageDocumentParser::appendBytes(const char* data, size_t length) {
142 if (!length) 142 if (!length)
143 return; 143 return;
144 144
145 LocalFrame* frame = document()->frame(); 145 LocalFrame* frame = document()->frame();
146 Settings* settings = frame->settings(); 146 Settings* settings = frame->settings();
147 if (!frame->loader().client()->allowImage( 147 if (!frame->loader().client()->allowImage(
148 !settings || settings->imagesEnabled(), document()->url())) 148 !settings || settings->imagesEnabled(), document()->url()))
149 return; 149 return;
150 150
151 if (document()->cachedImage()) { 151 if (document()->cachedImageResourceDeprecated()) {
152 RELEASE_ASSERT(length <= std::numeric_limits<unsigned>::max()); 152 RELEASE_ASSERT(length <= std::numeric_limits<unsigned>::max());
153 // If decoding has already failed, there's no point in sending additional 153 // If decoding has already failed, there's no point in sending additional
154 // data to the ImageResource. 154 // data to the ImageResource.
155 if (document()->cachedImage()->getStatus() != Resource::DecodeError) 155 if (document()->cachedImageResourceDeprecated()->getStatus() !=
156 document()->cachedImage()->appendData(data, length); 156 Resource::DecodeError)
157 document()->cachedImageResourceDeprecated()->appendData(data, length);
157 } 158 }
158 159
159 if (!isDetached()) 160 if (!isDetached())
160 document()->imageUpdated(); 161 document()->imageUpdated();
161 } 162 }
162 163
163 void ImageDocumentParser::finish() { 164 void ImageDocumentParser::finish() {
164 if (!isStopped() && document()->imageElement() && document()->cachedImage()) { 165 if (!isStopped() && document()->imageElement() &&
165 ImageResource* cachedImage = document()->cachedImage(); 166 document()->cachedImageResourceDeprecated()) {
167 // TODO(hiroshige): Use ImageResourceContent instead of ImageResource.
168 ImageResource* cachedImage = document()->cachedImageResourceDeprecated();
166 DocumentLoader* loader = document()->loader(); 169 DocumentLoader* loader = document()->loader();
167 cachedImage->setResponse(loader->response()); 170 cachedImage->setResponse(loader->response());
168 cachedImage->finish(loader->timing().responseEnd()); 171 cachedImage->finish(loader->timing().responseEnd());
169 172
170 // Report the natural image size in the page title, regardless of zoom 173 // Report the natural image size in the page title, regardless of zoom
171 // level. At a zoom level of 1 the image is guaranteed to have an integer 174 // level. At a zoom level of 1 the image is guaranteed to have an integer
172 // size. 175 // size.
173 IntSize size = flooredIntSize(cachedImageSize(document()->imageElement())); 176 IntSize size = flooredIntSize(cachedImageSize(document()->imageElement()));
174 if (size.width()) { 177 if (size.width()) {
175 // Compute the title, we use the decoded filename of the resource, falling 178 // Compute the title, we use the decoded filename of the resource, falling
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 body->setAttribute(styleAttr, "margin: 0px;"); 260 body->setAttribute(styleAttr, "margin: 0px;");
258 } 261 }
259 262
260 willInsertBody(); 263 willInsertBody();
261 264
262 m_imageElement = HTMLImageElement::create(*this); 265 m_imageElement = HTMLImageElement::create(*this);
263 updateImageStyle(); 266 updateImageStyle();
264 m_imageElement->setLoadingImageDocument(); 267 m_imageElement->setLoadingImageDocument();
265 m_imageElement->setSrc(url().getString()); 268 m_imageElement->setSrc(url().getString());
266 body->appendChild(m_imageElement.get()); 269 body->appendChild(m_imageElement.get());
267 if (loader() && m_imageElement->cachedImage()) 270 if (loader() && m_imageElement->cachedImageResourceForImageDocument()) {
268 m_imageElement->cachedImage()->responseReceived(loader()->response(), 271 m_imageElement->cachedImageResourceForImageDocument()->responseReceived(
269 nullptr); 272 loader()->response(), nullptr);
273 }
270 274
271 if (shouldShrinkToFit()) { 275 if (shouldShrinkToFit()) {
272 // Add event listeners 276 // Add event listeners
273 EventListener* listener = ImageEventListener::create(this); 277 EventListener* listener = ImageEventListener::create(this);
274 if (LocalDOMWindow* domWindow = this->domWindow()) 278 if (LocalDOMWindow* domWindow = this->domWindow())
275 domWindow->addEventListener(EventTypeNames::resize, listener, false); 279 domWindow->addEventListener(EventTypeNames::resize, listener, false);
276 280
277 if (m_shrinkToFitMode == Desktop) { 281 if (m_shrinkToFitMode == Desktop) {
278 m_imageElement->addEventListener(EventTypeNames::click, listener, false); 282 m_imageElement->addEventListener(EventTypeNames::click, listener, false);
279 } else if (m_shrinkToFitMode == Viewport) { 283 } else if (m_shrinkToFitMode == Viewport) {
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 resizeImageToFit(); 562 resizeImageToFit();
559 } else { 563 } else {
560 // If the image isn't resized but needs to be, then resize it. 564 // If the image isn't resized but needs to be, then resize it.
561 if (!fitsInWindow) { 565 if (!fitsInWindow) {
562 resizeImageToFit(); 566 resizeImageToFit();
563 m_didShrinkImage = true; 567 m_didShrinkImage = true;
564 } 568 }
565 } 569 }
566 } 570 }
567 571
568 ImageResource* ImageDocument::cachedImage() { 572 ImageResourceContent* ImageDocument::cachedImage() {
569 if (!m_imageElement) { 573 if (!m_imageElement) {
570 createDocumentStructure(); 574 createDocumentStructure();
571 if (isStopped()) { 575 if (isStopped()) {
572 m_imageElement = nullptr; 576 m_imageElement = nullptr;
573 return nullptr; 577 return nullptr;
574 } 578 }
575 } 579 }
576 580
577 return m_imageElement->cachedImage(); 581 return m_imageElement->cachedImage();
578 } 582 }
579 583
584 ImageResource* ImageDocument::cachedImageResourceDeprecated() {
585 if (!m_imageElement) {
586 createDocumentStructure();
587 if (isStopped()) {
588 m_imageElement = nullptr;
589 return nullptr;
590 }
591 }
592
593 return m_imageElement->cachedImageResourceForImageDocument();
594 }
595
580 bool ImageDocument::shouldShrinkToFit() const { 596 bool ImageDocument::shouldShrinkToFit() const {
581 return frame()->isMainFrame(); 597 return frame()->isMainFrame();
582 } 598 }
583 599
584 DEFINE_TRACE(ImageDocument) { 600 DEFINE_TRACE(ImageDocument) {
585 visitor->trace(m_divElement); 601 visitor->trace(m_divElement);
586 visitor->trace(m_imageElement); 602 visitor->trace(m_imageElement);
587 HTMLDocument::trace(visitor); 603 HTMLDocument::trace(visitor);
588 } 604 }
589 605
(...skipping 13 matching lines...) Expand all
603 } 619 }
604 620
605 bool ImageEventListener::operator==(const EventListener& listener) const { 621 bool ImageEventListener::operator==(const EventListener& listener) const {
606 if (const ImageEventListener* imageEventListener = 622 if (const ImageEventListener* imageEventListener =
607 ImageEventListener::cast(&listener)) 623 ImageEventListener::cast(&listener))
608 return m_doc == imageEventListener->m_doc; 624 return m_doc == imageEventListener->m_doc;
609 return false; 625 return false;
610 } 626 }
611 627
612 } // namespace blink 628 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/html/ImageDocument.h ('k') | third_party/WebKit/Source/core/html/forms/ImageInputType.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698