mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Derive ToComputedValue
For now, only impls for types like in style::values::generics can be derived. This also needed a few ToComputedValueAsSpecified impls that I would like to replace by some #[to_computed_value(clone)] attribute, but I think it is ok to keep it like this for now.
This commit is contained in:
parent
a99e73ba6b
commit
07c0456cfd
7 changed files with 247 additions and 422 deletions
|
@ -12,7 +12,6 @@ use parser::{Parse, ParserContext};
|
|||
use std::fmt;
|
||||
use style_traits::{HasViewportPercentage, ToCss};
|
||||
use super::CustomIdent;
|
||||
use super::computed::{Context, ToComputedValue};
|
||||
|
||||
pub use self::basic_shape::serialize_radius_values;
|
||||
|
||||
|
@ -20,9 +19,9 @@ pub mod basic_shape;
|
|||
pub mod image;
|
||||
pub mod position;
|
||||
|
||||
#[derive(Clone, PartialEq, Debug)]
|
||||
#[derive(Clone, Debug, PartialEq, ToComputedValue)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
/// A type for representing CSS `widthh` and `height` values.
|
||||
/// A type for representing CSS `width` and `height` values.
|
||||
pub struct BorderRadiusSize<L>(pub Size2D<L>);
|
||||
|
||||
impl<L> HasViewportPercentage for BorderRadiusSize<L> {
|
||||
|
@ -61,24 +60,6 @@ impl<L: ToCss> ToCss for BorderRadiusSize<L> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<L: ToComputedValue> ToComputedValue for BorderRadiusSize<L> {
|
||||
type ComputedValue = BorderRadiusSize<L::ComputedValue>;
|
||||
|
||||
#[inline]
|
||||
fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
|
||||
let w = self.0.width.to_computed_value(context);
|
||||
let h = self.0.height.to_computed_value(context);
|
||||
BorderRadiusSize(Size2D::new(w, h))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn from_computed_value(computed: &Self::ComputedValue) -> Self {
|
||||
let w = ToComputedValue::from_computed_value(&computed.0.width);
|
||||
let h = ToComputedValue::from_computed_value(&computed.0.height);
|
||||
BorderRadiusSize(Size2D::new(w, h))
|
||||
}
|
||||
}
|
||||
|
||||
/// https://drafts.csswg.org/css-counter-styles/#typedef-counter-style
|
||||
///
|
||||
/// Since wherever <counter-style> is used, 'none' is a valid value as
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue