/* 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.
#[cfg(feature = "servo")] usecrate::properties::StyleBuilder; usecrate::values::computed::length::LengthPercentage; usecrate::values::generics::NumberOrAuto; usecrate::values::generics::text::{
GenericHyphenateLimitChars, GenericInitialLetter, GenericTextDecorationLength, GenericTextIndent,
}; 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::{CssWriter, ToCss};
/// A computed value for the `initial-letter` property. pubtype InitialLetter = GenericInitialLetter<CSSFloat, CSSInteger>;
/// Implements type for `text-decoration-thickness` property. pubtype TextDecorationLength = GenericTextDecorationLength<LengthPercentage>;
/// 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)
}
}
/// 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()
}
}
/// A struct that represents the _used_ value of the text-decoration property. /// /// FIXME(emilio): This is done at style resolution time, though probably should /// be done at layout time, otherwise we need to account for display: contents /// and similar stuff when we implement it. /// /// FIXME(emilio): Also, should be just a bitfield instead of three bytes. #[derive(Clone, Copy, Debug, Default, MallocSizeOf, PartialEq, ToResolvedValue)] pubstruct TextDecorationsInEffect { /// Whether an underline is in effect. pub underline: bool, /// Whether an overline decoration is in effect. pub overline: bool, /// Whether a line-through style is in effect. pub line_through: bool,
}
impl TextDecorationsInEffect { /// Computes the text-decorations in effect for a given style. #[cfg(feature = "servo")] pubfn from_style(style: &StyleBuilder) -> Self { // Start with no declarations if this is an atomic inline-level box; // otherwise, start with the declarations in effect and add in the text // decorations that this block specifies. letmut 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();
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.