mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
style: Merge ImageLayer and Image.
ImageLayer is almost the only usage of Image, so keeping them in the same enum makes the resulting C++ struct smaller, and makes it map more cleanly to nsStyleImage. Differential Revision: https://phabricator.services.mozilla.com/D62161
This commit is contained in:
parent
c0d67f796c
commit
149cb5f5f1
12 changed files with 62 additions and 112 deletions
|
@ -13,51 +13,22 @@ use servo_arc::Arc;
|
|||
use std::fmt::{self, Write};
|
||||
use style_traits::{CssWriter, ToCss};
|
||||
|
||||
/// An <image> | <none> (for background-image, for example).
|
||||
#[derive(
|
||||
Clone,
|
||||
Debug,
|
||||
MallocSizeOf,
|
||||
Parse,
|
||||
PartialEq,
|
||||
SpecifiedValueInfo,
|
||||
ToComputedValue,
|
||||
ToCss,
|
||||
ToResolvedValue,
|
||||
ToShmem,
|
||||
)]
|
||||
pub enum GenericImageLayer<Image> {
|
||||
/// The `none` value.
|
||||
None,
|
||||
/// The `<image>` value.
|
||||
Image(Image),
|
||||
}
|
||||
|
||||
pub use self::GenericImageLayer as ImageLayer;
|
||||
|
||||
impl<I> ImageLayer<I> {
|
||||
/// Returns `none`.
|
||||
#[inline]
|
||||
pub fn none() -> Self {
|
||||
ImageLayer::None
|
||||
}
|
||||
}
|
||||
|
||||
/// An [image].
|
||||
/// An `<image> | none` value.
|
||||
///
|
||||
/// [image]: https://drafts.csswg.org/css-images/#image-values
|
||||
/// https://drafts.csswg.org/css-images/#image-values
|
||||
#[derive(
|
||||
Clone, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToComputedValue, ToResolvedValue, ToShmem,
|
||||
)]
|
||||
#[repr(C, u8)]
|
||||
pub enum GenericImage<Gradient, MozImageRect, ImageUrl> {
|
||||
pub enum GenericImage<G, MozImageRect, ImageUrl> {
|
||||
/// `none` variant.
|
||||
None,
|
||||
/// A `<url()>` image.
|
||||
Url(ImageUrl),
|
||||
|
||||
/// 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<Gradient>),
|
||||
|
||||
Gradient(Box<G>),
|
||||
/// A `-moz-image-rect` image. Also fairly large and rare.
|
||||
// not cfg’ed out on non-Gecko to avoid `error[E0392]: parameter `MozImageRect` is never used`
|
||||
// Instead we make MozImageRect an empty enum
|
||||
|
@ -285,7 +256,7 @@ impl ToCss for PaintWorklet {
|
|||
///
|
||||
/// `-moz-image-rect(<uri>, top, right, bottom, left);`
|
||||
#[allow(missing_docs)]
|
||||
#[css(comma, function)]
|
||||
#[css(comma, function = "-moz-image-rect")]
|
||||
#[derive(
|
||||
Clone,
|
||||
Debug,
|
||||
|
@ -297,7 +268,8 @@ impl ToCss for PaintWorklet {
|
|||
ToResolvedValue,
|
||||
ToShmem,
|
||||
)]
|
||||
pub struct MozImageRect<NumberOrPercentage, MozImageRectUrl> {
|
||||
#[repr(C)]
|
||||
pub struct GenericMozImageRect<NumberOrPercentage, MozImageRectUrl> {
|
||||
pub url: MozImageRectUrl,
|
||||
pub top: NumberOrPercentage,
|
||||
pub right: NumberOrPercentage,
|
||||
|
@ -305,6 +277,8 @@ pub struct MozImageRect<NumberOrPercentage, MozImageRectUrl> {
|
|||
pub left: NumberOrPercentage,
|
||||
}
|
||||
|
||||
pub use self::GenericMozImageRect as MozImageRect;
|
||||
|
||||
impl<G, R, U> fmt::Debug for Image<G, R, U>
|
||||
where
|
||||
G: ToCss,
|
||||
|
@ -327,6 +301,7 @@ where
|
|||
W: Write,
|
||||
{
|
||||
match *self {
|
||||
Image::None => dest.write_str("none"),
|
||||
Image::Url(ref url) => url.to_css(dest),
|
||||
Image::Gradient(ref gradient) => gradient.to_css(dest),
|
||||
Image::Rect(ref rect) => rect.to_css(dest),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue