/* 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/. */
/// Normalizes a float value to zero after a set of operations that might turn /// it into NaN. #[inline] pubfn normalize(v: CSSFloat) -> CSSFloat { if v.is_nan() { 0.0
} else {
v
}
}
/// A CSS integer value. pubtype CSSInteger = i32;
/// Serialize an identifier which is represented as an atom. #[cfg(feature = "gecko")] pubfn serialize_atom_identifier<W>(ident: &Atom, dest: &mut W) -> fmt::Result where
W: Write,
{
ident.with_str(|s| serialize_identifier(s, dest))
}
/// Serialize an identifier which is represented as an atom. #[cfg(feature = "servo")] pubfn serialize_atom_identifier<Static, W>(
ident: &::string_cache::Atom<Static>,
dest: &mut W,
) -> fmt::Result where Static: string_cache::StaticAtomSet,
W: Write,
{
serialize_identifier(&ident, dest)
}
/// Serialize a name which is represented as an Atom. #[cfg(feature = "gecko")] pubfn serialize_atom_name<W>(ident: &Atom, dest: &mut W) -> fmt::Result where
W: Write,
{
ident.with_str(|s| serialize_name(s, dest))
}
/// Serialize a name which is represented as an Atom. #[cfg(feature = "servo")] pubfn serialize_atom_name<Static, W>(
ident: &::string_cache::Atom<Static>,
dest: &mut W,
) -> fmt::Result where Static: string_cache::StaticAtomSet,
W: Write,
{
serialize_name(&ident, dest)
}
/// Serialize a number with calc, and NaN/infinity handling (if enabled) pubfn serialize_number<W>(v: f32, was_calc: bool, dest: &mut CssWriter<W>) -> fmt::Result where
W: Write,
{
serialize_specified_dimension(v, "", was_calc, dest)
}
/// Serialize a specified dimension with unit, calc, and NaN/infinity handling (if enabled) pubfn serialize_specified_dimension<W>(
v: f32,
unit: &str,
was_calc: bool,
dest: &mut CssWriter<W>,
) -> fmt::Result where
W: Write,
{ if was_calc {
dest.write_str("calc(")?;
}
if !v.is_finite() { // https://drafts.csswg.org/css-values/#calc-error-constants: // "While not technically numbers, these keywords act as numeric values, // similar to e and pi. Thus to get an infinite length, for example, // requires an expression like calc(infinity * 1px)."
if v.is_nan() {
dest.write_str("NaN")?;
} elseif v == f32::INFINITY {
dest.write_str("infinity")?;
} elseif v == f32::NEG_INFINITY {
dest.write_str("-infinity")?;
}
/// A generic CSS `<ident>` stored as an `Atom`. #[cfg(feature = "servo")] #[repr(transparent)] #[derive(Deref)] pubstruct GenericAtomIdent<Set>(pub string_cache::Atom<Set>) where
Set: string_cache::StaticAtomSet;
/// A generic CSS `<ident>` stored as an `Atom`, for the default atom set. #[cfg(feature = "servo")] pubtype AtomIdent = GenericAtomIdent<servo_atoms::AtomStaticSet>;
#[cfg(feature = "servo")] impl<Set: string_cache::StaticAtomSet> style_traits::SpecifiedValueInfo for GenericAtomIdent<Set> {}
/// Cast an atom ref to an AtomIdent ref. #[inline] pubfn cast<'a>(atom: &'a string_cache::Atom<Set>) -> &'a Self { let ptr = atom as *const _ as *constSelf; // safety: repr(transparent) unsafe { &*ptr }
}
}
/// A CSS `<ident>` stored as an `Atom`. #[cfg(feature = "gecko")] #[repr(transparent)] #[derive(
Clone, Debug, Default, Deref, Eq, Hash, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToShmem,
)] pubstruct AtomIdent(pub Atom);
#[cfg(feature = "gecko")] impl AtomIdent { /// Constructs a new AtomIdent. #[inline] pubfn new(atom: Atom) -> Self { Self(atom)
}
/// Like `Atom::with` but for `AtomIdent`. pubunsafefn with<F, R>(ptr: *constcrate::gecko_bindings::structs::nsAtom, callback: F) -> R where
F: FnOnce(&Self) -> R,
{
Atom::with(ptr, |atom: &Atom| { // safety: repr(transparent) let atom = atom as *const Atom as *const AtomIdent;
callback(&*atom)
})
}
/// Cast an atom ref to an AtomIdent ref. #[inline] pubfn cast<'a>(atom: &'a Atom) -> &'a Self { let ptr = atom as *const _ as *constSelf; // safety: repr(transparent) unsafe { &*ptr }
}
}
/// Serialize a value into percentage. pubfn serialize_percentage<W>(value: CSSFloat, dest: &mut CssWriter<W>) -> fmt::Result where
W: Write,
{
serialize_specified_dimension(value * 100., "%", /* was_calc = */ false, dest)
}
/// Serialize a value into normalized (no NaN/inf serialization) percentage. pubfn serialize_normalized_percentage<W>(value: CSSFloat, dest: &>mut CssWriter<W>) -> fmt::Result where
W: Write,
{
(value * 100.).to_css(dest)?;
dest.write_char('%')
}
/// Convenience void type to disable some properties and values through types. #[cfg_attr(feature = "servo", derive(Deserialize, MallocSizeOf, Serialize))] #[derive(
Clone,
Copy,
Debug,
PartialEq,
SpecifiedValueInfo,
ToAnimatedValue,
ToComputedValue,
ToCss,
ToResolvedValue,
)] pubenum Impossible {}
// FIXME(nox): This should be derived but the derive code cannot cope // with uninhabited enums. impl ComputeSquaredDistance for Impossible { #[inline] fn compute_squared_distance(&self, _other: &Self) -> Result<SquaredDistance, ()> { match *self {}
}
}
/// A struct representing one of two kinds of values. #[derive(
Animate,
Clone,
ComputeSquaredDistance,
Copy,
MallocSizeOf,
PartialEq,
Parse,
SpecifiedValueInfo,
ToAnimatedValue,
ToAnimatedZero,
ToComputedValue,
ToCss,
ToResolvedValue,
ToShmem,
)] pubenum Either<A, B> { /// The first value.
First(A), /// The second kind of value.
Second(B),
}
fn is_valid(ident: &str, excluding: &[&str]) -> bool { usecrate::properties::CSSWideKeyword; // https://drafts.csswg.org/css-values-4/#custom-idents: // // The CSS-wide keywords are not valid <custom-ident>s. The default // keyword is reserved and is also not a valid <custom-ident>. if CSSWideKeyword::from_ident(ident).is_ok() || ident.eq_ignore_ascii_case("default") { returnfalse;
}
impl ToCss for CustomIdent { fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where
W: Write,
{
serialize_atom_identifier(&self.0, dest)
}
}
/// <https://www.w3.org/TR/css-values-4/#dashed-idents> /// This is simply an Atom, but will only parse if the identifier starts with "--". #[repr(transparent)] #[derive(
Clone,
Debug,
Eq,
Hash,
MallocSizeOf,
PartialEq,
SpecifiedValueInfo,
ToAnimatedValue,
ToComputedValue,
ToResolvedValue,
ToShmem,
Serialize,
Deserialize,
)] pubstruct DashedIdent(pub Atom);
impl ToCss for DashedIdent { fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where
W: Write,
{
serialize_atom_identifier(&self.0, dest)
}
}
/// The <keyframes-name>. /// /// <https://drafts.csswg.org/css-animations/#typedef-keyframes-name> /// /// We use a single atom for this. Empty atom represents `none` animation. #[repr(transparent)] #[derive(
Clone,
Debug,
Eq,
Hash,
PartialEq,
MallocSizeOf,
SpecifiedValueInfo,
ToComputedValue,
ToResolvedValue,
ToShmem,
)] pubstruct KeyframesName(Atom);
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.