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

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

Issue 23861003: Enable srcset support in HTMLImageElement (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fix issues raised in review Created 7 years, 3 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/parser/HTMLPreloadScanner.cpp
diff --git a/Source/core/html/parser/HTMLPreloadScanner.cpp b/Source/core/html/parser/HTMLPreloadScanner.cpp
index 0b51791a374d39388adc0e23565c850647be29e6..bf719c6972d2dc5b172f116bee41884cb2030fd0 100644
--- a/Source/core/html/parser/HTMLPreloadScanner.cpp
+++ b/Source/core/html/parser/HTMLPreloadScanner.cpp
@@ -29,6 +29,7 @@
#include "core/html/parser/HTMLPreloadScanner.h"
#include "HTMLNames.h"
+#include "RuntimeEnabledFeatures.h"
#include "core/html/InputTypeNames.h"
#include "core/html/LinkRelAttribute.h"
#include "core/html/parser/HTMLParserIdioms.h"
@@ -90,10 +91,11 @@ static String initiatorFor(const StringImpl* tagImpl)
class TokenPreloadScanner::StartTagScanner {
public:
- explicit StartTagScanner(const StringImpl* tagImpl)
+ explicit StartTagScanner(const StringImpl* tagImpl, float deviceScaleFactor = 1.0)
abarth-chromium 2013/09/13 05:54:07 Please remove the default argument. All callers s
: m_tagImpl(tagImpl)
, m_linkIsStyleSheet(false)
, m_inputIsImage(false)
+ , m_deviceScaleFactor(deviceScaleFactor)
{
if (!match(m_tagImpl, imgTag)
&& !match(m_tagImpl, inputTag)
@@ -102,6 +104,14 @@ public:
m_tagImpl = 0;
}
+ void applySrcset()
+ {
+ // Resolve between src and srcSet if we have them.
+ if (RuntimeEnabledFeatures::srcsetEnabled() && !m_srcSetAttribute.isEmpty()) {
ojan 2013/09/12 23:26:38 Nit: single line if should not have curly braces.
+ setUrlToLoad(bestFitSourceForImageAttributes(m_deviceScaleFactor, m_urlToLoad, m_srcSetAttribute), true);
abarth-chromium 2013/09/13 05:54:07 This line of code isn't correct. You haven't dist
+ }
+ }
+
void processAttributes(const HTMLToken::AttributeList& attributes)
{
ASSERT(isMainThread());
@@ -112,6 +122,8 @@ public:
String attributeValue = StringImpl::create8BitIfPossible(iter->value);
processAttribute(attributeName, attributeValue);
}
+
+ applySrcset();
abarth-chromium 2013/09/13 05:54:07 Instead of doing the after every tag, we should on
Yoav Weiss 2013/09/13 10:04:18 Assuming m_srcSetAttribute is only initialized for
abarth-chromium 2013/09/13 17:58:12 The important thing is to only do srcset-specific
}
void processAttributes(const Vector<CompactHTMLToken::Attribute>& attributes)
@@ -120,6 +132,8 @@ public:
return;
for (Vector<CompactHTMLToken::Attribute>::const_iterator iter = attributes.begin(); iter != attributes.end(); ++iter)
processAttribute(iter->name, iter->value);
+
+ applySrcset();
}
PassOwnPtr<PreloadRequest> createPreloadRequest(const KURL& predictedBaseURL, const SegmentedString& source)
@@ -168,13 +182,16 @@ private:
return rel.isStyleSheet() && !rel.isAlternate() && rel.iconType() == InvalidIcon && !rel.isDNSPrefetch();
}
- void setUrlToLoad(const String& attributeValue)
+ void setUrlToLoad(const String& value, bool allowReplacement = false)
abarth-chromium 2013/09/13 05:54:07 Please remove the default value for the last argum
{
// We only respect the first src/href, per HTML5:
// http://www.whatwg.org/specs/web-apps/current-work/multipage/tokenization.html#attribute-name-state
- if (!m_urlToLoad.isEmpty())
+ if (!allowReplacement && !m_urlToLoad.isEmpty())
+ return;
+ String url = stripLeadingAndTrailingHTMLSpaces(value);
+ if (url.isEmpty())
return;
- m_urlToLoad = stripLeadingAndTrailingHTMLSpaces(attributeValue);
+ m_urlToLoad = url;
}
const String& charset() const
@@ -215,16 +232,19 @@ private:
const StringImpl* m_tagImpl;
String m_urlToLoad;
+ String m_srcSetAttribute;
abarth-chromium 2013/09/13 05:54:07 Where did you ever assign this member? Please add
Yoav Weiss 2013/09/13 10:04:18 That is a bug (assignment lost in merge). Thanks!
String m_charset;
String m_crossOriginMode;
bool m_linkIsStyleSheet;
String m_mediaAttribute;
bool m_inputIsImage;
+ float m_deviceScaleFactor;
};
-TokenPreloadScanner::TokenPreloadScanner(const KURL& documentURL)
+TokenPreloadScanner::TokenPreloadScanner(const KURL& documentURL, float deviceScaleFactor)
: m_documentURL(documentURL)
, m_inStyle(false)
+ , m_deviceScaleFactor(deviceScaleFactor)
, m_templateCount(0)
{
}
@@ -305,7 +325,7 @@ void TokenPreloadScanner::scanCommon(const Token& token, const SegmentedString&
return;
}
- StartTagScanner scanner(tagImpl);
+ StartTagScanner scanner(tagImpl, m_deviceScaleFactor);
scanner.processAttributes(token.attributes());
OwnPtr<PreloadRequest> request = scanner.createPreloadRequest(m_predictedBaseElementURL, source);
if (request)
@@ -326,8 +346,8 @@ void TokenPreloadScanner::updatePredictedBaseURL(const Token& token)
m_predictedBaseElementURL = KURL(m_documentURL, stripLeadingAndTrailingHTMLSpaces(hrefAttribute->value)).copy();
}
-HTMLPreloadScanner::HTMLPreloadScanner(const HTMLParserOptions& options, const KURL& documentURL)
- : m_scanner(documentURL)
+HTMLPreloadScanner::HTMLPreloadScanner(const HTMLParserOptions& options, const KURL& documentURL, float deviceScaleFactor)
+ : m_scanner(documentURL, deviceScaleFactor)
, m_tokenizer(HTMLTokenizer::create(options))
{
}

Powered by Google App Engine
This is Rietveld 408576698