use crate::parser::ParserContext;
use crate::Zero;
use cssparser::Parser;
use std::fmt::{self, Write};
use style_traits::{CssWriter, ParseError, ToCss};
#[derive(
Clone,
Copy,
Debug,
MallocSizeOf,
PartialEq,
SpecifiedValueInfo,
ToComputedValue,
ToResolvedValue,
ToShmem,
)]
#[repr(C)]
pub struct GenericInitialLetter<Number, Integer> {
pub size: Number,
pub sink: Integer,
}
pub use self::GenericInitialLetter as InitialLetter;
impl<N: Zero, I: Zero> InitialLetter<N, I> {
#[inline]
pub fn normal() -> Self {
InitialLetter {
size: N::zero(),
sink: I::zero(),
}
}
}
impl<N: ToCss + Zero, I: ToCss + Zero> ToCss for InitialLetter<N, I> {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
where
W: Write,
{
if self.size.is_zero() {
return dest.write_str("normal");
}
self.size.to_css(dest)?;
if !self.sink.is_zero() {
dest.write_char(' ')?;
self.sink.to_css(dest)?;
}
Ok(())
}
}
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToCss, ToShmem)]
pub enum Spacing<Value> {
Normal,
Value(Value),
}
impl<Value> Spacing<Value> {
#[inline]
pub fn normal() -> Self {
Spacing::Normal
}
#[inline]
pub fn parse_with<'i, 't, F>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
parse: F,
) -> Result<Self, ParseError<'i>>
where
F: FnOnce(&ParserContext, &mut Parser<'i, 't>) -> Result<Value, ParseError<'i>>,
{
if input
.try_parse(|i| i.expect_ident_matching("normal"))
.is_ok()
{
return Ok(Spacing::Normal);
}
parse(context, input).map(Spacing::Value)
}
}
#[repr(C, u8)]
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
#[derive(
Animate,
Clone,
Copy,
ComputeSquaredDistance,
Debug,
Eq,
MallocSizeOf,
Parse,
PartialEq,
SpecifiedValueInfo,
ToAnimatedValue,
ToAnimatedZero,
ToComputedValue,
ToCss,
ToResolvedValue,
ToShmem,
)]
#[allow(missing_docs)]
pub enum GenericTextDecorationLength<L> {
LengthPercentage(L),
Auto,
FromFont,
}
#[repr(C)]
#[derive(
Animate,
Clone,
ComputeSquaredDistance,
Debug,
Eq,
MallocSizeOf,
PartialEq,
SpecifiedValueInfo,
ToAnimatedValue,
ToAnimatedZero,
ToComputedValue,
ToCss,
ToResolvedValue,
ToShmem,
)]
pub struct GenericTextIndent<LengthPercentage> {
pub length: LengthPercentage,
#[animation(constant)]
#[css(represents_keyword)]
pub hanging: bool,
#[animation(constant)]
#[css(represents_keyword)]
pub each_line: bool,
}
impl<LengthPercentage: Zero> GenericTextIndent<LengthPercentage> {
pub fn zero() -> Self {
Self {
length: LengthPercentage::zero(),
hanging: false,
each_line: false,
}
}
}