Chromium Code Reviews| Index: Source/core/html/HTMLImageElement.cpp |
| diff --git a/Source/core/html/HTMLImageElement.cpp b/Source/core/html/HTMLImageElement.cpp |
| index ceeb1ede0923b0b2912ddc8e3cd7f60df49ccb64..1174afb4508b1230037f0702dd178084a700b4a2 100644 |
| --- a/Source/core/html/HTMLImageElement.cpp |
| +++ b/Source/core/html/HTMLImageElement.cpp |
| @@ -54,6 +54,9 @@ HTMLImageElement::HTMLImageElement(Document& document, HTMLFormElement* form, bo |
| , m_imageDevicePixelRatio(1.0f) |
| , m_formWasSetByParser(false) |
| , m_elementCreatedByParser(createdByParser) |
| + , m_intrinsicSizingViewportDependant(false) |
| + , m_effectiveSizeViewportDependant(false) |
| + , m_viewportListener(ImageViewportChangeListener::create(this)) |
| { |
| ScriptWrappable::init(this); |
| if (form && form->inDocument()) { |
| @@ -80,6 +83,7 @@ PassRefPtrWillBeRawPtr<HTMLImageElement> HTMLImageElement::create(Document& docu |
| HTMLImageElement::~HTMLImageElement() |
| { |
| + document().viewportChangeNotifier().removeListener(m_viewportListener); |
|
haraken
2014/07/11 06:10:21
In oilpan, destructors cannot touch other on-heap
|
| #if !ENABLE(OILPAN) |
| if (m_form) |
| m_form->disassociate(*this); |
| @@ -181,6 +185,8 @@ void HTMLImageElement::setBestFitURLAndDPRFromImageCandidate(const ImageCandidat |
| float candidateDensity = candidate.density(); |
| if (candidateDensity >= 0) |
| m_imageDevicePixelRatio = 1.0 / candidateDensity; |
| + if (candidate.resourceWidth() > 0) |
| + m_intrinsicSizingViewportDependant = true; |
| if (renderer() && renderer()->isImage()) |
| toRenderImage(renderer())->setImageDevicePixelRatio(m_imageDevicePixelRatio); |
| } |
| @@ -246,7 +252,7 @@ ImageCandidate HTMLImageElement::findBestFitImageFromPictureParent() |
| if (!source->mediaQueryMatches()) |
| continue; |
| - unsigned effectiveSize = SizesAttributeParser::findEffectiveSize(source->fastGetAttribute(sizesAttr), MediaValuesDynamic::create(document())); |
| + unsigned effectiveSize = SizesAttributeParser::findEffectiveSize(source->fastGetAttribute(sizesAttr), MediaValuesDynamic::create(document()), m_effectiveSizeViewportDependant); |
| ImageCandidate candidate = bestFitSourceForSrcsetAttribute(document().devicePixelRatio(), effectiveSize, source->fastGetAttribute(srcsetAttr)); |
| if (candidate.isEmpty()) |
| continue; |
| @@ -569,10 +575,12 @@ void HTMLImageElement::selectSourceURL(ImageLoader::UpdateFromElementBehavior be |
| if (!foundURL) { |
| unsigned effectiveSize = 0; |
| if (RuntimeEnabledFeatures::pictureSizesEnabled()) |
| - effectiveSize = SizesAttributeParser::findEffectiveSize(fastGetAttribute(sizesAttr), MediaValuesDynamic::create(document())); |
| + effectiveSize = SizesAttributeParser::findEffectiveSize(fastGetAttribute(sizesAttr), MediaValuesDynamic::create(document()), m_effectiveSizeViewportDependant); |
| ImageCandidate candidate = bestFitSourceForImageAttributes(document().devicePixelRatio(), effectiveSize, fastGetAttribute(srcAttr), fastGetAttribute(srcsetAttr)); |
| setBestFitURLAndDPRFromImageCandidate(candidate); |
| } |
| + if (m_intrinsicSizingViewportDependant && m_effectiveSizeViewportDependant) |
| + document().viewportChangeNotifier().addListener(m_viewportListener); |
| imageLoader().updateFromElement(behavior); |
| } |