| 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 29 matching lines...) Expand all Loading... |
| 40 #include "core/html/parser/HTMLParserIdioms.h" | 40 #include "core/html/parser/HTMLParserIdioms.h" |
| 41 #include "core/html/parser/HTMLSrcsetParser.h" | 41 #include "core/html/parser/HTMLSrcsetParser.h" |
| 42 #include "core/rendering/RenderImage.h" | 42 #include "core/rendering/RenderImage.h" |
| 43 #include "platform/MIMETypeRegistry.h" | 43 #include "platform/MIMETypeRegistry.h" |
| 44 #include "platform/RuntimeEnabledFeatures.h" | 44 #include "platform/RuntimeEnabledFeatures.h" |
| 45 | 45 |
| 46 namespace WebCore { | 46 namespace WebCore { |
| 47 | 47 |
| 48 using namespace HTMLNames; | 48 using namespace HTMLNames; |
| 49 | 49 |
| 50 class HTMLImageElement::Listener FINAL : public MediaQueryListListener { |
| 51 public: |
| 52 static RefPtrWillBeRawPtr<Listener> create(HTMLImageElement* element) |
| 53 { |
| 54 return adoptRefWillBeNoop(new Listener(element)); |
| 55 } |
| 56 |
| 57 virtual void call() OVERRIDE |
| 58 { |
| 59 if (m_element) |
| 60 m_element->notifyMediaQueryChanged(); |
| 61 } |
| 62 |
| 63 void clearElement() { m_element = nullptr; } |
| 64 virtual void trace(Visitor* visitor) OVERRIDE |
| 65 { |
| 66 visitor->trace(m_element); |
| 67 MediaQueryListListener::trace(visitor); |
| 68 } |
| 69 private: |
| 70 Listener(HTMLImageElement* element) : m_element(element) { } |
| 71 RawPtrWillBeMember<HTMLImageElement> m_element; |
| 72 }; |
| 73 |
| 50 HTMLImageElement::HTMLImageElement(Document& document, HTMLFormElement* form, bo
ol createdByParser) | 74 HTMLImageElement::HTMLImageElement(Document& document, HTMLFormElement* form, bo
ol createdByParser) |
| 51 : HTMLElement(imgTag, document) | 75 : HTMLElement(imgTag, document) |
| 52 , m_imageLoader(HTMLImageLoader::create(this)) | 76 , m_imageLoader(HTMLImageLoader::create(this)) |
| 53 , m_compositeOperator(CompositeSourceOver) | 77 , m_compositeOperator(CompositeSourceOver) |
| 54 , m_imageDevicePixelRatio(1.0f) | 78 , m_imageDevicePixelRatio(1.0f) |
| 55 , m_formWasSetByParser(false) | 79 , m_formWasSetByParser(false) |
| 56 , m_elementCreatedByParser(createdByParser) | 80 , m_elementCreatedByParser(createdByParser) |
| 81 , m_intrinsicSizingViewportDependant(false) |
| 82 , m_effectiveSizeViewportDependant(false) |
| 57 { | 83 { |
| 58 ScriptWrappable::init(this); | 84 ScriptWrappable::init(this); |
| 59 if (form && form->inDocument()) { | 85 if (form && form->inDocument()) { |
| 60 #if ENABLE(OILPAN) | 86 #if ENABLE(OILPAN) |
| 61 m_form = form; | 87 m_form = form; |
| 62 #else | 88 #else |
| 63 m_form = form->createWeakPtr(); | 89 m_form = form->createWeakPtr(); |
| 64 #endif | 90 #endif |
| 65 m_formWasSetByParser = true; | 91 m_formWasSetByParser = true; |
| 66 m_form->associate(*this); | 92 m_form->associate(*this); |
| 67 m_form->didAssociateByParser(); | 93 m_form->didAssociateByParser(); |
| 68 } | 94 } |
| 69 } | 95 } |
| 70 | 96 |
| 71 PassRefPtrWillBeRawPtr<HTMLImageElement> HTMLImageElement::create(Document& docu
ment) | 97 PassRefPtrWillBeRawPtr<HTMLImageElement> HTMLImageElement::create(Document& docu
ment) |
| 72 { | 98 { |
| 73 return adoptRefWillBeNoop(new HTMLImageElement(document)); | 99 return adoptRefWillBeNoop(new HTMLImageElement(document)); |
| 74 } | 100 } |
| 75 | 101 |
| 76 PassRefPtrWillBeRawPtr<HTMLImageElement> HTMLImageElement::create(Document& docu
ment, HTMLFormElement* form, bool createdByParser) | 102 PassRefPtrWillBeRawPtr<HTMLImageElement> HTMLImageElement::create(Document& docu
ment, HTMLFormElement* form, bool createdByParser) |
| 77 { | 103 { |
| 78 return adoptRefWillBeNoop(new HTMLImageElement(document, form, createdByPars
er)); | 104 return adoptRefWillBeNoop(new HTMLImageElement(document, form, createdByPars
er)); |
| 79 } | 105 } |
| 80 | 106 |
| 81 HTMLImageElement::~HTMLImageElement() | 107 HTMLImageElement::~HTMLImageElement() |
| 82 { | 108 { |
| 83 #if !ENABLE(OILPAN) | 109 #if !ENABLE(OILPAN) |
| 110 if (m_listener) |
| 111 m_listener->clearElement(); |
| 84 if (m_form) | 112 if (m_form) |
| 85 m_form->disassociate(*this); | 113 m_form->disassociate(*this); |
| 86 #endif | 114 #endif |
| 87 } | 115 } |
| 88 | 116 |
| 117 void HTMLImageElement::createMediaQueryListIfDoesNotExist() |
| 118 { |
| 119 if (m_mediaQueryList) |
| 120 return; |
| 121 RefPtrWillBeRawPtr<MediaQuerySet> set = MediaQuerySet::create(MediaTypeNames
::all); |
| 122 m_listener = Listener::create(this); |
| 123 m_mediaQueryList = MediaQueryList::create(&document().mediaQueryMatcher(), s
et.release()); |
| 124 m_mediaQueryList->addListener(m_listener); |
| 125 m_mediaQueryList->alwaysUpdate(); |
| 126 } |
| 127 |
| 89 void HTMLImageElement::trace(Visitor* visitor) | 128 void HTMLImageElement::trace(Visitor* visitor) |
| 90 { | 129 { |
| 91 visitor->trace(m_imageLoader); | 130 visitor->trace(m_imageLoader); |
| 92 visitor->trace(m_form); | 131 visitor->trace(m_form); |
| 132 visitor->trace(m_listener); |
| 133 visitor->trace(m_mediaQueryList); |
| 93 HTMLElement::trace(visitor); | 134 HTMLElement::trace(visitor); |
| 94 } | 135 } |
| 95 | 136 |
| 137 void HTMLImageElement::notifyMediaQueryChanged() |
| 138 { |
| 139 // Re-selecting the source URL in order to pick a more fitting resource |
| 140 // And update the image's intrinsic dimensions when the viewport changes. |
| 141 // Picking of a better fitting resource is UA dependant, not spec required. |
| 142 selectSourceURL(ImageLoader::UpdateForce); |
| 143 } |
| 144 |
| 96 PassRefPtrWillBeRawPtr<HTMLImageElement> HTMLImageElement::createForJSConstructo
r(Document& document, int width, int height) | 145 PassRefPtrWillBeRawPtr<HTMLImageElement> HTMLImageElement::createForJSConstructo
r(Document& document, int width, int height) |
| 97 { | 146 { |
| 98 RefPtrWillBeRawPtr<HTMLImageElement> image = adoptRefWillBeNoop(new HTMLImag
eElement(document)); | 147 RefPtrWillBeRawPtr<HTMLImageElement> image = adoptRefWillBeNoop(new HTMLImag
eElement(document)); |
| 99 if (width) | 148 if (width) |
| 100 image->setWidth(width); | 149 image->setWidth(width); |
| 101 if (height) | 150 if (height) |
| 102 image->setHeight(height); | 151 image->setHeight(height); |
| 103 image->m_elementCreatedByParser = false; | 152 image->m_elementCreatedByParser = false; |
| 104 return image.release(); | 153 return image.release(); |
| 105 } | 154 } |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 #endif | 223 #endif |
| 175 } | 224 } |
| 176 } | 225 } |
| 177 | 226 |
| 178 void HTMLImageElement::setBestFitURLAndDPRFromImageCandidate(const ImageCandidat
e& candidate) | 227 void HTMLImageElement::setBestFitURLAndDPRFromImageCandidate(const ImageCandidat
e& candidate) |
| 179 { | 228 { |
| 180 m_bestFitImageURL = candidate.url(); | 229 m_bestFitImageURL = candidate.url(); |
| 181 float candidateDensity = candidate.density(); | 230 float candidateDensity = candidate.density(); |
| 182 if (candidateDensity >= 0) | 231 if (candidateDensity >= 0) |
| 183 m_imageDevicePixelRatio = 1.0 / candidateDensity; | 232 m_imageDevicePixelRatio = 1.0 / candidateDensity; |
| 233 if (candidate.resourceWidth() > 0) |
| 234 m_intrinsicSizingViewportDependant = true; |
| 184 if (renderer() && renderer()->isImage()) | 235 if (renderer() && renderer()->isImage()) |
| 185 toRenderImage(renderer())->setImageDevicePixelRatio(m_imageDevicePixelRa
tio); | 236 toRenderImage(renderer())->setImageDevicePixelRatio(m_imageDevicePixelRa
tio); |
| 186 } | 237 } |
| 187 | 238 |
| 188 void HTMLImageElement::parseAttribute(const QualifiedName& name, const AtomicStr
ing& value) | 239 void HTMLImageElement::parseAttribute(const QualifiedName& name, const AtomicStr
ing& value) |
| 189 { | 240 { |
| 190 if (name == altAttr) { | 241 if (name == altAttr) { |
| 191 if (renderer() && renderer()->isImage()) | 242 if (renderer() && renderer()->isImage()) |
| 192 toRenderImage(renderer())->updateAltText(); | 243 toRenderImage(renderer())->updateAltText(); |
| 193 } else if (name == srcAttr || name == srcsetAttr || name == sizesAttr) { | 244 } else if (name == srcAttr || name == srcsetAttr || name == sizesAttr) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 String srcset = source->fastGetAttribute(srcsetAttr); | 290 String srcset = source->fastGetAttribute(srcsetAttr); |
| 240 if (srcset.isEmpty()) | 291 if (srcset.isEmpty()) |
| 241 continue; | 292 continue; |
| 242 String type = source->fastGetAttribute(typeAttr); | 293 String type = source->fastGetAttribute(typeAttr); |
| 243 if (!type.isEmpty() && !supportedImageType(type)) | 294 if (!type.isEmpty() && !supportedImageType(type)) |
| 244 continue; | 295 continue; |
| 245 | 296 |
| 246 if (!source->mediaQueryMatches()) | 297 if (!source->mediaQueryMatches()) |
| 247 continue; | 298 continue; |
| 248 | 299 |
| 249 unsigned effectiveSize = SizesAttributeParser::findEffectiveSize(source-
>fastGetAttribute(sizesAttr), MediaValuesDynamic::create(document())); | 300 SizesAttributeParser parser = SizesAttributeParser(MediaValuesDynamic::c
reate(document()), source->fastGetAttribute(sizesAttr)); |
| 301 unsigned effectiveSize = parser.length(); |
| 302 m_effectiveSizeViewportDependant = parser.viewportDependant(); |
| 250 ImageCandidate candidate = bestFitSourceForSrcsetAttribute(document().de
vicePixelRatio(), effectiveSize, source->fastGetAttribute(srcsetAttr)); | 303 ImageCandidate candidate = bestFitSourceForSrcsetAttribute(document().de
vicePixelRatio(), effectiveSize, source->fastGetAttribute(srcsetAttr)); |
| 251 if (candidate.isEmpty()) | 304 if (candidate.isEmpty()) |
| 252 continue; | 305 continue; |
| 253 return candidate; | 306 return candidate; |
| 254 } | 307 } |
| 255 return ImageCandidate(); | 308 return ImageCandidate(); |
| 256 } | 309 } |
| 257 | 310 |
| 258 RenderObject* HTMLImageElement::createRenderer(RenderStyle* style) | 311 RenderObject* HTMLImageElement::createRenderer(RenderStyle* style) |
| 259 { | 312 { |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 if (RuntimeEnabledFeatures::pictureEnabled()) { | 614 if (RuntimeEnabledFeatures::pictureEnabled()) { |
| 562 ImageCandidate candidate = findBestFitImageFromPictureParent(); | 615 ImageCandidate candidate = findBestFitImageFromPictureParent(); |
| 563 if (!candidate.isEmpty()) { | 616 if (!candidate.isEmpty()) { |
| 564 setBestFitURLAndDPRFromImageCandidate(candidate); | 617 setBestFitURLAndDPRFromImageCandidate(candidate); |
| 565 foundURL = true; | 618 foundURL = true; |
| 566 } | 619 } |
| 567 } | 620 } |
| 568 | 621 |
| 569 if (!foundURL) { | 622 if (!foundURL) { |
| 570 unsigned effectiveSize = 0; | 623 unsigned effectiveSize = 0; |
| 571 if (RuntimeEnabledFeatures::pictureSizesEnabled()) | 624 if (RuntimeEnabledFeatures::pictureSizesEnabled()) { |
| 572 effectiveSize = SizesAttributeParser::findEffectiveSize(fastGetAttri
bute(sizesAttr), MediaValuesDynamic::create(document())); | 625 SizesAttributeParser parser = SizesAttributeParser(MediaValuesDynami
c::create(document()), fastGetAttribute(sizesAttr)); |
| 626 effectiveSize = parser.length(); |
| 627 m_effectiveSizeViewportDependant = parser.viewportDependant(); |
| 628 } |
| 573 ImageCandidate candidate = bestFitSourceForImageAttributes(document().de
vicePixelRatio(), effectiveSize, fastGetAttribute(srcAttr), fastGetAttribute(src
setAttr)); | 629 ImageCandidate candidate = bestFitSourceForImageAttributes(document().de
vicePixelRatio(), effectiveSize, fastGetAttribute(srcAttr), fastGetAttribute(src
setAttr)); |
| 574 setBestFitURLAndDPRFromImageCandidate(candidate); | 630 setBestFitURLAndDPRFromImageCandidate(candidate); |
| 575 } | 631 } |
| 632 if (m_intrinsicSizingViewportDependant && m_effectiveSizeViewportDependant)
{ |
| 633 createMediaQueryListIfDoesNotExist(); |
| 634 document().mediaQueryMatcher().addMediaQueryList(m_mediaQueryList.get())
; |
| 635 } |
| 576 imageLoader().updateFromElement(behavior); | 636 imageLoader().updateFromElement(behavior); |
| 577 } | 637 } |
| 578 | 638 |
| 579 const KURL& HTMLImageElement::sourceURL() const | 639 const KURL& HTMLImageElement::sourceURL() const |
| 580 { | 640 { |
| 581 return cachedImage()->response().url(); | 641 return cachedImage()->response().url(); |
| 582 } | 642 } |
| 583 | 643 |
| 584 } | 644 } |
| OLD | NEW |