mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
style: Support ray() in offset-path and make it animatable.
1. Add `generics::motion::OffsetPath`, and use specified `Angle` and computed `Angle` to define specified `OffsetPath` and computed `OffsetPath`. 2. Add `ray` function into `OffsetPath`. We also tweak the degree from 150deg to 135deg in wpt (e.g. offset-path-ray-001.html and others) to avoid floating point precision issues. For example: ``` // offset-path: ray(150deg ...); // offset-distance: 20px; matrix: { {0.500000 0.866025 0.000000 0.000000}, {-0.866025 0.500000 0.000000 0.000000}, {0.000000 0.000000 1.000000 0.000000}, {10.000000 17.320509 0.000000 1.000000} } // rotate(60deg) translate(20px) matrix: { {0.500000 0.866025 0.000000 0.000000}, {-0.866025 0.500000 0.000000 0.000000}, {0.000000 0.000000 1.000000 0.000000}, {10.000000 17.320507 0.000000 1.000000} } ``` Their translate parts, 17.320509 vs 17.320507, are almost the same (only tiny difference), which may cause the reftest failed. Differential Revision: https://phabricator.services.mozilla.com/D42721
This commit is contained in:
parent
35a98af0ed
commit
5e77ba9bf4
5 changed files with 172 additions and 53 deletions
110
components/style/values/generics/motion.rs
Normal file
110
components/style/values/generics/motion.rs
Normal file
|
@ -0,0 +1,110 @@
|
|||
/* 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 types for CSS Motion Path.
|
||||
|
||||
use crate::values::specified::SVGPathData;
|
||||
|
||||
/// The <size> in ray() function.
|
||||
///
|
||||
/// https://drafts.fxtf.org/motion-1/#valdef-offsetpath-size
|
||||
#[allow(missing_docs)]
|
||||
#[derive(
|
||||
Clone,
|
||||
Copy,
|
||||
Debug,
|
||||
MallocSizeOf,
|
||||
Parse,
|
||||
PartialEq,
|
||||
SpecifiedValueInfo,
|
||||
ToAnimatedZero,
|
||||
ToComputedValue,
|
||||
ToCss,
|
||||
ToResolvedValue,
|
||||
ToShmem,
|
||||
)]
|
||||
#[repr(u8)]
|
||||
pub enum RaySize {
|
||||
ClosestSide,
|
||||
ClosestCorner,
|
||||
FarthestSide,
|
||||
FarthestCorner,
|
||||
Sides,
|
||||
}
|
||||
|
||||
/// The `ray()` function, `ray( [ <angle> && <size> && contain? ] )`
|
||||
///
|
||||
/// https://drafts.fxtf.org/motion-1/#valdef-offsetpath-ray
|
||||
#[derive(
|
||||
Animate,
|
||||
Clone,
|
||||
ComputeSquaredDistance,
|
||||
Debug,
|
||||
MallocSizeOf,
|
||||
PartialEq,
|
||||
SpecifiedValueInfo,
|
||||
ToAnimatedZero,
|
||||
ToComputedValue,
|
||||
ToCss,
|
||||
ToResolvedValue,
|
||||
ToShmem,
|
||||
)]
|
||||
#[repr(C)]
|
||||
pub struct RayFunction<Angle> {
|
||||
/// The bearing angle with `0deg` pointing up and positive angles
|
||||
/// representing clockwise rotation.
|
||||
pub angle: Angle,
|
||||
/// Decide the path length used when `offset-distance` is expressed
|
||||
/// as a percentage.
|
||||
#[animation(constant)]
|
||||
pub size: RaySize,
|
||||
/// Clamp `offset-distance` so that the box is entirely contained
|
||||
/// within the path.
|
||||
#[animation(constant)]
|
||||
#[css(represents_keyword)]
|
||||
pub contain: bool,
|
||||
}
|
||||
|
||||
/// The offset-path value.
|
||||
///
|
||||
/// https://drafts.fxtf.org/motion-1/#offset-path-property
|
||||
#[derive(
|
||||
Animate,
|
||||
Clone,
|
||||
ComputeSquaredDistance,
|
||||
Debug,
|
||||
MallocSizeOf,
|
||||
PartialEq,
|
||||
SpecifiedValueInfo,
|
||||
ToAnimatedZero,
|
||||
ToComputedValue,
|
||||
ToCss,
|
||||
ToResolvedValue,
|
||||
ToShmem,
|
||||
)]
|
||||
#[repr(C, u8)]
|
||||
pub enum GenericOffsetPath<Angle> {
|
||||
// We could merge SVGPathData into ShapeSource, so we could reuse them. However,
|
||||
// we don't want to support other value for offset-path, so use SVGPathData only for now.
|
||||
/// Path value for path(<string>).
|
||||
#[css(function)]
|
||||
Path(SVGPathData),
|
||||
/// ray() function, which defines a path in the polar coordinate system.
|
||||
#[css(function)]
|
||||
Ray(RayFunction<Angle>),
|
||||
/// None value.
|
||||
#[animation(error)]
|
||||
None,
|
||||
// Bug 1186329: Implement <basic-shape>, <geometry-box>, and <url>.
|
||||
}
|
||||
|
||||
pub use self::GenericOffsetPath as OffsetPath;
|
||||
|
||||
impl<Angle> OffsetPath<Angle> {
|
||||
/// Return None.
|
||||
#[inline]
|
||||
pub fn none() -> Self {
|
||||
OffsetPath::None
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue