 Chromium Code Reviews
 Chromium Code Reviews Issue 236713005:
  Use SizesAttributeParser to get the right srcset resource  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/blink.git@sizes_parser8
    
  
    Issue 236713005:
  Use SizesAttributeParser to get the right srcset resource  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/blink.git@sizes_parser8| Index: Source/core/html/parser/HTMLSrcsetParser.cpp | 
| diff --git a/Source/core/html/parser/HTMLSrcsetParser.cpp b/Source/core/html/parser/HTMLSrcsetParser.cpp | 
| index 1fffc5d561e1b182427536901fa24113b009f0df..00b14a489aa0b26a3cc51ffc30084219bfe72750 100644 | 
| --- a/Source/core/html/parser/HTMLSrcsetParser.cpp | 
| +++ b/Source/core/html/parser/HTMLSrcsetParser.cpp | 
| @@ -142,7 +142,7 @@ static void parseImageCandidatesFromSrcsetAttribute(const String& attribute, Vec | 
| parseImageCandidatesFromSrcsetAttribute<UChar>(attribute, attribute.characters16(), attribute.length(), imageCandidates); | 
| } | 
| -static ImageCandidate pickBestImageCandidate(float deviceScaleFactor, int effectiveSize, Vector<ImageCandidate>& imageCandidates) | 
| +static ImageCandidate pickBestImageCandidate(float deviceScaleFactor, unsigned sourceSize, Vector<ImageCandidate>& imageCandidates) | 
| { | 
| bool ignoreSrc = false; | 
| if (imageCandidates.isEmpty()) | 
| @@ -151,7 +151,7 @@ static ImageCandidate pickBestImageCandidate(float deviceScaleFactor, int effect | 
| // http://picture.responsiveimages.org/#normalize-source-densities | 
| for (Vector<ImageCandidate>::iterator it = imageCandidates.begin(); it != imageCandidates.end(); ++it) { | 
| if (it->resourceWidth() > 0) { | 
| - it->setScaleFactor((float)it->resourceWidth() / (float)effectiveSize); | 
| + it->setScaleFactor((float)it->resourceWidth() / (float)sourceSize); | 
| ignoreSrc = true; | 
| } | 
| } | 
| @@ -174,16 +174,16 @@ static ImageCandidate pickBestImageCandidate(float deviceScaleFactor, int effect | 
| return imageCandidates[winner]; | 
| } | 
| -ImageCandidate bestFitSourceForSrcsetAttribute(float deviceScaleFactor, int effectiveSize, const String& srcsetAttribute) | 
| +ImageCandidate bestFitSourceForSrcsetAttribute(float deviceScaleFactor, unsigned sourceSize, const String& srcsetAttribute) | 
| { | 
| Vector<ImageCandidate> imageCandidates; | 
| parseImageCandidatesFromSrcsetAttribute(srcsetAttribute, imageCandidates); | 
| - return pickBestImageCandidate(deviceScaleFactor, effectiveSize, imageCandidates); | 
| + return pickBestImageCandidate(deviceScaleFactor, sourceSize, imageCandidates); | 
| } | 
| -ImageCandidate bestFitSourceForImageAttributes(float deviceScaleFactor, int effectiveSize, const String& srcAttribute, const String& srcsetAttribute) | 
| +ImageCandidate bestFitSourceForImageAttributes(float deviceScaleFactor, unsigned sourceSize, const String& srcAttribute, const String& srcsetAttribute) | 
| { | 
| DescriptorParsingResult defaultResult; | 
| defaultResult.scaleFactor = 1.0; | 
| @@ -198,13 +198,13 @@ ImageCandidate bestFitSourceForImageAttributes(float deviceScaleFactor, int effe | 
| parseImageCandidatesFromSrcsetAttribute(srcsetAttribute, imageCandidates); | 
| - if (!srcAttribute.isEmpty()) | 
| + if (!srcAttribute.isNull() && !srcAttribute.isEmpty()) | 
| 
eseidel
2014/04/20 21:27:43
!isEmpty should be the same...
 | 
| imageCandidates.append(ImageCandidate(srcAttribute, 0, srcAttribute.length(), defaultResult, ImageCandidate::SrcOrigin)); | 
| - return pickBestImageCandidate(deviceScaleFactor, effectiveSize, imageCandidates); | 
| + return pickBestImageCandidate(deviceScaleFactor, sourceSize, imageCandidates); | 
| } | 
| -String bestFitSourceForImageAttributes(float deviceScaleFactor, int effectiveSize, const String& srcAttribute, ImageCandidate& srcsetImageCandidate) | 
| +String bestFitSourceForImageAttributes(float deviceScaleFactor, unsigned sourceSize, const String& srcAttribute, ImageCandidate& srcsetImageCandidate) | 
| { | 
| DescriptorParsingResult defaultResult; | 
| defaultResult.scaleFactor = 1.0; | 
| @@ -215,10 +215,10 @@ String bestFitSourceForImageAttributes(float deviceScaleFactor, int effectiveSiz | 
| Vector<ImageCandidate> imageCandidates; | 
| imageCandidates.append(srcsetImageCandidate); | 
| - if (!srcAttribute.isEmpty()) | 
| + if (!srcAttribute.isNull() && !srcAttribute.isEmpty()) | 
| imageCandidates.append(ImageCandidate(srcAttribute, 0, srcAttribute.length(), defaultResult, ImageCandidate::SrcOrigin)); | 
| 
eseidel
2014/04/20 21:27:43
Same thing, I think you have some confusiong with
 
Yoav Weiss
2014/04/20 21:48:03
For some reason I thought isEmpty is not safe to c
 | 
| - return pickBestImageCandidate(deviceScaleFactor, effectiveSize, imageCandidates).toString(); | 
| + return pickBestImageCandidate(deviceScaleFactor, sourceSize, imageCandidates).toString(); | 
| } | 
| } |