style: Support multiple track sizes for grid-auto-{columns|rows}.

Support `<track-size>+` on the implicit track sizing properties,
grid-auto-columns and grid-auto-rows.

Differential Revision: https://phabricator.services.mozilla.com/D38408
This commit is contained in:
Boris Chiou 2019-08-06 18:32:16 +00:00 committed by Emilio Cobos Álvarez
parent 69191d8b8c
commit 29f6db4d16
No known key found for this signature in database
GPG key ID: E1152D0994E4BF8A
6 changed files with 76 additions and 22 deletions

View file

@ -7,6 +7,7 @@
use self::transform::DirectionVector;
use super::animated::ToAnimatedValue;
use super::generics::grid::GridTemplateComponent as GenericGridTemplateComponent;
use super::generics::grid::ImplicitGridTracks as GenericImplicitGridTracks;
use super::generics::grid::{GenericGridLine, GenericTrackBreadth};
use super::generics::grid::{GenericTrackSize, TrackList as GenericTrackList};
use super::generics::transform::IsParallelTo;
@ -696,6 +697,9 @@ pub type TrackBreadth = GenericTrackBreadth<LengthPercentage>;
/// The computed value of a grid `<track-size>`
pub type TrackSize = GenericTrackSize<LengthPercentage>;
/// The computed value of a grid `<track-size>+`
pub type ImplicitGridTracks = GenericImplicitGridTracks<TrackSize>;
/// The computed value of a grid `<track-list>`
/// (could also be `<auto-track-list>` or `<explicit-track-list>`)
pub type TrackList = GenericTrackList<LengthPercentage, Integer>;

View file

@ -290,16 +290,17 @@ impl<L> TrackSize<L> {
}
}
impl<L> Default for TrackSize<L> {
fn default() -> Self {
TrackSize::Breadth(TrackBreadth::Auto)
impl<L: PartialEq> TrackSize<L> {
/// Return true if it is `auto`.
#[inline]
pub fn is_auto(&self) -> bool {
*self == TrackSize::Breadth(TrackBreadth::Auto)
}
}
impl<L: PartialEq> TrackSize<L> {
/// Returns true if current TrackSize is same as default.
pub fn is_default(&self) -> bool {
*self == TrackSize::default()
impl<L> Default for TrackSize<L> {
fn default() -> Self {
TrackSize::Breadth(TrackBreadth::Auto)
}
}
@ -334,6 +335,39 @@ impl<L: ToCss> ToCss for TrackSize<L> {
}
}
/// A `<track-size>+`.
/// We use the empty slice as `auto`, and always parse `auto` as an empty slice.
/// This means it's impossible to have a slice containing only one auto item.
#[derive(
Clone,
Debug,
Default,
MallocSizeOf,
PartialEq,
SpecifiedValueInfo,
ToComputedValue,
ToCss,
ToResolvedValue,
ToShmem,
)]
#[repr(transparent)]
pub struct GenericImplicitGridTracks<T>(
#[css(if_empty = "auto", iterable)] pub crate::OwnedSlice<T>,
);
pub use self::GenericImplicitGridTracks as ImplicitGridTracks;
impl<T: fmt::Debug + Default + PartialEq> ImplicitGridTracks<T> {
/// Returns true if current value is same as its initial value (i.e. auto).
pub fn is_initial(&self) -> bool {
debug_assert_ne!(
*self,
ImplicitGridTracks(crate::OwnedSlice::from(vec![Default::default()]))
);
self.0.is_empty()
}
}
/// Helper function for serializing identifiers with a prefix and suffix, used
/// for serializing <line-names> (in grid).
pub fn concat_serialize_idents<W>(

View file

@ -6,8 +6,8 @@
//! [grids](https://drafts.csswg.org/css-grid/)
use crate::parser::{Parse, ParserContext};
use crate::values::generics::grid::{GridTemplateComponent, RepeatCount, TrackBreadth};
use crate::values::generics::grid::{LineNameList, TrackRepeat, TrackSize};
use crate::values::generics::grid::{GridTemplateComponent, ImplicitGridTracks, RepeatCount};
use crate::values::generics::grid::{LineNameList, TrackBreadth, TrackRepeat, TrackSize};
use crate::values::generics::grid::{TrackList, TrackListValue};
use crate::values::specified::{Integer, LengthPercentage};
use crate::values::{CSSFloat, CustomIdent};
@ -95,6 +95,21 @@ impl Parse for TrackSize<LengthPercentage> {
}
}
impl Parse for ImplicitGridTracks<TrackSize<LengthPercentage>> {
fn parse<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
use style_traits::{Separator, Space};
let track_sizes = Space::parse(input, |i| TrackSize::parse(context, i))?;
if track_sizes.len() == 1 && track_sizes[0].is_auto() {
//`auto`, which is the initial value, is always represented by an empty slice.
return Ok(Default::default());
}
return Ok(ImplicitGridTracks(track_sizes.into()));
}
}
/// Parse the grid line names into a vector of owned strings.
///
/// <https://drafts.csswg.org/css-grid/#typedef-line-names>

View file

@ -8,6 +8,7 @@
use super::computed::transform::DirectionVector;
use super::computed::{Context, ToComputedValue};
use super::generics::grid::ImplicitGridTracks as GenericImplicitGridTracks;
use super::generics::grid::{GridLine as GenericGridLine, TrackBreadth as GenericTrackBreadth};
use super::generics::grid::{TrackList as GenericTrackList, TrackSize as GenericTrackSize};
use super::generics::transform::IsParallelTo;
@ -626,6 +627,9 @@ pub type TrackBreadth = GenericTrackBreadth<LengthPercentage>;
/// The specified value of a grid `<track-size>`
pub type TrackSize = GenericTrackSize<LengthPercentage>;
/// The specified value of a grid `<track-size>+`
pub type ImplicitGridTracks = GenericImplicitGridTracks<TrackSize>;
/// The specified value of a grid `<track-list>`
/// (could also be `<auto-track-list>` or `<explicit-track-list>`)
pub type TrackList = GenericTrackList<LengthPercentage, Integer>;