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

Unified Diff: Source/core/html/HTMLImageElement.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.h ('k') | Source/core/html/HTMLImageElement.idl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/html/HTMLImageElement.cpp
diff --git a/Source/core/html/HTMLImageElement.cpp b/Source/core/html/HTMLImageElement.cpp
index a2ee16b6e691f0e11ccd83c4abb17a58ae05c37c..6d15b5bfb7b3f4a01e93be6e07a907d6cd1887bc 100644
--- a/Source/core/html/HTMLImageElement.cpp
+++ b/Source/core/html/HTMLImageElement.cpp
@@ -51,7 +51,6 @@ HTMLImageElement::HTMLImageElement(Document& document, HTMLFormElement* form)
, m_compositeOperator(CompositeSourceOver)
, m_imageDevicePixelRatio(1.0f)
, m_formWasSetByParser(false)
- , m_effectiveSize(0)
{
ScriptWrappable::init(this);
if (form && form->inDocument()) {
@@ -156,18 +155,19 @@ void HTMLImageElement::parseAttribute(const QualifiedName& name, const AtomicStr
if (name == altAttr) {
if (renderer() && renderer()->isImage())
toRenderImage(renderer())->updateAltText();
- } else if (name == srcAttr || name == srcsetAttr) {
- int effectiveSize = -1; // FIXME - hook up the real value from `sizes`
+ } else if (name == srcAttr || name == srcsetAttr || name == sizesAttr) {
+ int effectiveSize = 0;
+ if (RuntimeEnabledFeatures::pictureSizesEnabled())
+ effectiveSize = SizesAttributeParser::findEffectiveSize(fastGetAttribute(sizesAttr), MediaValuesCached::create(document()));
ImageCandidate candidate = bestFitSourceForImageAttributes(document().devicePixelRatio(), effectiveSize, fastGetAttribute(srcAttr), fastGetAttribute(srcsetAttr));
m_bestFitImageURL = candidate.toAtomicString();
float candidateScaleFactor = candidate.scaleFactor();
+ // FIXME: Make this ">0" part match the spec, once it settles.
if (candidateScaleFactor > 0)
m_imageDevicePixelRatio = 1 / candidateScaleFactor;
if (renderer() && renderer()->isImage())
toRenderImage(renderer())->setImageDevicePixelRatio(m_imageDevicePixelRatio);
m_imageLoader.updateFromElementIgnoringPreviousError();
- } else if (RuntimeEnabledFeatures::pictureSizesEnabled() && name == sizesAttr) {
- m_effectiveSize = SizesAttributeParser::findEffectiveSize(value, MediaValuesCached::create(document()));
} else if (name == usemapAttr) {
setIsLink(!value.isNull());
} else if (name == compositeAttr) {
@@ -313,6 +313,11 @@ int HTMLImageElement::naturalHeight() const
return m_imageLoader.image()->imageSizeForRenderer(renderer(), 1.0f).height();
}
+const AtomicString& HTMLImageElement::currentSrc() const
+{
+ return m_bestFitImageURL;
+}
+
bool HTMLImageElement::isURLAttribute(const Attribute& attribute) const
{
return attribute.name() == srcAttr
« no previous file with comments | « Source/core/html/HTMLImageElement.h ('k') | Source/core/html/HTMLImageElement.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698