style: Support the type() function in image-set

Differential Revision: https://phabricator.services.mozilla.com/D109201
This commit is contained in:
Oriol Brufau 2023-05-17 00:30:20 +02:00
parent 7567ddd262
commit 773ddf31fe
4 changed files with 71 additions and 8 deletions

View file

@ -132,7 +132,7 @@ pub struct GenericImageSet<Image, Resolution> {
/// An optional percent and a cross fade image.
#[derive(
Clone, Debug, MallocSizeOf, PartialEq, ToComputedValue, ToResolvedValue, ToShmem, ToCss,
Clone, Debug, MallocSizeOf, PartialEq, ToComputedValue, ToResolvedValue, ToShmem,
)]
#[repr(C)]
pub struct GenericImageSetItem<Image, Resolution> {
@ -142,7 +142,33 @@ pub struct GenericImageSetItem<Image, Resolution> {
///
/// TODO: Skip serialization if it is 1x.
pub resolution: Resolution,
// TODO: type() function.
/// The `type(<string>)`
/// (Optional) Specify the image's MIME type
pub mime_type: crate::OwnedStr,
/// True if mime_type has been specified
pub has_mime_type: bool,
}
impl<I: style_traits::ToCss, R: style_traits::ToCss> ToCss for GenericImageSetItem<I, R>
{
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
where
W: fmt::Write,
{
self.image.to_css(dest)?;
dest.write_str(" ")?;
self.resolution.to_css(dest)?;
if self.has_mime_type {
dest.write_str(" ")?;
dest.write_str("type(")?;
self.mime_type.to_css(dest)?;
dest.write_str(")")?;
}
Ok(())
}
}
pub use self::GenericImageSet as ImageSet;