mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
Auto merge of #20237 - servo:derive-all-the-things, r=emilio
Opt into field bounds when deriving ToCss, instead of opting out <!-- Reviewable:start --> This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/20237) <!-- Reviewable:end -->
This commit is contained in:
commit
b6de0563fb
10 changed files with 99 additions and 150 deletions
|
@ -62,9 +62,9 @@ pub enum ShapeSource<BasicShape, ReferenceBox, ImageOrUrl> {
|
|||
#[derive(Animate, Clone, ComputeSquaredDistance, Debug, MallocSizeOf, PartialEq)]
|
||||
#[derive(ToComputedValue, ToCss)]
|
||||
pub enum BasicShape<H, V, LengthOrPercentage> {
|
||||
Inset(InsetRect<LengthOrPercentage>),
|
||||
Circle(Circle<H, V, LengthOrPercentage>),
|
||||
Ellipse(Ellipse<H, V, LengthOrPercentage>),
|
||||
Inset(#[css(field_bound)] InsetRect<LengthOrPercentage>),
|
||||
Circle(#[css(field_bound)] Circle<H, V, LengthOrPercentage>),
|
||||
Ellipse(#[css(field_bound)] Ellipse<H, V, LengthOrPercentage>),
|
||||
Polygon(Polygon<LengthOrPercentage>),
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ pub struct BorderImageSlice<NumberOrPercentage> {
|
|||
/// A generic value for the `border-*-radius` longhand properties.
|
||||
#[derive(Animate, Clone, ComputeSquaredDistance, Copy, Debug)]
|
||||
#[derive(MallocSizeOf, PartialEq, ToComputedValue, ToCss)]
|
||||
pub struct BorderCornerRadius<L>(pub Size<L>);
|
||||
pub struct BorderCornerRadius<L>(#[css(field_bound)] pub Size<L>);
|
||||
|
||||
impl<L> BorderCornerRadius<L> {
|
||||
/// Trivially create a `BorderCornerRadius`.
|
||||
|
@ -44,7 +44,7 @@ impl<L> BorderCornerRadius<L> {
|
|||
/// A generic value for the `border-spacing` property.
|
||||
#[derive(Animate, Clone, ComputeSquaredDistance, Copy, Debug, MallocSizeOf)]
|
||||
#[derive(PartialEq, ToAnimatedValue, ToAnimatedZero, ToComputedValue, ToCss)]
|
||||
pub struct BorderSpacing<L>(pub Size<L>);
|
||||
pub struct BorderSpacing<L>(#[css(field_bound)] pub Size<L>);
|
||||
|
||||
impl<L> BorderSpacing<L> {
|
||||
/// Trivially create a `BorderCornerRadius`.
|
||||
|
|
|
@ -68,8 +68,9 @@ where
|
|||
}
|
||||
|
||||
/// A value both for font-variation-settings and font-feature-settings.
|
||||
#[derive(Clone, Debug, Eq, MallocSizeOf, PartialEq, ToComputedValue)]
|
||||
pub struct FontSettings<T>(pub Box<[T]>);
|
||||
#[css(comma)]
|
||||
#[derive(Clone, Debug, Eq, MallocSizeOf, PartialEq, ToComputedValue, ToCss)]
|
||||
pub struct FontSettings<T>(#[css(if_empty = "normal", iterable)] pub Box<[T]>);
|
||||
|
||||
impl<T> FontSettings<T> {
|
||||
/// Default value of font settings as `normal`.
|
||||
|
@ -96,30 +97,6 @@ impl<T: Parse> Parse for FontSettings<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: ToCss> ToCss for FontSettings<T> {
|
||||
/// https://drafts.csswg.org/css-fonts-4/#descdef-font-face-font-feature-settings
|
||||
/// https://drafts.csswg.org/css-fonts-4/#font-variation-settings-def
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
||||
where
|
||||
W: Write,
|
||||
{
|
||||
if self.0.is_empty() {
|
||||
return dest.write_str("normal");
|
||||
}
|
||||
|
||||
let mut first = true;
|
||||
for item in self.0.iter() {
|
||||
if !first {
|
||||
dest.write_str(", ")?;
|
||||
}
|
||||
first = false;
|
||||
item.to_css(dest)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// A font four-character tag, represented as a u32 for convenience.
|
||||
///
|
||||
/// See:
|
||||
|
|
|
@ -6,8 +6,7 @@
|
|||
|
||||
use cssparser::Parser;
|
||||
use parser::{Parse, ParserContext};
|
||||
use std::fmt::{self, Write};
|
||||
use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss};
|
||||
use style_traits::{ParseError, StyleParseErrorKind};
|
||||
use values::{Either, None_};
|
||||
use values::computed::NumberOrPercentage;
|
||||
use values::computed::length::LengthOrPercentage;
|
||||
|
@ -199,41 +198,16 @@ pub enum SVGLength<LengthType> {
|
|||
}
|
||||
|
||||
/// Generic value for stroke-dasharray.
|
||||
#[derive(Clone, ComputeSquaredDistance, Debug, MallocSizeOf, PartialEq, ToAnimatedValue,
|
||||
ToComputedValue)]
|
||||
#[derive(Clone, ComputeSquaredDistance, Debug, MallocSizeOf, PartialEq)]
|
||||
#[derive(ToAnimatedValue, ToComputedValue, ToCss)]
|
||||
pub enum SVGStrokeDashArray<LengthType> {
|
||||
/// `[ <length> | <percentage> | <number> ]#`
|
||||
Values(Vec<LengthType>),
|
||||
#[css(comma)]
|
||||
Values(#[css(if_empty = "none", iterable)] Vec<LengthType>),
|
||||
/// `context-value`
|
||||
ContextValue,
|
||||
}
|
||||
|
||||
impl<LengthType> ToCss for SVGStrokeDashArray<LengthType> where LengthType: ToCss {
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
||||
where
|
||||
W: Write,
|
||||
{
|
||||
match self {
|
||||
&SVGStrokeDashArray::Values(ref values) => {
|
||||
let mut iter = values.iter();
|
||||
if let Some(first) = iter.next() {
|
||||
first.to_css(dest)?;
|
||||
for item in iter {
|
||||
dest.write_str(", ")?;
|
||||
item.to_css(dest)?;
|
||||
}
|
||||
Ok(())
|
||||
} else {
|
||||
dest.write_str("none")
|
||||
}
|
||||
}
|
||||
&SVGStrokeDashArray::ContextValue => {
|
||||
dest.write_str("context-value")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// An SVG opacity value accepts `context-{fill,stroke}-opacity` in
|
||||
/// addition to opacity value.
|
||||
#[derive(Clone, ComputeSquaredDistance, Copy, Debug, MallocSizeOf)]
|
||||
|
|
|
@ -7,8 +7,6 @@
|
|||
use app_units::Au;
|
||||
use euclid::{self, Rect, Transform3D};
|
||||
use num_traits::Zero;
|
||||
use std::fmt::{self, Write};
|
||||
use style_traits::{CssWriter, ToCss};
|
||||
use values::{computed, CSSFloat};
|
||||
use values::computed::length::Length as ComputedLength;
|
||||
use values::computed::length::LengthOrPercentage as ComputedLengthOrPercentage;
|
||||
|
@ -250,7 +248,6 @@ pub enum TransformOperation<Angle, Number, Length, Integer, LengthOrPercentage>
|
|||
#[css(comma, function = "interpolatematrix")]
|
||||
InterpolateMatrix {
|
||||
#[compute(ignore_bound)]
|
||||
#[css(ignore_bound)]
|
||||
from_list: Transform<
|
||||
TransformOperation<
|
||||
Angle,
|
||||
|
@ -261,7 +258,6 @@ pub enum TransformOperation<Angle, Number, Length, Integer, LengthOrPercentage>
|
|||
>,
|
||||
>,
|
||||
#[compute(ignore_bound)]
|
||||
#[css(ignore_bound)]
|
||||
to_list: Transform<
|
||||
TransformOperation<
|
||||
Angle,
|
||||
|
@ -279,7 +275,6 @@ pub enum TransformOperation<Angle, Number, Length, Integer, LengthOrPercentage>
|
|||
#[css(comma, function = "accumulatematrix")]
|
||||
AccumulateMatrix {
|
||||
#[compute(ignore_bound)]
|
||||
#[css(ignore_bound)]
|
||||
from_list: Transform<
|
||||
TransformOperation<
|
||||
Angle,
|
||||
|
@ -290,7 +285,6 @@ pub enum TransformOperation<Angle, Number, Length, Integer, LengthOrPercentage>
|
|||
>,
|
||||
>,
|
||||
#[compute(ignore_bound)]
|
||||
#[css(ignore_bound)]
|
||||
to_list: Transform<
|
||||
TransformOperation<
|
||||
Angle,
|
||||
|
@ -304,10 +298,9 @@ pub enum TransformOperation<Angle, Number, Length, Integer, LengthOrPercentage>
|
|||
},
|
||||
}
|
||||
|
||||
#[derive(Animate, ToComputedValue)]
|
||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq)]
|
||||
#[derive(Animate, Clone, Debug, MallocSizeOf, PartialEq, ToComputedValue, ToCss)]
|
||||
/// A value of the `transform` property
|
||||
pub struct Transform<T>(pub Vec<T>);
|
||||
pub struct Transform<T>(#[css(if_empty = "none", iterable)] pub Vec<T>);
|
||||
|
||||
impl<Angle, Number, Length, Integer, LengthOrPercentage>
|
||||
TransformOperation<Angle, Number, Length, Integer, LengthOrPercentage> {
|
||||
|
@ -515,27 +508,6 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: ToCss> ToCss for Transform<T> {
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
||||
where
|
||||
W: Write,
|
||||
{
|
||||
if self.0.is_empty() {
|
||||
return dest.write_str("none");
|
||||
}
|
||||
|
||||
let mut first = true;
|
||||
for operation in &self.0 {
|
||||
if !first {
|
||||
dest.write_str(" ")?;
|
||||
}
|
||||
first = false;
|
||||
operation.to_css(dest)?
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Transform<T> {
|
||||
/// `none`
|
||||
pub fn none() -> Self {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue