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