Skip to content

Commit 540afd6

Browse files
committed
Using rotate: x and transform: rotate(x) yields different behavior with SVG
https://bugs.webkit.org/show_bug.cgi?id=250387 Reviewed by Simon Fraser. Check whether any transform-related property changed in LegacyRenderSVGModelObject::styleDidChange() to determine whether an SVG element's needs to update its transform. To support this we add a new RenderStyle::affectsTransform() method which returns true when any of the RenderStyle data structures related to the "transform", "scale", "rotate", "translate" and "offset" CSS properties are non-empty or defined. * LayoutTests/imported/w3c/web-platform-tests/css/css-transforms/animation/rotate-animation-on-svg-expected.html: Added. * LayoutTests/imported/w3c/web-platform-tests/css/css-transforms/animation/rotate-animation-on-svg-ref.html: Added. * LayoutTests/imported/w3c/web-platform-tests/css/css-transforms/animation/rotate-animation-on-svg.html: Added. * LayoutTests/imported/w3c/web-platform-tests/css/css-transforms/animation/scale-animation-on-svg-expected.html: Added. * LayoutTests/imported/w3c/web-platform-tests/css/css-transforms/animation/scale-animation-on-svg-ref.html: Added. * LayoutTests/imported/w3c/web-platform-tests/css/css-transforms/animation/scale-animation-on-svg.html: Added. * LayoutTests/imported/w3c/web-platform-tests/css/css-transforms/animation/translate-animation-on-svg-expected.html: Added. * LayoutTests/imported/w3c/web-platform-tests/css/css-transforms/animation/translate-animation-on-svg-ref.html: Added. * LayoutTests/imported/w3c/web-platform-tests/css/css-transforms/animation/translate-animation-on-svg.html: Added. * Source/WebCore/rendering/style/RenderStyle.h: (WebCore::RenderStyle::affectsTransform const): * Source/WebCore/rendering/svg/LegacyRenderSVGModelObject.cpp: (WebCore::LegacyRenderSVGModelObject::styleDidChange): Canonical link: https://commits.webkit.org/258882@main
1 parent f5656e4 commit 540afd6

11 files changed

+283
-1
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Animating the "rotate" property on an SVG element</title>
5+
<link rel="help" href="https://drafts.csswg.org/css-transforms-2/#individual-transforms">
6+
7+
<style>
8+
9+
svg {
10+
width: 400px;
11+
height: 400px;
12+
}
13+
14+
rect {
15+
width: 100px;
16+
height: 100px;
17+
transform-origin: 100px 100px;
18+
rotate: 180deg;
19+
}
20+
21+
</style>
22+
</head>
23+
<body>
24+
<svg><rect></rect></svg>
25+
</body>
26+
</html>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Animating the "rotate" property on an SVG element</title>
5+
<link rel="help" href="https://drafts.csswg.org/css-transforms-2/#individual-transforms">
6+
7+
<style>
8+
9+
svg {
10+
width: 400px;
11+
height: 400px;
12+
}
13+
14+
rect {
15+
width: 100px;
16+
height: 100px;
17+
transform-origin: 100px 100px;
18+
rotate: 180deg;
19+
}
20+
21+
</style>
22+
</head>
23+
<body>
24+
<svg><rect></rect></svg>
25+
</body>
26+
</html>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<!DOCTYPE html>
2+
<html class="reftest-wait">
3+
<head>
4+
<title>Animating the "rotate" property on an SVG element</title>
5+
<link rel="help" href="https://drafts.csswg.org/css-transforms-2/#individual-transforms">
6+
<link rel="match" href="rotate-animation-on-svg-ref.html">
7+
8+
<style>
9+
10+
@keyframes rotate-animation {
11+
from { rotate: 0; }
12+
to { rotate: 180deg; }
13+
}
14+
15+
svg {
16+
width: 400px;
17+
height: 400px;
18+
overflow: visible;
19+
}
20+
21+
rect {
22+
width: 100px;
23+
height: 100px;
24+
transform-origin: 100px 100px;
25+
animation: rotate-animation 1ms linear forwards;
26+
}
27+
28+
</style>
29+
</head>
30+
<body>
31+
<svg><rect></rect></svg>
32+
33+
<script>
34+
35+
(async function() {
36+
await Promise.all(document.getAnimations().map(animation => animation.finished));
37+
document.documentElement.classList.remove("reftest-wait");
38+
})();
39+
40+
</script>
41+
</body>
42+
</html>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Animating the "scale" property on an SVG element</title>
5+
<link rel="help" href="https://drafts.csswg.org/css-transforms-2/#individual-transforms">
6+
7+
<style>
8+
9+
svg {
10+
width: 400px;
11+
height: 400px;
12+
}
13+
14+
rect {
15+
width: 100px;
16+
height: 100px;
17+
transform-origin: top left;
18+
scale: 2;
19+
}
20+
21+
</style>
22+
</head>
23+
<body>
24+
<svg><rect></rect></svg>
25+
</body>
26+
</html>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Animating the "scale" property on an SVG element</title>
5+
<link rel="help" href="https://drafts.csswg.org/css-transforms-2/#individual-transforms">
6+
7+
<style>
8+
9+
svg {
10+
width: 400px;
11+
height: 400px;
12+
}
13+
14+
rect {
15+
width: 100px;
16+
height: 100px;
17+
transform-origin: top left;
18+
scale: 2;
19+
}
20+
21+
</style>
22+
</head>
23+
<body>
24+
<svg><rect></rect></svg>
25+
</body>
26+
</html>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<!DOCTYPE html>
2+
<html class="reftest-wait">
3+
<head>
4+
<title>Animating the "scale" property on an SVG element</title>
5+
<link rel="help" href="https://drafts.csswg.org/css-transforms-2/#individual-transforms">
6+
<link rel="match" href="scale-animation-on-svg-ref.html">
7+
8+
<style>
9+
10+
@keyframes scale-animation {
11+
from { scale: 1; }
12+
to { scale: 2; }
13+
}
14+
15+
svg {
16+
width: 400px;
17+
height: 400px;
18+
}
19+
20+
rect {
21+
width: 100px;
22+
height: 100px;
23+
transform-origin: top left;
24+
animation: scale-animation 1ms linear forwards;
25+
}
26+
27+
</style>
28+
</head>
29+
<body>
30+
<svg><rect></rect></svg>
31+
32+
<script>
33+
34+
(async function() {
35+
await Promise.all(document.getAnimations().map(animation => animation.finished));
36+
document.documentElement.classList.remove("reftest-wait");
37+
})();
38+
39+
</script>
40+
</body>
41+
</html>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Animating the "translate" property on an SVG element</title>
5+
<link rel="help" href="https://drafts.csswg.org/css-transforms-2/#individual-transforms">
6+
7+
<style>
8+
9+
svg {
10+
width: 400px;
11+
height: 400px;
12+
}
13+
14+
rect {
15+
width: 100px;
16+
height: 100px;
17+
transform-origin: top left;
18+
translate: 100px 100px;
19+
}
20+
21+
</style>
22+
</head>
23+
<body>
24+
<svg><rect></rect></svg>
25+
</body>
26+
</html>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Animating the "translate" property on an SVG element</title>
5+
<link rel="help" href="https://drafts.csswg.org/css-transforms-2/#individual-transforms">
6+
7+
<style>
8+
9+
svg {
10+
width: 400px;
11+
height: 400px;
12+
}
13+
14+
rect {
15+
width: 200px;
16+
height: 200px;
17+
transform-origin: top left;
18+
translate: 100px 100px;
19+
}
20+
21+
</style>
22+
</head>
23+
<body>
24+
<svg><rect></rect></svg>
25+
</body>
26+
</html>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<!DOCTYPE html>
2+
<html class="reftest-wait">
3+
<head>
4+
<title>Animating the "translate" property on an SVG element</title>
5+
<link rel="help" href="https://drafts.csswg.org/css-transforms-2/#individual-transforms">
6+
<link rel="match" href="translate-animation-on-svg-ref.html">
7+
8+
<style>
9+
10+
@keyframes translate-animation {
11+
from { translate: 0 0; }
12+
to { translate: 100px 100px; }
13+
}
14+
15+
svg {
16+
width: 400px;
17+
height: 400px;
18+
}
19+
20+
rect {
21+
width: 100px;
22+
height: 100px;
23+
transform-origin: top left;
24+
animation: translate-animation 1ms linear forwards;
25+
}
26+
27+
</style>
28+
</head>
29+
<body>
30+
<svg><rect></rect></svg>
31+
32+
<script>
33+
34+
(async function() {
35+
await Promise.all(document.getAnimations().map(animation => animation.finished));
36+
document.documentElement.classList.remove("reftest-wait");
37+
})();
38+
39+
</script>
40+
</body>
41+
</html>

Source/WebCore/rendering/style/RenderStyle.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,8 @@ class RenderStyle {
712712
ScaleTransformOperation* scale() const { return m_rareNonInheritedData->scale.get(); }
713713
TranslateTransformOperation* translate() const { return m_rareNonInheritedData->translate.get(); }
714714

715+
bool affectsTransform() const { return hasTransform() || offsetPath() || rotate() || scale() || translate(); }
716+
715717
TextEmphasisFill textEmphasisFill() const { return static_cast<TextEmphasisFill>(m_rareInheritedData->textEmphasisFill); }
716718
TextEmphasisMark textEmphasisMark() const;
717719
const AtomString& textEmphasisCustomMark() const { return m_rareInheritedData->textEmphasisCustomMark; }

0 commit comments

Comments
 (0)