/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
usecrate::color::mix::ColorInterpolationMethod; usecrate::custom_properties; usecrate::values::generics::position::PositionComponent; usecrate::values::generics::Optional; usecrate::values::serialize_atom_identifier; usecrate::Atom; usecrate::Zero; use servo_arc::Arc; use std::fmt::{self, Write}; use style_traits::{CssWriter, ToCss};
/// A `<gradient>` image. Gradients are rather large, and not nearly as /// common as urls, so we box them here to keep the size of this enum sane.
Gradient(Box<G>),
/// 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>>),
/// An `image-set()` function.
ImageSet(#[compute(field_bound)] Box<GenericImageSet<Self, Resolution>>),
}
pubuseself::GenericImage as Image;
/// <https://drafts.csswg.org/css-images-4/#cross-fade-function> #[derive(
Clone, Debug, MallocSizeOf, PartialEq, ToResolvedValue, ToShmem, ToCss, ToComputedValue,
)] #[css(comma, function = "cross-fade")] #[repr(C)] pubstruct 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>>,
}
/// An optional percent and a cross fade image. #[derive(
Clone, Debug, MallocSizeOf, PartialEq, ToComputedValue, ToResolvedValue, ToShmem, ToCss,
)] #[repr(C)] pubstruct GenericCrossFadeElement<Image, Color, Percentage> { /// The percent of the final image that `image` will be. pub percent: Optional<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,
)] #[repr(C, u8)] pubenum 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),
}
pubuseself::GenericCrossFade as CrossFade; pubuseself::GenericCrossFadeElement as CrossFadeElement; pubuseself::GenericCrossFadeImage as CrossFadeImage;
/// https://drafts.csswg.org/css-images-4/#image-set-notation #[derive(Clone, Debug, MallocSizeOf, PartialEq, ToCss, ToResolvedValue, ToShmem)] #[css(comma, function = "image-set")] #[repr(C)] pubstruct GenericImageSet<Image, Resolution> { /// The index of the selected candidate. usize::MAX for specified values or invalid images. #[css(skip)] pub selected_index: usize,
/// All of the image and resolution pairs. #[css(iterable)] pub items: crate::OwnedSlice<GenericImageSetItem<Image, Resolution>>,
}
/// An optional percent and a cross fade image. #[derive(Clone, Debug, MallocSizeOf, PartialEq, ToComputedValue, ToResolvedValue, ToShmem)] #[repr(C)] pubstruct GenericImageSetItem<Image, Resolution> { /// `<image>`. `<string>` is converted to `Image::Url` at parse time. pub image: Image, /// The `<resolution>`. /// /// TODO: Skip serialization if it is 1x. pub resolution: Resolution,
/// 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,
}
pubuseself::GenericImageSet as ImageSet; pubuseself::GenericImageSetItem as ImageSetItem;
/// State flags stored on each variant of a Gradient. #[derive(
Clone, Copy, Debug, Default, MallocSizeOf, PartialEq, ToComputedValue, ToResolvedValue, ToShmem,
)] #[repr(C)] pubstruct GradientFlags(u8);
bitflags! { impl GradientFlags: u8 { /// Set if this is a repeating gradient. const REPEATING = 1 << 0; /// Set if the color interpolation method matches the default for the items. const HAS_DEFAULT_COLOR_INTERPOLATION_METHOD = 1 << 1;
}
}
/// A CSS gradient. /// <https://drafts.csswg.org/css-images/#gradients> #[derive(Clone, Debug, MallocSizeOf, PartialEq, ToComputedValue, ToResolvedValue, ToShmem)] #[repr(C)] pubenum GenericGradient<
LineDirection,
LengthPercentage,
NonNegativeLength,
NonNegativeLengthPercentage,
Position,
Angle,
AngleOrPercentage,
Color,
> { /// A linear gradient.
Linear { /// Line direction
direction: LineDirection, /// Method to use for color interpolation.
color_interpolation_method: ColorInterpolationMethod, /// The color stops and interpolation hints.
items: crate::OwnedSlice<GenericGradientItem<Color, LengthPercentage>>, /// State flags for the gradient.
flags: GradientFlags, /// Compatibility mode.
compat_mode: GradientCompatMode,
}, /// A radial gradient.
Radial { /// Shape of gradient
shape: GenericEndingShape<NonNegativeLength, NonNegativeLengthPercentage>, /// Center of gradient
position: Position, /// Method to use for color interpolation.
color_interpolation_method: ColorInterpolationMethod, /// The color stops and interpolation hints.
items: crate::OwnedSlice<GenericGradientItem<Color, LengthPercentage>>, /// State flags for the gradient.
flags: GradientFlags, /// Compatibility mode.
compat_mode: GradientCompatMode,
}, /// A conic gradient.
Conic { /// Start angle of gradient
angle: Angle, /// Center of gradient
position: Position, /// Method to use for color interpolation.
color_interpolation_method: ColorInterpolationMethod, /// The color stops and interpolation hints.
items: crate::OwnedSlice<GenericGradientItem<Color, AngleOrPercentage>>, /// State flags for the gradient.
flags: GradientFlags,
},
}
pubuseself::GenericGradient as Gradient;
#[derive(
Clone, Copy, Debug, MallocSizeOf, PartialEq, ToComputedValue, ToResolvedValue, ToShmem,
)] #[repr(u8)] /// Whether we used the modern notation or the compatibility `-webkit`, `-moz` prefixes. pubenum GradientCompatMode { /// Modern syntax.
Modern, /// `-webkit` prefix.
WebKit, /// `-moz` prefix
Moz,
}
/// A circle shape. #[derive(
Clone, Copy, Debug, MallocSizeOf, PartialEq, ToComputedValue, ToResolvedValue, ToShmem,
)] #[repr(C, u8)] pubenum GenericCircle<NonNegativeLength> { /// A circle radius.
Radius(NonNegativeLength), /// A circle extent.
Extent(ShapeExtent),
}
pubuseself::GenericCircle as Circle;
/// An ellipse shape. #[derive(
Clone, Copy, Debug, MallocSizeOf, PartialEq, ToComputedValue, ToCss, ToResolvedValue, ToShmem,
)] #[repr(C, u8)] pubenum GenericEllipse<NonNegativeLengthPercentage> { /// An ellipse pair of radii.
Radii(NonNegativeLengthPercentage, NonNegativeLengthPercentage), /// An ellipse extent.
Extent(ShapeExtent),
}
/// A gradient item. /// <https://drafts.csswg.org/css-images-4/#color-stop-syntax> #[derive(
Clone, Copy, Debug, MallocSizeOf, PartialEq, ToComputedValue, ToCss, ToResolvedValue, ToShmem,
)] #[repr(C, u8)] pubenum GenericGradientItem<Color, T> { /// A simple color stop, without position.
SimpleColorStop(Color), /// A complex color stop, with a position.
ComplexColorStop { /// The color for the stop.
color: Color, /// The position for the stop.
position: T,
}, /// An interpolation hint.
InterpolationHint(T),
}
pubuseself::GenericGradientItem as GradientItem;
/// A color stop. /// <https://drafts.csswg.org/css-images/#typedef-color-stop-list> #[derive(
Clone, Copy, Debug, MallocSizeOf, PartialEq, ToComputedValue, ToCss, ToResolvedValue, ToShmem,
)] pubstruct ColorStop<Color, T> { /// The color of this stop. pub color: Color, /// The position of this stop. pub position: Option<T>,
}
impl<Color, T> ColorStop<Color, T> { /// Convert the color stop into an appropriate `GradientItem`. #[inline] pubfn into_item(self) -> GradientItem<Color, T> { matchself.position {
Some(position) => GradientItem::ComplexColorStop {
color: self.color,
position,
},
None => GradientItem::SimpleColorStop(self.color),
}
}
}
/// Specified values for a paint worklet. /// <https://drafts.css-houdini.org/css-paint-api/> #[cfg_attr(feature = "servo", derive(MallocSizeOf))] #[derive(Clone, Debug, PartialEq, ToComputedValue, ToResolvedValue, ToShmem)] pubstruct PaintWorklet { /// The name the worklet was registered with. pub name: Atom, /// The arguments for the worklet. /// TODO: store a parsed representation of the arguments. #[cfg_attr(feature = "servo", ignore_malloc_size_of = "Arc")] #[compute(no_field_bound)] #[resolve(no_field_bound)] pub arguments: Vec<Arc<custom_properties::SpecifiedValue>>,
}
impl ::style_traits::SpecifiedValueInfo for PaintWorklet {}
impl ToCss for PaintWorklet { fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where
W: Write,
{
dest.write_str("paint(")?;
serialize_atom_identifier(&self.name, dest)?; for argument in &self.arguments {
dest.write_str(", ")?;
argument.to_css(dest)?;
}
dest.write_char(')')
}
}
impl<G, U, C, P, Resolution> fmt::Debug for Image<G, U, C, P, Resolution> where
Image<G, U, C, P, Resolution>: ToCss,
{ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.to_css(&mut CssWriter::new(f))
}
}
match *self {
Gradient::Linear { ref direction, ref color_interpolation_method, ref items,
compat_mode,
..
} => {
dest.write_str("linear-gradient(")?; letmut skip_comma = true; if !direction.points_downwards(compat_mode) {
direction.to_css(dest, compat_mode)?;
skip_comma = false;
} if !has_default_color_interpolation_method { if !skip_comma {
dest.write_char(' ')?;
}
color_interpolation_method.to_css(dest)?;
skip_comma = false;
} for item in &**items { if !skip_comma {
dest.write_str(", ")?;
}
skip_comma = false;
item.to_css(dest)?;
}
},
Gradient::Radial { ref shape, ref position, ref color_interpolation_method, ref items,
compat_mode,
..
} => {
dest.write_str("radial-gradient(")?; let omit_shape = match *shape {
EndingShape::Ellipse(Ellipse::Extent(ShapeExtent::Cover)) |
EndingShape::Ellipse(Ellipse::Extent(ShapeExtent::FarthestCorner)) => true,
_ => false,
}; let omit_position = position.is_center(); if compat_mode == GradientCompatMode::Modern { if !omit_shape {
shape.to_css(dest)?; if !omit_position {
dest.write_char(' ')?;
}
} if !omit_position {
dest.write_str("at ")?;
position.to_css(dest)?;
}
} else { if !omit_position {
position.to_css(dest)?; if !omit_shape {
dest.write_str(", ")?;
}
} if !omit_shape {
shape.to_css(dest)?;
}
} if !has_default_color_interpolation_method { if !omit_shape || !omit_position {
dest.write_char(' ')?;
}
color_interpolation_method.to_css(dest)?;
}
letmut skip_comma =
omit_shape && omit_position && has_default_color_interpolation_method; for item in &**items { if !skip_comma {
dest.write_str(", ")?;
}
skip_comma = false;
item.to_css(dest)?;
}
},
Gradient::Conic { ref angle, ref position, ref color_interpolation_method, ref items,
..
} => {
dest.write_str("conic-gradient(")?; let omit_angle = angle.is_zero(); let omit_position = position.is_center(); if !omit_angle {
dest.write_str("from ")?;
angle.to_css(dest)?; if !omit_position {
dest.write_char(' ')?;
}
} if !omit_position {
dest.write_str("at ")?;
position.to_css(dest)?;
} if !has_default_color_interpolation_method { if !omit_angle || !omit_position {
dest.write_char(' ')?;
}
color_interpolation_method.to_css(dest)?;
} letmut skip_comma =
omit_angle && omit_position && has_default_color_interpolation_method; for item in &**items { if !skip_comma {
dest.write_str(", ")?;
}
skip_comma = false;
item.to_css(dest)?;
}
},
}
dest.write_char(')')
}
}
/// The direction of a linear gradient. pubtrait LineDirection { /// Whether this direction points towards, and thus can be omitted. fn points_downwards(&self, compat_mode: GradientCompatMode) -> bool;
/// Serialises this direction according to the compatibility mode. fn to_css<W>(&self, dest: &mut CssWriter<W>, compat_mode: GradientCompatMode) -> fmt::Result where
W: Write;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.