Skip to content

Commit a2ba363

Browse files
committed
Bug 2030159 - Remove special serialization from specified shapes. r=boris,firefox-style-system-reviewers,layout-reviewers
As per w3c/csswg-drafts#8695. Differential Revision: https://phabricator.services.mozilla.com/D292580
1 parent fb4a7b7 commit a2ba363

7 files changed

Lines changed: 59 additions & 142 deletions

File tree

‎layout/base/MotionPathUtils.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ static already_AddRefed<gfx::Path> BuildDefaultPathForURL(
474474
}
475475

476476
using CommandEndPoint =
477-
StyleCommandEndPoint<StyleShapePosition<StyleCSSFloat>, StyleCSSFloat>;
477+
StyleCommandEndPoint<StyleSVGPathPosition, StyleCSSFloat>;
478478
Array<const StylePathCommand, 1> array(
479479
StylePathCommand::Move(CommandEndPoint::ByCoordinate({0.0, 0.0})));
480480
return SVGPathData::BuildPath(array, aBuilder, StyleStrokeLinecap::Butt, 0.0);

‎layout/style/ServoStyleConstsInlines.h‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,22 +1303,22 @@ inline gfx::Point StyleCoordinatePair<LengthPercentage>::ToGfxPoint(
13031303
}
13041304

13051305
template <>
1306-
inline gfx::Point StyleShapePosition<StyleCSSFloat>::ToGfxPoint(
1306+
inline gfx::Point
1307+
StyleGenericPosition<StyleCSSFloat, StyleCSSFloat>::ToGfxPoint(
13071308
const CSSSize* aBasis) const {
13081309
return gfx::Point(horizontal, vertical);
13091310
}
13101311

13111312
template <>
1312-
inline gfx::Point StyleShapePosition<LengthPercentage>::ToGfxPoint(
1313-
const CSSSize* aBasis) const {
1313+
inline gfx::Point StylePosition::ToGfxPoint(const CSSSize* aBasis) const {
13141314
MOZ_ASSERT(aBasis);
13151315
return gfx::Point(horizontal.ResolveToCSSPixels(aBasis->Width()),
13161316
vertical.ResolveToCSSPixels(aBasis->Height()));
13171317
}
13181318

13191319
template <>
13201320
inline gfx::Point
1321-
StyleCommandEndPoint<StyleShapePosition<StyleCSSFloat>,
1321+
StyleCommandEndPoint<StyleGenericPosition<StyleCSSFloat, StyleCSSFloat>,
13221322
StyleCSSFloat>::ToGfxPoint(const CSSSize* aBasis) const {
13231323
if (IsToPosition()) {
13241324
auto& pos = AsToPosition();
@@ -1330,9 +1330,9 @@ StyleCommandEndPoint<StyleShapePosition<StyleCSSFloat>,
13301330
}
13311331

13321332
template <>
1333-
inline gfx::Point StyleCommandEndPoint<
1334-
StyleShapePosition<LengthPercentage>,
1335-
LengthPercentage>::ToGfxPoint(const CSSSize* aBasis) const {
1333+
inline gfx::Point
1334+
StyleCommandEndPoint<StylePosition, LengthPercentage>::ToGfxPoint(
1335+
const CSSSize* aBasis) const {
13361336
MOZ_ASSERT(aBasis);
13371337
if (IsToPosition()) {
13381338
auto& pos = AsToPosition();
@@ -1368,9 +1368,10 @@ inline gfx::Coord StyleAxisEndPoint<LengthPercentage>::ToGfxCoord(
13681368

13691369
template <>
13701370
inline gfx::Point
1371-
StyleControlPoint<StyleShapePosition<StyleCSSFloat>, StyleCSSFloat>::ToGfxPoint(
1372-
const gfx::Point aStatePos, const gfx::Point aEndPoint,
1373-
const CSSSize* aBasis) const {
1371+
StyleControlPoint<StyleGenericPosition<StyleCSSFloat, StyleCSSFloat>,
1372+
StyleCSSFloat>::ToGfxPoint(const gfx::Point aStatePos,
1373+
const gfx::Point aEndPoint,
1374+
const CSSSize* aBasis) const {
13741375
if (IsAbsolute()) {
13751376
auto& pos = AsAbsolute();
13761377
return pos.ToGfxPoint();
@@ -1390,10 +1391,9 @@ StyleControlPoint<StyleShapePosition<StyleCSSFloat>, StyleCSSFloat>::ToGfxPoint(
13901391

13911392
template <>
13921393
inline gfx::Point
1393-
StyleControlPoint<StyleShapePosition<LengthPercentage>,
1394-
LengthPercentage>::ToGfxPoint(const gfx::Point aStatePos,
1395-
const gfx::Point aEndPoint,
1396-
const CSSSize* aBasis) const {
1394+
StyleControlPoint<StylePosition, LengthPercentage>::ToGfxPoint(
1395+
const gfx::Point aStatePos, const gfx::Point aEndPoint,
1396+
const CSSSize* aBasis) const {
13971397
MOZ_ASSERT(aBasis);
13981398
if (IsAbsolute()) {
13991399
auto& pos = AsAbsolute();

‎servo/components/style/values/computed/basic_shape.rs‎

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ use crate::values::computed::angle::Angle;
1212
use crate::values::computed::url::ComputedUrl;
1313
use crate::values::computed::{Image, LengthPercentage, Position};
1414
use crate::values::generics::basic_shape as generic;
15-
use crate::values::generics::basic_shape::ShapePosition;
16-
use crate::values::specified::svg_path::{CoordPair, PathCommand};
15+
use crate::values::specified::svg_path::{CoordPair, PathCommand, SVGPathPosition};
1716
use crate::values::CSSFloat;
1817

1918
/// A computed alias for FillRule.
@@ -32,10 +31,10 @@ pub type BasicShape = generic::GenericBasicShape<Angle, Position, LengthPercenta
3231
pub type InsetRect = generic::GenericInsetRect<LengthPercentage>;
3332

3433
/// A computed circle.
35-
pub type Circle = generic::Circle<LengthPercentage>;
34+
pub type Circle = generic::Circle<Position, LengthPercentage>;
3635

3736
/// A computed ellipse.
38-
pub type Ellipse = generic::Ellipse<LengthPercentage>;
37+
pub type Ellipse = generic::Ellipse<Position, LengthPercentage>;
3938

4039
/// The computed value of `ShapeRadius`.
4140
pub type ShapeRadius = generic::GenericShapeRadius<LengthPercentage>;
@@ -211,9 +210,9 @@ impl From<&CoordPair> for CoordinatePair {
211210
}
212211
}
213212

214-
impl From<&ShapePosition<CSSFloat>> for Position {
213+
impl From<&SVGPathPosition> for Position {
215214
#[inline]
216-
fn from(p: &ShapePosition<CSSFloat>) -> Self {
215+
fn from(p: &SVGPathPosition) -> Self {
217216
use crate::values::computed::CSSPixelLength;
218217
Self::new(
219218
LengthPercentage::new_length(CSSPixelLength::new(p.horizontal)),
@@ -222,9 +221,9 @@ impl From<&ShapePosition<CSSFloat>> for Position {
222221
}
223222
}
224223

225-
impl From<&generic::CommandEndPoint<ShapePosition<CSSFloat>, CSSFloat>> for CommandEndPoint {
224+
impl From<&generic::CommandEndPoint<SVGPathPosition, CSSFloat>> for CommandEndPoint {
226225
#[inline]
227-
fn from(p: &generic::CommandEndPoint<ShapePosition<CSSFloat>, CSSFloat>) -> Self {
226+
fn from(p: &generic::CommandEndPoint<SVGPathPosition, CSSFloat>) -> Self {
228227
match p {
229228
generic::CommandEndPoint::ToPosition(pos) => Self::ToPosition(pos.into()),
230229
generic::CommandEndPoint::ByCoordinate(coord) => Self::ByCoordinate(coord.into()),
@@ -251,9 +250,9 @@ impl From<&generic::AxisEndPoint<CSSFloat>> for AxisEndPoint {
251250
}
252251
}
253252

254-
impl From<&generic::ControlPoint<ShapePosition<CSSFloat>, CSSFloat>> for ControlPoint {
253+
impl From<&generic::ControlPoint<SVGPathPosition, CSSFloat>> for ControlPoint {
255254
#[inline]
256-
fn from(p: &generic::ControlPoint<ShapePosition<CSSFloat>, CSSFloat>) -> Self {
255+
fn from(p: &generic::ControlPoint<SVGPathPosition, CSSFloat>) -> Self {
257256
match p {
258257
generic::ControlPoint::Absolute(pos) => Self::Absolute(pos.into()),
259258
generic::ControlPoint::Relative(point) => Self::Relative(RelativeControlPoint {

‎servo/components/style/values/generics/basic_shape.rs‎

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,13 @@ use crate::values::animated::{lists, Animate, Procedure, ToAnimatedZero};
1010
use crate::values::computed::Percentage;
1111
use crate::values::distance::{ComputeSquaredDistance, SquaredDistance};
1212
use crate::values::generics::{
13-
border::GenericBorderRadius,
14-
position::{GenericPosition, GenericPositionOrAuto},
15-
rect::Rect,
16-
NonNegative, Optional,
13+
border::GenericBorderRadius, position::GenericPositionOrAuto, rect::Rect, NonNegative, Optional,
1714
};
1815
use crate::values::specified::svg_path::{PathCommand, SVGPathData};
1916
use crate::Zero;
2017
use std::fmt::{self, Write};
2118
use style_traits::{CssWriter, ToCss};
2219

23-
/// A generic value for `<position>` in circle(), ellipse(), and shape().
24-
pub type ShapePosition<LengthPercentage> = GenericPosition<LengthPercentage, LengthPercentage>;
25-
2620
/// <https://drafts.fxtf.org/css-masking-1/#typedef-geometry-box>
2721
#[allow(missing_docs)]
2822
#[derive(
@@ -208,14 +202,14 @@ pub enum GenericBasicShape<Angle, Position, LengthPercentage, BasicShapeRect> {
208202
#[animation(field_bound)]
209203
#[css(field_bound)]
210204
#[shmem(field_bound)]
211-
Circle<LengthPercentage>,
205+
Circle<Position, LengthPercentage>,
212206
),
213207
/// Defines an ellipse with a center and x-axis/y-axis radii.
214208
Ellipse(
215209
#[animation(field_bound)]
216210
#[css(field_bound)]
217211
#[shmem(field_bound)]
218-
Ellipse<LengthPercentage>,
212+
Ellipse<Position, LengthPercentage>,
219213
),
220214
/// Defines a polygon with pair arguments.
221215
Polygon(GenericPolygon<LengthPercentage>),
@@ -278,8 +272,8 @@ pub use self::GenericInsetRect as InsetRect;
278272
)]
279273
#[css(function)]
280274
#[repr(C)]
281-
pub struct Circle<LengthPercentage> {
282-
pub position: GenericPositionOrAuto<ShapePosition<LengthPercentage>>,
275+
pub struct Circle<Position, LengthPercentage> {
276+
pub position: GenericPositionOrAuto<Position>,
283277
#[animation(field_bound)]
284278
pub radius: GenericShapeRadius<LengthPercentage>,
285279
}
@@ -304,8 +298,8 @@ pub struct Circle<LengthPercentage> {
304298
)]
305299
#[css(function)]
306300
#[repr(C)]
307-
pub struct Ellipse<LengthPercentage> {
308-
pub position: GenericPositionOrAuto<ShapePosition<LengthPercentage>>,
301+
pub struct Ellipse<Position, LengthPercentage> {
302+
pub position: GenericPositionOrAuto<Position>,
309303
#[animation(field_bound)]
310304
pub semiaxis_x: GenericShapeRadius<LengthPercentage>,
311305
#[animation(field_bound)]
@@ -523,10 +517,10 @@ where
523517
}
524518
}
525519

526-
impl<LengthPercentage> ToCss for Circle<LengthPercentage>
520+
impl<Position, LengthPercentage> ToCss for Circle<Position, LengthPercentage>
527521
where
528522
LengthPercentage: ToCss + PartialEq,
529-
ShapePosition<LengthPercentage>: ToCss,
523+
Position: ToCss,
530524
{
531525
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
532526
where
@@ -552,10 +546,10 @@ where
552546
}
553547
}
554548

555-
impl<LengthPercentage> ToCss for Ellipse<LengthPercentage>
549+
impl<Position, LengthPercentage> ToCss for Ellipse<Position, LengthPercentage>
556550
where
557551
LengthPercentage: ToCss + PartialEq,
558-
ShapePosition<LengthPercentage>: ToCss,
552+
Position: ToCss,
559553
{
560554
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
561555
where

‎servo/components/style/values/specified/basic_shape.rs‎

Lines changed: 5 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ use crate::values::specified::angle::Angle;
2121
use crate::values::specified::border::BorderRadius;
2222
use crate::values::specified::image::Image;
2323
use crate::values::specified::length::LengthPercentageOrAuto;
24-
use crate::values::specified::position::{Position, Side};
24+
use crate::values::specified::position::Position;
2525
use crate::values::specified::url::SpecifiedUrl;
26-
use crate::values::specified::PositionComponent;
2726
use crate::values::specified::{LengthPercentage, NonNegativeLengthPercentage, SVGPathData};
2827
use crate::values::CSSFloat;
2928
use crate::Zero;
@@ -40,22 +39,17 @@ pub type ClipPath = generic::GenericClipPath<BasicShape, SpecifiedUrl>;
4039
/// A specified `shape-outside` value.
4140
pub type ShapeOutside = generic::GenericShapeOutside<BasicShape, Image>;
4241

43-
/// A specified value for `at <position>` in circle() and ellipse().
44-
// Note: its computed value is the same as computed::position::Position. We just want to always use
45-
// LengthPercentage as the type of its components, for basic shapes.
46-
pub type RadialPosition = generic::ShapePosition<LengthPercentage>;
47-
4842
/// A specified basic shape.
4943
pub type BasicShape = generic::GenericBasicShape<Angle, Position, LengthPercentage, BasicShapeRect>;
5044

5145
/// The specified value of `inset()`.
5246
pub type InsetRect = generic::GenericInsetRect<LengthPercentage>;
5347

5448
/// A specified circle.
55-
pub type Circle = generic::Circle<LengthPercentage>;
49+
pub type Circle = generic::Circle<Position, LengthPercentage>;
5650

5751
/// A specified ellipse.
58-
pub type Ellipse = generic::Ellipse<LengthPercentage>;
52+
pub type Ellipse = generic::Ellipse<Position, LengthPercentage>;
5953

6054
/// The specified value of `ShapeRadius`.
6155
pub type ShapeRadius = generic::ShapeRadius<LengthPercentage>;
@@ -390,60 +384,13 @@ impl InsetRect {
390384
}
391385
}
392386

393-
impl ToCss for RadialPosition {
394-
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
395-
where
396-
W: Write,
397-
{
398-
self.horizontal.to_css(dest)?;
399-
dest.write_char(' ')?;
400-
self.vertical.to_css(dest)
401-
}
402-
}
403-
404-
fn convert_to_length_percentage<S: Side>(c: PositionComponent<S>) -> LengthPercentage {
405-
use crate::values::specified::{AllowedNumericType, Percentage};
406-
// Convert the value when parsing, to make sure we serialize it properly for both
407-
// specified and computed values.
408-
// https://drafts.csswg.org/css-shapes-1/#basic-shape-serialization
409-
match c {
410-
// Since <position> keywords stand in for percentages, keywords without an offset
411-
// turn into percentages.
412-
PositionComponent::Center => LengthPercentage::from(Percentage::new(0.5)),
413-
PositionComponent::Side(keyword, None) => {
414-
Percentage::new(if keyword.is_start() { 0. } else { 1. }).into()
415-
},
416-
// Per spec issue, https://github.com/w3c/csswg-drafts/issues/8695, the part of
417-
// "avoiding calc() expressions where possible" and "avoiding calc()
418-
// transformations" will be removed from the spec, and we should follow the
419-
// css-values-4 for position, i.e. we make it as length-percentage always.
420-
// https://drafts.csswg.org/css-shapes-1/#basic-shape-serialization.
421-
// https://drafts.csswg.org/css-values-4/#typedef-position
422-
PositionComponent::Side(keyword, Some(length)) => {
423-
if keyword.is_start() {
424-
length
425-
} else {
426-
length.hundred_percent_minus(AllowedNumericType::All)
427-
}
428-
},
429-
PositionComponent::Length(length) => length,
430-
}
431-
}
432-
433387
fn parse_at_position<'i, 't>(
434388
context: &ParserContext,
435389
input: &mut Parser<'i, 't>,
436-
) -> Result<GenericPositionOrAuto<RadialPosition>, ParseError<'i>> {
437-
use crate::values::specified::position::Position;
390+
) -> Result<GenericPositionOrAuto<Position>, ParseError<'i>> {
438391
if input.try_parse(|i| i.expect_ident_matching("at")).is_ok() {
439-
Position::parse(context, input).map(|pos| {
440-
GenericPositionOrAuto::Position(RadialPosition::new(
441-
convert_to_length_percentage(pos.horizontal),
442-
convert_to_length_percentage(pos.vertical),
443-
))
444-
})
392+
Position::parse(context, input).map(GenericPositionOrAuto::Position)
445393
} else {
446-
// `at <position>` is omitted.
447394
Ok(GenericPositionOrAuto::Auto)
448395
}
449396
}

‎servo/components/style/values/specified/length.rs‎

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1991,32 +1991,6 @@ impl LengthPercentage {
19911991
AllowAnchorPositioningFunctions::No,
19921992
)
19931993
}
1994-
1995-
/// Returns self as specified::calc::CalcNode.
1996-
/// Note that this expect the clamping_mode is AllowedNumericType::All for Calc. The caller
1997-
/// should take care about it when using this function.
1998-
fn to_calc_node(self) -> CalcNode {
1999-
match self {
2000-
LengthPercentage::Length(l) => CalcNode::Leaf(calc::Leaf::Length(l)),
2001-
LengthPercentage::Percentage(p) => CalcNode::Leaf(calc::Leaf::Percentage(p.0)),
2002-
LengthPercentage::Calc(p) => p.node,
2003-
}
2004-
}
2005-
2006-
/// Construct the value representing `calc(100% - self)`.
2007-
pub fn hundred_percent_minus(self, clamping_mode: AllowedNumericType) -> Self {
2008-
let mut sum = smallvec::SmallVec::<[CalcNode; 2]>::new();
2009-
sum.push(CalcNode::Leaf(calc::Leaf::Percentage(1.0)));
2010-
2011-
let mut node = self.to_calc_node();
2012-
node.negate();
2013-
sum.push(node);
2014-
2015-
let calc = CalcNode::Sum(sum.into_boxed_slice().into());
2016-
LengthPercentage::Calc(Box::new(
2017-
calc.into_length_or_percentage(clamping_mode).unwrap(),
2018-
))
2019-
}
20201994
}
20211995

20221996
impl Zero for LengthPercentage {

0 commit comments

Comments
 (0)
Sponsor
SponsoredKunjungi sekarang
Promo