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

Unified Diff: Source/core/html/parser/HTMLPreloadScanner.cpp

Issue 236713005: Use SizesAttributeParser to get the right srcset resource (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@sizes_parser8
Patch Set: Fixed nits Created 6 years, 8 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
« no previous file with comments | « Source/core/html/HTMLImageElement.idl ('k') | Source/core/html/parser/HTMLSrcsetParser.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/html/parser/HTMLPreloadScanner.cpp
diff --git a/Source/core/html/parser/HTMLPreloadScanner.cpp b/Source/core/html/parser/HTMLPreloadScanner.cpp
index f443fd73daa8b5c3d4b6e16af164f0887a969b98..706fb0e51034b954e74e60534ba1610ac8e53691 100644
--- a/Source/core/html/parser/HTMLPreloadScanner.cpp
+++ b/Source/core/html/parser/HTMLPreloadScanner.cpp
@@ -34,6 +34,7 @@
#include "core/css/MediaList.h"
#include "core/css/MediaQueryEvaluator.h"
#include "core/css/MediaValues.h"
+#include "core/css/parser/SizesAttributeParser.h"
#include "core/html/LinkRelAttribute.h"
#include "core/html/parser/HTMLParserIdioms.h"
#include "core/html/parser/HTMLSrcsetParser.h"
@@ -107,7 +108,8 @@ public:
, m_linkIsStyleSheet(false)
, m_matchedMediaAttribute(true)
, m_inputIsImage(false)
- , m_encounteredImgSrc(false)
+ , m_imgSourceSize(0)
+ , m_sourceSizeSet(false)
, m_isCORSEnabled(false)
, m_allowCredentials(DoNotAllowStoredCredentials)
, m_mediaValues(mediaValues)
@@ -117,6 +119,8 @@ public:
&& !match(m_tagImpl, linkTag)
&& !match(m_tagImpl, scriptTag))
m_tagImpl = 0;
+ if (RuntimeEnabledFeatures::pictureSizesEnabled())
+ m_imgSourceSize = SizesAttributeParser::findEffectiveSize(String(), m_mediaValues);
}
enum URLReplacement {
@@ -171,15 +175,22 @@ private:
else if (match(attributeName, crossoriginAttr))
setCrossOriginAllowed(attributeValue);
} else if (match(m_tagImpl, imgTag)) {
- int effectiveSize = -1; // FIXME - hook up the real value from `sizes`
- if (match(attributeName, srcAttr) && !m_encounteredImgSrc) {
- m_encounteredImgSrc = true;
- setUrlToLoad(bestFitSourceForImageAttributes(m_mediaValues->devicePixelRatio(), effectiveSize, attributeValue, m_srcsetImageCandidate), AllowURLReplacement);
+ if (match(attributeName, srcAttr) && m_imgSrcUrl.isNull()) {
+ m_imgSrcUrl = attributeValue;
+ setUrlToLoad(bestFitSourceForImageAttributes(m_mediaValues->devicePixelRatio(), m_imgSourceSize, attributeValue, m_srcsetImageCandidate), AllowURLReplacement);
} else if (match(attributeName, crossoriginAttr)) {
setCrossOriginAllowed(attributeValue);
} else if (match(attributeName, srcsetAttr) && m_srcsetImageCandidate.isEmpty()) {
- m_srcsetImageCandidate = bestFitSourceForSrcsetAttribute(m_mediaValues->devicePixelRatio(), effectiveSize, attributeValue);
- setUrlToLoad(bestFitSourceForImageAttributes(m_mediaValues->devicePixelRatio(), effectiveSize, m_urlToLoad, m_srcsetImageCandidate), AllowURLReplacement);
+ m_imgSrcsetAttributeValue = attributeValue;
+ m_srcsetImageCandidate = bestFitSourceForSrcsetAttribute(m_mediaValues->devicePixelRatio(), m_imgSourceSize, attributeValue);
+ setUrlToLoad(bestFitSourceForImageAttributes(m_mediaValues->devicePixelRatio(), m_imgSourceSize, m_imgSrcUrl, m_srcsetImageCandidate), AllowURLReplacement);
+ } else if (RuntimeEnabledFeatures::pictureSizesEnabled() && match(attributeName, sizesAttr) && !m_sourceSizeSet) {
+ m_imgSourceSize = SizesAttributeParser::findEffectiveSize(attributeValue, m_mediaValues);
+ m_sourceSizeSet = true;
+ if (!m_srcsetImageCandidate.isEmpty()) {
+ m_srcsetImageCandidate = bestFitSourceForSrcsetAttribute(m_mediaValues->devicePixelRatio(), m_imgSourceSize, m_imgSrcsetAttributeValue);
+ setUrlToLoad(bestFitSourceForImageAttributes(m_mediaValues->devicePixelRatio(), m_imgSourceSize, m_imgSrcUrl, m_srcsetImageCandidate), AllowURLReplacement);
+ }
}
} else if (match(m_tagImpl, linkTag)) {
if (match(attributeName, hrefAttr))
@@ -273,7 +284,10 @@ private:
bool m_linkIsStyleSheet;
bool m_matchedMediaAttribute;
bool m_inputIsImage;
- bool m_encounteredImgSrc;
+ String m_imgSrcUrl;
+ String m_imgSrcsetAttributeValue;
+ unsigned m_imgSourceSize;
+ bool m_sourceSizeSet;
bool m_isCORSEnabled;
StoredCredentials m_allowCredentials;
RefPtr<MediaValues> m_mediaValues;
« no previous file with comments | « Source/core/html/HTMLImageElement.idl ('k') | Source/core/html/parser/HTMLSrcsetParser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698