mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
style: Use cbindgen for grid track sizing.
Differential Revision: https://phabricator.services.mozilla.com/D36118
This commit is contained in:
parent
034557a717
commit
cc15afa348
6 changed files with 75 additions and 257 deletions
|
@ -7,7 +7,6 @@
|
|||
|
||||
use crate::{Atom, Zero};
|
||||
use crate::parser::{Parse, ParserContext};
|
||||
use crate::values::computed::{Context, ToComputedValue};
|
||||
use crate::values::specified;
|
||||
use crate::values::specified::grid::parse_line_names;
|
||||
use crate::values::{CSSFloat, CustomIdent};
|
||||
|
@ -180,33 +179,12 @@ impl Parse for GridLine<specified::Integer> {
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(missing_docs)]
|
||||
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
|
||||
#[derive(
|
||||
Animate,
|
||||
Clone,
|
||||
Copy,
|
||||
Debug,
|
||||
Eq,
|
||||
MallocSizeOf,
|
||||
Parse,
|
||||
PartialEq,
|
||||
SpecifiedValueInfo,
|
||||
ToComputedValue,
|
||||
ToCss,
|
||||
ToResolvedValue,
|
||||
ToShmem,
|
||||
)]
|
||||
pub enum TrackKeyword {
|
||||
Auto,
|
||||
MaxContent,
|
||||
MinContent,
|
||||
}
|
||||
|
||||
/// A track breadth for explicit grid track sizing. It's generic solely to
|
||||
/// avoid re-implementing it for the computed type.
|
||||
///
|
||||
/// <https://drafts.csswg.org/css-grid/#typedef-track-breadth>
|
||||
///
|
||||
/// cbindgen:derive-tagged-enum-copy-constructor=true
|
||||
#[derive(
|
||||
Animate,
|
||||
Clone,
|
||||
|
@ -219,16 +197,23 @@ pub enum TrackKeyword {
|
|||
ToResolvedValue,
|
||||
ToShmem,
|
||||
)]
|
||||
pub enum TrackBreadth<L> {
|
||||
#[repr(C, u8)]
|
||||
pub enum GenericTrackBreadth<L> {
|
||||
/// The generic type is almost always a non-negative `<length-percentage>`
|
||||
Breadth(L),
|
||||
/// A flex fraction specified in `fr` units.
|
||||
#[css(dimension)]
|
||||
Fr(CSSFloat),
|
||||
/// One of the track-sizing keywords (`auto`, `min-content`, `max-content`)
|
||||
Keyword(TrackKeyword),
|
||||
/// `auto`
|
||||
Auto,
|
||||
/// `min-content`
|
||||
MinContent,
|
||||
/// `max-content`
|
||||
MaxContent,
|
||||
}
|
||||
|
||||
pub use self::GenericTrackBreadth as TrackBreadth;
|
||||
|
||||
impl<L> TrackBreadth<L> {
|
||||
/// Check whether this is a `<fixed-breadth>` (i.e., it only has `<length-percentage>`)
|
||||
///
|
||||
|
@ -243,23 +228,31 @@ impl<L> TrackBreadth<L> {
|
|||
/// generic only to avoid code bloat. It only takes `<length-percentage>`
|
||||
///
|
||||
/// <https://drafts.csswg.org/css-grid/#typedef-track-size>
|
||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToResolvedValue, ToShmem)]
|
||||
pub enum TrackSize<L> {
|
||||
///
|
||||
/// cbindgen:derive-tagged-enum-copy-constructor=true
|
||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToComputedValue, ToResolvedValue, ToShmem)]
|
||||
#[repr(C, u8)]
|
||||
pub enum GenericTrackSize<L> {
|
||||
/// A flexible `<track-breadth>`
|
||||
Breadth(TrackBreadth<L>),
|
||||
Breadth(GenericTrackBreadth<L>),
|
||||
/// A `minmax` function for a range over an inflexible `<track-breadth>`
|
||||
/// and a flexible `<track-breadth>`
|
||||
///
|
||||
/// <https://drafts.csswg.org/css-grid/#valdef-grid-template-columns-minmax>
|
||||
#[css(function)]
|
||||
Minmax(TrackBreadth<L>, TrackBreadth<L>),
|
||||
Minmax(GenericTrackBreadth<L>, GenericTrackBreadth<L>),
|
||||
/// A `fit-content` function.
|
||||
///
|
||||
/// This stores a TrackBreadth<L> for convenience, but it can only be a
|
||||
/// LengthPercentage.
|
||||
///
|
||||
/// <https://drafts.csswg.org/css-grid/#valdef-grid-template-columns-fit-content>
|
||||
#[css(function)]
|
||||
FitContent(L),
|
||||
FitContent(GenericTrackBreadth<L>),
|
||||
}
|
||||
|
||||
pub use self::GenericTrackSize as TrackSize;
|
||||
|
||||
impl<L> TrackSize<L> {
|
||||
/// Check whether this is a `<fixed-size>`
|
||||
///
|
||||
|
@ -288,7 +281,7 @@ impl<L> TrackSize<L> {
|
|||
|
||||
impl<L> Default for TrackSize<L> {
|
||||
fn default() -> Self {
|
||||
TrackSize::Breadth(TrackBreadth::Keyword(TrackKeyword::Auto))
|
||||
TrackSize::Breadth(TrackBreadth::Auto)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -309,7 +302,7 @@ impl<L: ToCss> ToCss for TrackSize<L> {
|
|||
TrackSize::Minmax(ref min, ref max) => {
|
||||
// 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::Auto = *min {
|
||||
if let TrackBreadth::Fr(_) = *max {
|
||||
return max.to_css(dest);
|
||||
}
|
||||
|
@ -330,48 +323,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(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>
|
||||
// implies `minmax(auto, <flex>)`, not that it should be changed
|
||||
// into `minmax` at computed value time.
|
||||
TrackSize::Minmax(
|
||||
TrackBreadth::Keyword(TrackKeyword::Auto),
|
||||
TrackBreadth::Fr(f.to_computed_value(context)),
|
||||
)
|
||||
},
|
||||
TrackSize::Breadth(ref b) => TrackSize::Breadth(b.to_computed_value(context)),
|
||||
TrackSize::Minmax(ref b1, ref b2) => {
|
||||
TrackSize::Minmax(b1.to_computed_value(context), b2.to_computed_value(context))
|
||||
},
|
||||
TrackSize::FitContent(ref lp) => TrackSize::FitContent(lp.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 b1, ref b2) => TrackSize::Minmax(
|
||||
ToComputedValue::from_computed_value(b1),
|
||||
ToComputedValue::from_computed_value(b2),
|
||||
),
|
||||
TrackSize::FitContent(ref lp) => {
|
||||
TrackSize::FitContent(ToComputedValue::from_computed_value(lp))
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Helper function for serializing identifiers with a prefix and suffix, used
|
||||
/// for serializing <line-names> (in grid).
|
||||
pub fn concat_serialize_idents<W>(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue