/* 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::derives::*; usecrate::parser::{Parse, ParserContext}; usecrate::properties::{NonCustomPropertyId, PropertyId, ShorthandId}; usecrate::typed_om::ToTyped; usecrate::values::generics::animation as generics; usecrate::values::generics::position::{IsTreeScoped, TreeScoped}; usecrate::values::specified::{LengthPercentage, NonNegativeNumber, Time}; usecrate::values::{AtomIdent, CustomIdent, DashedIdent, KeyframesName}; usecrate::Atom; use cssparser::{match_ignore_ascii_case, 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,
ToTyped,
)] #[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,
ToTyped,
)] #[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(name) = name.as_atom() { #[cfg(feature = "gecko")] return name.with_str(|n| Self::from_ident(n).is_ok()); #[cfg(feature = "servo")] returnSelf::from_ident(name).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(),
};
impl Parse for ViewTransitionNameKeyword { 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());
}
if ident.eq_ignore_ascii_case("match-element") { return Ok(Self(AtomIdent::new(atom!("match-element"))));
}
// We check none already, so don't need to exclude none here. // Note: "auto" is not supported yet so we exclude it.
CustomIdent::from_ident(location, ident, &["auto"]).map(|i| Self(AtomIdent::new(i.0)))
}
}
impl ViewTransitionClassList { /// Returns the default value, `none`. We use the default slice (i.e. empty) to represent it. pubfn none() -> Self { Self(Default::default())
}
/// Returns whether this is the `none` value. pubfn is_none(&self) -> bool { self.0.is_empty()
}
/// Iterates over the contained custom idents. pubfn iter(&self) -> impl Iterator<Item = &CustomIdent> { self.0.iter()
}
}
/// The <timeline-range-name> value type, which indicates a CSS identifier representing one of the /// predefined named timeline ranges. /// https://drafts.csswg.org/scroll-animations-1/#named-ranges /// /// For now, only view timeline ranges use this type. /// https://drafts.csswg.org/scroll-animations-1/#view-timelines-ranges #[derive(
Copy,
Clone,
Debug,
Eq,
MallocSizeOf,
Parse,
PartialEq,
SpecifiedValueInfo,
ToComputedValue,
ToCss,
ToResolvedValue,
ToShmem,
ToTyped,
)] #[repr(u8)] pubenum TimelineRangeName { /// The default normal value. #[css(skip)]
Normal, /// No timeline range name specified. #[css(skip)]
None, /// Represents the full range of the view progress timeline
Cover, /// Represents the range during which the principal box is either fully contained by, or fully /// covers, its view progress visibility range within the scrollport.
Contain, /// Represents the range during which the principal box is entering the view progress /// visibility range.
Entry, /// Represents the range during which the principal box is exiting the view progress visibility /// range.
Exit, /// Represents the range during which the principal box crosses the end border edge.
EntryCrossing, /// Represents the range during which the principal box crosses the start border edge.
ExitCrossing, /// Represents the full range of the scroll container on which the view progress timeline is /// defined.
Scroll,
}
impl TimelineRangeName { /// Returns true if it is `normal`. #[inline] pubfn is_normal(&self) -> bool {
matches!(*self, Self::Normal)
}
/// Returns true if it is `none`. #[inline] pubfn is_none(&self) -> bool {
matches!(*self, Self::None)
}
}
/// The internal value for `animation-range-start` and `animation-range-end`. pubtype AnimationRangeValue = generics::GenericAnimationRangeValue<LengthPercentage>;
let name = TimelineRangeName::parse(input)?; let lp = input
.try_parse(|i| LengthPercentage::parse(context, i))
.unwrap_or(default);
Ok(AnimationRangeValue::new(name, lp))
}
/// A specified value for the `animation-range-start`. pubtype AnimationRangeStart = generics::GenericAnimationRangeStart<LengthPercentage>;
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.