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::values::computed::basic_shape::BasicShape;
8use crate::values::computed::url::ComputedUrl;
9use crate::values::computed::{Angle, LengthPercentage, Position};
10use crate::values::generics::motion::{
11    GenericOffsetPath, GenericOffsetPathFunction, GenericOffsetPosition, GenericRayFunction,
12};
13use crate::Zero;
14
15/// The computed value of ray() function.
16pub type RayFunction = GenericRayFunction<Angle, Position>;
17
18/// The computed value of <offset-path>.
19pub type OffsetPathFunction = GenericOffsetPathFunction<BasicShape, RayFunction, ComputedUrl>;
20
21/// The computed value of `offset-path`.
22pub type OffsetPath = GenericOffsetPath<OffsetPathFunction>;
23
24/// The computed value of `offset-position`.
25pub type OffsetPosition = GenericOffsetPosition<LengthPercentage, LengthPercentage>;
26
27#[inline]
28fn is_auto_zero_angle(auto: &bool, angle: &Angle) -> bool {
29    *auto && angle.is_zero()
30}
31
32/// A computed offset-rotate.
33#[derive(
34    Animate,
35    Clone,
36    ComputeSquaredDistance,
37    Copy,
38    Debug,
39    Deserialize,
40    MallocSizeOf,
41    PartialEq,
42    Serialize,
43    ToAnimatedValue,
44    ToAnimatedZero,
45    ToCss,
46    ToResolvedValue,
47)]
48#[repr(C)]
49pub struct OffsetRotate {
50    /// If auto is false, this is a fixed angle which indicates a
51    /// constant clockwise rotation transformation applied to it by this
52    /// specified rotation angle. Otherwise, the angle will be added to
53    /// the angle of the direction in layout.
54    #[animation(constant)]
55    #[css(represents_keyword)]
56    pub auto: bool,
57    /// The angle value.
58    #[css(contextual_skip_if = "is_auto_zero_angle")]
59    pub angle: Angle,
60}
61
62impl OffsetRotate {
63    /// Returns "auto 0deg".
64    #[inline]
65    pub fn auto() -> Self {
66        OffsetRotate {
67            auto: true,
68            angle: Zero::zero(),
69        }
70    }
71}