mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35:33 +01:00
style: Add at <position> into ray() in style system
We reuse PositionOrAuto here, and let "auto" represent the situation when the author omits "at <position>" because it has a special meaning. https://drafts.fxtf.org/motion-1/#valdef-ray-at-position Note: No need to update css/motion/parsing/offset-path-parsing-valid.html because Blink added some to the upstream repo already. Differential Revision: https://phabricator.services.mozilla.com/D179860
This commit is contained in:
parent
8b60424e29
commit
2fef5d1a17
4 changed files with 86 additions and 33 deletions
|
@ -4,12 +4,17 @@
|
||||||
|
|
||||||
//! Computed types for CSS values that are related to motion path.
|
//! Computed types for CSS values that are related to motion path.
|
||||||
|
|
||||||
use crate::values::computed::{Angle, LengthPercentage};
|
use crate::values::computed::{Angle, LengthPercentage, Position};
|
||||||
use crate::values::generics::motion::{GenericOffsetPath, GenericOffsetPosition};
|
use crate::values::generics::motion::{
|
||||||
|
GenericOffsetPath, GenericOffsetPosition, GenericRayFunction,
|
||||||
|
};
|
||||||
use crate::Zero;
|
use crate::Zero;
|
||||||
|
|
||||||
|
/// The computed value of ray() function.
|
||||||
|
pub type RayFunction = GenericRayFunction<Angle, Position>;
|
||||||
|
|
||||||
/// The computed value of `offset-path`.
|
/// The computed value of `offset-path`.
|
||||||
pub type OffsetPath = GenericOffsetPath<Angle>;
|
pub type OffsetPath = GenericOffsetPath<RayFunction>;
|
||||||
|
|
||||||
/// The computed value of `offset-position`.
|
/// The computed value of `offset-position`.
|
||||||
pub type OffsetPosition = GenericOffsetPosition<LengthPercentage, LengthPercentage>;
|
pub type OffsetPosition = GenericOffsetPosition<LengthPercentage, LengthPercentage>;
|
||||||
|
|
|
@ -5,15 +5,19 @@
|
||||||
//! Generic types for CSS Motion Path.
|
//! Generic types for CSS Motion Path.
|
||||||
|
|
||||||
use crate::values::animated::ToAnimatedZero;
|
use crate::values::animated::ToAnimatedZero;
|
||||||
use crate::values::generics::position::GenericPosition;
|
use crate::values::generics::position::{GenericPosition, GenericPositionOrAuto};
|
||||||
use crate::values::specified::SVGPathData;
|
use crate::values::specified::SVGPathData;
|
||||||
|
use std::fmt::{self, Write};
|
||||||
|
use style_traits::{CssWriter, ToCss};
|
||||||
|
|
||||||
/// The <size> in ray() function.
|
/// The <size> in ray() function.
|
||||||
///
|
///
|
||||||
/// https://drafts.fxtf.org/motion-1/#valdef-offsetpath-size
|
/// https://drafts.fxtf.org/motion-1/#valdef-offsetpath-size
|
||||||
#[allow(missing_docs)]
|
#[allow(missing_docs)]
|
||||||
#[derive(
|
#[derive(
|
||||||
|
Animate,
|
||||||
Clone,
|
Clone,
|
||||||
|
ComputeSquaredDistance,
|
||||||
Copy,
|
Copy,
|
||||||
Debug,
|
Debug,
|
||||||
Deserialize,
|
Deserialize,
|
||||||
|
@ -36,15 +40,7 @@ pub enum RaySize {
|
||||||
Sides,
|
Sides,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RaySize {
|
/// The `ray()` function, `ray( [ <angle> && <size> && contain? && [at <position>]? ] )`
|
||||||
/// Returns true if it is the default value.
|
|
||||||
#[inline]
|
|
||||||
pub fn is_default(&self) -> bool {
|
|
||||||
*self == RaySize::ClosestSide
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The `ray()` function, `ray( [ <angle> && <size> && contain? ] )`
|
|
||||||
///
|
///
|
||||||
/// https://drafts.fxtf.org/motion-1/#valdef-offsetpath-ray
|
/// https://drafts.fxtf.org/motion-1/#valdef-offsetpath-ray
|
||||||
#[derive(
|
#[derive(
|
||||||
|
@ -58,25 +54,54 @@ impl RaySize {
|
||||||
Serialize,
|
Serialize,
|
||||||
SpecifiedValueInfo,
|
SpecifiedValueInfo,
|
||||||
ToComputedValue,
|
ToComputedValue,
|
||||||
ToCss,
|
|
||||||
ToResolvedValue,
|
ToResolvedValue,
|
||||||
ToShmem,
|
ToShmem,
|
||||||
)]
|
)]
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct RayFunction<Angle> {
|
pub struct GenericRayFunction<Angle, Position> {
|
||||||
/// The bearing angle with `0deg` pointing up and positive angles
|
/// The bearing angle with `0deg` pointing up and positive angles
|
||||||
/// representing clockwise rotation.
|
/// representing clockwise rotation.
|
||||||
pub angle: Angle,
|
pub angle: Angle,
|
||||||
/// Decide the path length used when `offset-distance` is expressed
|
/// Decide the path length used when `offset-distance` is expressed
|
||||||
/// as a percentage.
|
/// as a percentage.
|
||||||
#[animation(constant)]
|
|
||||||
#[css(skip_if = "RaySize::is_default")]
|
|
||||||
pub size: RaySize,
|
pub size: RaySize,
|
||||||
/// Clamp `offset-distance` so that the box is entirely contained
|
/// Clamp `offset-distance` so that the box is entirely contained
|
||||||
/// within the path.
|
/// within the path.
|
||||||
#[animation(constant)]
|
#[animation(constant)]
|
||||||
#[css(represents_keyword)]
|
|
||||||
pub contain: bool,
|
pub contain: bool,
|
||||||
|
/// The "at <position>" part. If omitted, we use auto to represent it.
|
||||||
|
pub position: GenericPositionOrAuto<Position>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub use self::GenericRayFunction as RayFunction;
|
||||||
|
|
||||||
|
impl<Angle, Position> ToCss for RayFunction<Angle, Position>
|
||||||
|
where
|
||||||
|
Angle: ToCss,
|
||||||
|
Position: ToCss,
|
||||||
|
{
|
||||||
|
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
||||||
|
where
|
||||||
|
W: Write,
|
||||||
|
{
|
||||||
|
self.angle.to_css(dest)?;
|
||||||
|
|
||||||
|
if !matches!(self.size, RaySize::ClosestSide) {
|
||||||
|
dest.write_char(' ')?;
|
||||||
|
self.size.to_css(dest)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.contain {
|
||||||
|
dest.write_str(" contain")?;
|
||||||
|
}
|
||||||
|
|
||||||
|
if !matches!(self.position, GenericPositionOrAuto::Auto) {
|
||||||
|
dest.write_str(" at ")?;
|
||||||
|
self.position.to_css(dest)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The offset-path value.
|
/// The offset-path value.
|
||||||
|
@ -98,15 +123,16 @@ pub struct RayFunction<Angle> {
|
||||||
ToShmem,
|
ToShmem,
|
||||||
)]
|
)]
|
||||||
#[repr(C, u8)]
|
#[repr(C, u8)]
|
||||||
pub enum GenericOffsetPath<Angle> {
|
pub enum GenericOffsetPath<RayFunction> {
|
||||||
// We could merge SVGPathData into ShapeSource, so we could reuse them. However,
|
// 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.
|
// we don't want to support other value for offset-path, so use SVGPathData only for now.
|
||||||
/// Path value for path(<string>).
|
/// Path value for path(<string>).
|
||||||
#[css(function)]
|
#[css(function)]
|
||||||
Path(SVGPathData),
|
Path(SVGPathData),
|
||||||
/// ray() function, which defines a path in the polar coordinate system.
|
/// ray() function, which defines a path in the polar coordinate system.
|
||||||
|
/// Use Box<> to make sure the size of offset-path is not too large.
|
||||||
#[css(function)]
|
#[css(function)]
|
||||||
Ray(RayFunction<Angle>),
|
Ray(Box<RayFunction>),
|
||||||
/// None value.
|
/// None value.
|
||||||
#[animation(error)]
|
#[animation(error)]
|
||||||
None,
|
None,
|
||||||
|
@ -115,7 +141,7 @@ pub enum GenericOffsetPath<Angle> {
|
||||||
|
|
||||||
pub use self::GenericOffsetPath as OffsetPath;
|
pub use self::GenericOffsetPath as OffsetPath;
|
||||||
|
|
||||||
impl<Angle> OffsetPath<Angle> {
|
impl<Ray> OffsetPath<Ray> {
|
||||||
/// Return None.
|
/// Return None.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn none() -> Self {
|
pub fn none() -> Self {
|
||||||
|
@ -123,7 +149,7 @@ impl<Angle> OffsetPath<Angle> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Angle> ToAnimatedZero for OffsetPath<Angle> {
|
impl<Ray> ToAnimatedZero for OffsetPath<Ray> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn to_animated_zero(&self) -> Result<Self, ()> {
|
fn to_animated_zero(&self) -> Result<Self, ()> {
|
||||||
Err(())
|
Err(())
|
||||||
|
|
|
@ -101,6 +101,12 @@ impl<Pos> PositionOrAuto<Pos> {
|
||||||
pub fn auto() -> Self {
|
pub fn auto() -> Self {
|
||||||
PositionOrAuto::Auto
|
PositionOrAuto::Auto
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return true if it is 'auto'.
|
||||||
|
#[inline]
|
||||||
|
pub fn is_auto(&self) -> bool {
|
||||||
|
matches!(self, PositionOrAuto::Auto)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A generic value for the `z-index` property.
|
/// A generic value for the `z-index` property.
|
||||||
|
|
|
@ -7,20 +7,21 @@
|
||||||
use crate::parser::{Parse, ParserContext};
|
use crate::parser::{Parse, ParserContext};
|
||||||
use crate::values::computed::motion::OffsetRotate as ComputedOffsetRotate;
|
use crate::values::computed::motion::OffsetRotate as ComputedOffsetRotate;
|
||||||
use crate::values::computed::{Context, ToComputedValue};
|
use crate::values::computed::{Context, ToComputedValue};
|
||||||
use crate::values::generics::motion::{
|
use crate::values::generics::motion as generics;
|
||||||
GenericOffsetPath, GenericOffsetPosition, RayFunction, RaySize,
|
|
||||||
};
|
|
||||||
use crate::values::specified::position::{HorizontalPosition, VerticalPosition};
|
use crate::values::specified::position::{HorizontalPosition, VerticalPosition};
|
||||||
use crate::values::specified::{Angle, SVGPathData};
|
use crate::values::specified::{Angle, Position};
|
||||||
use crate::Zero;
|
use crate::Zero;
|
||||||
use cssparser::Parser;
|
use cssparser::Parser;
|
||||||
use style_traits::{ParseError, StyleParseErrorKind};
|
use style_traits::{ParseError, StyleParseErrorKind};
|
||||||
|
|
||||||
|
/// The specified value of ray() function.
|
||||||
|
pub type RayFunction = generics::GenericRayFunction<Angle, Position>;
|
||||||
|
|
||||||
/// The specified value of `offset-path`.
|
/// The specified value of `offset-path`.
|
||||||
pub type OffsetPath = GenericOffsetPath<Angle>;
|
pub type OffsetPath = generics::GenericOffsetPath<RayFunction>;
|
||||||
|
|
||||||
/// The specified value of `offset-position`.
|
/// The specified value of `offset-position`.
|
||||||
pub type OffsetPosition = GenericOffsetPosition<HorizontalPosition, VerticalPosition>;
|
pub type OffsetPosition = generics::GenericOffsetPosition<HorizontalPosition, VerticalPosition>;
|
||||||
|
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
fn is_ray_enabled() -> bool {
|
fn is_ray_enabled() -> bool {
|
||||||
|
@ -31,11 +32,13 @@ fn is_ray_enabled() -> bool {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Parse for RayFunction<Angle> {
|
impl Parse for RayFunction {
|
||||||
fn parse<'i, 't>(
|
fn parse<'i, 't>(
|
||||||
context: &ParserContext,
|
context: &ParserContext,
|
||||||
input: &mut Parser<'i, 't>,
|
input: &mut Parser<'i, 't>,
|
||||||
) -> Result<Self, ParseError<'i>> {
|
) -> Result<Self, ParseError<'i>> {
|
||||||
|
use crate::values::specified::PositionOrAuto;
|
||||||
|
|
||||||
if !is_ray_enabled() {
|
if !is_ray_enabled() {
|
||||||
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError));
|
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError));
|
||||||
}
|
}
|
||||||
|
@ -43,13 +46,14 @@ impl Parse for RayFunction<Angle> {
|
||||||
let mut angle = None;
|
let mut angle = None;
|
||||||
let mut size = None;
|
let mut size = None;
|
||||||
let mut contain = false;
|
let mut contain = false;
|
||||||
|
let mut position = None;
|
||||||
loop {
|
loop {
|
||||||
if angle.is_none() {
|
if angle.is_none() {
|
||||||
angle = input.try_parse(|i| Angle::parse(context, i)).ok();
|
angle = input.try_parse(|i| Angle::parse(context, i)).ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
if size.is_none() {
|
if size.is_none() {
|
||||||
size = input.try_parse(RaySize::parse).ok();
|
size = input.try_parse(generics::RaySize::parse).ok();
|
||||||
if size.is_some() {
|
if size.is_some() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -63,6 +67,17 @@ impl Parse for RayFunction<Angle> {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if position.is_none() {
|
||||||
|
if input.try_parse(|i| i.expect_ident_matching("at")).is_ok() {
|
||||||
|
let pos = Position::parse(context, input)?;
|
||||||
|
position = Some(PositionOrAuto::Position(pos));
|
||||||
|
}
|
||||||
|
|
||||||
|
if position.is_some() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,8 +88,9 @@ impl Parse for RayFunction<Angle> {
|
||||||
Ok(RayFunction {
|
Ok(RayFunction {
|
||||||
angle: angle.unwrap(),
|
angle: angle.unwrap(),
|
||||||
// If no <ray-size> is specified it defaults to closest-side.
|
// If no <ray-size> is specified it defaults to closest-side.
|
||||||
size: size.unwrap_or(RaySize::ClosestSide),
|
size: size.unwrap_or(generics::RaySize::ClosestSide),
|
||||||
contain,
|
contain,
|
||||||
|
position: position.unwrap_or(PositionOrAuto::auto()),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -84,7 +100,7 @@ impl Parse for OffsetPath {
|
||||||
context: &ParserContext,
|
context: &ParserContext,
|
||||||
input: &mut Parser<'i, 't>,
|
input: &mut Parser<'i, 't>,
|
||||||
) -> Result<Self, ParseError<'i>> {
|
) -> Result<Self, ParseError<'i>> {
|
||||||
use crate::values::specified::svg_path::AllowEmpty;
|
use crate::values::specified::svg_path::{AllowEmpty, SVGPathData};
|
||||||
|
|
||||||
// Parse none.
|
// Parse none.
|
||||||
if input.try_parse(|i| i.expect_ident_matching("none")).is_ok() {
|
if input.try_parse(|i| i.expect_ident_matching("none")).is_ok() {
|
||||||
|
@ -99,7 +115,7 @@ impl Parse for OffsetPath {
|
||||||
// Bug 1186329: Implement the parser for <basic-shape>, <geometry-box>,
|
// Bug 1186329: Implement the parser for <basic-shape>, <geometry-box>,
|
||||||
// and <url>.
|
// and <url>.
|
||||||
"path" => SVGPathData::parse(i, AllowEmpty::No).map(OffsetPath::Path),
|
"path" => SVGPathData::parse(i, AllowEmpty::No).map(OffsetPath::Path),
|
||||||
"ray" => RayFunction::parse(context, i).map(OffsetPath::Ray),
|
"ray" => RayFunction::parse(context, i).map(|v| OffsetPath::Ray(Box::new(v))),
|
||||||
_ => {
|
_ => {
|
||||||
Err(location.new_custom_error(
|
Err(location.new_custom_error(
|
||||||
StyleParseErrorKind::UnexpectedFunction(function.clone())
|
StyleParseErrorKind::UnexpectedFunction(function.clone())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue