style/values/computed/
motion.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5//! Computed types for CSS values that are related to motion path.
6
7use crate::derives::*;
8use crate::values::computed::basic_shape::BasicShape;
9use crate::values::computed::url::ComputedUrl;
10use crate::values::computed::{Angle, LengthPercentage, Position};
11use crate::values::generics::motion::{
12    GenericOffsetPath, GenericOffsetPathFunction, GenericOffsetPosition, GenericRayFunction,
13};
14use crate::Zero;
15
16/// The computed value of ray() function.
17pub type RayFunction = GenericRayFunction<Angle, Position>;
18
19/// The computed value of <offset-path>.
20pub type OffsetPathFunction = GenericOffsetPathFunction<BasicShape, RayFunction, ComputedUrl>;
21
22/// The computed value of `offset-path`.
23pub type OffsetPath = GenericOffsetPath<OffsetPathFunction>;
24
25/// The computed value of `offset-position`.
26pub type OffsetPosition = GenericOffsetPosition<LengthPercentage, LengthPercentage>;
27
28#[inline]
29fn is_auto_zero_angle(auto: &bool, angle: &Angle) -> bool {
30    *auto && angle.is_zero()
31}
32
33/// A computed offset-rotate.
34#[derive(
35    Animate,
36    Clone,
37    ComputeSquaredDistance,
38    Copy,
39    Debug,
40    Deserialize,
41    MallocSizeOf,
42    PartialEq,
43    Serialize,
44    ToAnimatedValue,
45    ToAnimatedZero,
46    ToCss,
47    ToResolvedValue,
48    ToTyped,
49)]
50#[repr(C)]
51pub struct OffsetRotate {
52    /// If auto is false, this is a fixed angle which indicates a
53    /// constant clockwise rotation transformation applied to it by this
54    /// specified rotation angle. Otherwise, the angle will be added to
55    /// the angle of the direction in layout.
56    #[animation(constant)]
57    #[css(represents_keyword)]
58    pub auto: bool,
59    /// The angle value.
60    #[css(contextual_skip_if = "is_auto_zero_angle")]
61    pub angle: Angle,
62}
63
64impl OffsetRotate {
65    /// Returns "auto 0deg".
66    #[inline]
67    pub fn auto() -> Self {
68        OffsetRotate {
69            auto: true,
70            angle: Zero::zero(),
71        }
72    }
73}