/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
//! Computed types for text properties.
usecrate::derives::*; usecrate::typed_om::{KeywordValue, ToTyped, TypedValue}; usecrate::values::computed::length::{Length, LengthPercentage}; usecrate::values::generics::text::{
GenericHyphenateLimitChars, GenericInitialLetter, GenericTextDecorationInset,
GenericTextDecorationLength, GenericTextIndent,
}; usecrate::values::generics::NumberOrAuto; usecrate::values::specified::text as specified; usecrate::values::specified::text::{TextEmphasisFillMode, TextEmphasisShapeKeyword}; usecrate::values::{CSSFloat, CSSInteger}; usecrate::Zero; use std::fmt::{self, Write}; use style_traits::{CssString, CssWriter, ToCss}; use thin_vec::ThinVec;
/// A computed value for the `initial-letter` property. pubtype InitialLetter = GenericInitialLetter<CSSFloat, CSSInteger>;
/// Implements type for `text-decoration-thickness` property. pubtype TextDecorationLength = GenericTextDecorationLength<LengthPercentage>;
/// Implements type for `text-decoration-inset` property. pubtype TextDecorationInset = GenericTextDecorationInset<Length>;
/// The computed value of `text-align`. pubtype TextAlign = specified::TextAlignKeyword;
/// The computed value of `text-indent`. pubtype TextIndent = GenericTextIndent<LengthPercentage>;
/// A computed value for the `hyphenate-character` property. pubtype HyphenateLimitChars = GenericHyphenateLimitChars<CSSInteger>;
impl HyphenateLimitChars { /// Return the `auto` value, which has all three component values as `auto`. #[inline] pubfn auto() -> Self { Self {
total_word_length: NumberOrAuto::Auto,
pre_hyphen_length: NumberOrAuto::Auto,
post_hyphen_length: NumberOrAuto::Auto,
}
}
}
/// A computed value for the `letter-spacing` property. #[repr(transparent)] #[derive(
Animate,
Clone,
ComputeSquaredDistance,
Copy,
Debug,
MallocSizeOf,
PartialEq,
ToAnimatedValue,
ToAnimatedZero,
ToResolvedValue,
)] pubstruct GenericLetterSpacing<L>(pub L); /// This is generic just to make the #[derive()] code do the right thing for lengths. pubtype LetterSpacing = GenericLetterSpacing<LengthPercentage>;
impl LetterSpacing { /// Return the `normal` computed value, which is just zero. #[inline] pubfn normal() -> Self { Self(LengthPercentage::zero())
}
}
impl ToCss for LetterSpacing { fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where
W: Write,
{ // https://drafts.csswg.org/css-text/#propdef-letter-spacing // // For legacy reasons, a computed letter-spacing of zero yields a // resolved value (getComputedStyle() return value) of normal. ifself.0.is_zero() { return dest.write_str("normal");
} self.0.to_css(dest)
}
}
impl ToTyped for LetterSpacing { // Note: The specification does not currently define how letter spacing // should be reified into Typed OM. The current behavior follows existing // WPT coverage (letter-spacing.html). Syncing spec with UA/WPT behavior // tracked in https://github.com/w3c/csswg-drafts/issues/13907 fn to_typed(&self, dest: &mut ThinVec<TypedValue>) -> Result<(), ()> { if !self.0.has_percentage() && self.0.is_zero() {
dest.push(TypedValue::Keyword(KeywordValue(CssString::from("normal")))); return Ok(());
} self.0.to_typed(dest)
}
}
/// A computed value for the `word-spacing` property. pubtype WordSpacing = LengthPercentage;
impl WordSpacing { /// Return the `normal` computed value, which is just zero. #[inline] pubfn normal() -> Self {
LengthPercentage::zero()
}
}
/// Computed value for the text-emphasis-style property #[derive(Clone, Debug, MallocSizeOf, PartialEq, ToCss, ToResolvedValue, ToTyped)] #[allow(missing_docs)] #[repr(C, u8)] #[typed(todo_derive_fields)] pubenum TextEmphasisStyle { /// [ <fill> || <shape> ]
Keyword { #[css(skip_if = "TextEmphasisFillMode::is_filled")]
fill: TextEmphasisFillMode,
shape: TextEmphasisShapeKeyword,
}, /// `none`
None, /// `<string>` (of which only the first grapheme cluster will be used).
String(crate::OwnedStr),
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.