mirror of
https://github.com/servo/servo.git
synced 2025-08-04 05:00:08 +01:00
style: Avoid selecting zero-resolution images in image-set
Fairly straight-forward. This fixes the two tests mentioned in comment 0 which aren't still in the repo. Differential Revision: https://phabricator.services.mozilla.com/D180414
This commit is contained in:
parent
5842cfc127
commit
7c8cf00033
1 changed files with 11 additions and 7 deletions
|
@ -80,24 +80,28 @@ impl ToComputedValue for specified::ImageSet {
|
||||||
|
|
||||||
let mut supported_image = false;
|
let mut supported_image = false;
|
||||||
let mut selected_index = std::usize::MAX;
|
let mut selected_index = std::usize::MAX;
|
||||||
let mut selected_resolution = items[0].resolution.dppx();
|
let mut selected_resolution = 0.0;
|
||||||
|
|
||||||
for (i, item) in items.iter().enumerate() {
|
for (i, item) in items.iter().enumerate() {
|
||||||
// If the MIME type is not supported, we discard the ImageSetItem
|
|
||||||
if item.has_mime_type && !context.device().is_supported_mime_type(&item.mime_type) {
|
if item.has_mime_type && !context.device().is_supported_mime_type(&item.mime_type) {
|
||||||
|
// If the MIME type is not supported, we discard the ImageSetItem.
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let candidate_resolution = item.resolution.dppx();
|
let candidate_resolution = item.resolution.dppx();
|
||||||
|
debug_assert!(candidate_resolution >= 0.0, "Resolutions should be non-negative");
|
||||||
|
if candidate_resolution == 0.0 {
|
||||||
|
// If the resolution is 0, we also treat it as an invalid image.
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// https://drafts.csswg.org/css-images-4/#image-set-notation:
|
// https://drafts.csswg.org/css-images-4/#image-set-notation:
|
||||||
//
|
//
|
||||||
// Make a UA-specific choice of which to load, based on whatever
|
// Make a UA-specific choice of which to load, based on whatever criteria deemed
|
||||||
// criteria deemed relevant (such as the resolution of the
|
// relevant (such as the resolution of the display, connection speed, etc).
|
||||||
// display, connection speed, etc).
|
|
||||||
//
|
//
|
||||||
// For now, select the lowest resolution greater than display
|
// For now, select the lowest resolution greater than display density, otherwise the
|
||||||
// density, otherwise the greatest resolution available
|
// greatest resolution available.
|
||||||
let better_candidate = || {
|
let better_candidate = || {
|
||||||
if selected_resolution < dpr && candidate_resolution > selected_resolution {
|
if selected_resolution < dpr && candidate_resolution > selected_resolution {
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue