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:
Emilio Cobos Álvarez 2023-06-09 17:42:08 +00:00 committed by Martin Robinson
parent 5842cfc127
commit 7c8cf00033

View file

@ -80,24 +80,28 @@ impl ToComputedValue for specified::ImageSet {
let mut supported_image = false;
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() {
// 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 the MIME type is not supported, we discard the ImageSetItem.
continue;
}
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:
//
// Make a UA-specific choice of which to load, based on whatever
// criteria deemed relevant (such as the resolution of the
// display, connection speed, etc).
// Make a UA-specific choice of which to load, based on whatever criteria deemed
// relevant (such as the resolution of the display, connection speed, etc).
//
// For now, select the lowest resolution greater than display
// density, otherwise the greatest resolution available
// For now, select the lowest resolution greater than display density, otherwise the
// greatest resolution available.
let better_candidate = || {
if selected_resolution < dpr && candidate_resolution > selected_resolution {
return true;