mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35:33 +01:00
Improve handling of trait bounds when deriving fmap-like traits
This commit is contained in:
parent
8101887d31
commit
efc852f6e3
12 changed files with 229 additions and 136 deletions
|
@ -203,33 +203,3 @@ impl ToComputedValue for SpecifiedGradient {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToComputedValue for SpecifiedGradientKind {
|
||||
type ComputedValue = GradientKind;
|
||||
|
||||
fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
|
||||
match self {
|
||||
&GenericGradientKind::Linear(ref line_direction) => {
|
||||
GenericGradientKind::Linear(line_direction.to_computed_value(context))
|
||||
},
|
||||
&GenericGradientKind::Radial(ref ending_shape, ref position, ref angle) => {
|
||||
GenericGradientKind::Radial(ending_shape.to_computed_value(context),
|
||||
position.to_computed_value(context),
|
||||
angle.map(|angle| angle.to_computed_value(context)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn from_computed_value(computed: &Self::ComputedValue) -> Self {
|
||||
match *computed {
|
||||
GenericGradientKind::Linear(line_direction) => {
|
||||
GenericGradientKind::Linear(SpecifiedLineDirection::from_computed_value(&line_direction))
|
||||
},
|
||||
GenericGradientKind::Radial(ending_shape, position, angle) => {
|
||||
GenericGradientKind::Radial(ToComputedValue::from_computed_value(&ending_shape),
|
||||
ToComputedValue::from_computed_value(&position),
|
||||
angle.map(|angle| ToComputedValue::from_computed_value(&angle)))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -204,7 +204,7 @@ impl<L: ToComputedValue> ToComputedValue for TrackBreadth<L> {
|
|||
///
|
||||
/// https://drafts.csswg.org/css-grid/#typedef-track-size
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[derive(Clone, Debug, HasViewportPercentage, PartialEq)]
|
||||
#[derive(Clone, Debug, HasViewportPercentage, PartialEq, ToComputedValue)]
|
||||
pub enum TrackSize<L> {
|
||||
/// A flexible `<track-breadth>`
|
||||
Breadth(TrackBreadth<L>),
|
||||
|
@ -286,39 +286,6 @@ impl<L: ToCss> ToCss for TrackSize<L> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<L: ToComputedValue> ToComputedValue for TrackSize<L> {
|
||||
type ComputedValue = TrackSize<L::ComputedValue>;
|
||||
|
||||
#[inline]
|
||||
fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
|
||||
match *self {
|
||||
TrackSize::Breadth(ref b) => match *b {
|
||||
// <flex> outside `minmax()` expands to `mimmax(auto, <flex>)`
|
||||
// https://drafts.csswg.org/css-grid/#valdef-grid-template-columns-flex
|
||||
TrackBreadth::Flex(f) =>
|
||||
TrackSize::Minmax(TrackBreadth::Keyword(TrackKeyword::Auto), TrackBreadth::Flex(f)),
|
||||
_ => TrackSize::Breadth(b.to_computed_value(context)),
|
||||
},
|
||||
TrackSize::Minmax(ref b_1, ref b_2) =>
|
||||
TrackSize::Minmax(b_1.to_computed_value(context), b_2.to_computed_value(context)),
|
||||
TrackSize::FitContent(ref lop) => TrackSize::FitContent(lop.to_computed_value(context)),
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn from_computed_value(computed: &Self::ComputedValue) -> Self {
|
||||
match *computed {
|
||||
TrackSize::Breadth(ref b) =>
|
||||
TrackSize::Breadth(ToComputedValue::from_computed_value(b)),
|
||||
TrackSize::Minmax(ref b_1, ref b_2) =>
|
||||
TrackSize::Minmax(ToComputedValue::from_computed_value(b_1),
|
||||
ToComputedValue::from_computed_value(b_2)),
|
||||
TrackSize::FitContent(ref lop) =>
|
||||
TrackSize::FitContent(ToComputedValue::from_computed_value(lop)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Helper function for serializing identifiers with a prefix and suffix, used
|
||||
/// for serializing <line-names> (in grid).
|
||||
pub fn concat_serialize_idents<W>(prefix: &str, suffix: &str,
|
||||
|
@ -698,8 +665,8 @@ no_viewport_percentage!(LineNameList);
|
|||
/// Variants for `<grid-template-rows> | <grid-template-columns>`
|
||||
/// Subgrid deferred to Level 2 spec due to lack of implementation.
|
||||
/// But it's implemented in gecko, so we have to as well.
|
||||
#[derive(Clone, Debug, PartialEq, ToCss)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[derive(Clone, Debug, PartialEq, ToComputedValue, ToCss)]
|
||||
pub enum GridTemplateComponent<L> {
|
||||
/// `none` value.
|
||||
None,
|
||||
|
|
|
@ -61,8 +61,8 @@ pub enum CompatMode {
|
|||
}
|
||||
|
||||
/// A gradient kind.
|
||||
#[derive(Clone, Copy, Debug, HasViewportPercentage, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[derive(Clone, Copy, Debug, HasViewportPercentage, PartialEq, ToComputedValue)]
|
||||
pub enum GradientKind<LineDirection, Length, LengthOrPercentage, Position, Angle> {
|
||||
/// A linear gradient.
|
||||
Linear(LineDirection),
|
||||
|
|
|
@ -354,27 +354,3 @@ impl HasViewportPercentage for GridTemplateComponent<LengthOrPercentage> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToComputedValue for GridTemplateComponent<LengthOrPercentage> {
|
||||
type ComputedValue = GridTemplateComponent<computed::LengthOrPercentage>;
|
||||
|
||||
#[inline]
|
||||
fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
|
||||
match *self {
|
||||
GridTemplateComponent::None => GridTemplateComponent::None,
|
||||
GridTemplateComponent::TrackList(ref l) => GridTemplateComponent::TrackList(l.to_computed_value(context)),
|
||||
GridTemplateComponent::Subgrid(ref n) => GridTemplateComponent::Subgrid(n.to_computed_value(context)),
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn from_computed_value(computed: &Self::ComputedValue) -> Self {
|
||||
match *computed {
|
||||
GridTemplateComponent::None => GridTemplateComponent::None,
|
||||
GridTemplateComponent::TrackList(ref l) =>
|
||||
GridTemplateComponent::TrackList(ToComputedValue::from_computed_value(l)),
|
||||
GridTemplateComponent::Subgrid(ref n) =>
|
||||
GridTemplateComponent::Subgrid(ToComputedValue::from_computed_value(n)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue