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

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

Issue 184523003: Fix two srcset related bugs (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Removed a useless if Created 6 years, 10 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 | « LayoutTests/fast/hidpi/image-srcset-src-selection-1x-both-expected.txt ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/html/parser/HTMLSrcsetParser.cpp
diff --git a/Source/core/html/parser/HTMLSrcsetParser.cpp b/Source/core/html/parser/HTMLSrcsetParser.cpp
index 7002dffab3be1be216d2a0fb127f5383d0302f73..1002d8aeee668b208353f524f47ac4ce377ae194 100644
--- a/Source/core/html/parser/HTMLSrcsetParser.cpp
+++ b/Source/core/html/parser/HTMLSrcsetParser.cpp
@@ -51,8 +51,9 @@ template<typename CharType>
static bool parseDescriptors(const CharType* descriptorsStart, const CharType* descriptorsEnd, float& imgScaleFactor)
{
const CharType* position = descriptorsStart;
- bool isValid = true;
- bool isScaleFactorFound = false;
+ bool isValid = false;
+ bool isFoundScaleFactor = false;
+ bool isEmptyDescriptor = !(descriptorsEnd > descriptorsStart);
while (position < descriptorsEnd) {
// 13.1. Let descriptor list be the result of splitting unparsed descriptors on spaces.
skipWhile<CharType, isHTMLSpace<CharType> >(position, descriptorsEnd);
@@ -65,15 +66,15 @@ static bool parseDescriptors(const CharType* descriptorsStart, const CharType* d
--currentDescriptorEnd;
unsigned descriptorLength = currentDescriptorEnd - currentDescriptorStart;
if (*currentDescriptorEnd == 'x') {
- if (isScaleFactorFound)
+ if (isFoundScaleFactor)
return false;
imgScaleFactor = charactersToFloat(currentDescriptorStart, descriptorLength, &isValid);
- isScaleFactorFound = true;
+ isFoundScaleFactor = true;
} else {
continue;
}
}
- return isValid;
+ return isEmptyDescriptor || isValid;
}
// http://www.whatwg.org/specs/web-apps/current-work/multipage/embedded-content-1.html#processing-the-image-candidates
@@ -138,11 +139,18 @@ static ImageCandidate pickBestImageCandidate(float deviceScaleFactor, Vector<Ima
std::stable_sort(imageCandidates.begin(), imageCandidates.end(), compareByScaleFactor);
unsigned i;
- for (i = 0; i < imageCandidates.size() - 1; ++i) {
+ for (i = 0; i < imageCandidates.size() - 1; ++i)
if (imageCandidates[i].scaleFactor() >= deviceScaleFactor)
break;
- }
- return imageCandidates[i];
+
+ float winningScaleFactor = imageCandidates[i].scaleFactor();
+ unsigned winner = i;
+ // 16. If an entry b in candidates has the same associated ... pixel density as an earlier entry a in candidates,
+ // then remove entry b
+ while ((i > 0) && (imageCandidates[--i].scaleFactor() == winningScaleFactor))
+ winner = i;
+
+ return imageCandidates[winner];
}
ImageCandidate bestFitSourceForSrcsetAttribute(float deviceScaleFactor, const String& srcsetAttribute)
« no previous file with comments | « LayoutTests/fast/hidpi/image-srcset-src-selection-1x-both-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698