Skip to content

Commit

Permalink
CSSTransitionDiscrete: implement transition-animation-type
Browse files Browse the repository at this point in the history
This is being discussed here:
w3c/csswg-drafts#8857
The name and values of the property are still under discussion.

This patch does not implement the transition shorthand integration, I'm
going to do that next.

Bug: 1453112
Change-Id: I808cf6bc090ca0f99229eb4a9d9c3c28ccf22afc
  • Loading branch information
josepharhar authored and chromium-wpt-export-bot committed Jun 20, 2023
1 parent 4d24e2f commit 87bc395
Show file tree
Hide file tree
Showing 18 changed files with 50 additions and 18 deletions.
4 changes: 4 additions & 0 deletions css/css-animations/display-interpolation.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

test_interpolation({
property: 'display',
propertyType: 'discrete',
from: 'block',
to: 'none',
// transition:all is not supposed to allow display to be transitioned.
Expand All @@ -44,6 +45,7 @@
// can be worked around by using @initial.
test_interpolation({
property: 'display',
propertyType: 'discrete',
from: 'none',
to: 'block',
'CSS Transitions with transition: all': alwaysBlock,
Expand All @@ -65,12 +67,14 @@

test_interpolation({
property: 'display',
propertyType: 'discrete',
from: 'block',
to: 'block'
}, alwaysBlock);

test_interpolation({
property: 'display',
propertyType: 'discrete',
from: 'none',
to: 'none'
}, alwaysNone);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

test_interpolation({
property: 'content-visibility',
propertyType: 'discrete',
from: 'visible',
to: 'hidden',
// transition:all is not supposed to allow content-visibility to be transitioned.
Expand All @@ -41,6 +42,7 @@

test_interpolation({
property: 'content-visibility',
propertyType: 'discrete',
from: 'hidden',
to: 'visible',
// transition:all is not supposed to allow content-visibility to be transitioned.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
transition-delay: 2s;
transition-property: overlay;
transition-duration: 2s;
transition-animation-type: discrete;
}
[popover]::backdrop {
background-color: blue;
Expand Down
1 change: 1 addition & 0 deletions css/css-position/overlay/overlay-transition-backdrop.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
display: block;
visibility: hidden;
transition: overlay 60s step-end;
transition-animation-type: discrete;
}
[popover]::backdrop {
background-color: green;
Expand Down
1 change: 1 addition & 0 deletions css/css-position/overlay/overlay-transition-finished.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
}
#transition-in {
transition: overlay 0.1s step-end;
transition-animation-type: discrete;
background-color: green;
}
</style>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
}
#transition-in {
transition: overlay 60s step-end;
transition-animation-type: discrete;
background-color: red;
}
</style>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
}
#green.transition-enabled {
transition: overlay 60s step-end;
transition-animation-type: discrete;
}
</style>
<div id="red" popover="manual"></div>
Expand Down
1 change: 1 addition & 0 deletions css/css-position/overlay/overlay-transition.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
}
.enable-transitions :is(#transition-in, #transition-out) {
transition: overlay 60s step-end;
transition-animation-type: discrete;
}
</style>
<div id="container">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from: "from",
to: "to",
expected: "to",
propertyType: "discrete",
}, 'A custom property of type <custom-ident> can yield a discrete CSS Transition');

</script>
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from: 'url("https://example.com/from")',
to: 'url("https://example.com/to")',
expected: 'url("https://example.com/to")',
propertyType: 'discrete',
}, 'A custom property of type <image> can yield a CSS Transition');

</script>
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,23 @@
from: '100deg, 200deg',
to: '300deg',
expected: '300deg',
propertyType: 'discrete',
}, 'A custom property of type <angle># yields a discrete CSS Transition if the lists do not contain the same number of values');

transition_test({
syntax: "<angle>+",
from: '100deg 200deg',
to: '300deg',
expected: '300deg',
propertyType: 'discrete',
}, 'A custom property of type <angle>+ yields a discrete CSS Transition if the lists do not contain the same number of values');

transition_test({
syntax: "<color>#",
from: 'rgb(100, 100, 100), rgb(150, 150, 150)',
to: 'rgb(200, 200, 200)',
expected: 'rgb(200, 200, 200)',
propertyType: 'discrete',
}, 'A custom property of type <color># yields a discrete CSS Transition if the lists do not contain the same number of values');

transition_test({
Expand Down Expand Up @@ -174,4 +177,4 @@
expected: 'url("https://example.com/to")',
}, 'A custom property of type <url>+ yields a discrete CSS Transition if the lists do not contain the same number of values');

</script>
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
syntax: "<transform-function>",
from: "translateX(100px)",
to: "translateX(200px)",
expected: "translateX(150px)"
expected: "translateX(150px)",
propertyType: 'discrete',
}, 'A custom property of type <transform-function> can yield a CSS Transition');

</script>
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
syntax: "<transform-list>",
from: "translateX(100px) scale(2)",
to: "translateX(200px) scale(4)",
expected: "translateX(150px) scale(3)"
expected: "translateX(150px) scale(3)",
propertyType: 'discrete',
}, 'A custom property of type <transform-list> can yield a CSS Transition');

</script>
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from: 'url("https://example.com/from")',
to: 'url("https://example.com/to")',
expected: 'url("https://example.com/to")',
propertyType: 'discrete',
}, 'A custom property of type <url> can yield a discrete CSS Transition');

</script>
</script>
3 changes: 3 additions & 0 deletions css/css-properties-values-api/resources/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ function transition_test(options, description) {
});

target.style.transition = `${options.transitionProperty} 1s -500ms linear`;
if (options.propertyType) {
target.style.transitionPropertyType = options.propertyType;
}
target.style.setProperty(customProperty, options.to);

const animations = target.getAnimations();
Expand Down
2 changes: 2 additions & 0 deletions css/css-transitions/all-with-discrete.tentative.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
}

#target1 {
transition-animation-type: discrete;
transition: all 1s, float 1s;
}

#target2 {
transition-animation-type: discrete;
transition: all 1s;
}
</style>
Expand Down
12 changes: 6 additions & 6 deletions css/motion/animation/offset-interpolation.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
to: 'path("M0 300H 700 Z") 600px 900deg',
method: 'CSS Transitions',
}, [
{at: -0.3, expect: 'path("M0 200H 700") 470px 770deg'},
{at: 0, expect: 'path("M0 200H 700") 500px 800deg'},
{at: 0.3, expect: 'path("M0 200H 700") 530px 830deg'},
{at: -0.3, expect: 'path("M0 300H 700 Z") 470px 770deg'},
{at: 0, expect: 'path("M0 300H 700 Z") 500px 800deg'},
{at: 0.3, expect: 'path("M0 300H 700 Z") 530px 830deg'},
{at: 0.6, expect: 'path("M0 300H 700 Z") 560px 860deg'},
{at: 1, expect: 'path("M0 300H 700 Z") 600px 900deg'},
{at: 1.5, expect: 'path("M0 300H 700 Z") 650px 950deg'},
Expand All @@ -29,9 +29,9 @@
to: 'path("M0 0H 300") 600px 0deg',
method: 'CSS Transitions',
}, [
{at: -0.3, expect: 'path("M0 0H 170") 470px auto 0deg'},
{at: 0, expect: 'path("M0 0H 200") 500px auto 0deg'},
{at: 0.3, expect: 'path("M0 0H 230") 530px auto 0deg'},
{at: -0.3, expect: 'path("M0 0H 170") 470px 0deg'},
{at: 0, expect: 'path("M0 0H 200") 500px 0deg'},
{at: 0.3, expect: 'path("M0 0H 230") 530px 0deg'},
{at: 0.6, expect: 'path("M0 0H 260") 560px 0deg'},
{at: 1, expect: 'path("M0 0H 300") 600px 0deg'},
{at: 1.5, expect: 'path("M0 0H 350") 650px 0deg'},
Expand Down
15 changes: 11 additions & 4 deletions css/support/interpolation-testcommon.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,21 @@
target.style.setProperty(property, isNeutralKeyframe(from) ? '' : from);
},
nonInterpolationExpectations: function(from, to) {
return expectFlip(from, to, 0.5);
return expectFlip(from, to, -Infinity);
},
notAnimatableExpectations: function(from, to, underlying) {
return expectFlip(from, to, -Infinity);
},
interpolate: function(property, from, to, at, target) {
interpolate: function(property, from, to, at, target, propertyType) {
// Force a style recalc on target to set the 'from' value.
getComputedStyle(target).getPropertyValue(property);
target.style.transitionDuration = '100s';
target.style.transitionDelay = '-50s';
target.style.transitionTimingFunction = createEasing(at);
target.style.transitionProperty = property;
if (propertyType) {
target.style.transitionPropertyType = propertyType;
}
target.style.setProperty(property, isNeutralKeyframe(to) ? '' : to);
},
};
Expand All @@ -87,13 +90,16 @@
notAnimatableExpectations: function(from, to, underlying) {
return expectFlip(from, to, -Infinity);
},
interpolate: function(property, from, to, at, target) {
interpolate: function(property, from, to, at, target, propertyType) {
// Force a style recalc on target to set the 'from' value.
getComputedStyle(target).getPropertyValue(property);
target.style.transitionDuration = '100s';
target.style.transitionDelay = '-50s';
target.style.transitionTimingFunction = createEasing(at);
target.style.transitionProperty = 'all';
if (propertyType) {
target.style.transitionPropertyType = propertyType;
}
target.style.setProperty(property, isNeutralKeyframe(to) ? '' : to);
},
};
Expand Down Expand Up @@ -256,6 +262,7 @@
var from = interpolationTest.options.from;
var to = interpolationTest.options.to;
var comparisonFunction = interpolationTest.options.comparisonFunction;
var propertyType = interpolationTest.options.propertyType;

if ((interpolationTest.options.method && interpolationTest.options.method != interpolationMethod.name)
|| !interpolationMethod.supportsProperty(property)
Expand Down Expand Up @@ -301,7 +308,7 @@
}
interpolationMethod.setup(property, from, target);
target.interpolate = function() {
interpolationMethod.interpolate(property, from, to, expectation.at, target);
interpolationMethod.interpolate(property, from, to, expectation.at, target, propertyType);
};
target.measure = function() {
for (var [expectedProp, expectedStr] of Object.entries(expectedProperties)) {
Expand Down

0 comments on commit 87bc395

Please sign in to comment.