From 7c8cf000333ad883b9b28a60fa6ccd1a251ca5dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Fri, 9 Jun 2023 17:42:08 +0000 Subject: [PATCH] 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 --- components/style/values/computed/image.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/components/style/values/computed/image.rs b/components/style/values/computed/image.rs index 8844f7306c0..0f8a11f9197 100644 --- a/components/style/values/computed/image.rs +++ b/components/style/values/computed/image.rs @@ -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;