style: Make image-set without valid images render nothing

Differential Revision: https://phabricator.services.mozilla.com/D172341
This commit is contained in:
Emilio Cobos Álvarez 2023-03-13 11:22:06 +00:00 committed by Martin Robinson
parent 29105eeb49
commit 76e8eeda72
3 changed files with 4 additions and 6 deletions

View file

@ -78,10 +78,8 @@ impl ToComputedValue for specified::ImageSet {
let items = self.items.to_computed_value(context); let items = self.items.to_computed_value(context);
let dpr = context.device().device_pixel_ratio().get(); let dpr = context.device().device_pixel_ratio().get();
// If no item have a supported MIME type, the behavior is undefined by the standard
// By default, we select the first item
let mut supported_image = false; let mut supported_image = false;
let mut selected_index = 0; let mut selected_index = std::usize::MAX;
let mut selected_resolution = items[0].resolution.dppx(); let mut selected_resolution = items[0].resolution.dppx();
for (i, item) in items.iter().enumerate() { for (i, item) in items.iter().enumerate() {
@ -126,7 +124,7 @@ impl ToComputedValue for specified::ImageSet {
fn from_computed_value(computed: &Self::ComputedValue) -> Self { fn from_computed_value(computed: &Self::ComputedValue) -> Self {
Self { Self {
selected_index: 0, selected_index: std::usize::MAX,
items: ToComputedValue::from_computed_value(&computed.items), items: ToComputedValue::from_computed_value(&computed.items),
} }
} }

View file

@ -108,7 +108,7 @@ pub use self::GenericCrossFadeImage as CrossFadeImage;
#[css(comma, function = "image-set")] #[css(comma, function = "image-set")]
#[repr(C)] #[repr(C)]
pub struct GenericImageSet<Image, Resolution> { pub struct GenericImageSet<Image, Resolution> {
/// The index of the selected candidate. Zero for specified values. /// The index of the selected candidate. usize::MAX for specified values or invalid images.
#[css(skip)] #[css(skip)]
pub selected_index: usize, pub selected_index: usize,

View file

@ -399,7 +399,7 @@ impl ImageSet {
}) })
})?; })?;
Ok(Self { Ok(Self {
selected_index: 0, selected_index: std::usize::MAX,
items: items.into(), items: items.into(),
}) })
} }