@@ -55,12 +55,14 @@ use crate::vendor_prefix::VendorPrefix;
5555use crate :: parser:: ParserOptions ;
5656use crate :: error:: { ParserError , PrinterError } ;
5757use crate :: logical:: LogicalProperty ;
58+ use crate :: targets:: Browsers ;
59+ use crate :: prefixes:: Feature ;
5860
5961macro_rules! define_properties {
6062 (
6163 $(
6264 $( #[ $meta: meta] ) *
63- $name: literal: $property: ident( $type: ty $( , $vp: ty) ?) $( / $prefix: tt ) * $( if $condition: ident ) ?,
65+ $name: literal: $property: ident( $type: ty $( , $vp: ty) ?) $( / $prefix: tt ) * $( unprefixed : $unprefixed : literal ) ? $ ( if $condition: ident ) ?,
6466 ) +
6567 ) => {
6668 #[ derive( Debug , Clone , PartialEq ) ]
@@ -107,17 +109,41 @@ macro_rules! define_properties {
107109 $(
108110 $( #[ $meta] ) *
109111 $property$( ( vp_name!( $vp, prefix) ) ) ? => {
110- // TODO: this assumes there is only one prefix. How should we handle multiple?
112+ let mut first = true ;
113+ macro_rules! delim {
114+ ( ) => {
115+ #[ allow( unused_assignments) ]
116+ if first {
117+ first = false ;
118+ } else {
119+ dest. delim( ',' , false ) ?;
120+ }
121+ } ;
122+ }
123+
124+ macro_rules! write {
125+ ( $p: expr) => {
126+ delim!( ) ;
127+ dest. write_str( & $name) ?;
128+ } ;
129+ ( $v: ty, $p: expr) => {
130+ if prefix. contains( $p) {
131+ delim!( ) ;
132+ $p. to_css( dest) ?;
133+ dest. write_str( & $name) ?;
134+ }
135+ } ;
136+ }
137+
111138 $(
112- macro_rules! write_prefix {
113- ( $v: ty) => {
114- prefix. to_css( dest) ?;
115- } ;
116- }
117-
118- write_prefix!( $vp) ;
139+ write!( $vp, VendorPrefix :: WebKit ) ;
140+ write!( $vp, VendorPrefix :: Moz ) ;
141+ write!( $vp, VendorPrefix :: Ms ) ;
142+ write!( $vp, VendorPrefix :: O ) ;
119143 ) ?
120- dest. write_str( & $name)
144+
145+ write!( $( $vp, ) ? VendorPrefix :: None ) ;
146+ Ok ( ( ) )
121147 } ,
122148 ) +
123149 All => dest. write_str( "all" ) ,
@@ -172,6 +198,31 @@ macro_rules! define_properties {
172198 }
173199 }
174200
201+ fn set_prefixes_for_targets( & mut self , targets: Option <Browsers >) {
202+ match self {
203+ $(
204+ $( #[ $meta] ) *
205+ #[ allow( unused_variables) ]
206+ PropertyId :: $property$( ( vp_name!( $vp, prefix) ) ) ? => {
207+ macro_rules! get_prefixed {
208+ ( $v: ty, $u: literal) => { } ;
209+ ( $v: ty) => { {
210+ if prefix. contains( VendorPrefix :: None ) {
211+ if let Some ( targets) = targets {
212+ * prefix = Feature :: $property. prefixes_for( targets) ;
213+ }
214+ } ;
215+ } } ;
216+ ( ) => { } ;
217+ }
218+
219+ get_prefixed!( $( $vp) ? $( , $unprefixed) ?) ;
220+ } ,
221+ ) +
222+ _ => { }
223+ }
224+ }
225+
175226 fn to_css_with_prefix<W >( & self , dest: & mut Printer <W >, prefix: VendorPrefix ) -> Result <( ) , PrinterError > where W : std:: fmt:: Write {
176227 use PropertyId :: * ;
177228 match self {
@@ -228,7 +279,7 @@ macro_rules! define_properties {
228279 match name. as_ref( ) {
229280 $(
230281 $( #[ $meta] ) *
231- $name $( if options. $condition) ? => {
282+ $name $( if $unprefixed ) ? $ ( if options. $condition) ? => {
232283 if let Ok ( c) = <$type>:: parse( input) {
233284 if input. expect_exhausted( ) . is_ok( ) {
234285 return Ok ( Property :: $property( c, $( <$vp>:: None ) ?) )
@@ -581,26 +632,26 @@ define_properties! {
581632 "gap" : Gap ( Gap ) ,
582633
583634 // Old flex (2009): https://www.w3.org/TR/2009/WD-css3-flexbox-20090723/
584- "box-orient" : BoxOrient ( BoxOrient , VendorPrefix ) / "webkit" / "moz" ,
585- "box-direction" : BoxDirection ( BoxDirection , VendorPrefix ) / "webkit" / "moz" ,
586- "box-ordinal-group" : BoxOrdinalGroup ( f32 , VendorPrefix ) / "webkit" / "moz" ,
587- "box-align" : BoxAlign ( BoxAlign , VendorPrefix ) / "webkit" / "moz" ,
588- "box-flex" : BoxFlex ( f32 , VendorPrefix ) / "webkit" / "moz" ,
589- "box-flex-group" : BoxFlexGroup ( f32 , VendorPrefix ) / "webkit" ,
590- "box-pack" : BoxPack ( BoxPack , VendorPrefix ) / "webkit" / "moz" ,
591- "box-lines" : BoxLines ( BoxLines , VendorPrefix ) / "webkit" / "moz" ,
635+ "box-orient" : BoxOrient ( BoxOrient , VendorPrefix ) / "webkit" / "moz" unprefixed : false ,
636+ "box-direction" : BoxDirection ( BoxDirection , VendorPrefix ) / "webkit" / "moz" unprefixed : false ,
637+ "box-ordinal-group" : BoxOrdinalGroup ( f32 , VendorPrefix ) / "webkit" / "moz" unprefixed : false ,
638+ "box-align" : BoxAlign ( BoxAlign , VendorPrefix ) / "webkit" / "moz" unprefixed : false ,
639+ "box-flex" : BoxFlex ( f32 , VendorPrefix ) / "webkit" / "moz" unprefixed : false ,
640+ "box-flex-group" : BoxFlexGroup ( f32 , VendorPrefix ) / "webkit" unprefixed : false ,
641+ "box-pack" : BoxPack ( BoxPack , VendorPrefix ) / "webkit" / "moz" unprefixed : false ,
642+ "box-lines" : BoxLines ( BoxLines , VendorPrefix ) / "webkit" / "moz" unprefixed : false ,
592643
593644 // Old flex (2012): https://www.w3.org/TR/2012/WD-css3-flexbox-20120322/
594- "flex-pack" : FlexPack ( FlexPack , VendorPrefix ) / "ms" ,
595- "flex-order" : FlexOrder ( f32 , VendorPrefix ) / "ms" ,
596- "flex-align" : FlexAlign ( BoxAlign , VendorPrefix ) / "ms" ,
597- "flex-item-align" : FlexItemAlign ( FlexItemAlign , VendorPrefix ) / "ms" ,
598- "flex-line-pack" : FlexLinePack ( FlexLinePack , VendorPrefix ) / "ms" ,
645+ "flex-pack" : FlexPack ( FlexPack , VendorPrefix ) / "ms" unprefixed : false ,
646+ "flex-order" : FlexOrder ( f32 , VendorPrefix ) / "ms" unprefixed : false ,
647+ "flex-align" : FlexAlign ( BoxAlign , VendorPrefix ) / "ms" unprefixed : false ,
648+ "flex-item-align" : FlexItemAlign ( FlexItemAlign , VendorPrefix ) / "ms" unprefixed : false ,
649+ "flex-line-pack" : FlexLinePack ( FlexLinePack , VendorPrefix ) / "ms" unprefixed : false ,
599650
600651 // Microsoft extensions
601- "flex-positive" : FlexPositive ( f32 , VendorPrefix ) / "ms" ,
602- "flex-negative" : FlexNegative ( f32 , VendorPrefix ) / "ms" ,
603- "flex-preferred-size" : FlexPreferredSize ( LengthPercentageOrAuto , VendorPrefix ) / "ms" ,
652+ "flex-positive" : FlexPositive ( f32 , VendorPrefix ) / "ms" unprefixed : false ,
653+ "flex-negative" : FlexNegative ( f32 , VendorPrefix ) / "ms" unprefixed : false ,
654+ "flex-preferred-size" : FlexPreferredSize ( LengthPercentageOrAuto , VendorPrefix ) / "ms" unprefixed : false ,
604655
605656 #[ cfg( feature = "grid" ) ]
606657 "grid-template-columns" : GridTemplateColumns ( TrackSizing ) ,
0 commit comments