Skip to content

[web-animations] account for display animations when resolving style - #26248

Merged
webkit-commit-queue merged 1 commit into
WebKit:mainfrom
graouts:display-animatable-in-style-resolution
Mar 22, 2024
Merged

webkit-commit-queue merged 1 commit into
WebKit:mainfrom
graouts:display-animatable-in-style-resolution

Conversation

@graouts

@graouts graouts commented Mar 21, 2024 •

Copy link
Copy Markdown
Contributor

6778ef1

[web-animations] account for `display` animations when resolving style
https://bugs.webkit.org/show_bug.cgi?id=271386

Reviewed by Antti Koivisto.

While we added animation support for the `display` property in bug 271372 / 276464@main, we are
not yet fully accounting for the possibility that the `display` property is animated when resolving
styles in Style::TreeResolver.

There are some subtleties there since, historically, transitions could not be started on an element
with `display: none` and setting `display: none` on an element with running style-originated animations
would cancel those animations.

In this patch we now call `createAnimatedElementUpdate()` under `Style::TreeResolver::resolveElement()`
even when the non-animated style has `display: none`. Within `createAnimatedElementUpdate()`, we now
keep track of the non-animated `display` value prior to updating animations, and when we're done compare
this value to its animated counterpart to determine whether animations affected `display`.

If after updating animations `display: none` is set and that value was not affected by animations, we
cancel any animation created in the process silently (see bug 271365 / 276453@main) such that Web content
may not observe that those animations ever were created.

We also make sure to keep track of whether `display` was affected by updating animations as a new member
of the `ElementUpdate` struct such that when updating renderers in `RenderTreeUpdater::updateElementRenderer()`
we only cancel style-originated animations with a `display: none` style if that that `display` value did not
come from an animation. Otherwise, style-originated animations setting `display: none` would cancel themselves.

These changes allow us to pass the remainder of the WPT test coverage for animating `display`.

* LayoutTests/imported/w3c/web-platform-tests/css/css-animations/display-interpolation-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/css/css-animations/display-none-dont-cancel.tentative-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/css/css-display/animations/display-interpolation-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/web-animations/animation-model/animation-types/display.tentative-expected.txt:
* Source/WebCore/animation/KeyframeEffect.cpp:
(WebCore::KeyframeEffect::ticksContinuouslyWhileActive const):
* Source/WebCore/rendering/updating/RenderTreeUpdater.cpp:
(WebCore::RenderTreeUpdater::updateElementRenderer):
* Source/WebCore/style/StyleTreeResolver.cpp:
(WebCore::Style::affectsRenderedSubtree):
(WebCore::Style::TreeResolver::resolveElement):
(WebCore::Style::TreeResolver::createAnimatedElementUpdate):
* Source/WebCore/style/StyleUpdate.h:
* Source/WebCore/style/Styleable.cpp:
(WebCore::Styleable::updateCSSAnimations const):
(WebCore::Styleable::updateCSSTransitions const):

Canonical link: https://commits.webkit.org/276531@main

71f32c7

Misc iOS, tvOS & watchOS macOS Linux Windows
✅ 🧪 style ✅ 🛠 ios ✅ 🛠 mac ✅ 🛠 wpe ✅ 🛠 wincairo
✅ 🧪 bindings ✅ 🛠 ios-sim ✅ 🛠 mac-AS-debug ✅ 🧪 wpe-wk2
✅ 🧪 webkitperl ✅ 🧪 ios-wk2 ✅ 🧪 api-mac ✅ 🧪 api-wpe
✅ 🧪 ios-wk2-wpt ✅ 🧪 mac-wk1 ✅ 🛠 wpe-skia
✅ 🧪 api-ios ✅ 🧪 mac-wk2 ✅ 🛠 gtk
✅ 🛠 tv ✅ 🧪 mac-AS-debug-wk2 ✅ 🧪 gtk-wk2
✅ 🛠 tv-sim ✅ 🧪 api-gtk
✅ 🛠 watch
✅ 🛠 🧪 unsafe-merge ✅ 🛠 watch-sim

@graouts graouts self-assigned this Mar 21, 2024
@graouts graouts added the Animations Bugs related to CSS + SVG animations and transitions label Mar 21, 2024

@anttijk anttijk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems reasonable but you might want to A/B it for perf. I'm not entirely sure what the effect is.

Comment on lines 192 to 195

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does affectsRenderedSubtree ever return false now?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does since making that function return true yielded a couple of test failures in the subset of tests I've tried this with locally:

imported/w3c/web-platform-tests/css/cssom/getComputedStyle-display-none-001.html → one new PASS result
imported/w3c/web-platform-tests/css/css-transitions/starting-style-cascade.html → one new FAIL result

@graouts graouts added the unsafe-merge-queue Applied to send a pull request to merge-queue, but skip building and testing label Mar 22, 2024
https://bugs.webkit.org/show_bug.cgi?id=271386

Reviewed by Antti Koivisto.

While we added animation support for the `display` property in bug 271372 / 276464@main, we are
not yet fully accounting for the possibility that the `display` property is animated when resolving
styles in Style::TreeResolver.

There are some subtleties there since, historically, transitions could not be started on an element
with `display: none` and setting `display: none` on an element with running style-originated animations
would cancel those animations.

In this patch we now call `createAnimatedElementUpdate()` under `Style::TreeResolver::resolveElement()`
even when the non-animated style has `display: none`. Within `createAnimatedElementUpdate()`, we now
keep track of the non-animated `display` value prior to updating animations, and when we're done compare
this value to its animated counterpart to determine whether animations affected `display`.

If after updating animations `display: none` is set and that value was not affected by animations, we
cancel any animation created in the process silently (see bug 271365 / 276453@main) such that Web content
may not observe that those animations ever were created.

We also make sure to keep track of whether `display` was affected by updating animations as a new member
of the `ElementUpdate` struct such that when updating renderers in `RenderTreeUpdater::updateElementRenderer()`
we only cancel style-originated animations with a `display: none` style if that that `display` value did not
come from an animation. Otherwise, style-originated animations setting `display: none` would cancel themselves.

These changes allow us to pass the remainder of the WPT test coverage for animating `display`.

* LayoutTests/imported/w3c/web-platform-tests/css/css-animations/display-interpolation-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/css/css-animations/display-none-dont-cancel.tentative-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/css/css-display/animations/display-interpolation-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/web-animations/animation-model/animation-types/display.tentative-expected.txt:
* Source/WebCore/animation/KeyframeEffect.cpp:
(WebCore::KeyframeEffect::ticksContinuouslyWhileActive const):
* Source/WebCore/rendering/updating/RenderTreeUpdater.cpp:
(WebCore::RenderTreeUpdater::updateElementRenderer):
* Source/WebCore/style/StyleTreeResolver.cpp:
(WebCore::Style::affectsRenderedSubtree):
(WebCore::Style::TreeResolver::resolveElement):
(WebCore::Style::TreeResolver::createAnimatedElementUpdate):
* Source/WebCore/style/StyleUpdate.h:
* Source/WebCore/style/Styleable.cpp:
(WebCore::Styleable::updateCSSAnimations const):
(WebCore::Styleable::updateCSSTransitions const):

Canonical link: https://commits.webkit.org/276531@main
@webkit-commit-queue
webkit-commit-queue force-pushed the display-animatable-in-style-resolution branch from 71f32c7 to 6778ef1 Compare March 22, 2024 06:08
@webkit-commit-queue

Copy link
Copy Markdown
Collaborator

Committed 276531@main (6778ef1): https://commits.webkit.org/276531@main

Reviewed commits have been landed. Closing PR #26248 and removing active labels.

@webkit-commit-queue
webkit-commit-queue merged commit 6778ef1 into WebKit:main Mar 22, 2024
@webkit-commit-queue webkit-commit-queue removed the unsafe-merge-queue Applied to send a pull request to merge-queue, but skip building and testing label Mar 22, 2024
@graouts
graouts deleted the display-animatable-in-style-resolution branch March 22, 2024 06:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Animations Bugs related to CSS + SVG animations and transitions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants