/* 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/. */
//! Specified types for properties related to animations and transitions.
usecrate::parser::{Parse, ParserContext}; usecrate::properties::{NonCustomPropertyId, PropertyId, ShorthandId}; usecrate::values::generics::animation as generics; usecrate::values::specified::{LengthPercentage, NonNegativeNumber, Time}; usecrate::values::{CustomIdent, DashedIdent, KeyframesName}; usecrate::Atom; use cssparser::Parser; use std::fmt::{self, Write}; use style_traits::{
CssWriter, KeywordsCollectFn, ParseError, SpecifiedValueInfo, StyleParseErrorKind, ToCss,
};
/// A given transition property, that is either `All`, a longhand or shorthand /// property, or an unsupported or custom property. #[derive(
Clone, Debug, Eq, Hash, MallocSizeOf, PartialEq, ToComputedValue, ToResolvedValue, ToShmem,
)] #[repr(u8)] pubenum TransitionProperty { /// A non-custom property.
NonCustom(NonCustomPropertyId), /// A custom property.
Custom(Atom), /// Unrecognized property which could be any non-transitionable, custom property, or /// unknown property.
Unsupported(CustomIdent),
}
impl Parse for TransitionProperty { fn parse<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { let location = input.current_source_location(); let ident = input.expect_ident()?;
let id = match PropertyId::parse_ignoring_rule_type(&ident, context) {
Ok(id) => id,
Err(..) => { // None is not acceptable as a single transition-property. return Ok(TransitionProperty::Unsupported(CustomIdent::from_ident(
location,
ident,
&["none"],
)?));
},
};
impl SpecifiedValueInfo for TransitionProperty { fn collect_completion_keywords(f: KeywordsCollectFn) { // `transition-property` can actually accept all properties and // arbitrary identifiers, but `all` is a special one we'd like // to list.
f(&["all"]);
}
}
/// Returns true if it is `all`. #[inline] pubfn is_all(&self) -> bool { self == &TransitionProperty::NonCustom(NonCustomPropertyId::from_shorthand(
ShorthandId::All,
))
}
}
/// A specified value for <transition-behavior-value>. /// /// https://drafts.csswg.org/css-transitions-2/#transition-behavior-property #[derive(
Clone,
Copy,
Debug,
MallocSizeOf,
Parse,
PartialEq,
SpecifiedValueInfo,
ToComputedValue,
ToCss,
ToResolvedValue,
ToShmem,
)] #[repr(u8)] pubenum TransitionBehavior { /// Transitions will not be started for discrete properties, only for interpolable properties.
Normal, /// Transitions will be started for discrete properties as well as interpolable properties.
AllowDiscrete,
}
/// A value for the `animation-name` property. #[derive(
Clone,
Debug,
Eq,
Hash,
MallocSizeOf,
PartialEq,
SpecifiedValueInfo,
ToComputedValue,
ToCss,
ToResolvedValue,
ToShmem,
)] #[value_info(other_values = "none")] #[repr(C)] pubstruct AnimationName(pub KeyframesName);
impl AnimationName { /// Get the name of the animation as an `Atom`. pubfn as_atom(&self) -> Option<&Atom> { ifself.is_none() { return None;
}
Some(self.0.as_atom())
}
impl AnimationFillMode { /// Returns true if the name matches any animation-fill-mode keyword. /// Note: animation-name:none is its initial value, so we don't have to match none here. #[inline] pubfn match_keywords(name: &AnimationName) -> bool { iflet Some(atom) = name.as_atom() { return !name.is_none() && atom.with_str(|n| Self::from_ident(n).is_ok());
} false
}
}
/// A value for the <Scroller> used in scroll(). /// /// https://drafts.csswg.org/scroll-animations-1/rewrite#typedef-scroller #[derive(
Copy,
Clone,
Debug,
Eq,
Hash,
MallocSizeOf,
Parse,
PartialEq,
SpecifiedValueInfo,
ToComputedValue,
ToCss,
ToResolvedValue,
ToShmem,
)] #[repr(u8)] pubenum Scroller { /// The nearest ancestor scroll container. (Default.)
Nearest, /// The document viewport as the scroll container.
Root, /// Specifies to use the element’s own principal box as the scroll container. #[css(keyword = "self")]
SelfElement,
}
impl Scroller { /// Returns true if it is default. #[inline] fn is_default(&self) -> bool {
matches!(*self, Self::Nearest)
}
}
/// The scroll() notation. /// https://drafts.csswg.org/scroll-animations-1/#scroll-notation #[derive(
Copy,
Clone,
Debug,
MallocSizeOf,
PartialEq,
SpecifiedValueInfo,
ToComputedValue,
ToCss,
ToResolvedValue,
ToShmem,
)] #[css(function = "scroll")] #[repr(C)] pubstruct ScrollFunction { /// The scroll container element whose scroll position drives the progress of the timeline. #[css(skip_if = "Scroller::is_default")] pub scroller: Scroller, /// The axis of scrolling that drives the progress of the timeline. #[css(skip_if = "ScrollAxis::is_default")] pub axis: ScrollAxis,
}
let start = LengthPercentageOrAuto::parse(context, input)?; let end = match input.try_parse(|input| LengthPercentageOrAuto::parse(context, input)) {
Ok(end) => end,
Err(_) => start.clone(),
};
Ok(Self { start, end })
}
}
/// The view-transition-name: `none | <custom-ident>`. /// /// https://drafts.csswg.org/css-view-transitions-1/#view-transition-name-prop /// /// We use a single atom for this. Empty atom represents `none`. #[derive(
Clone,
Debug,
Eq,
Hash,
PartialEq,
MallocSizeOf,
SpecifiedValueInfo,
ToComputedValue,
ToResolvedValue,
ToShmem,
)] #[repr(C)] pubstruct ViewTransitionName(Atom);
/// Returns whether this is the special `none` value. pubfn is_none(&self) -> bool { self.0 == atom!("")
}
}
impl Parse for ViewTransitionName { fn parse<'i, 't>(
_: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { let location = input.current_source_location(); let ident = input.expect_ident()?; if ident.eq_ignore_ascii_case("none") { return Ok(Self::none());
}
// We check none already, so don't need to exclude none here. // Note: The values none and auto are excluded from <custom-ident> here.
Ok(Self(CustomIdent::from_ident(location, ident, &["auto"])?.0))
}
}
impl ToCss for ViewTransitionName { fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where
W: Write,
{ usecrate::values::serialize_atom_identifier;
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.