mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
style: Make css(dimension) apply to the variant.
This commit is contained in:
parent
4927786d90
commit
92944cd5eb
8 changed files with 39 additions and 37 deletions
|
@ -263,13 +263,15 @@ impl PartialEq for Expression {
|
|||
|
||||
/// A resolution.
|
||||
#[derive(Clone, Debug, PartialEq, ToCss)]
|
||||
#[css(dimension)]
|
||||
pub enum Resolution {
|
||||
/// Dots per inch.
|
||||
#[css(dimension)]
|
||||
Dpi(CSSFloat),
|
||||
/// Dots per pixel.
|
||||
#[css(dimension)]
|
||||
Dppx(CSSFloat),
|
||||
/// Dots per centimeter.
|
||||
#[css(dimension)]
|
||||
Dpcm(CSSFloat),
|
||||
}
|
||||
|
||||
|
|
|
@ -214,7 +214,7 @@ impl<L: GeckoStyleCoordConvertible> GeckoStyleCoordConvertible for TrackBreadth<
|
|||
fn to_gecko_style_coord<T: CoordDataMut>(&self, coord: &mut T) {
|
||||
match *self {
|
||||
TrackBreadth::Breadth(ref lop) => lop.to_gecko_style_coord(coord),
|
||||
TrackBreadth::Flex(fr) => coord.set_value(CoordDataValue::FlexFraction(fr)),
|
||||
TrackBreadth::Fr(fr) => coord.set_value(CoordDataValue::FlexFraction(fr)),
|
||||
TrackBreadth::Keyword(TrackKeyword::Auto) => coord.set_value(CoordDataValue::Auto),
|
||||
TrackBreadth::Keyword(TrackKeyword::MinContent) =>
|
||||
coord.set_value(CoordDataValue::Enumerated(StyleGridTrackBreadth::MinContent as u32)),
|
||||
|
@ -235,7 +235,7 @@ impl<L: GeckoStyleCoordConvertible> GeckoStyleCoordConvertible for TrackBreadth<
|
|||
None
|
||||
}
|
||||
},
|
||||
CoordDataValue::FlexFraction(fr) => Some(TrackBreadth::Flex(fr)),
|
||||
CoordDataValue::FlexFraction(fr) => Some(TrackBreadth::Fr(fr)),
|
||||
CoordDataValue::Auto => Some(TrackBreadth::Keyword(TrackKeyword::Auto)),
|
||||
_ => L::from_gecko_style_coord(coord).map(TrackBreadth::Breadth),
|
||||
}
|
||||
|
|
|
@ -16,15 +16,18 @@ use values::distance::{ComputeSquaredDistance, SquaredDistance};
|
|||
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
|
||||
#[derive(Animate, Clone, Copy, Debug, MallocSizeOf, PartialEq, ToCss)]
|
||||
#[derive(PartialOrd, ToAnimatedZero)]
|
||||
#[css(dimension)]
|
||||
pub enum Angle {
|
||||
/// An angle with degree unit.
|
||||
#[css(dimension)]
|
||||
Deg(CSSFloat),
|
||||
/// An angle with gradian unit.
|
||||
#[css(dimension)]
|
||||
Grad(CSSFloat),
|
||||
/// An angle with radian unit.
|
||||
#[css(dimension)]
|
||||
Rad(CSSFloat),
|
||||
/// An angle with turn unit.
|
||||
#[css(dimension)]
|
||||
Turn(CSSFloat),
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ use cssparser::Parser;
|
|||
use parser::{Parse, ParserContext};
|
||||
use std::{fmt, mem, usize};
|
||||
use style_traits::{ToCss, ParseError, StyleParseErrorKind};
|
||||
use values::{CSSFloat, CustomIdent, serialize_dimension};
|
||||
use values::{CSSFloat, CustomIdent};
|
||||
use values::computed::{Context, ToComputedValue};
|
||||
use values::specified;
|
||||
use values::specified::grid::parse_line_names;
|
||||
|
@ -143,12 +143,13 @@ add_impls_for_keyword_enum!(TrackKeyword);
|
|||
/// avoid re-implementing it for the computed type.
|
||||
///
|
||||
/// <https://drafts.csswg.org/css-grid/#typedef-track-breadth>
|
||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToComputedValue)]
|
||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToComputedValue, ToCss)]
|
||||
pub enum TrackBreadth<L> {
|
||||
/// The generic type is almost always a non-negative `<length-percentage>`
|
||||
Breadth(L),
|
||||
/// A flex fraction specified in `fr` units.
|
||||
Flex(CSSFloat),
|
||||
#[css(dimension)]
|
||||
Fr(CSSFloat),
|
||||
/// One of the track-sizing keywords (`auto`, `min-content`, `max-content`)
|
||||
Keyword(TrackKeyword),
|
||||
}
|
||||
|
@ -166,16 +167,6 @@ impl<L> TrackBreadth<L> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<L: ToCss> ToCss for TrackBreadth<L> {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match *self {
|
||||
TrackBreadth::Breadth(ref lop) => lop.to_css(dest),
|
||||
TrackBreadth::Flex(ref value) => serialize_dimension(*value, "fr", dest),
|
||||
TrackBreadth::Keyword(ref k) => k.to_css(dest),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A `<track-size>` type for explicit grid track sizing. Like `<track-breadth>`, this is
|
||||
/// generic only to avoid code bloat. It only takes `<length-percentage>`
|
||||
///
|
||||
|
@ -212,7 +203,7 @@ impl<L> TrackSize<L> {
|
|||
}
|
||||
|
||||
match *breadth_1 {
|
||||
TrackBreadth::Flex(_) => false, // should be <inflexible-breadth> at this point
|
||||
TrackBreadth::Fr(_) => false, // should be <inflexible-breadth> at this point
|
||||
_ => breadth_2.is_fixed(),
|
||||
}
|
||||
},
|
||||
|
@ -242,7 +233,7 @@ impl<L: ToCss> ToCss for TrackSize<L> {
|
|||
// According to gecko minmax(auto, <flex>) is equivalent to <flex>,
|
||||
// and both are serialized as <flex>.
|
||||
if let TrackBreadth::Keyword(TrackKeyword::Auto) = *min {
|
||||
if let TrackBreadth::Flex(_) = *max {
|
||||
if let TrackBreadth::Fr(_) = *max {
|
||||
return max.to_css(dest);
|
||||
}
|
||||
}
|
||||
|
@ -268,7 +259,7 @@ impl<L: ToComputedValue> ToComputedValue for TrackSize<L> {
|
|||
#[inline]
|
||||
fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
|
||||
match *self {
|
||||
TrackSize::Breadth(TrackBreadth::Flex(ref f)) => {
|
||||
TrackSize::Breadth(TrackBreadth::Fr(ref f)) => {
|
||||
// <flex> outside `minmax()` expands to `mimmax(auto, <flex>)`
|
||||
// https://drafts.csswg.org/css-grid/#valdef-grid-template-columns-flex
|
||||
// FIXME(nox): This sounds false, the spec just says that <flex>
|
||||
|
@ -276,7 +267,7 @@ impl<L: ToComputedValue> ToComputedValue for TrackSize<L> {
|
|||
// into `minmax` at computed value time.
|
||||
TrackSize::Minmax(
|
||||
TrackBreadth::Keyword(TrackKeyword::Auto),
|
||||
TrackBreadth::Flex(f.to_computed_value(context)),
|
||||
TrackBreadth::Fr(f.to_computed_value(context)),
|
||||
)
|
||||
},
|
||||
TrackSize::Breadth(ref b) => {
|
||||
|
|
|
@ -41,14 +41,6 @@ pub fn serialize_percentage<W>(value: CSSFloat, dest: &mut W)
|
|||
dest.write_str("%")
|
||||
}
|
||||
|
||||
/// Serialize a value with given unit into dest.
|
||||
pub fn serialize_dimension<W>(value: CSSFloat, unit: &str, dest: &mut W)
|
||||
-> fmt::Result where W: fmt::Write
|
||||
{
|
||||
value.to_css(dest)?;
|
||||
dest.write_str(unit)
|
||||
}
|
||||
|
||||
/// Convenience void type to disable some properties and values through types.
|
||||
#[cfg_attr(feature = "servo", derive(Deserialize, MallocSizeOf, Serialize))]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, ToComputedValue, ToCss)]
|
||||
|
|
|
@ -33,7 +33,7 @@ impl Parse for TrackBreadth<LengthOrPercentage> {
|
|||
}
|
||||
|
||||
if let Ok(f) = input.try(parse_flex) {
|
||||
return Ok(TrackBreadth::Flex(f))
|
||||
return Ok(TrackBreadth::Fr(f))
|
||||
}
|
||||
|
||||
TrackKeyword::parse(input).map(TrackBreadth::Keyword)
|
||||
|
|
|
@ -53,15 +53,18 @@ pub fn au_to_int_px(au: f32) -> i32 {
|
|||
|
||||
/// A font relative length.
|
||||
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, ToCss)]
|
||||
#[css(dimension)]
|
||||
pub enum FontRelativeLength {
|
||||
/// A "em" value: https://drafts.csswg.org/css-values/#em
|
||||
#[css(dimension)]
|
||||
Em(CSSFloat),
|
||||
/// A "ex" value: https://drafts.csswg.org/css-values/#ex
|
||||
#[css(dimension)]
|
||||
Ex(CSSFloat),
|
||||
/// A "ch" value: https://drafts.csswg.org/css-values/#ch
|
||||
#[css(dimension)]
|
||||
Ch(CSSFloat),
|
||||
/// A "rem" value: https://drafts.csswg.org/css-values/#rem
|
||||
#[css(dimension)]
|
||||
Rem(CSSFloat)
|
||||
}
|
||||
|
||||
|
@ -197,15 +200,18 @@ impl FontRelativeLength {
|
|||
///
|
||||
/// <https://drafts.csswg.org/css-values/#viewport-relative-lengths>
|
||||
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, ToCss)]
|
||||
#[css(dimension)]
|
||||
pub enum ViewportPercentageLength {
|
||||
/// A vw unit: https://drafts.csswg.org/css-values/#vw
|
||||
#[css(dimension)]
|
||||
Vw(CSSFloat),
|
||||
/// A vh unit: https://drafts.csswg.org/css-values/#vh
|
||||
#[css(dimension)]
|
||||
Vh(CSSFloat),
|
||||
/// <https://drafts.csswg.org/css-values/#vmin>
|
||||
#[css(dimension)]
|
||||
Vmin(CSSFloat),
|
||||
/// <https://drafts.csswg.org/css-values/#vmax>
|
||||
#[css(dimension)]
|
||||
Vmax(CSSFloat)
|
||||
}
|
||||
|
||||
|
@ -251,21 +257,27 @@ impl CharacterWidth {
|
|||
|
||||
/// Represents an absolute length with its unit
|
||||
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, ToCss)]
|
||||
#[css(dimension)]
|
||||
pub enum AbsoluteLength {
|
||||
/// An absolute length in pixels (px)
|
||||
#[css(dimension)]
|
||||
Px(CSSFloat),
|
||||
/// An absolute length in inches (in)
|
||||
#[css(dimension)]
|
||||
In(CSSFloat),
|
||||
/// An absolute length in centimeters (cm)
|
||||
#[css(dimension)]
|
||||
Cm(CSSFloat),
|
||||
/// An absolute length in millimeters (mm)
|
||||
#[css(dimension)]
|
||||
Mm(CSSFloat),
|
||||
/// An absolute length in quarter-millimeters (q)
|
||||
#[css(dimension)]
|
||||
Q(CSSFloat),
|
||||
/// An absolute length in points (pt)
|
||||
#[css(dimension)]
|
||||
Pt(CSSFloat),
|
||||
/// An absolute length in pica (pc)
|
||||
#[css(dimension)]
|
||||
Pc(CSSFloat),
|
||||
}
|
||||
|
||||
|
@ -348,11 +360,13 @@ impl Add<AbsoluteLength> for AbsoluteLength {
|
|||
}
|
||||
|
||||
/// Represents a physical length based on DPI.
|
||||
///
|
||||
/// FIXME(emilio): Unship (https://bugzilla.mozilla.org/show_bug.cgi?id=1416564)
|
||||
#[derive(Clone, Copy, Debug, PartialEq, ToCss)]
|
||||
#[derive(MallocSizeOf)]
|
||||
#[css(dimension)]
|
||||
pub enum PhysicalLength {
|
||||
/// A physical length in millimetres.
|
||||
#[css(dimension)]
|
||||
Mozmm(CSSFloat),
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ pub fn derive(input: DeriveInput) -> Tokens {
|
|||
let variant_attrs = cg::parse_variant_attrs::<CssVariantAttrs>(variant);
|
||||
let separator = if variant_attrs.comma { ", " } else { " " };
|
||||
|
||||
if input_attrs.dimension {
|
||||
if variant_attrs.dimension {
|
||||
assert_eq!(bindings.len(), 1);
|
||||
assert!(!variant_attrs.function, "That makes no sense");
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ pub fn derive(input: DeriveInput) -> Tokens {
|
|||
}
|
||||
};
|
||||
|
||||
if input_attrs.dimension {
|
||||
if variant_attrs.dimension {
|
||||
// FIXME(emilio): Remove when bug 1416564 lands.
|
||||
if identifier == "-mozmm" {
|
||||
identifier = "mozmm".into();
|
||||
|
@ -112,7 +112,6 @@ pub fn derive(input: DeriveInput) -> Tokens {
|
|||
struct CssInputAttrs {
|
||||
derive_debug: bool,
|
||||
function: bool,
|
||||
dimension: bool,
|
||||
comma: bool,
|
||||
}
|
||||
|
||||
|
@ -122,6 +121,7 @@ struct CssVariantAttrs {
|
|||
function: bool,
|
||||
iterable: bool,
|
||||
comma: bool,
|
||||
dimension: bool,
|
||||
}
|
||||
|
||||
/// Transforms "FooBar" to "foo-bar".
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue