Skip to main content

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)]
51#[typed(todo_derive_fields)]
52pub struct OffsetRotate {
53    /// If auto is false, this is a fixed angle which indicates a
54    /// constant clockwise rotation transformation applied to it by this
55    /// specified rotation angle. Otherwise, the angle will be added to
56    /// the angle of the direction in layout.
57    #[animation(constant)]
58    #[css(represents_keyword)]
59    pub auto: bool,
60    /// The angle value.
61    #[css(contextual_skip_if = "is_auto_zero_angle")]
62    pub angle: Angle,
63}
64
65impl OffsetRotate {
66    /// Returns "auto 0deg".
67    #[inline]
68    pub fn auto() -> Self {
69        OffsetRotate {
70            auto: true,
71            angle: Zero::zero(),
72        }
73    }
74}