| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
| 4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010 Apple Inc. All rights reserv
ed. | 4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010 Apple Inc. All rights reserv
ed. |
| 5 * Copyright (C) 2010 Google Inc. All rights reserved. | 5 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 6 * | 6 * |
| 7 * This library is free software; you can redistribute it and/or | 7 * This library is free software; you can redistribute it and/or |
| 8 * modify it under the terms of the GNU Library General Public | 8 * modify it under the terms of the GNU Library General Public |
| 9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
| 10 * version 2 of the License, or (at your option) any later version. | 10 * version 2 of the License, or (at your option) any later version. |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 #include "platform/MIMETypeRegistry.h" | 54 #include "platform/MIMETypeRegistry.h" |
| 55 #include "platform/RuntimeEnabledFeatures.h" | 55 #include "platform/RuntimeEnabledFeatures.h" |
| 56 #include "platform/weborigin/SecurityPolicy.h" | 56 #include "platform/weborigin/SecurityPolicy.h" |
| 57 | 57 |
| 58 namespace blink { | 58 namespace blink { |
| 59 | 59 |
| 60 using namespace HTMLNames; | 60 using namespace HTMLNames; |
| 61 | 61 |
| 62 class HTMLImageElement::ViewportChangeListener final : public MediaQueryListList
ener { | 62 class HTMLImageElement::ViewportChangeListener final : public MediaQueryListList
ener { |
| 63 public: | 63 public: |
| 64 static RefPtrWillBeRawPtr<ViewportChangeListener> create(HTMLImageElement* e
lement) | 64 static RawPtr<ViewportChangeListener> create(HTMLImageElement* element) |
| 65 { | 65 { |
| 66 return adoptRefWillBeNoop(new ViewportChangeListener(element)); | 66 return (new ViewportChangeListener(element)); |
| 67 } | 67 } |
| 68 | 68 |
| 69 void notifyMediaQueryChanged() override | 69 void notifyMediaQueryChanged() override |
| 70 { | 70 { |
| 71 if (m_element) | 71 if (m_element) |
| 72 m_element->notifyViewportChanged(); | 72 m_element->notifyViewportChanged(); |
| 73 } | 73 } |
| 74 | 74 |
| 75 #if !ENABLE(OILPAN) | 75 #if !ENABLE(OILPAN) |
| 76 void clearElement() { m_element = nullptr; } | 76 void clearElement() { m_element = nullptr; } |
| 77 #endif | 77 #endif |
| 78 DEFINE_INLINE_VIRTUAL_TRACE() | 78 DEFINE_INLINE_VIRTUAL_TRACE() |
| 79 { | 79 { |
| 80 visitor->trace(m_element); | 80 visitor->trace(m_element); |
| 81 MediaQueryListListener::trace(visitor); | 81 MediaQueryListListener::trace(visitor); |
| 82 } | 82 } |
| 83 private: | 83 private: |
| 84 explicit ViewportChangeListener(HTMLImageElement* element) : m_element(eleme
nt) { } | 84 explicit ViewportChangeListener(HTMLImageElement* element) : m_element(eleme
nt) { } |
| 85 RawPtrWillBeMember<HTMLImageElement> m_element; | 85 Member<HTMLImageElement> m_element; |
| 86 }; | 86 }; |
| 87 | 87 |
| 88 HTMLImageElement::HTMLImageElement(Document& document, HTMLFormElement* form, bo
ol createdByParser) | 88 HTMLImageElement::HTMLImageElement(Document& document, HTMLFormElement* form, bo
ol createdByParser) |
| 89 : HTMLElement(imgTag, document) | 89 : HTMLElement(imgTag, document) |
| 90 , m_imageLoader(HTMLImageLoader::create(this)) | 90 , m_imageLoader(HTMLImageLoader::create(this)) |
| 91 , m_imageDevicePixelRatio(1.0f) | 91 , m_imageDevicePixelRatio(1.0f) |
| 92 , m_source(nullptr) | 92 , m_source(nullptr) |
| 93 , m_formWasSetByParser(false) | 93 , m_formWasSetByParser(false) |
| 94 , m_elementCreatedByParser(createdByParser) | 94 , m_elementCreatedByParser(createdByParser) |
| 95 , m_useFallbackContent(false) | 95 , m_useFallbackContent(false) |
| 96 , m_isFallbackImage(false) | 96 , m_isFallbackImage(false) |
| 97 , m_referrerPolicy(ReferrerPolicyDefault) | 97 , m_referrerPolicy(ReferrerPolicyDefault) |
| 98 { | 98 { |
| 99 setHasCustomStyleCallbacks(); | 99 setHasCustomStyleCallbacks(); |
| 100 if (form && form->inDocument()) { | 100 if (form && form->inDocument()) { |
| 101 #if ENABLE(OILPAN) | 101 #if ENABLE(OILPAN) |
| 102 m_form = form; | 102 m_form = form; |
| 103 #else | 103 #else |
| 104 m_form = form->createWeakPtr(); | 104 m_form = form->createWeakPtr(); |
| 105 #endif | 105 #endif |
| 106 m_formWasSetByParser = true; | 106 m_formWasSetByParser = true; |
| 107 m_form->associate(*this); | 107 m_form->associate(*this); |
| 108 m_form->didAssociateByParser(); | 108 m_form->didAssociateByParser(); |
| 109 } | 109 } |
| 110 } | 110 } |
| 111 | 111 |
| 112 PassRefPtrWillBeRawPtr<HTMLImageElement> HTMLImageElement::create(Document& docu
ment) | 112 RawPtr<HTMLImageElement> HTMLImageElement::create(Document& document) |
| 113 { | 113 { |
| 114 return adoptRefWillBeNoop(new HTMLImageElement(document)); | 114 return (new HTMLImageElement(document)); |
| 115 } | 115 } |
| 116 | 116 |
| 117 PassRefPtrWillBeRawPtr<HTMLImageElement> HTMLImageElement::create(Document& docu
ment, HTMLFormElement* form, bool createdByParser) | 117 RawPtr<HTMLImageElement> HTMLImageElement::create(Document& document, HTMLFormEl
ement* form, bool createdByParser) |
| 118 { | 118 { |
| 119 return adoptRefWillBeNoop(new HTMLImageElement(document, form, createdByPars
er)); | 119 return (new HTMLImageElement(document, form, createdByParser)); |
| 120 } | 120 } |
| 121 | 121 |
| 122 HTMLImageElement::~HTMLImageElement() | 122 HTMLImageElement::~HTMLImageElement() |
| 123 { | 123 { |
| 124 #if !ENABLE(OILPAN) | 124 #if !ENABLE(OILPAN) |
| 125 if (m_listener) { | 125 if (m_listener) { |
| 126 document().mediaQueryMatcher().removeViewportListener(m_listener.get()); | 126 document().mediaQueryMatcher().removeViewportListener(m_listener.get()); |
| 127 m_listener->clearElement(); | 127 m_listener->clearElement(); |
| 128 } | 128 } |
| 129 if (m_form) | 129 if (m_form) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 141 } | 141 } |
| 142 | 142 |
| 143 void HTMLImageElement::notifyViewportChanged() | 143 void HTMLImageElement::notifyViewportChanged() |
| 144 { | 144 { |
| 145 // Re-selecting the source URL in order to pick a more fitting resource | 145 // Re-selecting the source URL in order to pick a more fitting resource |
| 146 // And update the image's intrinsic dimensions when the viewport changes. | 146 // And update the image's intrinsic dimensions when the viewport changes. |
| 147 // Picking of a better fitting resource is UA dependant, not spec required. | 147 // Picking of a better fitting resource is UA dependant, not spec required. |
| 148 selectSourceURL(ImageLoader::UpdateSizeChanged); | 148 selectSourceURL(ImageLoader::UpdateSizeChanged); |
| 149 } | 149 } |
| 150 | 150 |
| 151 PassRefPtrWillBeRawPtr<HTMLImageElement> HTMLImageElement::createForJSConstructo
r(Document& document) | 151 RawPtr<HTMLImageElement> HTMLImageElement::createForJSConstructor(Document& docu
ment) |
| 152 { | 152 { |
| 153 RefPtrWillBeRawPtr<HTMLImageElement> image = adoptRefWillBeNoop(new HTMLImag
eElement(document)); | 153 RawPtr<HTMLImageElement> image = (new HTMLImageElement(document)); |
| 154 image->m_elementCreatedByParser = false; | 154 image->m_elementCreatedByParser = false; |
| 155 return image.release(); | 155 return image.release(); |
| 156 } | 156 } |
| 157 | 157 |
| 158 PassRefPtrWillBeRawPtr<HTMLImageElement> HTMLImageElement::createForJSConstructo
r(Document& document, int width) | 158 RawPtr<HTMLImageElement> HTMLImageElement::createForJSConstructor(Document& docu
ment, int width) |
| 159 { | 159 { |
| 160 RefPtrWillBeRawPtr<HTMLImageElement> image = adoptRefWillBeNoop(new HTMLImag
eElement(document)); | 160 RawPtr<HTMLImageElement> image = (new HTMLImageElement(document)); |
| 161 image->setWidth(width); | 161 image->setWidth(width); |
| 162 image->m_elementCreatedByParser = false; | 162 image->m_elementCreatedByParser = false; |
| 163 return image.release(); | 163 return image.release(); |
| 164 } | 164 } |
| 165 | 165 |
| 166 PassRefPtrWillBeRawPtr<HTMLImageElement> HTMLImageElement::createForJSConstructo
r(Document& document, int width, int height) | 166 RawPtr<HTMLImageElement> HTMLImageElement::createForJSConstructor(Document& docu
ment, int width, int height) |
| 167 { | 167 { |
| 168 RefPtrWillBeRawPtr<HTMLImageElement> image = adoptRefWillBeNoop(new HTMLImag
eElement(document)); | 168 RawPtr<HTMLImageElement> image = (new HTMLImageElement(document)); |
| 169 image->setWidth(width); | 169 image->setWidth(width); |
| 170 image->setHeight(height); | 170 image->setHeight(height); |
| 171 image->m_elementCreatedByParser = false; | 171 image->m_elementCreatedByParser = false; |
| 172 return image.release(); | 172 return image.release(); |
| 173 } | 173 } |
| 174 | 174 |
| 175 bool HTMLImageElement::isPresentationAttribute(const QualifiedName& name) const | 175 bool HTMLImageElement::isPresentationAttribute(const QualifiedName& name) const |
| 176 { | 176 { |
| 177 if (name == widthAttr || name == heightAttr || name == borderAttr || name ==
vspaceAttr || name == hspaceAttr || name == alignAttr || name == valignAttr) | 177 if (name == widthAttr || name == heightAttr || name == borderAttr || name ==
vspaceAttr || name == hspaceAttr || name == alignAttr || name == valignAttr) |
| 178 return true; | 178 return true; |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 void HTMLImageElement::attach(const AttachContext& context) | 373 void HTMLImageElement::attach(const AttachContext& context) |
| 374 { | 374 { |
| 375 HTMLElement::attach(context); | 375 HTMLElement::attach(context); |
| 376 | 376 |
| 377 if (layoutObject() && layoutObject()->isImage()) { | 377 if (layoutObject() && layoutObject()->isImage()) { |
| 378 LayoutImage* layoutImage = toLayoutImage(layoutObject()); | 378 LayoutImage* layoutImage = toLayoutImage(layoutObject()); |
| 379 LayoutImageResource* layoutImageResource = layoutImage->imageResource(); | 379 LayoutImageResource* layoutImageResource = layoutImage->imageResource(); |
| 380 if (m_isFallbackImage) { | 380 if (m_isFallbackImage) { |
| 381 float deviceScaleFactor = blink::deviceScaleFactor(layoutImage->fram
e()); | 381 float deviceScaleFactor = blink::deviceScaleFactor(layoutImage->fram
e()); |
| 382 std::pair<Image*, float> brokenImageAndImageScaleFactor = ImageResou
rce::brokenImage(deviceScaleFactor); | 382 std::pair<Image*, float> brokenImageAndImageScaleFactor = ImageResou
rce::brokenImage(deviceScaleFactor); |
| 383 RefPtrWillBeRawPtr<ImageResource> newImageResource = ImageResource::
create(brokenImageAndImageScaleFactor.first); | 383 RawPtr<ImageResource> newImageResource = ImageResource::create(broke
nImageAndImageScaleFactor.first); |
| 384 layoutImage->imageResource()->setImageResource(newImageResource.get(
)); | 384 layoutImage->imageResource()->setImageResource(newImageResource.get(
)); |
| 385 } | 385 } |
| 386 if (layoutImageResource->hasImage()) | 386 if (layoutImageResource->hasImage()) |
| 387 return; | 387 return; |
| 388 | 388 |
| 389 if (!imageLoader().image() && !layoutImageResource->cachedImage()) | 389 if (!imageLoader().image() && !layoutImageResource->cachedImage()) |
| 390 return; | 390 return; |
| 391 layoutImageResource->setImageResource(imageLoader().image()); | 391 layoutImageResource->setImageResource(imageLoader().image()); |
| 392 } | 392 } |
| 393 } | 393 } |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 812 { | 812 { |
| 813 ImageResource* image = cachedImage(); | 813 ImageResource* image = cachedImage(); |
| 814 if (!image) | 814 if (!image) |
| 815 return IntSize(); | 815 return IntSize(); |
| 816 LayoutSize lSize = image->imageSize(LayoutObject::shouldRespectImageOrientat
ion(layoutObject()), 1.0f); | 816 LayoutSize lSize = image->imageSize(LayoutObject::shouldRespectImageOrientat
ion(layoutObject()), 1.0f); |
| 817 ASSERT(lSize.fraction().isZero()); | 817 ASSERT(lSize.fraction().isZero()); |
| 818 return IntSize(lSize.width(), lSize.height()); | 818 return IntSize(lSize.width(), lSize.height()); |
| 819 } | 819 } |
| 820 | 820 |
| 821 } // namespace blink | 821 } // namespace blink |
| OLD | NEW |