mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
style: Add parsing for cross-fade from CSS Image Values and Replaced Content Module Level 4.
This is the first of what will likely be a couple patches for cross-fade's implementation. Bug 546052 tracks it's complete implementation. Differential Revision: https://phabricator.services.mozilla.com/D81889
This commit is contained in:
parent
7c3d815f78
commit
8f89ebffec
4 changed files with 204 additions and 5 deletions
|
@ -22,7 +22,7 @@ use style_traits::{CssWriter, ToCss};
|
|||
Clone, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToComputedValue, ToResolvedValue, ToShmem,
|
||||
)]
|
||||
#[repr(C, u8)]
|
||||
pub enum GenericImage<G, MozImageRect, ImageUrl> {
|
||||
pub enum GenericImage<G, MozImageRect, ImageUrl, Color, Percentage> {
|
||||
/// `none` variant.
|
||||
None,
|
||||
/// A `<url()>` image.
|
||||
|
@ -45,10 +45,96 @@ pub enum GenericImage<G, MozImageRect, ImageUrl> {
|
|||
/// <https://drafts.css-houdini.org/css-paint-api/>
|
||||
#[cfg(feature = "servo-layout-2013")]
|
||||
PaintWorklet(PaintWorklet),
|
||||
|
||||
/// A `<cross-fade()>` image. Storing this directly inside of
|
||||
/// GenericImage increases the size by 8 bytes so we box it here
|
||||
/// and store images directly inside of cross-fade instead of
|
||||
/// boxing them there.
|
||||
CrossFade(Box<GenericCrossFade<Self, Color, Percentage>>),
|
||||
}
|
||||
|
||||
pub use self::GenericImage as Image;
|
||||
|
||||
/// <https://drafts.csswg.org/css-images-4/#cross-fade-function>
|
||||
#[css(comma, function = "cross-fade")]
|
||||
#[derive(
|
||||
Clone, Debug, MallocSizeOf, PartialEq, ToResolvedValue, ToShmem, ToCss, ToComputedValue,
|
||||
)]
|
||||
#[repr(C)]
|
||||
pub struct GenericCrossFade<Image, Color, Percentage> {
|
||||
/// All of the image percent pairings passed as arguments to
|
||||
/// cross-fade.
|
||||
#[css(iterable)]
|
||||
pub elements: crate::OwnedSlice<GenericCrossFadeElement<Image, Color, Percentage>>,
|
||||
}
|
||||
|
||||
/// A `<percent> | none` value. Represents optional percentage values
|
||||
/// assosicated with cross-fade images.
|
||||
#[derive(
|
||||
Clone,
|
||||
Debug,
|
||||
MallocSizeOf,
|
||||
PartialEq,
|
||||
ToComputedValue,
|
||||
ToResolvedValue,
|
||||
ToShmem,
|
||||
ToCss,
|
||||
)]
|
||||
#[repr(C, u8)]
|
||||
pub enum PercentOrNone<Percentage> {
|
||||
/// `none` variant.
|
||||
#[css(skip)]
|
||||
None,
|
||||
/// A percentage variant.
|
||||
Percent(Percentage),
|
||||
}
|
||||
|
||||
/// An optional percent and a cross fade image.
|
||||
#[derive(
|
||||
Clone,
|
||||
Debug,
|
||||
MallocSizeOf,
|
||||
PartialEq,
|
||||
ToComputedValue,
|
||||
ToResolvedValue,
|
||||
ToShmem,
|
||||
ToCss,
|
||||
)]
|
||||
#[repr(C)]
|
||||
pub struct GenericCrossFadeElement<Image, Color, Percentage> {
|
||||
/// The percent of the final image that `image` will be.
|
||||
pub percent: PercentOrNone<Percentage>,
|
||||
/// A color or image that will be blended when cross-fade is
|
||||
/// evaluated.
|
||||
pub image: GenericCrossFadeImage<Image, Color>,
|
||||
}
|
||||
|
||||
/// An image or a color. `cross-fade` takes either when blending
|
||||
/// images together.
|
||||
#[derive(
|
||||
Clone,
|
||||
Debug,
|
||||
MallocSizeOf,
|
||||
PartialEq,
|
||||
ToComputedValue,
|
||||
ToResolvedValue,
|
||||
ToShmem,
|
||||
ToCss,
|
||||
Parse,
|
||||
)]
|
||||
#[repr(C, u8)]
|
||||
pub enum GenericCrossFadeImage<I, C> {
|
||||
/// A boxed image value. Boxing provides indirection so images can
|
||||
/// be cross-fades and cross-fades can be images.
|
||||
Image(I),
|
||||
/// A color value.
|
||||
Color(C),
|
||||
}
|
||||
|
||||
pub use self::GenericCrossFade as CrossFade;
|
||||
pub use self::GenericCrossFadeElement as CrossFadeElement;
|
||||
pub use self::GenericCrossFadeImage as CrossFadeImage;
|
||||
|
||||
/// A CSS gradient.
|
||||
/// <https://drafts.csswg.org/css-images/#gradients>
|
||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToComputedValue, ToResolvedValue, ToShmem)]
|
||||
|
@ -291,22 +377,26 @@ pub struct GenericMozImageRect<NumberOrPercentage, MozImageRectUrl> {
|
|||
|
||||
pub use self::GenericMozImageRect as MozImageRect;
|
||||
|
||||
impl<G, R, U> fmt::Debug for Image<G, R, U>
|
||||
impl<G, R, U, C, P> fmt::Debug for Image<G, R, U, C, P>
|
||||
where
|
||||
G: ToCss,
|
||||
R: ToCss,
|
||||
U: ToCss,
|
||||
C: ToCss,
|
||||
P: ToCss,
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
self.to_css(&mut CssWriter::new(f))
|
||||
}
|
||||
}
|
||||
|
||||
impl<G, R, U> ToCss for Image<G, R, U>
|
||||
impl<G, R, U, C, P> ToCss for Image<G, R, U, C, P>
|
||||
where
|
||||
G: ToCss,
|
||||
R: ToCss,
|
||||
U: ToCss,
|
||||
C: ToCss,
|
||||
P: ToCss,
|
||||
{
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
||||
where
|
||||
|
@ -325,6 +415,7 @@ where
|
|||
serialize_atom_identifier(selector, dest)?;
|
||||
dest.write_str(")")
|
||||
},
|
||||
Image::CrossFade(ref cf) => cf.to_css(dest),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue