mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
Derive ToComputedValue for Image<..>
This commit is contained in:
parent
7c31202dda
commit
95f2d93960
1 changed files with 1 additions and 39 deletions
|
@ -11,13 +11,12 @@ use cssparser::serialize_identifier;
|
||||||
use custom_properties;
|
use custom_properties;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use style_traits::ToCss;
|
use style_traits::ToCss;
|
||||||
use values::computed::{Context, ToComputedValue};
|
|
||||||
|
|
||||||
/// An [image].
|
/// An [image].
|
||||||
///
|
///
|
||||||
/// [image]: https://drafts.csswg.org/css-images/#image-values
|
/// [image]: https://drafts.csswg.org/css-images/#image-values
|
||||||
#[derive(Clone, PartialEq)]
|
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||||
|
#[derive(Clone, PartialEq, ToComputedValue)]
|
||||||
pub enum Image<Gradient, MozImageRect, ImageUrl> {
|
pub enum Image<Gradient, MozImageRect, ImageUrl> {
|
||||||
/// A `<url()>` image.
|
/// A `<url()>` image.
|
||||||
Url(ImageUrl),
|
Url(ImageUrl),
|
||||||
|
@ -34,43 +33,6 @@ pub enum Image<Gradient, MozImageRect, ImageUrl> {
|
||||||
PaintWorklet(PaintWorklet),
|
PaintWorklet(PaintWorklet),
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME(nox): Implement TCV for Box<T> and derive this.
|
|
||||||
impl<Gradient: ToComputedValue,
|
|
||||||
MozImageRect: ToComputedValue,
|
|
||||||
ImageUrl: ToComputedValue> ToComputedValue for Image<Gradient, MozImageRect, ImageUrl> {
|
|
||||||
type ComputedValue = Image<<Gradient as ToComputedValue>::ComputedValue,
|
|
||||||
<MozImageRect as ToComputedValue>::ComputedValue,
|
|
||||||
<ImageUrl as ToComputedValue>::ComputedValue>;
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
|
|
||||||
match *self {
|
|
||||||
Image::Url(ref url) => Image::Url(url.to_computed_value(context)),
|
|
||||||
Image::Gradient(ref gradient) =>
|
|
||||||
Image::Gradient(Box::new(gradient.to_computed_value(context))),
|
|
||||||
Image::Rect(ref rect) => Image::Rect(Box::new(rect.to_computed_value(context))),
|
|
||||||
Image::Element(ref atom) => Image::Element(atom.to_computed_value(context)),
|
|
||||||
#[cfg(feature = "servo")]
|
|
||||||
Image::PaintWorklet(ref worklet) => Image::PaintWorklet(worklet.to_computed_value(context)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn from_computed_value(computed: &Self::ComputedValue) -> Self {
|
|
||||||
match *computed {
|
|
||||||
Image::Url(ref url) => Image::Url(ImageUrl::from_computed_value(url)),
|
|
||||||
Image::Gradient(ref boxed_gradient) =>
|
|
||||||
Image::Gradient(Box::new(Gradient::from_computed_value(&*boxed_gradient))),
|
|
||||||
Image::Rect(ref boxed_rect) =>
|
|
||||||
Image::Rect(Box::new(MozImageRect::from_computed_value(&*boxed_rect))),
|
|
||||||
Image::Element(ref atom) => Image::Element(Atom::from_computed_value(atom)),
|
|
||||||
#[cfg(feature = "servo")]
|
|
||||||
Image::PaintWorklet(ref worklet) =>
|
|
||||||
Image::PaintWorklet(PaintWorklet::from_computed_value(worklet)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A CSS gradient.
|
/// A CSS gradient.
|
||||||
/// https://drafts.csswg.org/css-images/#gradients
|
/// https://drafts.csswg.org/css-images/#gradients
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue