style/values/computed/
text.rs1use crate::derives::*;
8use crate::values::computed::length::{Length, LengthPercentage};
9use crate::values::generics::text::{
10 GenericHyphenateLimitChars, GenericInitialLetter, GenericTextDecorationInset,
11 GenericTextDecorationLength, GenericTextIndent,
12};
13use crate::values::generics::NumberOrAuto;
14use crate::values::specified::text as specified;
15use crate::values::specified::text::{TextEmphasisFillMode, TextEmphasisShapeKeyword};
16use crate::values::{CSSFloat, CSSInteger};
17use crate::Zero;
18use std::fmt::{self, Write};
19use style_traits::{CssString, CssWriter, ToCss, ToTyped, TypedValue};
20
21pub use crate::values::specified::text::{
22 HyphenateCharacter, LineBreak, MozControlCharacterVisibility, OverflowWrap, RubyPosition,
23 TextAlignLast, TextAutospace, TextDecorationLine, TextDecorationSkipInk, TextEmphasisPosition,
24 TextJustify, TextOverflow, TextTransform, TextUnderlinePosition, WordBreak,
25};
26
27pub type InitialLetter = GenericInitialLetter<CSSFloat, CSSInteger>;
29
30pub type TextDecorationLength = GenericTextDecorationLength<LengthPercentage>;
32
33pub type TextDecorationInset = GenericTextDecorationInset<Length>;
35
36pub type TextAlign = specified::TextAlignKeyword;
38
39pub type TextIndent = GenericTextIndent<LengthPercentage>;
41
42pub type HyphenateLimitChars = GenericHyphenateLimitChars<CSSInteger>;
44
45impl HyphenateLimitChars {
46 #[inline]
48 pub fn auto() -> Self {
49 Self {
50 total_word_length: NumberOrAuto::Auto,
51 pre_hyphen_length: NumberOrAuto::Auto,
52 post_hyphen_length: NumberOrAuto::Auto,
53 }
54 }
55}
56
57#[repr(transparent)]
59#[derive(
60 Animate,
61 Clone,
62 ComputeSquaredDistance,
63 Copy,
64 Debug,
65 MallocSizeOf,
66 PartialEq,
67 ToAnimatedValue,
68 ToAnimatedZero,
69 ToResolvedValue,
70)]
71pub struct GenericLetterSpacing<L>(pub L);
72pub type LetterSpacing = GenericLetterSpacing<LengthPercentage>;
74
75impl LetterSpacing {
76 #[inline]
78 pub fn normal() -> Self {
79 Self(LengthPercentage::zero())
80 }
81}
82
83impl ToCss for LetterSpacing {
84 fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
85 where
86 W: Write,
87 {
88 if self.0.is_zero() {
93 return dest.write_str("normal");
94 }
95 self.0.to_css(dest)
96 }
97}
98
99impl ToTyped for LetterSpacing {
100 fn to_typed(&self) -> Option<TypedValue> {
106 if self.0.is_zero() {
107 return Some(TypedValue::Keyword(CssString::from("normal")));
108 }
109 None
113 }
114}
115
116pub type WordSpacing = LengthPercentage;
118
119impl WordSpacing {
120 #[inline]
122 pub fn normal() -> Self {
123 LengthPercentage::zero()
124 }
125}
126
127#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToCss, ToResolvedValue, ToTyped)]
129#[allow(missing_docs)]
130#[repr(C, u8)]
131pub enum TextEmphasisStyle {
132 Keyword {
134 #[css(skip_if = "TextEmphasisFillMode::is_filled")]
135 fill: TextEmphasisFillMode,
136 shape: TextEmphasisShapeKeyword,
137 },
138 None,
140 String(crate::OwnedStr),
142}