@@ -590,6 +590,7 @@ impl ToCss for TextEmphasisStyle {
590590 }
591591}
592592
593+ /// https://www.w3.org/TR/2020/WD-css-text-decor-4-20200506/#text-emphasis-property
593594#[ derive( Debug , Clone , PartialEq ) ]
594595pub struct TextEmphasis {
595596 style : TextEmphasisStyle ,
@@ -639,6 +640,47 @@ impl ToCss for TextEmphasis {
639640 }
640641}
641642
643+ enum_property ! ( TextEmphasisPositionVertical ,
644+ Over ,
645+ Under
646+ ) ;
647+
648+ enum_property ! ( TextEmphasisPositionHorizontal ,
649+ Left ,
650+ Right
651+ ) ;
652+
653+ /// https://www.w3.org/TR/2020/WD-css-text-decor-4-20200506/#text-emphasis-position-property
654+ #[ derive( Debug , Clone , PartialEq ) ]
655+ pub struct TextEmphasisPosition {
656+ vertical : TextEmphasisPositionVertical ,
657+ horizontal : TextEmphasisPositionHorizontal
658+ }
659+
660+ impl Parse for TextEmphasisPosition {
661+ fn parse < ' i , ' t > ( input : & mut Parser < ' i , ' t > ) -> Result < Self , ParseError < ' i , ( ) > > {
662+ if let Ok ( horizontal) = input. try_parse ( TextEmphasisPositionHorizontal :: parse) {
663+ let vertical = TextEmphasisPositionVertical :: parse ( input) ?;
664+ Ok ( TextEmphasisPosition { horizontal, vertical } )
665+ } else {
666+ let vertical = TextEmphasisPositionVertical :: parse ( input) ?;
667+ let horizontal = input. try_parse ( TextEmphasisPositionHorizontal :: parse) . unwrap_or ( TextEmphasisPositionHorizontal :: Right ) ;
668+ Ok ( TextEmphasisPosition { horizontal, vertical } )
669+ }
670+ }
671+ }
672+
673+ impl ToCss for TextEmphasisPosition {
674+ fn to_css < W > ( & self , dest : & mut Printer < W > ) -> std:: fmt:: Result where W : std:: fmt:: Write {
675+ self . vertical . to_css ( dest) ?;
676+ if self . horizontal != TextEmphasisPositionHorizontal :: Right {
677+ dest. write_char ( ' ' ) ?;
678+ self . horizontal . to_css ( dest) ?;
679+ }
680+ Ok ( ( ) )
681+ }
682+ }
683+
642684#[ derive( Default ) ]
643685pub struct TextDecorationHandler {
644686 targets : Option < Browsers > ,
@@ -648,6 +690,7 @@ pub struct TextDecorationHandler {
648690 color : Option < ( CssColor , VendorPrefix ) > ,
649691 emphasis_style : Option < ( TextEmphasisStyle , VendorPrefix ) > ,
650692 emphasis_color : Option < ( CssColor , VendorPrefix ) > ,
693+ emphasis_position : Option < ( TextEmphasisPosition , VendorPrefix ) > ,
651694 decls : Vec < Property >
652695}
653696
@@ -712,6 +755,7 @@ impl PropertyHandler for TextDecorationHandler {
712755 property ! ( emphasis_style, & val. style, vp) ;
713756 property ! ( emphasis_color, & val. color, vp) ;
714757 }
758+ TextEmphasisPosition ( val, vp) => property ! ( emphasis_position, val, vp) ,
715759 _ => return false
716760 }
717761
@@ -732,6 +776,7 @@ impl TextDecorationHandler {
732776 let mut color = std:: mem:: take ( & mut self . color ) ;
733777 let mut emphasis_style = std:: mem:: take ( & mut self . emphasis_style ) ;
734778 let mut emphasis_color = std:: mem:: take ( & mut self . emphasis_color ) ;
779+ let mut emphasis_position = std:: mem:: take ( & mut self . emphasis_position ) ;
735780
736781 if let ( Some ( ( line, line_vp) ) , Some ( thickness_val) , Some ( ( style, style_vp) ) , Some ( ( color, color_vp) ) ) = ( & mut line, & mut thickness, & mut style, & mut color) {
737782 let intersection = * line_vp | * style_vp | * color_vp;
@@ -803,5 +848,21 @@ impl TextDecorationHandler {
803848
804849 single_property ! ( emphasis_style, TextEmphasisStyle ) ;
805850 single_property ! ( emphasis_color, TextEmphasisColor ) ;
851+
852+ if let Some ( ( pos, vp) ) = emphasis_position {
853+ if !vp. is_empty ( ) {
854+ let mut prefix = vp;
855+ if prefix. contains ( VendorPrefix :: None ) {
856+ if let Some ( targets) = self . targets {
857+ prefix = Feature :: TextEmphasisPosition . prefixes_for ( targets) ;
858+ // Prefixed version does not support horizontal keyword.
859+ if pos. horizontal != TextEmphasisPositionHorizontal :: Right {
860+ prefix = VendorPrefix :: None ;
861+ }
862+ }
863+ }
864+ self . decls . push ( Property :: TextEmphasisPosition ( pos, prefix) )
865+ }
866+ }
806867 }
807868}
0 commit comments