Skip to content

Commit f00d201

Browse files
author
Sandor Molnar
committed
Revert "Bug 1921501 - Support parsing of <control-point> in shape(). r=boris,longsonr,firefox-style-system-reviewers,firefox-svg-reviewers,layout-reviewers" for causing wpt failures
This reverts commit ee2f8cd.
1 parent 1bd71e9 commit f00d201

File tree

19 files changed

+208
-483
lines changed

19 files changed

+208
-483
lines changed

dom/svg/SVGAnimatedPathSegList.cpp

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,6 @@ static StyleCommandEndPoint<float> MakeEndPoint(PositionType type, float x,
3939
}
4040
}
4141

42-
static StyleControlPoint<float> MakeControlPoint(PositionType type, float x,
43-
float y) {
44-
if (type == PositionType::Absolute) {
45-
return StyleControlPoint<float>::Position({x, y});
46-
} else {
47-
return StyleControlPoint<float>::Relative(
48-
StyleRelativeControlPoint<float>{{x, y}, StyleControlReference::None});
49-
}
50-
}
51-
5242
class MOZ_STACK_CLASS SVGPathSegmentInitWrapper final {
5343
public:
5444
explicit SVGPathSegmentInitWrapper(const SVGPathSegmentInit& aSVGPathSegment)
@@ -97,30 +87,24 @@ class MOZ_STACK_CLASS SVGPathSegmentInitWrapper final {
9787
return StylePathCommand::CubicCurve(
9888
MakeEndPoint(PositionType::Absolute, mInit.mValues[4],
9989
mInit.mValues[5]),
100-
MakeControlPoint(PositionType::Absolute, mInit.mValues[0],
101-
mInit.mValues[1]),
102-
MakeControlPoint(PositionType::Absolute, mInit.mValues[2],
103-
mInit.mValues[3]));
90+
{mInit.mValues[0], mInit.mValues[1]},
91+
{mInit.mValues[2], mInit.mValues[3]});
10492
case 'c':
10593
return StylePathCommand::CubicCurve(
10694
MakeEndPoint(PositionType::Relative, mInit.mValues[4],
10795
mInit.mValues[5]),
108-
MakeControlPoint(PositionType::Relative, mInit.mValues[0],
109-
mInit.mValues[1]),
110-
MakeControlPoint(PositionType::Relative, mInit.mValues[2],
111-
mInit.mValues[3]));
96+
{mInit.mValues[0], mInit.mValues[1]},
97+
{mInit.mValues[2], mInit.mValues[3]});
11298
case 'Q':
11399
return StylePathCommand::QuadCurve(
114100
MakeEndPoint(PositionType::Absolute, mInit.mValues[2],
115101
mInit.mValues[3]),
116-
MakeControlPoint(PositionType::Absolute, mInit.mValues[0],
117-
mInit.mValues[1]));
102+
{mInit.mValues[0], mInit.mValues[1]});
118103
case 'q':
119104
return StylePathCommand::QuadCurve(
120105
MakeEndPoint(PositionType::Relative, mInit.mValues[2],
121106
mInit.mValues[3]),
122-
MakeControlPoint(PositionType::Relative, mInit.mValues[0],
123-
mInit.mValues[1]));
107+
{mInit.mValues[0], mInit.mValues[1]});
124108
case 'A':
125109
return StylePathCommand::Arc(
126110
MakeEndPoint(PositionType::Absolute, mInit.mValues[5],
@@ -149,14 +133,12 @@ class MOZ_STACK_CLASS SVGPathSegmentInitWrapper final {
149133
return StylePathCommand::SmoothCubic(
150134
MakeEndPoint(PositionType::Absolute, mInit.mValues[2],
151135
mInit.mValues[3]),
152-
MakeControlPoint(PositionType::Absolute, mInit.mValues[0],
153-
mInit.mValues[1]));
136+
{mInit.mValues[0], mInit.mValues[1]});
154137
case 's':
155138
return StylePathCommand::SmoothCubic(
156139
MakeEndPoint(PositionType::Relative, mInit.mValues[2],
157140
mInit.mValues[3]),
158-
MakeControlPoint(PositionType::Relative, mInit.mValues[0],
159-
mInit.mValues[1]));
141+
{mInit.mValues[0], mInit.mValues[1]});
160142
case 'T':
161143
return StylePathCommand::SmoothQuad(MakeEndPoint(
162144
PositionType::Absolute, mInit.mValues[0], mInit.mValues[1]));

dom/svg/SVGPathData.cpp

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,6 @@ static already_AddRefed<Path> BuildPathInternal(
245245

246246
for (const auto& cmd : aPath) {
247247
seg = &cmd;
248-
bool isRelative = false;
249248
switch (cmd.tag) {
250249
case Command::Tag::Close:
251250
// set this early to allow drawing of square caps for "M{x},{y} Z":
@@ -272,13 +271,15 @@ static already_AddRefed<Path> BuildPathInternal(
272271
break;
273272
}
274273
case Command::Tag::CubicCurve:
275-
isRelative = cmd.cubic_curve.point.IsByCoordinate();
274+
cp1 = cmd.cubic_curve.control1.ToGfxPoint(aPercentageBasis);
275+
cp2 = cmd.cubic_curve.control2.ToGfxPoint(aPercentageBasis);
276276
segEnd = cmd.cubic_curve.point.ToGfxPoint(aPercentageBasis);
277-
segEnd = isRelative ? segEnd + segStart : segEnd;
278-
cp1 = cmd.cubic_curve.control1.ToGfxPoint(segStart, segEnd, isRelative,
279-
aPercentageBasis);
280-
cp2 = cmd.cubic_curve.control2.ToGfxPoint(segStart, segEnd, isRelative,
281-
aPercentageBasis);
277+
278+
if (cmd.cubic_curve.point.IsByCoordinate()) {
279+
cp1 += segStart;
280+
cp2 += segStart;
281+
segEnd += segStart;
282+
}
282283

283284
if (segEnd != segStart || segEnd != cp1 || segEnd != cp2) {
284285
subpathHasLength = true;
@@ -287,12 +288,13 @@ static already_AddRefed<Path> BuildPathInternal(
287288
break;
288289

289290
case Command::Tag::QuadCurve:
290-
isRelative = cmd.quad_curve.point.IsByCoordinate();
291+
cp1 = cmd.quad_curve.control1.ToGfxPoint(aPercentageBasis);
291292
segEnd = cmd.quad_curve.point.ToGfxPoint(aPercentageBasis);
292-
segEnd = isRelative ? segEnd + segStart
293-
: segEnd; // set before setting tcp2!
294-
cp1 = cmd.quad_curve.control1.ToGfxPoint(segStart, segEnd, isRelative,
295-
aPercentageBasis);
293+
294+
if (cmd.quad_curve.point.IsByCoordinate()) {
295+
cp1 += segStart;
296+
segEnd += segStart; // set before setting tcp2!
297+
}
296298

297299
// Convert quadratic curve to cubic curve:
298300
tcp1 = segStart + (cp1 - segStart) * 2 / 3;
@@ -357,12 +359,14 @@ static already_AddRefed<Path> BuildPathInternal(
357359
break;
358360
}
359361
case Command::Tag::SmoothCubic:
360-
isRelative = cmd.smooth_cubic.point.IsByCoordinate();
361-
segEnd = cmd.smooth_cubic.point.ToGfxPoint(aPercentageBasis);
362-
segEnd = isRelative ? segEnd + segStart : segEnd;
363362
cp1 = prevSeg && prevSeg->IsCubicType() ? segStart * 2 - cp2 : segStart;
364-
cp2 = cmd.smooth_cubic.control2.ToGfxPoint(segStart, segEnd, isRelative,
365-
aPercentageBasis);
363+
cp2 = cmd.smooth_cubic.control2.ToGfxPoint(aPercentageBasis);
364+
segEnd = cmd.smooth_cubic.point.ToGfxPoint(aPercentageBasis);
365+
366+
if (cmd.smooth_cubic.point.IsByCoordinate()) {
367+
cp2 += segStart;
368+
segEnd += segStart;
369+
}
366370

367371
if (segEnd != segStart || segEnd != cp1 || segEnd != cp2) {
368372
subpathHasLength = true;
@@ -542,7 +546,6 @@ void SVGPathData::GetMarkerPositioningData(Span<const StylePathCommand> aPath,
542546
Point& segStart = prevSegEnd;
543547
Point segEnd;
544548
float segStartAngle, segEndAngle;
545-
bool isRelative = false;
546549

547550
switch (cmd.tag) // to find segStartAngle, segEnd and segEndAngle
548551
{
@@ -567,15 +570,15 @@ void SVGPathData::GetMarkerPositioningData(Span<const StylePathCommand> aPath,
567570
break;
568571
}
569572
case StylePathCommand::Tag::CubicCurve: {
570-
isRelative = cmd.cubic_curve.point.IsByCoordinate();
573+
Point cp1 = cmd.cubic_curve.control1.ToGfxPoint() * aZoom;
574+
Point cp2 = cmd.cubic_curve.control2.ToGfxPoint() * aZoom;
571575
segEnd = cmd.cubic_curve.point.ToGfxPoint() * aZoom;
572-
segEnd = isRelative ? segEnd + segStart : segEnd;
573-
Point cp1 =
574-
cmd.cubic_curve.control1.ToGfxPoint(segStart, segEnd, isRelative) *
575-
aZoom;
576-
Point cp2 =
577-
cmd.cubic_curve.control2.ToGfxPoint(segStart, segEnd, isRelative) *
578-
aZoom;
576+
577+
if (cmd.cubic_curve.point.IsByCoordinate()) {
578+
cp1 += segStart;
579+
cp2 += segStart;
580+
segEnd += segStart;
581+
}
579582

580583
prevCP = cp2;
581584
segStartAngle = AngleOfVector(
@@ -585,13 +588,13 @@ void SVGPathData::GetMarkerPositioningData(Span<const StylePathCommand> aPath,
585588
break;
586589
}
587590
case StylePathCommand::Tag::QuadCurve: {
588-
isRelative = cmd.quad_curve.point.IsByCoordinate();
591+
Point cp1 = cmd.quad_curve.control1.ToGfxPoint() * aZoom;
589592
segEnd = cmd.quad_curve.point.ToGfxPoint() * aZoom;
590-
segEnd = isRelative ? segEnd + segStart
591-
: segEnd; // set before setting tcp2!
592-
Point cp1 =
593-
cmd.quad_curve.control1.ToGfxPoint(segStart, segEnd, isRelative) *
594-
aZoom;
593+
594+
if (cmd.quad_curve.point.IsByCoordinate()) {
595+
cp1 += segStart;
596+
segEnd += segStart; // set before setting tcp2!
597+
}
595598

596599
prevCP = cp1;
597600
segStartAngle = AngleOfVector(cp1 == segStart ? segEnd : cp1, segStart);
@@ -662,12 +665,13 @@ void SVGPathData::GetMarkerPositioningData(Span<const StylePathCommand> aPath,
662665
const Point& cp1 = prevSeg && prevSeg->IsCubicType()
663666
? segStart * 2 - prevCP
664667
: segStart;
665-
isRelative = cmd.smooth_cubic.point.IsByCoordinate();
668+
Point cp2 = cmd.smooth_cubic.control2.ToGfxPoint() * aZoom;
666669
segEnd = cmd.smooth_cubic.point.ToGfxPoint() * aZoom;
667-
segEnd = isRelative ? segEnd + segStart : segEnd;
668-
Point cp2 =
669-
cmd.smooth_cubic.control2.ToGfxPoint(segStart, segEnd, isRelative) *
670-
aZoom;
670+
671+
if (cmd.smooth_cubic.point.IsByCoordinate()) {
672+
cp2 += segStart;
673+
segEnd += segStart;
674+
}
671675

672676
prevCP = cp2;
673677
segStartAngle = AngleOfVector(

dom/svg/SVGPathElement.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ static void CreatePathSegments(SVGPathElement* aPathElement,
139139
auto curve = StylePathCommand::CubicCurve(
140140
StyleCommandEndPoint<StyleCSSFloat>::ToPosition(
141141
{segEnd.x, segEnd.y}),
142-
StyleControlPoint<StyleCSSFloat>::Position({cp1.x, cp1.y}),
143-
StyleControlPoint<StyleCSSFloat>::Position({cp2.x, cp2.y}));
142+
StyleCoordinatePair<StyleCSSFloat>{cp1.x, cp1.y},
143+
StyleCoordinatePair<StyleCSSFloat>{cp2.x, cp2.y});
144144
aValues.AppendElement(new SVGPathSegment(aPathElement, curve));
145145
}
146146
break;

dom/svg/SVGPathSegUtils.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,12 @@ void SVGPathSegUtils::TraversePathSegment(const StylePathCommand& aCommand,
134134
? aState.pos + aCommand.cubic_curve.point.ToGfxPoint()
135135
: aCommand.cubic_curve.point.ToGfxPoint();
136136
if (aState.ShouldUpdateLengthAndControlPoints()) {
137-
Point cp1 = aCommand.cubic_curve.control1.ToGfxPoint(aState.pos, to,
138-
isRelative);
139-
Point cp2 = aCommand.cubic_curve.control2.ToGfxPoint(aState.pos, to,
140-
isRelative);
137+
Point cp1 = aCommand.cubic_curve.control1.ToGfxPoint();
138+
Point cp2 = aCommand.cubic_curve.control2.ToGfxPoint();
139+
if (isRelative) {
140+
cp1 += aState.pos;
141+
cp2 += aState.pos;
142+
}
141143
aState.length +=
142144
(float)CalcLengthOfCubicBezier(aState.pos, cp1, cp2, to);
143145
aState.cp2 = cp2;
@@ -152,8 +154,9 @@ void SVGPathSegUtils::TraversePathSegment(const StylePathCommand& aCommand,
152154
? aState.pos + aCommand.quad_curve.point.ToGfxPoint()
153155
: aCommand.quad_curve.point.ToGfxPoint();
154156
if (aState.ShouldUpdateLengthAndControlPoints()) {
155-
Point cp =
156-
aCommand.quad_curve.control1.ToGfxPoint(aState.pos, to, isRelative);
157+
Point cp = isRelative
158+
? aState.pos + aCommand.quad_curve.control1.ToGfxPoint()
159+
: aCommand.quad_curve.control1.ToGfxPoint();
157160
aState.length += (float)CalcLengthOfQuadraticBezier(aState.pos, cp, to);
158161
aState.cp1 = cp;
159162
aState.cp2 = to;
@@ -217,8 +220,9 @@ void SVGPathSegUtils::TraversePathSegment(const StylePathCommand& aCommand,
217220
: aCommand.smooth_cubic.point.ToGfxPoint();
218221
if (aState.ShouldUpdateLengthAndControlPoints()) {
219222
Point cp1 = aState.pos - (aState.cp2 - aState.pos);
220-
Point cp2 = aCommand.smooth_cubic.control2.ToGfxPoint(aState.pos, to,
221-
isRelative);
223+
Point cp2 = isRelative ? aState.pos +
224+
aCommand.smooth_cubic.control2.ToGfxPoint()
225+
: aCommand.smooth_cubic.control2.ToGfxPoint();
222226
aState.length +=
223227
(float)CalcLengthOfCubicBezier(aState.pos, cp1, cp2, to);
224228
aState.cp2 = cp2;

dom/svg/SVGPathSegment.cpp

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(SVGPathSegment, mSVGPathElement)
2020

2121
//----------------------------------------------------------------------
2222
// Implementation
23-
void SVGPathSegment::AppendEndPoint(
23+
void SVGPathSegment::AppendPoint(
2424
const StyleCommandEndPoint<StyleCSSFloat>& point) {
2525
if (point.IsToPosition()) {
2626
const auto& pos = point.AsToPosition();
@@ -33,19 +33,6 @@ void SVGPathSegment::AppendEndPoint(
3333
}
3434
}
3535

36-
void SVGPathSegment::AppendControlPoint(
37-
const StyleControlPoint<StyleCSSFloat>& point) {
38-
if (point.IsPosition()) {
39-
const auto& pos = point.AsPosition();
40-
mValues.AppendElement(pos.horizontal);
41-
mValues.AppendElement(pos.vertical);
42-
} else if (point.IsRelative()) {
43-
const auto& rel_point = point.AsRelative();
44-
mValues.AppendElement(rel_point.coord.x);
45-
mValues.AppendElement(rel_point.coord.y);
46-
}
47-
}
48-
4936
SVGPathSegment::SVGPathSegment(SVGPathElement* aSVGPathElement,
5037
const StylePathCommand& aCommand)
5138
: mSVGPathElement(aSVGPathElement) {
@@ -55,24 +42,27 @@ SVGPathSegment::SVGPathSegment(SVGPathElement* aSVGPathElement,
5542
break;
5643
case StylePathCommand::Tag::Move:
5744
mCommand.AssignLiteral(aCommand.move.point.IsToPosition() ? "M" : "m");
58-
AppendEndPoint(aCommand.move.point);
45+
AppendPoint(aCommand.move.point);
5946
break;
6047
case StylePathCommand::Tag::Line:
6148
mCommand.AssignLiteral(aCommand.line.point.IsToPosition() ? "L" : "l");
62-
AppendEndPoint(aCommand.line.point);
49+
AppendPoint(aCommand.line.point);
6350
break;
6451
case StylePathCommand::Tag::CubicCurve:
6552
mCommand.AssignLiteral(aCommand.cubic_curve.point.IsToPosition() ? "C"
6653
: "c");
67-
AppendControlPoint(aCommand.cubic_curve.control1);
68-
AppendControlPoint(aCommand.cubic_curve.control2);
69-
AppendEndPoint(aCommand.cubic_curve.point);
54+
mValues.AppendElement(aCommand.cubic_curve.control1.x);
55+
mValues.AppendElement(aCommand.cubic_curve.control1.y);
56+
mValues.AppendElement(aCommand.cubic_curve.control2.x);
57+
mValues.AppendElement(aCommand.cubic_curve.control2.y);
58+
AppendPoint(aCommand.cubic_curve.point);
7059
break;
7160
case StylePathCommand::Tag::QuadCurve:
7261
mCommand.AssignLiteral(aCommand.quad_curve.point.IsToPosition() ? "Q"
7362
: "q");
74-
AppendControlPoint(aCommand.quad_curve.control1);
75-
AppendEndPoint(aCommand.quad_curve.point);
63+
mValues.AppendElement(aCommand.quad_curve.control1.x);
64+
mValues.AppendElement(aCommand.quad_curve.control1.y);
65+
AppendPoint(aCommand.quad_curve.point);
7666
break;
7767
case StylePathCommand::Tag::Arc:
7868
mCommand.AssignLiteral(aCommand.arc.point.IsToPosition() ? "A" : "a");
@@ -81,7 +71,7 @@ SVGPathSegment::SVGPathSegment(SVGPathElement* aSVGPathElement,
8171
mValues.AppendElement(aCommand.arc.rotate);
8272
mValues.AppendElement(aCommand.arc.arc_size == StyleArcSize::Large);
8373
mValues.AppendElement(aCommand.arc.arc_sweep == StyleArcSweep::Cw);
84-
AppendEndPoint(aCommand.arc.point);
74+
AppendPoint(aCommand.arc.point);
8575
break;
8676
case StylePathCommand::Tag::HLine:
8777
mCommand.AssignLiteral(aCommand.h_line.by_to == StyleByTo::To ? "H"
@@ -96,13 +86,14 @@ SVGPathSegment::SVGPathSegment(SVGPathElement* aSVGPathElement,
9686
case StylePathCommand::Tag::SmoothCubic:
9787
mCommand.AssignLiteral(aCommand.smooth_cubic.point.IsToPosition() ? "S"
9888
: "s");
99-
AppendControlPoint(aCommand.smooth_cubic.control2);
100-
AppendEndPoint(aCommand.smooth_cubic.point);
89+
mValues.AppendElement(aCommand.smooth_cubic.control2.x);
90+
mValues.AppendElement(aCommand.smooth_cubic.control2.y);
91+
AppendPoint(aCommand.smooth_cubic.point);
10192
break;
10293
case StylePathCommand::Tag::SmoothQuad:
10394
mCommand.AssignLiteral(aCommand.smooth_quad.point.IsToPosition() ? "T"
10495
: "t");
105-
AppendEndPoint(aCommand.smooth_quad.point);
96+
AppendPoint(aCommand.smooth_quad.point);
10697
break;
10798
}
10899
}

dom/svg/SVGPathSegment.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ class SVGPathSegment final : public nsWrapperCache {
4242
RefPtr<SVGPathElement> mSVGPathElement;
4343
nsString mCommand;
4444
nsTArray<float> mValues;
45-
void AppendEndPoint(const StyleCommandEndPoint<StyleCSSFloat>& point);
46-
void AppendControlPoint(const StyleControlPoint<StyleCSSFloat>& point);
45+
void AppendPoint(const StyleCommandEndPoint<StyleCSSFloat>& point);
4746
};
4847

4948
} // namespace mozilla::dom

layout/inspector/tests/test_bug877690.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@
293293

294294
// Regression test for bug 1255379.
295295
var shapeFunction = [ "close", "evenodd", "nonzero", "by", "to", "cw", "ccw",
296-
"small", "large", "end", "origin", "start"];
296+
"small", "large" ];
297297
var expected = [ "inherit", "initial", "unset", "revert", "revert-layer",
298298
"none", "url", "polygon", "circle", "ellipse", "inset",
299299
"path", "rect", "xywh", "fill-box", "stroke-box",

0 commit comments

Comments
 (0)