mirror of
https://github.com/servo/servo.git
synced 2025-08-04 05:00:08 +01:00
style: Move animation-related values from box.rs/ui.rs to animation.rs
Although we store animation and transition style values in StyleUIReset and define their properties in longhands/ui.mako.rs, but we may move them in the future if this style struct becomes too large. So let's move the definition of their values to an independent module, animation, so we don't have to worry about this again. This patch doesn't change any other things. Only move code. Differential Revision: https://phabricator.services.mozilla.com/D173903
This commit is contained in:
parent
1816d7750f
commit
b1bcb22650
11 changed files with 518 additions and 479 deletions
66
components/style/values/computed/animation.rs
Normal file
66
components/style/values/computed/animation.rs
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
//! Computed values for properties related to animations and transitions
|
||||||
|
|
||||||
|
use crate::values::computed::{Context, LengthPercentage, ToComputedValue};
|
||||||
|
use crate::values::generics::animation as generics;
|
||||||
|
use crate::values::specified::animation as specified;
|
||||||
|
use std::fmt::{self, Write};
|
||||||
|
use style_traits::{CssWriter, ToCss};
|
||||||
|
|
||||||
|
pub use crate::values::specified::animation::{
|
||||||
|
AnimationName, AnimationTimeline, ScrollAxis, ScrollTimelineName, TransitionProperty,
|
||||||
|
};
|
||||||
|
|
||||||
|
/// A computed value for the `animation-iteration-count` property.
|
||||||
|
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, ToResolvedValue, ToShmem)]
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct AnimationIterationCount(pub f32);
|
||||||
|
|
||||||
|
impl ToComputedValue for specified::AnimationIterationCount {
|
||||||
|
type ComputedValue = AnimationIterationCount;
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
|
||||||
|
AnimationIterationCount(match *self {
|
||||||
|
specified::AnimationIterationCount::Number(n) => n.to_computed_value(context).0,
|
||||||
|
specified::AnimationIterationCount::Infinite => std::f32::INFINITY,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn from_computed_value(computed: &Self::ComputedValue) -> Self {
|
||||||
|
use crate::values::specified::NonNegativeNumber;
|
||||||
|
if computed.0.is_infinite() {
|
||||||
|
specified::AnimationIterationCount::Infinite
|
||||||
|
} else {
|
||||||
|
specified::AnimationIterationCount::Number(NonNegativeNumber::new(computed.0))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AnimationIterationCount {
|
||||||
|
/// Returns the value `1.0`.
|
||||||
|
#[inline]
|
||||||
|
pub fn one() -> Self {
|
||||||
|
Self(1.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ToCss for AnimationIterationCount {
|
||||||
|
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
||||||
|
where
|
||||||
|
W: Write,
|
||||||
|
{
|
||||||
|
if self.0.is_infinite() {
|
||||||
|
dest.write_str("infinite")
|
||||||
|
} else {
|
||||||
|
self.0.to_css(dest)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A computed value for the `view-timeline-inset` property.
|
||||||
|
pub type ViewTimelineInset = generics::GenericViewTimelineInset<LengthPercentage>;
|
|
@ -13,68 +13,15 @@ use crate::values::generics::box_::{
|
||||||
use crate::values::specified::box_ as specified;
|
use crate::values::specified::box_ as specified;
|
||||||
|
|
||||||
pub use crate::values::specified::box_::{
|
pub use crate::values::specified::box_::{
|
||||||
AnimationName, AnimationTimeline, Appearance, BreakBetween, BreakWithin,
|
Appearance, BreakBetween, BreakWithin, Clear as SpecifiedClear, Contain, ContainerName,
|
||||||
Clear as SpecifiedClear, Contain, ContainerName, ContainerType, ContentVisibility, Display,
|
ContainerType, ContentVisibility, Display, Float as SpecifiedFloat, Overflow, OverflowAnchor,
|
||||||
Float as SpecifiedFloat, Overflow, OverflowAnchor, OverflowClipBox, OverscrollBehavior,
|
OverflowClipBox, OverscrollBehavior, ScrollSnapAlign, ScrollSnapAxis, ScrollSnapStop,
|
||||||
ScrollAxis, ScrollSnapAlign, ScrollSnapAxis, ScrollSnapStop, ScrollSnapStrictness,
|
ScrollSnapStrictness, ScrollSnapType, ScrollbarGutter, TouchAction, WillChange,
|
||||||
ScrollSnapType, ScrollTimelineName, ScrollbarGutter, TouchAction, TransitionProperty,
|
|
||||||
WillChange,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use std::fmt::{self, Write};
|
|
||||||
use style_traits::{ToCss, CssWriter};
|
|
||||||
|
|
||||||
/// A computed value for the `vertical-align` property.
|
/// A computed value for the `vertical-align` property.
|
||||||
pub type VerticalAlign = GenericVerticalAlign<LengthPercentage>;
|
pub type VerticalAlign = GenericVerticalAlign<LengthPercentage>;
|
||||||
|
|
||||||
/// A computed value for the `animation-iteration-count` property.
|
|
||||||
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, ToResolvedValue, ToShmem)]
|
|
||||||
#[repr(C)]
|
|
||||||
pub struct AnimationIterationCount(pub f32);
|
|
||||||
|
|
||||||
impl ToComputedValue for specified::AnimationIterationCount {
|
|
||||||
type ComputedValue = AnimationIterationCount;
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
|
|
||||||
AnimationIterationCount(match *self {
|
|
||||||
specified::AnimationIterationCount::Number(n) => n.to_computed_value(context).0,
|
|
||||||
specified::AnimationIterationCount::Infinite => std::f32::INFINITY,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn from_computed_value(computed: &Self::ComputedValue) -> Self {
|
|
||||||
use crate::values::specified::NonNegativeNumber;
|
|
||||||
if computed.0.is_infinite() {
|
|
||||||
specified::AnimationIterationCount::Infinite
|
|
||||||
} else {
|
|
||||||
specified::AnimationIterationCount::Number(NonNegativeNumber::new(computed.0))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl AnimationIterationCount {
|
|
||||||
/// Returns the value `1.0`.
|
|
||||||
#[inline]
|
|
||||||
pub fn one() -> Self {
|
|
||||||
Self(1.0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ToCss for AnimationIterationCount {
|
|
||||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
|
||||||
where
|
|
||||||
W: Write,
|
|
||||||
{
|
|
||||||
if self.0.is_infinite() {
|
|
||||||
dest.write_str("infinite")
|
|
||||||
} else {
|
|
||||||
self.0.to_css(dest)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A computed value for the `contain-intrinsic-size` property.
|
/// A computed value for the `contain-intrinsic-size` property.
|
||||||
pub type ContainIntrinsicSize = GenericContainIntrinsicSize<NonNegativeLength>;
|
pub type ContainIntrinsicSize = GenericContainIntrinsicSize<NonNegativeLength>;
|
||||||
|
|
||||||
|
|
|
@ -47,25 +47,26 @@ pub use self::basic_shape::FillRule;
|
||||||
pub use self::border::{BorderCornerRadius, BorderRadius, BorderSpacing};
|
pub use self::border::{BorderCornerRadius, BorderRadius, BorderSpacing};
|
||||||
pub use self::border::{BorderImageRepeat, BorderImageSideWidth};
|
pub use self::border::{BorderImageRepeat, BorderImageSideWidth};
|
||||||
pub use self::border::{BorderImageSlice, BorderImageWidth};
|
pub use self::border::{BorderImageSlice, BorderImageWidth};
|
||||||
pub use self::box_::{
|
|
||||||
AnimationIterationCount, AnimationName, AnimationTimeline, Contain, ContainerName,
|
|
||||||
ContainerType,
|
|
||||||
};
|
|
||||||
pub use self::box_::{
|
pub use self::box_::{
|
||||||
Appearance, BreakBetween, BreakWithin, Clear, ContainIntrinsicSize, ContentVisibility, Float,
|
Appearance, BreakBetween, BreakWithin, Clear, ContainIntrinsicSize, ContentVisibility, Float,
|
||||||
};
|
};
|
||||||
pub use self::box_::{Display, LineClamp, Overflow, OverflowAnchor, TransitionProperty};
|
pub use self::box_::{
|
||||||
|
Contain, ContainerName, ContainerType, Display, LineClamp, Overflow, OverflowAnchor,
|
||||||
|
};
|
||||||
pub use self::box_::{OverflowClipBox, OverscrollBehavior, Perspective, Resize, ScrollbarGutter};
|
pub use self::box_::{OverflowClipBox, OverscrollBehavior, Perspective, Resize, ScrollbarGutter};
|
||||||
pub use self::box_::{ScrollAxis, ScrollSnapAlign, ScrollSnapAxis, ScrollSnapStop};
|
pub use self::box_::{
|
||||||
pub use self::box_::{ScrollSnapStrictness, ScrollSnapType, ScrollTimelineName};
|
ScrollSnapAlign, ScrollSnapAxis, ScrollSnapStop, ScrollSnapStrictness, ScrollSnapType,
|
||||||
|
};
|
||||||
pub use self::box_::{TouchAction, VerticalAlign, WillChange};
|
pub use self::box_::{TouchAction, VerticalAlign, WillChange};
|
||||||
pub use self::color::{Color, ColorOrAuto, ColorPropertyValue, ColorScheme, PrintColorAdjust, ForcedColorAdjust};
|
pub use self::color::{
|
||||||
|
Color, ColorOrAuto, ColorPropertyValue, ColorScheme, ForcedColorAdjust, PrintColorAdjust,
|
||||||
|
};
|
||||||
pub use self::column::ColumnCount;
|
pub use self::column::ColumnCount;
|
||||||
pub use self::counters::{Content, ContentItem, CounterIncrement, CounterReset, CounterSet};
|
pub use self::counters::{Content, ContentItem, CounterIncrement, CounterReset, CounterSet};
|
||||||
pub use self::easing::TimingFunction;
|
pub use self::easing::TimingFunction;
|
||||||
pub use self::effects::{BoxShadow, Filter, SimpleShadow};
|
pub use self::effects::{BoxShadow, Filter, SimpleShadow};
|
||||||
pub use self::flex::FlexBasis;
|
pub use self::flex::FlexBasis;
|
||||||
pub use self::font::{FontFamily, FontLanguageOverride, FontStyle, FontPalette};
|
pub use self::font::{FontFamily, FontLanguageOverride, FontPalette, FontStyle};
|
||||||
pub use self::font::{FontFeatureSettings, FontVariantLigatures, FontVariantNumeric};
|
pub use self::font::{FontFeatureSettings, FontVariantLigatures, FontVariantNumeric};
|
||||||
pub use self::font::{FontSize, FontSizeAdjust, FontStretch, FontSynthesis};
|
pub use self::font::{FontSize, FontSizeAdjust, FontStretch, FontSynthesis};
|
||||||
pub use self::font::{FontVariantAlternates, FontWeight};
|
pub use self::font::{FontVariantAlternates, FontWeight};
|
||||||
|
@ -104,7 +105,9 @@ pub use self::transform::{Rotate, Scale, Transform, TransformOperation};
|
||||||
pub use self::transform::{TransformOrigin, TransformStyle, Translate};
|
pub use self::transform::{TransformOrigin, TransformStyle, Translate};
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
pub use self::ui::CursorImage;
|
pub use self::ui::CursorImage;
|
||||||
pub use self::ui::{BoolInteger, Cursor, UserSelect, ViewTimelineInset};
|
pub use self::ui::{BoolInteger, Cursor, UserSelect};
|
||||||
|
pub use self::animation::{AnimationIterationCount, AnimationName, AnimationTimeline};
|
||||||
|
pub use self::animation::{ScrollAxis, ScrollTimelineName, TransitionProperty, ViewTimelineInset};
|
||||||
pub use super::specified::TextTransform;
|
pub use super::specified::TextTransform;
|
||||||
pub use super::specified::ViewportVariant;
|
pub use super::specified::ViewportVariant;
|
||||||
pub use super::specified::{BorderStyle, TextDecorationLine};
|
pub use super::specified::{BorderStyle, TextDecorationLine};
|
||||||
|
@ -113,6 +116,7 @@ pub use app_units::Au;
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
pub mod align;
|
pub mod align;
|
||||||
pub mod angle;
|
pub mod angle;
|
||||||
|
pub mod animation;
|
||||||
pub mod background;
|
pub mod background;
|
||||||
pub mod basic_shape;
|
pub mod basic_shape;
|
||||||
pub mod border;
|
pub mod border;
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
use crate::values::computed::color::Color;
|
use crate::values::computed::color::Color;
|
||||||
use crate::values::computed::image::Image;
|
use crate::values::computed::image::Image;
|
||||||
use crate::values::computed::{LengthPercentage, Number};
|
use crate::values::computed::Number;
|
||||||
use crate::values::generics::ui as generics;
|
use crate::values::generics::ui as generics;
|
||||||
|
|
||||||
pub use crate::values::specified::ui::CursorKind;
|
pub use crate::values::specified::ui::CursorKind;
|
||||||
|
@ -20,6 +20,3 @@ pub type CursorImage = generics::GenericCursorImage<Image, Number>;
|
||||||
|
|
||||||
/// A computed value for `scrollbar-color` property.
|
/// A computed value for `scrollbar-color` property.
|
||||||
pub type ScrollbarColor = generics::GenericScrollbarColor<Color>;
|
pub type ScrollbarColor = generics::GenericScrollbarColor<Color>;
|
||||||
|
|
||||||
/// A computed value for the `view-timeline-inset` property.
|
|
||||||
pub type ViewTimelineInset = generics::GenericViewTimelineInset<LengthPercentage>;
|
|
||||||
|
|
59
components/style/values/generics/animation.rs
Normal file
59
components/style/values/generics/animation.rs
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
//! Generic values for properties related to animations and transitions.
|
||||||
|
|
||||||
|
use crate::values::generics::length::GenericLengthPercentageOrAuto;
|
||||||
|
use std::fmt::{self, Write};
|
||||||
|
use style_traits::{CssWriter, ToCss};
|
||||||
|
|
||||||
|
/// A generic value for the `[ [ auto | <length-percentage> ]{1,2} ]`.
|
||||||
|
///
|
||||||
|
/// https://drafts.csswg.org/scroll-animations-1/#view-timeline-inset
|
||||||
|
#[derive(
|
||||||
|
Clone,
|
||||||
|
Copy,
|
||||||
|
Debug,
|
||||||
|
MallocSizeOf,
|
||||||
|
PartialEq,
|
||||||
|
SpecifiedValueInfo,
|
||||||
|
ToComputedValue,
|
||||||
|
ToResolvedValue,
|
||||||
|
ToShmem,
|
||||||
|
)]
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct GenericViewTimelineInset<LengthPercent> {
|
||||||
|
/// The start inset in the relevant axis.
|
||||||
|
pub start: GenericLengthPercentageOrAuto<LengthPercent>,
|
||||||
|
/// The end inset.
|
||||||
|
pub end: GenericLengthPercentageOrAuto<LengthPercent>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub use self::GenericViewTimelineInset as ViewTimelineInset;
|
||||||
|
|
||||||
|
impl<LengthPercent> ToCss for ViewTimelineInset<LengthPercent>
|
||||||
|
where
|
||||||
|
LengthPercent: PartialEq + ToCss,
|
||||||
|
{
|
||||||
|
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
||||||
|
where
|
||||||
|
W: Write,
|
||||||
|
{
|
||||||
|
self.start.to_css(dest)?;
|
||||||
|
if self.end != self.start {
|
||||||
|
dest.write_char(' ')?;
|
||||||
|
self.end.to_css(dest)?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<LengthPercent> Default for ViewTimelineInset<LengthPercent> {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
start: GenericLengthPercentageOrAuto::auto(),
|
||||||
|
end: GenericLengthPercentageOrAuto::auto(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -13,6 +13,7 @@ use cssparser::Parser;
|
||||||
use std::ops::Add;
|
use std::ops::Add;
|
||||||
use style_traits::{KeywordsCollectFn, ParseError, SpecifiedValueInfo, StyleParseErrorKind};
|
use style_traits::{KeywordsCollectFn, ParseError, SpecifiedValueInfo, StyleParseErrorKind};
|
||||||
|
|
||||||
|
pub mod animation;
|
||||||
pub mod background;
|
pub mod background;
|
||||||
pub mod basic_shape;
|
pub mod basic_shape;
|
||||||
pub mod border;
|
pub mod border;
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
|
|
||||||
//! Generic values for UI properties.
|
//! Generic values for UI properties.
|
||||||
|
|
||||||
use crate::values::generics::length::GenericLengthPercentageOrAuto;
|
|
||||||
use crate::values::specified::ui::CursorKind;
|
use crate::values::specified::ui::CursorKind;
|
||||||
use std::fmt::{self, Write};
|
use std::fmt::{self, Write};
|
||||||
use style_traits::{CssWriter, ToCss};
|
use style_traits::{CssWriter, ToCss};
|
||||||
|
@ -128,53 +127,3 @@ impl<Color> Default for ScrollbarColor<Color> {
|
||||||
ScrollbarColor::Auto
|
ScrollbarColor::Auto
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A generic value for the `[ [ auto | <length-percentage> ]{1,2} ]`.
|
|
||||||
///
|
|
||||||
/// https://drafts.csswg.org/scroll-animations-1/#view-timeline-inset
|
|
||||||
#[derive(
|
|
||||||
Clone,
|
|
||||||
Copy,
|
|
||||||
Debug,
|
|
||||||
MallocSizeOf,
|
|
||||||
PartialEq,
|
|
||||||
SpecifiedValueInfo,
|
|
||||||
ToComputedValue,
|
|
||||||
ToResolvedValue,
|
|
||||||
ToShmem,
|
|
||||||
)]
|
|
||||||
#[repr(C)]
|
|
||||||
pub struct GenericViewTimelineInset<LengthPercent> {
|
|
||||||
/// The start inset in the relevant axis.
|
|
||||||
pub start: GenericLengthPercentageOrAuto<LengthPercent>,
|
|
||||||
/// The end inset.
|
|
||||||
pub end: GenericLengthPercentageOrAuto<LengthPercent>,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub use self::GenericViewTimelineInset as ViewTimelineInset;
|
|
||||||
|
|
||||||
impl<LengthPercent> ToCss for ViewTimelineInset<LengthPercent>
|
|
||||||
where
|
|
||||||
LengthPercent: ToCss + PartialEq,
|
|
||||||
{
|
|
||||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
|
||||||
where
|
|
||||||
W: Write,
|
|
||||||
{
|
|
||||||
self.start.to_css(dest)?;
|
|
||||||
if self.end != self.start {
|
|
||||||
dest.write_char(' ')?;
|
|
||||||
self.end.to_css(dest)?;
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<LengthPercent> Default for ViewTimelineInset<LengthPercent> {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
start: GenericLengthPercentageOrAuto::auto(),
|
|
||||||
end: GenericLengthPercentageOrAuto::auto(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
355
components/style/values/specified/animation.rs
Normal file
355
components/style/values/specified/animation.rs
Normal file
|
@ -0,0 +1,355 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
//! Specified types for properties related to animations and transitions.
|
||||||
|
|
||||||
|
use crate::custom_properties::Name as CustomPropertyName;
|
||||||
|
use crate::parser::{Parse, ParserContext};
|
||||||
|
use crate::properties::{LonghandId, PropertyDeclarationId, PropertyId, ShorthandId};
|
||||||
|
use crate::values::generics::animation as generics;
|
||||||
|
use crate::values::specified::{LengthPercentage, NonNegativeNumber};
|
||||||
|
use crate::values::{CustomIdent, KeyframesName, TimelineName};
|
||||||
|
use crate::Atom;
|
||||||
|
use cssparser::Parser;
|
||||||
|
use std::fmt::{self, Write};
|
||||||
|
use style_traits::{CssWriter, KeywordsCollectFn, ParseError, SpecifiedValueInfo, 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,
|
||||||
|
)]
|
||||||
|
pub enum TransitionProperty {
|
||||||
|
/// A shorthand.
|
||||||
|
Shorthand(ShorthandId),
|
||||||
|
/// A longhand transitionable property.
|
||||||
|
Longhand(LonghandId),
|
||||||
|
/// A custom property.
|
||||||
|
Custom(CustomPropertyName),
|
||||||
|
/// Unrecognized property which could be any non-transitionable, custom property, or
|
||||||
|
/// unknown property.
|
||||||
|
Unsupported(CustomIdent),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ToCss for TransitionProperty {
|
||||||
|
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
||||||
|
where
|
||||||
|
W: Write,
|
||||||
|
{
|
||||||
|
use crate::values::serialize_atom_name;
|
||||||
|
match *self {
|
||||||
|
TransitionProperty::Shorthand(ref s) => s.to_css(dest),
|
||||||
|
TransitionProperty::Longhand(ref l) => l.to_css(dest),
|
||||||
|
TransitionProperty::Custom(ref name) => {
|
||||||
|
dest.write_str("--")?;
|
||||||
|
serialize_atom_name(name, dest)
|
||||||
|
},
|
||||||
|
TransitionProperty::Unsupported(ref i) => i.to_css(dest),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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(..) => {
|
||||||
|
return Ok(TransitionProperty::Unsupported(CustomIdent::from_ident(
|
||||||
|
location,
|
||||||
|
ident,
|
||||||
|
&["none"],
|
||||||
|
)?));
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(match id.as_shorthand() {
|
||||||
|
Ok(s) => TransitionProperty::Shorthand(s),
|
||||||
|
Err(longhand_or_custom) => match longhand_or_custom {
|
||||||
|
PropertyDeclarationId::Longhand(id) => TransitionProperty::Longhand(id),
|
||||||
|
PropertyDeclarationId::Custom(custom) => TransitionProperty::Custom(custom.clone()),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TransitionProperty {
|
||||||
|
/// Returns `all`.
|
||||||
|
#[inline]
|
||||||
|
pub fn all() -> Self {
|
||||||
|
TransitionProperty::Shorthand(ShorthandId::All)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Convert TransitionProperty to nsCSSPropertyID.
|
||||||
|
#[cfg(feature = "gecko")]
|
||||||
|
pub fn to_nscsspropertyid(
|
||||||
|
&self,
|
||||||
|
) -> Result<crate::gecko_bindings::structs::nsCSSPropertyID, ()> {
|
||||||
|
Ok(match *self {
|
||||||
|
TransitionProperty::Shorthand(ShorthandId::All) => {
|
||||||
|
crate::gecko_bindings::structs::nsCSSPropertyID::eCSSPropertyExtra_all_properties
|
||||||
|
},
|
||||||
|
TransitionProperty::Shorthand(ref id) => id.to_nscsspropertyid(),
|
||||||
|
TransitionProperty::Longhand(ref id) => id.to_nscsspropertyid(),
|
||||||
|
TransitionProperty::Custom(..) | TransitionProperty::Unsupported(..) => return Err(()),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// https://drafts.csswg.org/css-animations/#animation-iteration-count
|
||||||
|
#[derive(Clone, Debug, MallocSizeOf, PartialEq, Parse, SpecifiedValueInfo, ToCss, ToShmem)]
|
||||||
|
pub enum AnimationIterationCount {
|
||||||
|
/// A `<number>` value.
|
||||||
|
Number(NonNegativeNumber),
|
||||||
|
/// The `infinite` keyword.
|
||||||
|
Infinite,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AnimationIterationCount {
|
||||||
|
/// Returns the value `1.0`.
|
||||||
|
#[inline]
|
||||||
|
pub fn one() -> Self {
|
||||||
|
Self::Number(NonNegativeNumber::new(1.0))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 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)]
|
||||||
|
pub struct AnimationName(pub KeyframesName);
|
||||||
|
|
||||||
|
impl AnimationName {
|
||||||
|
/// Get the name of the animation as an `Atom`.
|
||||||
|
pub fn as_atom(&self) -> Option<&Atom> {
|
||||||
|
if self.is_none() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
Some(self.0.as_atom())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns the `none` value.
|
||||||
|
pub fn none() -> Self {
|
||||||
|
AnimationName(KeyframesName::none())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns whether this is the none value.
|
||||||
|
pub fn is_none(&self) -> bool {
|
||||||
|
self.0.is_none()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Parse for AnimationName {
|
||||||
|
fn parse<'i, 't>(
|
||||||
|
context: &ParserContext,
|
||||||
|
input: &mut Parser<'i, 't>,
|
||||||
|
) -> Result<Self, ParseError<'i>> {
|
||||||
|
if let Ok(name) = input.try_parse(|input| KeyframesName::parse(context, input)) {
|
||||||
|
return Ok(AnimationName(name));
|
||||||
|
}
|
||||||
|
|
||||||
|
input.expect_ident_matching("none")?;
|
||||||
|
Ok(AnimationName(KeyframesName::none()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A value for the <Scroller> used in scroll().
|
||||||
|
///
|
||||||
|
/// https://drafts.csswg.org/scroll-animations-1/rewrite#typedef-scroller
|
||||||
|
#[derive(
|
||||||
|
Clone,
|
||||||
|
Debug,
|
||||||
|
Eq,
|
||||||
|
Hash,
|
||||||
|
MallocSizeOf,
|
||||||
|
Parse,
|
||||||
|
PartialEq,
|
||||||
|
SpecifiedValueInfo,
|
||||||
|
ToComputedValue,
|
||||||
|
ToCss,
|
||||||
|
ToResolvedValue,
|
||||||
|
ToShmem,
|
||||||
|
)]
|
||||||
|
#[repr(u8)]
|
||||||
|
pub enum Scroller {
|
||||||
|
/// The nearest ancestor scroll container. (Default.)
|
||||||
|
Nearest,
|
||||||
|
/// The document viewport as the scroll container.
|
||||||
|
Root,
|
||||||
|
// FIXME: Bug 1764450: Once we support container-name CSS property (Bug 1744224), we may add
|
||||||
|
// <custom-ident> here, based on the result of the spec issue:
|
||||||
|
// https://github.com/w3c/csswg-drafts/issues/7046
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for Scroller {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::Nearest
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A value for the <Axis> used in scroll(), or a value for {scroll|view}-timeline-axis.
|
||||||
|
///
|
||||||
|
/// https://drafts.csswg.org/scroll-animations-1/#typedef-axis
|
||||||
|
/// https://drafts.csswg.org/scroll-animations-1/#scroll-timeline-axis
|
||||||
|
/// https://drafts.csswg.org/scroll-animations-1/#view-timeline-axis
|
||||||
|
#[derive(
|
||||||
|
Clone,
|
||||||
|
Debug,
|
||||||
|
Eq,
|
||||||
|
Hash,
|
||||||
|
MallocSizeOf,
|
||||||
|
Parse,
|
||||||
|
PartialEq,
|
||||||
|
SpecifiedValueInfo,
|
||||||
|
ToComputedValue,
|
||||||
|
ToCss,
|
||||||
|
ToResolvedValue,
|
||||||
|
ToShmem,
|
||||||
|
)]
|
||||||
|
#[repr(u8)]
|
||||||
|
pub enum ScrollAxis {
|
||||||
|
/// The block axis of the scroll container. (Default.)
|
||||||
|
Block = 0,
|
||||||
|
/// The inline axis of the scroll container.
|
||||||
|
Inline = 1,
|
||||||
|
/// The vertical block axis of the scroll container.
|
||||||
|
Vertical = 2,
|
||||||
|
/// The horizontal axis of the scroll container.
|
||||||
|
Horizontal = 3,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for ScrollAxis {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::Block
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn is_default<T: Default + PartialEq>(value: &T) -> bool {
|
||||||
|
*value == Default::default()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A value for the <single-animation-timeline>.
|
||||||
|
///
|
||||||
|
/// https://drafts.csswg.org/css-animations-2/#typedef-single-animation-timeline
|
||||||
|
#[derive(
|
||||||
|
Clone,
|
||||||
|
Debug,
|
||||||
|
Eq,
|
||||||
|
Hash,
|
||||||
|
MallocSizeOf,
|
||||||
|
PartialEq,
|
||||||
|
SpecifiedValueInfo,
|
||||||
|
ToComputedValue,
|
||||||
|
ToCss,
|
||||||
|
ToResolvedValue,
|
||||||
|
ToShmem,
|
||||||
|
)]
|
||||||
|
#[repr(C, u8)]
|
||||||
|
pub enum AnimationTimeline {
|
||||||
|
/// Use default timeline. The animation’s timeline is a DocumentTimeline.
|
||||||
|
Auto,
|
||||||
|
/// The scroll-timeline name or view-timeline-name.
|
||||||
|
/// https://drafts.csswg.org/scroll-animations-1/#scroll-timelines-named
|
||||||
|
/// https://drafts.csswg.org/scroll-animations-1/#view-timeline-name
|
||||||
|
Timeline(TimelineName),
|
||||||
|
/// The scroll() notation.
|
||||||
|
/// https://drafts.csswg.org/scroll-animations-1/#scroll-notation
|
||||||
|
#[css(function)]
|
||||||
|
Scroll(
|
||||||
|
#[css(skip_if = "is_default")] ScrollAxis,
|
||||||
|
#[css(skip_if = "is_default")] Scroller,
|
||||||
|
),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AnimationTimeline {
|
||||||
|
/// Returns the `auto` value.
|
||||||
|
pub fn auto() -> Self {
|
||||||
|
Self::Auto
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns true if it is auto (i.e. the default value).
|
||||||
|
pub fn is_auto(&self) -> bool {
|
||||||
|
matches!(self, Self::Auto)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Parse for AnimationTimeline {
|
||||||
|
fn parse<'i, 't>(
|
||||||
|
context: &ParserContext,
|
||||||
|
input: &mut Parser<'i, 't>,
|
||||||
|
) -> Result<Self, ParseError<'i>> {
|
||||||
|
if input.try_parse(|i| i.expect_ident_matching("auto")).is_ok() {
|
||||||
|
return Ok(Self::Auto);
|
||||||
|
}
|
||||||
|
|
||||||
|
if input.try_parse(|i| i.expect_ident_matching("none")).is_ok() {
|
||||||
|
return Ok(AnimationTimeline::Timeline(TimelineName::none()));
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://drafts.csswg.org/scroll-animations-1/#scroll-notation
|
||||||
|
if input
|
||||||
|
.try_parse(|i| i.expect_function_matching("scroll"))
|
||||||
|
.is_ok()
|
||||||
|
{
|
||||||
|
return input.parse_nested_block(|i| {
|
||||||
|
Ok(Self::Scroll(
|
||||||
|
i.try_parse(ScrollAxis::parse).unwrap_or(ScrollAxis::Block),
|
||||||
|
i.try_parse(Scroller::parse).unwrap_or(Scroller::Nearest),
|
||||||
|
))
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
TimelineName::parse(context, input).map(AnimationTimeline::Timeline)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A value for the scroll-timeline-name or view-timeline-name.
|
||||||
|
pub type ScrollTimelineName = AnimationName;
|
||||||
|
|
||||||
|
/// A specified value for the `view-timeline-inset` property.
|
||||||
|
pub type ViewTimelineInset = generics::GenericViewTimelineInset<LengthPercentage>;
|
||||||
|
|
||||||
|
impl Parse for ViewTimelineInset {
|
||||||
|
fn parse<'i, 't>(
|
||||||
|
context: &ParserContext,
|
||||||
|
input: &mut Parser<'i, 't>,
|
||||||
|
) -> Result<Self, ParseError<'i>> {
|
||||||
|
use crate::values::specified::LengthPercentageOrAuto;
|
||||||
|
|
||||||
|
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 })
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,18 +4,15 @@
|
||||||
|
|
||||||
//! Specified types for box properties.
|
//! Specified types for box properties.
|
||||||
|
|
||||||
use crate::custom_properties::Name as CustomPropertyName;
|
|
||||||
use crate::parser::{Parse, ParserContext};
|
use crate::parser::{Parse, ParserContext};
|
||||||
use crate::properties::{LonghandId, PropertyDeclarationId};
|
use crate::properties::{LonghandId, PropertyDeclarationId, PropertyId};
|
||||||
use crate::properties::{PropertyId, ShorthandId};
|
|
||||||
use crate::values::generics::box_::{
|
use crate::values::generics::box_::{
|
||||||
GenericLineClamp, GenericPerspective, GenericContainIntrinsicSize, GenericVerticalAlign,
|
GenericLineClamp, GenericPerspective, GenericContainIntrinsicSize, GenericVerticalAlign,
|
||||||
VerticalAlignKeyword,
|
VerticalAlignKeyword,
|
||||||
};
|
};
|
||||||
use crate::values::specified::length::{LengthPercentage, NonNegativeLength};
|
use crate::values::specified::length::{LengthPercentage, NonNegativeLength};
|
||||||
use crate::values::specified::{AllowQuirks, Integer, NonNegativeNumber};
|
use crate::values::specified::{AllowQuirks, Integer};
|
||||||
use crate::values::{CustomIdent, KeyframesName, TimelineName};
|
use crate::values::CustomIdent;
|
||||||
use crate::Atom;
|
|
||||||
use cssparser::Parser;
|
use cssparser::Parser;
|
||||||
use num_traits::FromPrimitive;
|
use num_traits::FromPrimitive;
|
||||||
use std::fmt::{self, Debug, Formatter, Write};
|
use std::fmt::{self, Debug, Formatter, Write};
|
||||||
|
@ -606,229 +603,6 @@ impl Parse for VerticalAlign {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// https://drafts.csswg.org/css-animations/#animation-iteration-count
|
|
||||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq, Parse, SpecifiedValueInfo, ToCss, ToShmem)]
|
|
||||||
pub enum AnimationIterationCount {
|
|
||||||
/// A `<number>` value.
|
|
||||||
Number(NonNegativeNumber),
|
|
||||||
/// The `infinite` keyword.
|
|
||||||
Infinite,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl AnimationIterationCount {
|
|
||||||
/// Returns the value `1.0`.
|
|
||||||
#[inline]
|
|
||||||
pub fn one() -> Self {
|
|
||||||
Self::Number(NonNegativeNumber::new(1.0))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 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)]
|
|
||||||
pub struct AnimationName(pub KeyframesName);
|
|
||||||
|
|
||||||
impl AnimationName {
|
|
||||||
/// Get the name of the animation as an `Atom`.
|
|
||||||
pub fn as_atom(&self) -> Option<&Atom> {
|
|
||||||
if self.is_none() {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
Some(self.0.as_atom())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the `none` value.
|
|
||||||
pub fn none() -> Self {
|
|
||||||
AnimationName(KeyframesName::none())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns whether this is the none value.
|
|
||||||
pub fn is_none(&self) -> bool {
|
|
||||||
self.0.is_none()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Parse for AnimationName {
|
|
||||||
fn parse<'i, 't>(
|
|
||||||
context: &ParserContext,
|
|
||||||
input: &mut Parser<'i, 't>,
|
|
||||||
) -> Result<Self, ParseError<'i>> {
|
|
||||||
if let Ok(name) = input.try_parse(|input| KeyframesName::parse(context, input)) {
|
|
||||||
return Ok(AnimationName(name));
|
|
||||||
}
|
|
||||||
|
|
||||||
input.expect_ident_matching("none")?;
|
|
||||||
Ok(AnimationName(KeyframesName::none()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A value for the <Scroller> used in scroll().
|
|
||||||
///
|
|
||||||
/// https://drafts.csswg.org/scroll-animations-1/rewrite#typedef-scroller
|
|
||||||
#[derive(
|
|
||||||
Clone,
|
|
||||||
Debug,
|
|
||||||
Eq,
|
|
||||||
Hash,
|
|
||||||
MallocSizeOf,
|
|
||||||
Parse,
|
|
||||||
PartialEq,
|
|
||||||
SpecifiedValueInfo,
|
|
||||||
ToComputedValue,
|
|
||||||
ToCss,
|
|
||||||
ToResolvedValue,
|
|
||||||
ToShmem,
|
|
||||||
)]
|
|
||||||
#[repr(u8)]
|
|
||||||
pub enum Scroller {
|
|
||||||
/// The nearest ancestor scroll container. (Default.)
|
|
||||||
Nearest,
|
|
||||||
/// The document viewport as the scroll container.
|
|
||||||
Root,
|
|
||||||
// FIXME: Bug 1764450: Once we support container-name CSS property (Bug 1744224), we may add
|
|
||||||
// <custom-ident> here, based on the result of the spec issue:
|
|
||||||
// https://github.com/w3c/csswg-drafts/issues/7046
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for Scroller {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self::Nearest
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A value for the <Axis> used in scroll(), or a value for {scroll|view}-timeline-axis.
|
|
||||||
///
|
|
||||||
/// https://drafts.csswg.org/scroll-animations-1/#typedef-axis
|
|
||||||
/// https://drafts.csswg.org/scroll-animations-1/#scroll-timeline-axis
|
|
||||||
/// https://drafts.csswg.org/scroll-animations-1/#view-timeline-axis
|
|
||||||
#[derive(
|
|
||||||
Clone,
|
|
||||||
Debug,
|
|
||||||
Eq,
|
|
||||||
Hash,
|
|
||||||
MallocSizeOf,
|
|
||||||
Parse,
|
|
||||||
PartialEq,
|
|
||||||
SpecifiedValueInfo,
|
|
||||||
ToComputedValue,
|
|
||||||
ToCss,
|
|
||||||
ToResolvedValue,
|
|
||||||
ToShmem,
|
|
||||||
)]
|
|
||||||
#[repr(u8)]
|
|
||||||
pub enum ScrollAxis {
|
|
||||||
/// The block axis of the scroll container. (Default.)
|
|
||||||
Block = 0,
|
|
||||||
/// The inline axis of the scroll container.
|
|
||||||
Inline = 1,
|
|
||||||
/// The vertical block axis of the scroll container.
|
|
||||||
Vertical = 2,
|
|
||||||
/// The horizontal axis of the scroll container.
|
|
||||||
Horizontal = 3,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for ScrollAxis {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self::Block
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn is_default<T: Default + PartialEq>(value: &T) -> bool {
|
|
||||||
*value == Default::default()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A value for the <single-animation-timeline>.
|
|
||||||
///
|
|
||||||
/// https://drafts.csswg.org/css-animations-2/#typedef-single-animation-timeline
|
|
||||||
#[derive(
|
|
||||||
Clone,
|
|
||||||
Debug,
|
|
||||||
Eq,
|
|
||||||
Hash,
|
|
||||||
MallocSizeOf,
|
|
||||||
PartialEq,
|
|
||||||
SpecifiedValueInfo,
|
|
||||||
ToComputedValue,
|
|
||||||
ToCss,
|
|
||||||
ToResolvedValue,
|
|
||||||
ToShmem,
|
|
||||||
)]
|
|
||||||
#[repr(C, u8)]
|
|
||||||
pub enum AnimationTimeline {
|
|
||||||
/// Use default timeline. The animation’s timeline is a DocumentTimeline.
|
|
||||||
Auto,
|
|
||||||
/// The scroll-timeline name or view-timeline-name.
|
|
||||||
/// https://drafts.csswg.org/scroll-animations-1/#scroll-timelines-named
|
|
||||||
/// https://drafts.csswg.org/scroll-animations-1/#view-timeline-name
|
|
||||||
Timeline(TimelineName),
|
|
||||||
/// The scroll() notation.
|
|
||||||
/// https://drafts.csswg.org/scroll-animations-1/#scroll-notation
|
|
||||||
#[css(function)]
|
|
||||||
Scroll(
|
|
||||||
#[css(skip_if = "is_default")] ScrollAxis,
|
|
||||||
#[css(skip_if = "is_default")] Scroller,
|
|
||||||
),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl AnimationTimeline {
|
|
||||||
/// Returns the `auto` value.
|
|
||||||
pub fn auto() -> Self {
|
|
||||||
Self::Auto
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns true if it is auto (i.e. the default value).
|
|
||||||
pub fn is_auto(&self) -> bool {
|
|
||||||
matches!(self, Self::Auto)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Parse for AnimationTimeline {
|
|
||||||
fn parse<'i, 't>(
|
|
||||||
context: &ParserContext,
|
|
||||||
input: &mut Parser<'i, 't>,
|
|
||||||
) -> Result<Self, ParseError<'i>> {
|
|
||||||
if input.try_parse(|i| i.expect_ident_matching("auto")).is_ok() {
|
|
||||||
return Ok(Self::Auto);
|
|
||||||
}
|
|
||||||
|
|
||||||
if input.try_parse(|i| i.expect_ident_matching("none")).is_ok() {
|
|
||||||
return Ok(AnimationTimeline::Timeline(TimelineName::none()));
|
|
||||||
}
|
|
||||||
|
|
||||||
// https://drafts.csswg.org/scroll-animations-1/#scroll-notation
|
|
||||||
if input
|
|
||||||
.try_parse(|i| i.expect_function_matching("scroll"))
|
|
||||||
.is_ok()
|
|
||||||
{
|
|
||||||
return input.parse_nested_block(|i| {
|
|
||||||
Ok(Self::Scroll(
|
|
||||||
i.try_parse(ScrollAxis::parse).unwrap_or(ScrollAxis::Block),
|
|
||||||
i.try_parse(Scroller::parse).unwrap_or(Scroller::Nearest),
|
|
||||||
))
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
TimelineName::parse(context, input).map(AnimationTimeline::Timeline)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A value for the scroll-timeline-name or view-timeline-name.
|
|
||||||
pub type ScrollTimelineName = AnimationName;
|
|
||||||
|
|
||||||
/// https://drafts.csswg.org/css-scroll-snap-1/#snap-axis
|
/// https://drafts.csswg.org/css-scroll-snap-1/#snap-axis
|
||||||
#[allow(missing_docs)]
|
#[allow(missing_docs)]
|
||||||
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
|
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
|
||||||
|
@ -1501,102 +1275,6 @@ impl Parse for ContainerName {
|
||||||
/// A specified value for the `perspective` property.
|
/// A specified value for the `perspective` property.
|
||||||
pub type Perspective = GenericPerspective<NonNegativeLength>;
|
pub type Perspective = GenericPerspective<NonNegativeLength>;
|
||||||
|
|
||||||
/// 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,
|
|
||||||
)]
|
|
||||||
pub enum TransitionProperty {
|
|
||||||
/// A shorthand.
|
|
||||||
Shorthand(ShorthandId),
|
|
||||||
/// A longhand transitionable property.
|
|
||||||
Longhand(LonghandId),
|
|
||||||
/// A custom property.
|
|
||||||
Custom(CustomPropertyName),
|
|
||||||
/// Unrecognized property which could be any non-transitionable, custom property, or
|
|
||||||
/// unknown property.
|
|
||||||
Unsupported(CustomIdent),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ToCss for TransitionProperty {
|
|
||||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
|
||||||
where
|
|
||||||
W: Write,
|
|
||||||
{
|
|
||||||
use crate::values::serialize_atom_name;
|
|
||||||
match *self {
|
|
||||||
TransitionProperty::Shorthand(ref s) => s.to_css(dest),
|
|
||||||
TransitionProperty::Longhand(ref l) => l.to_css(dest),
|
|
||||||
TransitionProperty::Custom(ref name) => {
|
|
||||||
dest.write_str("--")?;
|
|
||||||
serialize_atom_name(name, dest)
|
|
||||||
},
|
|
||||||
TransitionProperty::Unsupported(ref i) => i.to_css(dest),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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(..) => {
|
|
||||||
return Ok(TransitionProperty::Unsupported(CustomIdent::from_ident(
|
|
||||||
location,
|
|
||||||
ident,
|
|
||||||
&["none"],
|
|
||||||
)?));
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(match id.as_shorthand() {
|
|
||||||
Ok(s) => TransitionProperty::Shorthand(s),
|
|
||||||
Err(longhand_or_custom) => match longhand_or_custom {
|
|
||||||
PropertyDeclarationId::Longhand(id) => TransitionProperty::Longhand(id),
|
|
||||||
PropertyDeclarationId::Custom(custom) => TransitionProperty::Custom(custom.clone()),
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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"]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TransitionProperty {
|
|
||||||
/// Returns `all`.
|
|
||||||
#[inline]
|
|
||||||
pub fn all() -> Self {
|
|
||||||
TransitionProperty::Shorthand(ShorthandId::All)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Convert TransitionProperty to nsCSSPropertyID.
|
|
||||||
#[cfg(feature = "gecko")]
|
|
||||||
pub fn to_nscsspropertyid(
|
|
||||||
&self,
|
|
||||||
) -> Result<crate::gecko_bindings::structs::nsCSSPropertyID, ()> {
|
|
||||||
Ok(match *self {
|
|
||||||
TransitionProperty::Shorthand(ShorthandId::All) => {
|
|
||||||
crate::gecko_bindings::structs::nsCSSPropertyID::eCSSPropertyExtra_all_properties
|
|
||||||
},
|
|
||||||
TransitionProperty::Shorthand(ref id) => id.to_nscsspropertyid(),
|
|
||||||
TransitionProperty::Longhand(ref id) => id.to_nscsspropertyid(),
|
|
||||||
TransitionProperty::Custom(..) | TransitionProperty::Unsupported(..) => return Err(()),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(missing_docs)]
|
#[allow(missing_docs)]
|
||||||
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
|
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
|
||||||
#[derive(
|
#[derive(
|
||||||
|
|
|
@ -36,22 +36,24 @@ pub use self::basic_shape::FillRule;
|
||||||
pub use self::border::{BorderCornerRadius, BorderImageSlice, BorderImageWidth};
|
pub use self::border::{BorderCornerRadius, BorderImageSlice, BorderImageWidth};
|
||||||
pub use self::border::{BorderImageRepeat, BorderImageSideWidth};
|
pub use self::border::{BorderImageRepeat, BorderImageSideWidth};
|
||||||
pub use self::border::{BorderRadius, BorderSideWidth, BorderSpacing, BorderStyle};
|
pub use self::border::{BorderRadius, BorderSideWidth, BorderSpacing, BorderStyle};
|
||||||
pub use self::box_::{AnimationIterationCount, AnimationName, AnimationTimeline, Contain, Display};
|
|
||||||
pub use self::box_::{Appearance, BreakBetween, BreakWithin, ContainerName, ContainerType};
|
pub use self::box_::{Appearance, BreakBetween, BreakWithin, ContainerName, ContainerType};
|
||||||
pub use self::box_::{
|
pub use self::box_::{
|
||||||
Clear, ContainIntrinsicSize, ContentVisibility, Float, LineClamp, Overflow, OverflowAnchor,
|
Clear, ContainIntrinsicSize, ContentVisibility, Float, LineClamp, Overflow, OverflowAnchor,
|
||||||
};
|
};
|
||||||
|
pub use self::box_::{Contain, Display};
|
||||||
pub use self::box_::{OverflowClipBox, OverscrollBehavior, Perspective, Resize, ScrollbarGutter};
|
pub use self::box_::{OverflowClipBox, OverscrollBehavior, Perspective, Resize, ScrollbarGutter};
|
||||||
pub use self::box_::{ScrollAxis, ScrollSnapAlign, ScrollSnapAxis, ScrollSnapStop};
|
pub use self::box_::{ScrollSnapAlign, ScrollSnapAxis, ScrollSnapStop};
|
||||||
pub use self::box_::{ScrollSnapStrictness, ScrollSnapType, ScrollTimelineName};
|
pub use self::box_::{ScrollSnapStrictness, ScrollSnapType};
|
||||||
pub use self::box_::{TouchAction, TransitionProperty, VerticalAlign, WillChange};
|
pub use self::box_::{TouchAction, VerticalAlign, WillChange};
|
||||||
pub use self::color::{Color, ColorOrAuto, ColorPropertyValue, ColorScheme, PrintColorAdjust, ForcedColorAdjust};
|
pub use self::color::{
|
||||||
|
Color, ColorOrAuto, ColorPropertyValue, ColorScheme, ForcedColorAdjust, PrintColorAdjust,
|
||||||
|
};
|
||||||
pub use self::column::ColumnCount;
|
pub use self::column::ColumnCount;
|
||||||
pub use self::counters::{Content, ContentItem, CounterIncrement, CounterReset, CounterSet};
|
pub use self::counters::{Content, ContentItem, CounterIncrement, CounterReset, CounterSet};
|
||||||
pub use self::easing::TimingFunction;
|
pub use self::easing::TimingFunction;
|
||||||
pub use self::effects::{BoxShadow, Filter, SimpleShadow};
|
pub use self::effects::{BoxShadow, Filter, SimpleShadow};
|
||||||
pub use self::flex::FlexBasis;
|
pub use self::flex::FlexBasis;
|
||||||
pub use self::font::{FontFamily, FontLanguageOverride, FontStyle, FontPalette};
|
pub use self::font::{FontFamily, FontLanguageOverride, FontPalette, FontStyle};
|
||||||
pub use self::font::{FontFeatureSettings, FontVariantLigatures, FontVariantNumeric};
|
pub use self::font::{FontFeatureSettings, FontVariantLigatures, FontVariantNumeric};
|
||||||
pub use self::font::{FontSize, FontSizeAdjust, FontSizeKeyword, FontStretch, FontSynthesis};
|
pub use self::font::{FontSize, FontSizeAdjust, FontSizeKeyword, FontStretch, FontSynthesis};
|
||||||
pub use self::font::{FontVariantAlternates, FontWeight};
|
pub use self::font::{FontVariantAlternates, FontWeight};
|
||||||
|
@ -75,10 +77,8 @@ pub use self::outline::OutlineStyle;
|
||||||
pub use self::page::{PageName, PageOrientation, PageSize, PageSizeOrientation, PaperSize};
|
pub use self::page::{PageName, PageOrientation, PageSize, PageSizeOrientation, PaperSize};
|
||||||
pub use self::percentage::{NonNegativePercentage, Percentage};
|
pub use self::percentage::{NonNegativePercentage, Percentage};
|
||||||
pub use self::position::AspectRatio;
|
pub use self::position::AspectRatio;
|
||||||
pub use self::position::{
|
pub use self::position::{GridAutoFlow, GridTemplateAreas, Position, PositionOrAuto};
|
||||||
GridAutoFlow, GridTemplateAreas, Position, PositionOrAuto,
|
pub use self::position::{MasonryAutoFlow, MasonryItemOrder, MasonryPlacement};
|
||||||
};
|
|
||||||
pub use self::position::{MasonryAutoFlow, MasonryPlacement, MasonryItemOrder};
|
|
||||||
pub use self::position::{PositionComponent, ZIndex};
|
pub use self::position::{PositionComponent, ZIndex};
|
||||||
pub use self::ratio::Ratio;
|
pub use self::ratio::Ratio;
|
||||||
pub use self::rect::NonNegativeLengthOrNumberRect;
|
pub use self::rect::NonNegativeLengthOrNumberRect;
|
||||||
|
@ -100,12 +100,15 @@ pub use self::transform::{Rotate, Scale, Transform};
|
||||||
pub use self::transform::{TransformOrigin, TransformStyle, Translate};
|
pub use self::transform::{TransformOrigin, TransformStyle, Translate};
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
pub use self::ui::CursorImage;
|
pub use self::ui::CursorImage;
|
||||||
pub use self::ui::{BoolInteger, Cursor, UserSelect, ViewTimelineInset};
|
pub use self::ui::{BoolInteger, Cursor, UserSelect};
|
||||||
|
pub use self::animation::{AnimationIterationCount, AnimationName, AnimationTimeline};
|
||||||
|
pub use self::animation::{ScrollAxis, ScrollTimelineName, TransitionProperty, ViewTimelineInset};
|
||||||
pub use super::generics::grid::GridTemplateComponent as GenericGridTemplateComponent;
|
pub use super::generics::grid::GridTemplateComponent as GenericGridTemplateComponent;
|
||||||
|
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
pub mod align;
|
pub mod align;
|
||||||
pub mod angle;
|
pub mod angle;
|
||||||
|
pub mod animation;
|
||||||
pub mod background;
|
pub mod background;
|
||||||
pub mod basic_shape;
|
pub mod basic_shape;
|
||||||
pub mod border;
|
pub mod border;
|
||||||
|
|
|
@ -8,7 +8,7 @@ use crate::parser::{Parse, ParserContext};
|
||||||
use crate::values::generics::ui as generics;
|
use crate::values::generics::ui as generics;
|
||||||
use crate::values::specified::color::Color;
|
use crate::values::specified::color::Color;
|
||||||
use crate::values::specified::image::Image;
|
use crate::values::specified::image::Image;
|
||||||
use crate::values::specified::{LengthPercentage, Number};
|
use crate::values::specified::Number;
|
||||||
use cssparser::Parser;
|
use cssparser::Parser;
|
||||||
use std::fmt::{self, Write};
|
use std::fmt::{self, Write};
|
||||||
use style_traits::{
|
use style_traits::{
|
||||||
|
@ -230,23 +230,3 @@ pub enum CursorKind {
|
||||||
ZoomOut,
|
ZoomOut,
|
||||||
Auto,
|
Auto,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A specified value for the `view-timeline-inset` property.
|
|
||||||
pub type ViewTimelineInset = generics::GenericViewTimelineInset<LengthPercentage>;
|
|
||||||
|
|
||||||
impl Parse for ViewTimelineInset {
|
|
||||||
fn parse<'i, 't>(
|
|
||||||
context: &ParserContext,
|
|
||||||
input: &mut Parser<'i, 't>,
|
|
||||||
) -> Result<Self, ParseError<'i>> {
|
|
||||||
use crate::values::specified::LengthPercentageOrAuto;
|
|
||||||
|
|
||||||
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 })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue