#[cfg(feature = "servo")]
use crate::properties::StyleBuilder;
use crate::values::computed::length::{Length, LengthPercentage};
use crate::values::computed::{Context, ToComputedValue};
use crate::values::generics::text::{
GenericInitialLetter, GenericTextDecorationLength, GenericTextIndent, Spacing,
};
use crate::values::specified::text as specified;
use crate::values::specified::text::{TextEmphasisFillMode, TextEmphasisShapeKeyword};
use crate::values::{CSSFloat, CSSInteger};
use crate::Zero;
use std::fmt::{self, Write};
use style_traits::{CssWriter, ToCss};
pub use crate::values::specified::text::{
HyphenateCharacter, LineBreak, MozControlCharacterVisibility, OverflowWrap, RubyPosition,
TextAlignLast, TextDecorationLine, TextDecorationSkipInk, TextEmphasisPosition, TextJustify,
TextOverflow, TextTransform, TextUnderlinePosition, WordBreak,
};
pub type InitialLetter = GenericInitialLetter<CSSFloat, CSSInteger>;
pub type TextDecorationLength = GenericTextDecorationLength<LengthPercentage>;
pub type TextAlign = specified::TextAlignKeyword;
pub type TextIndent = GenericTextIndent<LengthPercentage>;
#[repr(transparent)]
#[derive(
Animate,
Clone,
ComputeSquaredDistance,
Copy,
Debug,
MallocSizeOf,
PartialEq,
ToAnimatedValue,
ToAnimatedZero,
ToResolvedValue,
)]
pub struct GenericLetterSpacing<L>(pub L);
pub type LetterSpacing = GenericLetterSpacing<Length>;
impl LetterSpacing {
#[inline]
pub fn normal() -> Self {
Self(Length::zero())
}
}
impl ToCss for LetterSpacing {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
where
W: Write,
{
if self.0.is_zero() {
return dest.write_str("normal");
}
self.0.to_css(dest)
}
}
impl ToComputedValue for specified::LetterSpacing {
type ComputedValue = LetterSpacing;
fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
match *self {
Spacing::Normal => GenericLetterSpacing(Length::zero()),
Spacing::Value(ref v) => GenericLetterSpacing(v.to_computed_value(context)),
}
}
fn from_computed_value(computed: &Self::ComputedValue) -> Self {
if computed.0.is_zero() {
return Spacing::Normal;
}
Spacing::Value(ToComputedValue::from_computed_value(&computed.0))
}
}
pub type WordSpacing = LengthPercentage;
impl ToComputedValue for specified::WordSpacing {
type ComputedValue = WordSpacing;
fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
match *self {
Spacing::Normal => LengthPercentage::zero(),
Spacing::Value(ref v) => v.to_computed_value(context),
}
}
fn from_computed_value(computed: &Self::ComputedValue) -> Self {
Spacing::Value(ToComputedValue::from_computed_value(computed))
}
}
impl WordSpacing {
#[inline]
pub fn normal() -> Self {
LengthPercentage::zero()
}
}
#[derive(Clone, Copy, Debug, Default, MallocSizeOf, PartialEq, ToResolvedValue)]
pub struct TextDecorationsInEffect {
pub underline: bool,
pub overline: bool,
pub line_through: bool,
}
impl TextDecorationsInEffect {
#[cfg(feature = "servo")]
pub fn from_style(style: &StyleBuilder) -> Self {
let mut result = if style.get_box().clone_display().is_atomic_inline_level() {
Self::default()
} else {
style
.get_parent_inherited_text()
.text_decorations_in_effect
.clone()
};
let line = style.get_text().clone_text_decoration_line();
result.underline |= line.contains(TextDecorationLine::UNDERLINE);
result.overline |= line.contains(TextDecorationLine::OVERLINE);
result.line_through |= line.contains(TextDecorationLine::LINE_THROUGH);
result
}
}
#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToCss, ToResolvedValue)]
#[allow(missing_docs)]
#[repr(C, u8)]
pub enum TextEmphasisStyle {
Keyword {
#[css(skip_if = "TextEmphasisFillMode::is_filled")]
fill: TextEmphasisFillMode,
shape: TextEmphasisShapeKeyword,
},
None,
String(crate::OwnedStr),
}