Commit 058b9ddc authored by commit-queue@webkit.org's avatar commit-queue@webkit.org
Browse files

Fix srcset's image candidate algorithm when DPR exceeds all candidates

https://bugs.webkit.org/show_bug.cgi?id=120168

Source/WebCore:

When the DPR exceeded the 'x' qualifier of all image candidates, none was chosen.

From the srcset spec: "If there are any entries in candidates that have an associated pixel density that is less than a
user-agent-defined value giving the nominal pixel density of the display, then remove them, unless that would remove all the
entries, in which case remove only the entries whose associated pixel density is less than the greatest such pixel density."

Fixed by returning the last one in the list of candidates sorted by their qualifier, in case none of them is equal or greater than
DPR.

Patch by Yoav Weiss <yoav@yoav.ws> on 2013-08-23
Reviewed by Andreas Kling.

Test: fast/hidpi/image-srcset-fraction.html

* html/parser/HTMLParserIdioms.cpp:
(WebCore::bestFitSourceForImageAttributes):

LayoutTests:

From the srcset spec: "If there are any entries in candidates that have an associated pixel density that is less than a
user-agent-defined value giving the nominal pixel density of the display, then remove them, unless that would remove all the
entries, in which case remove only the entries whose associated pixel density is less than the greatest such pixel density."

This test verifies that when all the candidates' qualifiers are smaller than the DPR, the highest one is returned.

Patch by Yoav Weiss <yoav@yoav.ws> on 2013-08-23
Reviewed by Andreas Kling.

* fast/hidpi/image-srcset-fraction-expected.txt: Added.
* fast/hidpi/image-srcset-fraction.html: Added.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@154497 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent d67d4c4e
2013-08-23 Yoav Weiss <yoav@yoav.ws>
Fix srcset's image candidate algorithm when DPR exceeds all candidates
https://bugs.webkit.org/show_bug.cgi?id=120168
From the srcset spec: "If there are any entries in candidates that have an associated pixel density that is less than a
user-agent-defined value giving the nominal pixel density of the display, then remove them, unless that would remove all the
entries, in which case remove only the entries whose associated pixel density is less than the greatest such pixel density."
This test verifies that when all the candidates' qualifiers are smaller than the DPR, the highest one is returned.
Reviewed by Andreas Kling.
* fast/hidpi/image-srcset-fraction-expected.txt: Added.
* fast/hidpi/image-srcset-fraction.html: Added.
2013-08-23 Chris Fleizach <cfleizach@apple.com>
 
<https://webkit.org/b/113895> Webkit exposes aria-expanded="undefined" as aria-expanded="false" (AXExpanded = NO)
blue-100-px-square.png has MIME type image/png
image-srcset-fraction.html has MIME type text/html
srcset-helper.js has MIME type text/javascript
js-test-pre.js has MIME type text/javascript
green-200-px-square.png has MIME type image/png
PASS document.getElementById("testimg").clientWidth==200 is true
This test passes if the srcset resource is loaded and displayed as the image
<html>
<head>
<script>
window.targetScaleFactor = 2.5;
</script>
<script src="resources/srcset-helper.js"></script>
<script src="../js/resources/js-test-pre.js"></script>
<script>
if (window.testRunner) {
testRunner.dumpAsText();
testRunner.dumpResourceResponseMIMETypes();
}
addEventListener("load", function() {
if (internals)
shouldBeTrue('document.getElementById("testimg").clientWidth==200');
}, false);
</script>
</head>
<body>
<div>This test passes if the srcset resource is loaded and displayed as the image</div>
<img src="resources/blue-100-px-square.png" srcset="resources/green-200-px-square.png 2x" id="testimg">
</body>
</html>
2013-08-23 Yoav Weiss <yoav@yoav.ws>
Fix srcset's image candidate algorithm when DPR exceeds all candidates
https://bugs.webkit.org/show_bug.cgi?id=120168
When the DPR exceeded the 'x' qualifier of all image candidates, none was chosen.
From the srcset spec: "If there are any entries in candidates that have an associated pixel density that is less than a
user-agent-defined value giving the nominal pixel density of the display, then remove them, unless that would remove all the
entries, in which case remove only the entries whose associated pixel density is less than the greatest such pixel density."
Fixed by returning the last one in the list of candidates sorted by their qualifier, in case none of them is equal or greater than
DPR.
Reviewed by Andreas Kling.
Test: fast/hidpi/image-srcset-fraction.html
* html/parser/HTMLParserIdioms.cpp:
(WebCore::bestFitSourceForImageAttributes):
2013-08-23 Chris Fleizach <cfleizach@apple.com>
 
<https://webkit.org/b/113895> Webkit exposes aria-expanded="undefined" as aria-expanded="false" (AXExpanded = NO)
......@@ -357,13 +357,16 @@ String bestFitSourceForImageAttributes(float deviceScaleFactor, const String& sr
imageCandidates.append(image);
}
if (imageCandidates.isEmpty())
return String();
std::stable_sort(imageCandidates.begin(), imageCandidates.end(), compareByScaleFactor);
for (size_t i = 0; i < imageCandidates.size(); ++i) {
if (imageCandidates[i].scaleFactor >= deviceScaleFactor)
return imageCandidates[i].imageURL;
}
return String();
return imageCandidates.last().imageURL;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment