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

Unified Diff: Source/core/html/HTMLImageElement.cpp

Issue 369423002: Have srcset respond to viewport changes (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Oilpan comments Created 6 years, 5 months 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 side-by-side diff with in-line comments
Download patch
Index: Source/core/html/HTMLImageElement.cpp
diff --git a/Source/core/html/HTMLImageElement.cpp b/Source/core/html/HTMLImageElement.cpp
index ceeb1ede0923b0b2912ddc8e3cd7f60df49ccb64..9543bd3f4b1d8a6c3d0836a35bbcb1a62a2d81f7 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()) {
@@ -81,6 +84,7 @@ PassRefPtrWillBeRawPtr<HTMLImageElement> HTMLImageElement::create(Document& docu
HTMLImageElement::~HTMLImageElement()
{
#if !ENABLE(OILPAN)
+ document().viewportChangeNotifier().removeListener(m_viewportListener.get());
esprehn 2014/07/14 08:39:49 Or slower...
if (m_form)
m_form->disassociate(*this);
#endif
@@ -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.get());
imageLoader().updateFromElement(behavior);
}

Powered by Google App Engine
This is Rietveld 408576698