зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1820070 - Part 2: Add at <position> into ray() in style system. r=emilio
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:
Родитель
069ab2df90
Коммит
ffe41dcabb
|
@ -166,7 +166,7 @@ static CSSCoord ComputeRayPathLength(const StyleRaySize aRaySizeType,
|
|||
return 0.0;
|
||||
}
|
||||
|
||||
static CSSCoord ComputeRayUsedDistance(const RayFunction& aRay,
|
||||
static CSSCoord ComputeRayUsedDistance(const StyleRayFunction& aRay,
|
||||
const LengthPercentage& aDistance,
|
||||
const CSSCoord& aPathLength,
|
||||
const CSSSize& aBorderBoxSize) {
|
||||
|
@ -317,7 +317,7 @@ static OffsetPathData GenerateOffsetPathData(const nsIFrame* aFrame) {
|
|||
return OffsetPathData::Path(pathData, gfxPath.forget());
|
||||
}
|
||||
case StyleOffsetPath::Tag::Ray:
|
||||
return OffsetPathData::Ray(path.AsRay(), RayReferenceData(aFrame));
|
||||
return OffsetPathData::Ray(*path.AsRay(), RayReferenceData(aFrame));
|
||||
case StyleOffsetPath::Tag::None:
|
||||
return OffsetPathData::None();
|
||||
default:
|
||||
|
@ -362,7 +362,7 @@ static OffsetPathData GenerateOffsetPathData(
|
|||
return OffsetPathData::Path(pathData, path.forget());
|
||||
}
|
||||
case StyleOffsetPath::Tag::Ray:
|
||||
return OffsetPathData::Ray(aPath.AsRay(), aRayReferenceData);
|
||||
return OffsetPathData::Ray(*aPath.AsRay(), aRayReferenceData);
|
||||
case StyleOffsetPath::Tag::None:
|
||||
default:
|
||||
return OffsetPathData::None();
|
||||
|
|
|
@ -22,8 +22,6 @@ class TransformReferenceBox;
|
|||
|
||||
namespace mozilla {
|
||||
|
||||
using RayFunction = StyleRayFunction<StyleAngle>;
|
||||
|
||||
namespace layers {
|
||||
class MotionPathData;
|
||||
class PathCommand;
|
||||
|
@ -70,7 +68,7 @@ struct OffsetPathData {
|
|||
};
|
||||
|
||||
struct RayData {
|
||||
const RayFunction* mRay;
|
||||
const StyleRayFunction* mRay;
|
||||
RayReferenceData mData;
|
||||
};
|
||||
|
||||
|
@ -87,11 +85,12 @@ struct OffsetPathData {
|
|||
return OffsetPathData(std::move(aGfxPath),
|
||||
!path.empty() && path.rbegin()->IsClosePath());
|
||||
}
|
||||
static OffsetPathData Ray(const RayFunction& aRay,
|
||||
static OffsetPathData Ray(const StyleRayFunction& aRay,
|
||||
const RayReferenceData& aData) {
|
||||
return OffsetPathData(&aRay, aData);
|
||||
}
|
||||
static OffsetPathData Ray(const RayFunction& aRay, RayReferenceData&& aData) {
|
||||
static OffsetPathData Ray(const StyleRayFunction& aRay,
|
||||
RayReferenceData&& aData) {
|
||||
return OffsetPathData(&aRay, std::move(aData));
|
||||
}
|
||||
|
||||
|
@ -152,9 +151,9 @@ struct OffsetPathData {
|
|||
OffsetPathData() : mType(Type::None) {}
|
||||
OffsetPathData(already_AddRefed<gfx::Path>&& aPath, bool aIsClosed)
|
||||
: mType(Type::Path), mPath{std::move(aPath), aIsClosed} {}
|
||||
OffsetPathData(const RayFunction* aRay, RayReferenceData&& aRef)
|
||||
OffsetPathData(const StyleRayFunction* aRay, RayReferenceData&& aRef)
|
||||
: mType(Type::Ray), mRay{aRay, std::move(aRef)} {}
|
||||
OffsetPathData(const RayFunction* aRay, const RayReferenceData& aRef)
|
||||
OffsetPathData(const StyleRayFunction* aRay, const RayReferenceData& aRef)
|
||||
: mType(Type::Ray), mRay{aRay, aRef} {}
|
||||
OffsetPathData& operator=(const OffsetPathData&) = delete;
|
||||
OffsetPathData& operator=(OffsetPathData&&) = delete;
|
||||
|
|
|
@ -102,7 +102,6 @@ GROUP_RULE_FUNCS_UNLOCKED(Container)
|
|||
bool Servo_##type_##_Deserialize(mozilla::ipc::ByteBuf* input, type_* v); \
|
||||
bool Servo_##type_##_Serialize(const type_* v, mozilla::ipc::ByteBuf* output);
|
||||
|
||||
using RayFunction = StyleRayFunction<StyleAngle>;
|
||||
BASIC_SERDE_FUNCS(LengthPercentage)
|
||||
BASIC_SERDE_FUNCS(StyleRotate)
|
||||
BASIC_SERDE_FUNCS(StyleScale)
|
||||
|
|
|
@ -451,7 +451,7 @@ cbindgen-types = [
|
|||
{ gecko = "StyleOffsetPosition", servo = "crate::values::computed::motion::OffsetPosition" },
|
||||
{ gecko = "StyleOffsetRotate", servo = "crate::values::computed::motion::OffsetRotate" },
|
||||
{ gecko = "StylePathCommand", servo = "crate::values::specified::svg_path::PathCommand" },
|
||||
{ gecko = "StyleRayFunction", servo = "crate::values::generics::motion::RayFunction" },
|
||||
{ gecko = "StyleRayFunction", servo = "crate::values::computed::motion::RayFunction" },
|
||||
{ gecko = "StyleUnicodeRange", servo = "cssparser::UnicodeRange" },
|
||||
{ gecko = "StyleOverflowWrap", servo = "crate::values::computed::OverflowWrap" },
|
||||
{ gecko = "StyleWordBreak", servo = "crate::values::computed::WordBreak" },
|
||||
|
|
|
@ -13454,7 +13454,9 @@ if (IsCSSPropertyPrefEnabled("layout.css.motion-path.enabled")) {
|
|||
"ray(200grad farthest-corner)",
|
||||
"ray(sides 180deg)",
|
||||
"ray(contain farthest-side 180deg)",
|
||||
"ray(calc(180deg - 45deg) farthest-side)"
|
||||
"ray(calc(180deg - 45deg) farthest-side)",
|
||||
"ray(0deg at center center)",
|
||||
"ray(at 10% 10% 1rad)"
|
||||
);
|
||||
|
||||
gCSSProperties["offset-path"]["invalid_values"].push(
|
||||
|
|
|
@ -4,12 +4,17 @@
|
|||
|
||||
//! Computed types for CSS values that are related to motion path.
|
||||
|
||||
use crate::values::computed::{Angle, LengthPercentage};
|
||||
use crate::values::generics::motion::{GenericOffsetPath, GenericOffsetPosition};
|
||||
use crate::values::computed::{Angle, LengthPercentage, Position};
|
||||
use crate::values::generics::motion::{
|
||||
GenericOffsetPath, GenericOffsetPosition, GenericRayFunction,
|
||||
};
|
||||
use crate::Zero;
|
||||
|
||||
/// The computed value of ray() function.
|
||||
pub type RayFunction = GenericRayFunction<Angle, Position>;
|
||||
|
||||
/// The computed value of `offset-path`.
|
||||
pub type OffsetPath = GenericOffsetPath<Angle>;
|
||||
pub type OffsetPath = GenericOffsetPath<RayFunction>;
|
||||
|
||||
/// The computed value of `offset-position`.
|
||||
pub type OffsetPosition = GenericOffsetPosition<LengthPercentage, LengthPercentage>;
|
||||
|
|
|
@ -5,15 +5,19 @@
|
|||
//! Generic types for CSS Motion Path.
|
||||
|
||||
use crate::values::animated::ToAnimatedZero;
|
||||
use crate::values::generics::position::GenericPosition;
|
||||
use crate::values::generics::position::{GenericPosition, GenericPositionOrAuto};
|
||||
use crate::values::specified::SVGPathData;
|
||||
use std::fmt::{self, Write};
|
||||
use style_traits::{CssWriter, ToCss};
|
||||
|
||||
/// The <size> in ray() function.
|
||||
///
|
||||
/// https://drafts.fxtf.org/motion-1/#valdef-offsetpath-size
|
||||
#[allow(missing_docs)]
|
||||
#[derive(
|
||||
Animate,
|
||||
Clone,
|
||||
ComputeSquaredDistance,
|
||||
Copy,
|
||||
Debug,
|
||||
Deserialize,
|
||||
|
@ -36,15 +40,7 @@ pub enum RaySize {
|
|||
Sides,
|
||||
}
|
||||
|
||||
impl RaySize {
|
||||
/// 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? ] )`
|
||||
/// The `ray()` function, `ray( [ <angle> && <size> && contain? && [at <position>]? ] )`
|
||||
///
|
||||
/// https://drafts.fxtf.org/motion-1/#valdef-offsetpath-ray
|
||||
#[derive(
|
||||
|
@ -58,25 +54,54 @@ impl RaySize {
|
|||
Serialize,
|
||||
SpecifiedValueInfo,
|
||||
ToComputedValue,
|
||||
ToCss,
|
||||
ToResolvedValue,
|
||||
ToShmem,
|
||||
)]
|
||||
#[repr(C)]
|
||||
pub struct RayFunction<Angle> {
|
||||
pub struct GenericRayFunction<Angle, Position> {
|
||||
/// 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)]
|
||||
#[css(skip_if = "RaySize::is_default")]
|
||||
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 "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.
|
||||
|
@ -98,15 +123,16 @@ pub struct RayFunction<Angle> {
|
|||
ToShmem,
|
||||
)]
|
||||
#[repr(C, u8)]
|
||||
pub enum GenericOffsetPath<Angle> {
|
||||
pub enum GenericOffsetPath<RayFunction> {
|
||||
// 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.
|
||||
/// Use Box<> to make sure the size of offset-path is not too large.
|
||||
#[css(function)]
|
||||
Ray(RayFunction<Angle>),
|
||||
Ray(Box<RayFunction>),
|
||||
/// None value.
|
||||
#[animation(error)]
|
||||
None,
|
||||
|
@ -115,7 +141,7 @@ pub enum GenericOffsetPath<Angle> {
|
|||
|
||||
pub use self::GenericOffsetPath as OffsetPath;
|
||||
|
||||
impl<Angle> OffsetPath<Angle> {
|
||||
impl<Ray> OffsetPath<Ray> {
|
||||
/// Return None.
|
||||
#[inline]
|
||||
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]
|
||||
fn to_animated_zero(&self) -> Result<Self, ()> {
|
||||
Err(())
|
||||
|
|
|
@ -101,6 +101,12 @@ impl<Pos> PositionOrAuto<Pos> {
|
|||
pub fn auto() -> Self {
|
||||
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.
|
||||
|
|
|
@ -7,26 +7,29 @@
|
|||
use crate::parser::{Parse, ParserContext};
|
||||
use crate::values::computed::motion::OffsetRotate as ComputedOffsetRotate;
|
||||
use crate::values::computed::{Context, ToComputedValue};
|
||||
use crate::values::generics::motion::{
|
||||
GenericOffsetPath, GenericOffsetPosition, RayFunction, RaySize,
|
||||
};
|
||||
use crate::values::generics::motion as generics;
|
||||
use crate::values::specified::position::{HorizontalPosition, VerticalPosition};
|
||||
use crate::values::specified::{Angle, SVGPathData};
|
||||
use crate::values::specified::{Angle, Position};
|
||||
use crate::Zero;
|
||||
use cssparser::Parser;
|
||||
use style_traits::{ParseError, StyleParseErrorKind};
|
||||
|
||||
/// The specified value of ray() function.
|
||||
pub type RayFunction = generics::GenericRayFunction<Angle, Position>;
|
||||
|
||||
/// The specified value of `offset-path`.
|
||||
pub type OffsetPath = GenericOffsetPath<Angle>;
|
||||
pub type OffsetPath = generics::GenericOffsetPath<RayFunction>;
|
||||
|
||||
/// The specified value of `offset-position`.
|
||||
pub type OffsetPosition = GenericOffsetPosition<HorizontalPosition, VerticalPosition>;
|
||||
pub type OffsetPosition = generics::GenericOffsetPosition<HorizontalPosition, VerticalPosition>;
|
||||
|
||||
impl Parse for RayFunction<Angle> {
|
||||
impl Parse for RayFunction {
|
||||
fn parse<'i, 't>(
|
||||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
use crate::values::specified::PositionOrAuto;
|
||||
|
||||
if !static_prefs::pref!("layout.css.motion-path-ray.enabled") {
|
||||
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError));
|
||||
}
|
||||
|
@ -34,13 +37,14 @@ impl Parse for RayFunction<Angle> {
|
|||
let mut angle = None;
|
||||
let mut size = None;
|
||||
let mut contain = false;
|
||||
let mut position = None;
|
||||
loop {
|
||||
if angle.is_none() {
|
||||
angle = input.try_parse(|i| Angle::parse(context, i)).ok();
|
||||
}
|
||||
|
||||
if size.is_none() {
|
||||
size = input.try_parse(RaySize::parse).ok();
|
||||
size = input.try_parse(generics::RaySize::parse).ok();
|
||||
if size.is_some() {
|
||||
continue;
|
||||
}
|
||||
|
@ -54,6 +58,17 @@ impl Parse for RayFunction<Angle> {
|
|||
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;
|
||||
}
|
||||
|
||||
|
@ -64,8 +79,9 @@ impl Parse for RayFunction<Angle> {
|
|||
Ok(RayFunction {
|
||||
angle: angle.unwrap(),
|
||||
// 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,
|
||||
position: position.unwrap_or(PositionOrAuto::auto()),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -75,7 +91,7 @@ impl Parse for OffsetPath {
|
|||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
use crate::values::specified::svg_path::AllowEmpty;
|
||||
use crate::values::specified::svg_path::{AllowEmpty, SVGPathData};
|
||||
|
||||
// Parse none.
|
||||
if input.try_parse(|i| i.expect_ident_matching("none")).is_ok() {
|
||||
|
@ -90,7 +106,7 @@ impl Parse for OffsetPath {
|
|||
// Bug 1186329: Implement the parser for <basic-shape>, <geometry-box>,
|
||||
// and <url>.
|
||||
"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(
|
||||
StyleParseErrorKind::UnexpectedFunction(function.clone())
|
||||
|
|
|
@ -115,6 +115,7 @@ include = [
|
|||
"OffsetPath",
|
||||
"OffsetPosition",
|
||||
"OffsetRotate",
|
||||
"RayFunction",
|
||||
"UnicodeRange",
|
||||
"UserSelect",
|
||||
"Float",
|
||||
|
|
|
@ -21,6 +21,11 @@ test_computed_value("offset-path", "ray(200grad farthest-side)", "ray(180deg far
|
|||
test_computed_value("offset-path", "ray(270deg farthest-corner contain)");
|
||||
test_computed_value("offset-path", "ray(-720deg sides)");
|
||||
test_computed_value("offset-path", "ray(calc(180deg - 45deg) farthest-side)", "ray(135deg farthest-side)");
|
||||
test_computed_value("offset-path", "ray(0deg at 100px 100px)");
|
||||
test_computed_value("offset-path", "ray(0deg sides at center center)", "ray(0deg sides at 50% 50%)");
|
||||
test_computed_value("offset-path", "ray(0deg at center center sides)", "ray(0deg sides at 50% 50%)");
|
||||
test_computed_value("offset-path", "ray(0deg at center center contain)", "ray(0deg contain at 50% 50%)");
|
||||
test_computed_value("offset-path", "ray(at 10px 10px 0deg contain)", "ray(0deg contain at 10px 10px)");
|
||||
|
||||
// It's unclear about the normalization at computed time, so we accept both
|
||||
// cases for now.
|
||||
|
|
Загрузка…
Ссылка в новой задаче