| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 #include <limits> | 49 #include <limits> |
| 50 | 50 |
| 51 using namespace std; | 51 using namespace std; |
| 52 | 52 |
| 53 namespace blink { | 53 namespace blink { |
| 54 | 54 |
| 55 using namespace HTMLNames; | 55 using namespace HTMLNames; |
| 56 | 56 |
| 57 class ImageEventListener : public EventListener { | 57 class ImageEventListener : public EventListener { |
| 58 public: | 58 public: |
| 59 static PassRefPtrWillBeRawPtr<ImageEventListener> create(ImageDocument* docu
ment) | 59 static RawPtr<ImageEventListener> create(ImageDocument* document) |
| 60 { | 60 { |
| 61 return adoptRefWillBeNoop(new ImageEventListener(document)); | 61 return (new ImageEventListener(document)); |
| 62 } | 62 } |
| 63 static const ImageEventListener* cast(const EventListener* listener) | 63 static const ImageEventListener* cast(const EventListener* listener) |
| 64 { | 64 { |
| 65 return listener->type() == ImageEventListenerType | 65 return listener->type() == ImageEventListenerType |
| 66 ? static_cast<const ImageEventListener*>(listener) | 66 ? static_cast<const ImageEventListener*>(listener) |
| 67 : 0; | 67 : 0; |
| 68 } | 68 } |
| 69 | 69 |
| 70 bool operator==(const EventListener& other) const override; | 70 bool operator==(const EventListener& other) const override; |
| 71 | 71 |
| 72 DEFINE_INLINE_VIRTUAL_TRACE() | 72 DEFINE_INLINE_VIRTUAL_TRACE() |
| 73 { | 73 { |
| 74 visitor->trace(m_doc); | 74 visitor->trace(m_doc); |
| 75 EventListener::trace(visitor); | 75 EventListener::trace(visitor); |
| 76 } | 76 } |
| 77 | 77 |
| 78 private: | 78 private: |
| 79 ImageEventListener(ImageDocument* document) | 79 ImageEventListener(ImageDocument* document) |
| 80 : EventListener(ImageEventListenerType) | 80 : EventListener(ImageEventListenerType) |
| 81 , m_doc(document) | 81 , m_doc(document) |
| 82 { | 82 { |
| 83 } | 83 } |
| 84 | 84 |
| 85 virtual void handleEvent(ExecutionContext*, Event*); | 85 virtual void handleEvent(ExecutionContext*, Event*); |
| 86 | 86 |
| 87 RawPtrWillBeMember<ImageDocument> m_doc; | 87 Member<ImageDocument> m_doc; |
| 88 }; | 88 }; |
| 89 | 89 |
| 90 class ImageDocumentParser : public RawDataDocumentParser { | 90 class ImageDocumentParser : public RawDataDocumentParser { |
| 91 public: | 91 public: |
| 92 static PassRefPtrWillBeRawPtr<ImageDocumentParser> create(ImageDocument* doc
ument) | 92 static RawPtr<ImageDocumentParser> create(ImageDocument* document) |
| 93 { | 93 { |
| 94 return adoptRefWillBeNoop(new ImageDocumentParser(document)); | 94 return (new ImageDocumentParser(document)); |
| 95 } | 95 } |
| 96 | 96 |
| 97 ImageDocument* document() const | 97 ImageDocument* document() const |
| 98 { | 98 { |
| 99 return toImageDocument(RawDataDocumentParser::document()); | 99 return toImageDocument(RawDataDocumentParser::document()); |
| 100 } | 100 } |
| 101 | 101 |
| 102 private: | 102 private: |
| 103 ImageDocumentParser(ImageDocument* document) | 103 ImageDocumentParser(ImageDocument* document) |
| 104 : RawDataDocumentParser(document) | 104 : RawDataDocumentParser(document) |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 , m_imageElement(nullptr) | 189 , m_imageElement(nullptr) |
| 190 , m_imageSizeIsKnown(false) | 190 , m_imageSizeIsKnown(false) |
| 191 , m_didShrinkImage(false) | 191 , m_didShrinkImage(false) |
| 192 , m_shouldShrinkImage(shouldShrinkToFit()) | 192 , m_shouldShrinkImage(shouldShrinkToFit()) |
| 193 , m_shrinkToFitMode(frame()->settings()->viewportEnabled() ? Viewport : Desk
top) | 193 , m_shrinkToFitMode(frame()->settings()->viewportEnabled() ? Viewport : Desk
top) |
| 194 { | 194 { |
| 195 setCompatibilityMode(QuirksMode); | 195 setCompatibilityMode(QuirksMode); |
| 196 lockCompatibilityMode(); | 196 lockCompatibilityMode(); |
| 197 } | 197 } |
| 198 | 198 |
| 199 PassRefPtrWillBeRawPtr<DocumentParser> ImageDocument::createParser() | 199 RawPtr<DocumentParser> ImageDocument::createParser() |
| 200 { | 200 { |
| 201 return ImageDocumentParser::create(this); | 201 return ImageDocumentParser::create(this); |
| 202 } | 202 } |
| 203 | 203 |
| 204 void ImageDocument::createDocumentStructure(bool loadingMultipartContent) | 204 void ImageDocument::createDocumentStructure(bool loadingMultipartContent) |
| 205 { | 205 { |
| 206 RefPtrWillBeRawPtr<HTMLHtmlElement> rootElement = HTMLHtmlElement::create(*t
his); | 206 RawPtr<HTMLHtmlElement> rootElement = HTMLHtmlElement::create(*this); |
| 207 appendChild(rootElement); | 207 appendChild(rootElement); |
| 208 rootElement->insertedByParser(); | 208 rootElement->insertedByParser(); |
| 209 | 209 |
| 210 if (frame()) | 210 if (frame()) |
| 211 frame()->loader().dispatchDocumentElementAvailable(); | 211 frame()->loader().dispatchDocumentElementAvailable(); |
| 212 // Normally, ImageDocument creates an HTMLImageElement that doesn't actually
load | 212 // Normally, ImageDocument creates an HTMLImageElement that doesn't actually
load |
| 213 // anything, and the ImageDocument routes the main resource data into the HT
MLImageElement's | 213 // anything, and the ImageDocument routes the main resource data into the HT
MLImageElement's |
| 214 // ImageResource. However, the main resource pipeline doesn't know how to ha
ndle multipart content. | 214 // ImageResource. However, the main resource pipeline doesn't know how to ha
ndle multipart content. |
| 215 // For multipart content, we instead stop streaming data through the main re
source and re-request | 215 // For multipart content, we instead stop streaming data through the main re
source and re-request |
| 216 // the data directly. | 216 // the data directly. |
| 217 if (loadingMultipartContent) | 217 if (loadingMultipartContent) |
| 218 loader()->stopLoading(); | 218 loader()->stopLoading(); |
| 219 | 219 |
| 220 RefPtrWillBeRawPtr<HTMLHeadElement> head = HTMLHeadElement::create(*this); | 220 RawPtr<HTMLHeadElement> head = HTMLHeadElement::create(*this); |
| 221 RefPtrWillBeRawPtr<HTMLMetaElement> meta = HTMLMetaElement::create(*this); | 221 RawPtr<HTMLMetaElement> meta = HTMLMetaElement::create(*this); |
| 222 meta->setAttribute(nameAttr, "viewport"); | 222 meta->setAttribute(nameAttr, "viewport"); |
| 223 meta->setAttribute(contentAttr, "width=device-width, minimum-scale=0.1"); | 223 meta->setAttribute(contentAttr, "width=device-width, minimum-scale=0.1"); |
| 224 head->appendChild(meta); | 224 head->appendChild(meta); |
| 225 | 225 |
| 226 RefPtrWillBeRawPtr<HTMLBodyElement> body = HTMLBodyElement::create(*this); | 226 RawPtr<HTMLBodyElement> body = HTMLBodyElement::create(*this); |
| 227 body->setAttribute(styleAttr, "margin: 0px;"); | 227 body->setAttribute(styleAttr, "margin: 0px;"); |
| 228 | 228 |
| 229 if (frame()) | 229 if (frame()) |
| 230 frame()->loader().client()->dispatchWillInsertBody(); | 230 frame()->loader().client()->dispatchWillInsertBody(); |
| 231 | 231 |
| 232 m_imageElement = HTMLImageElement::create(*this); | 232 m_imageElement = HTMLImageElement::create(*this); |
| 233 m_imageElement->setAttribute(styleAttr, "-webkit-user-select: none"); | 233 m_imageElement->setAttribute(styleAttr, "-webkit-user-select: none"); |
| 234 // If the image is multipart, we neglect to mention to the HTMLImageElement
that it's in an | 234 // If the image is multipart, we neglect to mention to the HTMLImageElement
that it's in an |
| 235 // ImageDocument, so that it requests the image normally. | 235 // ImageDocument, so that it requests the image normally. |
| 236 if (!loadingMultipartContent) | 236 if (!loadingMultipartContent) |
| 237 m_imageElement->setLoadingImageDocument(); | 237 m_imageElement->setLoadingImageDocument(); |
| 238 m_imageElement->setSrc(url().string()); | 238 m_imageElement->setSrc(url().string()); |
| 239 body->appendChild(m_imageElement.get()); | 239 body->appendChild(m_imageElement.get()); |
| 240 | 240 |
| 241 if (shouldShrinkToFit()) { | 241 if (shouldShrinkToFit()) { |
| 242 // Add event listeners | 242 // Add event listeners |
| 243 RefPtrWillBeRawPtr<EventListener> listener = ImageEventListener::create(
this); | 243 RawPtr<EventListener> listener = ImageEventListener::create(this); |
| 244 if (LocalDOMWindow* domWindow = this->domWindow()) | 244 if (LocalDOMWindow* domWindow = this->domWindow()) |
| 245 domWindow->addEventListener("resize", listener, false); | 245 domWindow->addEventListener("resize", listener, false); |
| 246 if (m_shrinkToFitMode == Desktop) | 246 if (m_shrinkToFitMode == Desktop) |
| 247 m_imageElement->addEventListener("click", listener.release(), false)
; | 247 m_imageElement->addEventListener("click", listener.release(), false)
; |
| 248 } | 248 } |
| 249 | 249 |
| 250 rootElement->appendChild(head); | 250 rootElement->appendChild(head); |
| 251 rootElement->appendChild(body); | 251 rootElement->appendChild(body); |
| 252 if (loadingMultipartContent) | 252 if (loadingMultipartContent) |
| 253 finishedParsing(); | 253 finishedParsing(); |
| (...skipping 200 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 |