@@ -10,6 +10,7 @@ use crate::values::ident::CustomIdent;
1010use smallvec:: SmallVec ;
1111use crate :: values:: length:: serialize_dimension;
1212use bitflags:: bitflags;
13+ use crate :: values:: number:: serialize_integer;
1314
1415/// https://drafts.csswg.org/css-grid-2/#track-sizing
1516#[ derive( Debug , Clone , PartialEq ) ]
@@ -739,6 +740,7 @@ impl ToCss for GridTemplate {
739740}
740741
741742bitflags ! {
743+ /// https://drafts.csswg.org/css-grid-2/#grid-auto-flow-property
742744 pub struct GridAutoFlow : u8 {
743745 const Row = 0b00 ;
744746 const Column = 0b01 ;
@@ -828,6 +830,7 @@ impl ToCss for GridAutoFlow {
828830 }
829831}
830832
833+ /// https://drafts.csswg.org/css-grid-2/#grid-shorthand
831834#[ derive( Debug , Clone , PartialEq ) ]
832835pub struct Grid {
833836 rows : TrackSizing ,
@@ -842,7 +845,6 @@ impl Parse for Grid {
842845 fn parse < ' i , ' t > ( input : & mut Parser < ' i , ' t > ) -> Result < Self , ParseError < ' i , ( ) > > {
843846 // <'grid-template'>
844847 if let Ok ( template) = input. try_parse ( GridTemplate :: parse) {
845- println ! ( "{:?}" , template) ;
846848 Ok ( Grid {
847849 rows : template. rows ,
848850 columns : template. columns ,
@@ -901,7 +903,6 @@ fn parse_grid_auto_flow<'i, 't>(input: &mut Parser<'i, 't>, flow: GridAutoFlow)
901903
902904impl ToCss for Grid {
903905 fn to_css < W > ( & self , dest : & mut Printer < W > ) -> std:: fmt:: Result where W : std:: fmt:: Write {
904- println ! ( "{:?}" , self ) ;
905906 if self . areas != GridTemplateAreas :: None ||
906907 ( self . rows != TrackSizing :: None && self . columns != TrackSizing :: None ) ||
907908 ( self . areas == GridTemplateAreas :: None && self . auto_rows == TrackSizeList :: default ( ) && self . auto_columns == TrackSizeList :: default ( ) && self . auto_flow == GridAutoFlow :: default ( ) ) {
@@ -938,3 +939,88 @@ impl ToCss for Grid {
938939 Ok ( ( ) )
939940 }
940941}
942+
943+ /// https://drafts.csswg.org/css-grid-2/#typedef-grid-row-start-grid-line
944+ #[ derive( Debug , Clone , PartialEq ) ]
945+ pub enum GridLine {
946+ Auto ,
947+ Ident ( CustomIdent ) ,
948+ Line ( i32 , Option < CustomIdent > ) ,
949+ Span ( i32 , Option < CustomIdent > )
950+ }
951+
952+ impl Parse for GridLine {
953+ fn parse < ' i , ' t > ( input : & mut Parser < ' i , ' t > ) -> Result < Self , ParseError < ' i , ( ) > > {
954+ if input. try_parse ( |input| input. expect_ident_matching ( "auto" ) ) . is_ok ( ) {
955+ return Ok ( GridLine :: Auto )
956+ }
957+
958+ if input. try_parse ( |input| input. expect_ident_matching ( "span" ) ) . is_ok ( ) {
959+ // TODO: is calc() supported here??
960+ let ( line_number, ident) = if let Ok ( line_number) = input. try_parse ( |input| input. expect_integer ( ) ) {
961+ let ident = input. try_parse ( CustomIdent :: parse) . ok ( ) ;
962+ ( line_number, ident)
963+ } else if let Ok ( ident) = input. try_parse ( CustomIdent :: parse) {
964+ let line_number = input. try_parse ( |input| input. expect_integer ( ) ) . unwrap_or ( 1 ) ;
965+ ( line_number, Some ( ident) )
966+ } else {
967+ return Err ( input. new_error ( BasicParseErrorKind :: QualifiedRuleInvalid ) )
968+ } ;
969+
970+ if line_number == 0 {
971+ return Err ( input. new_error ( BasicParseErrorKind :: QualifiedRuleInvalid ) )
972+ }
973+
974+ return Ok ( GridLine :: Span ( line_number, ident) )
975+ }
976+
977+ if let Ok ( line_number) = input. try_parse ( |input| input. expect_integer ( ) ) {
978+ if line_number == 0 {
979+ return Err ( input. new_error ( BasicParseErrorKind :: QualifiedRuleInvalid ) )
980+ }
981+ let ident = input. try_parse ( CustomIdent :: parse) . ok ( ) ;
982+ return Ok ( GridLine :: Line ( line_number, ident) )
983+ }
984+
985+ let ident = CustomIdent :: parse ( input) ?;
986+ if let Ok ( line_number) = input. try_parse ( |input| input. expect_integer ( ) ) {
987+ if line_number == 0 {
988+ return Err ( input. new_error ( BasicParseErrorKind :: QualifiedRuleInvalid ) )
989+ }
990+ return Ok ( GridLine :: Line ( line_number, Some ( ident) ) )
991+ }
992+
993+ Ok ( GridLine :: Ident ( ident) )
994+ }
995+ }
996+
997+ impl ToCss for GridLine {
998+ fn to_css < W > ( & self , dest : & mut Printer < W > ) -> std:: fmt:: Result where W : std:: fmt:: Write {
999+ match self {
1000+ GridLine :: Auto => dest. write_str ( "auto" ) ,
1001+ GridLine :: Ident ( id) => id. to_css ( dest) ,
1002+ GridLine :: Line ( line_number, id) => {
1003+ serialize_integer ( * line_number, dest) ?;
1004+ if let Some ( id) = id {
1005+ dest. write_char ( ' ' ) ?;
1006+ id. to_css ( dest) ?;
1007+ }
1008+ Ok ( ( ) )
1009+ }
1010+ GridLine :: Span ( line_number, id) => {
1011+ dest. write_str ( "span " ) ?;
1012+ if * line_number != 1 || id. is_none ( ) {
1013+ serialize_integer ( * line_number, dest) ?;
1014+ if id. is_some ( ) {
1015+ dest. write_char ( ' ' ) ?;
1016+ }
1017+ }
1018+
1019+ if let Some ( id) = id {
1020+ id. to_css ( dest) ?;
1021+ }
1022+ Ok ( ( ) )
1023+ }
1024+ }
1025+ }
1026+ }
0 commit comments