[webkit-changes] [WebKit/WebKit] c64584: Add private WKWebView APIs to globally control ani...
Tyler Wilcock
noreply at github.com
Mon Jan 9 10:14:02 PST 2023
Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: c6458455e6dae557244f23cdb6f9f6aec6899f43
https://github.com/WebKit/WebKit/commit/c6458455e6dae557244f23cdb6f9f6aec6899f43
Author: Tyler Wilcock <tyler_w at apple.com>
Date: 2023-01-09 (Mon, 09 Jan 2023)
Changed paths:
M Source/WebCore/html/HTMLImageElement.cpp
M Source/WebCore/page/ChromeClient.h
M Source/WebCore/page/Page.cpp
M Source/WebCore/page/Page.h
M Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
M Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h
M Source/WebKit/UIProcess/WebPageProxy.cpp
M Source/WebKit/UIProcess/WebPageProxy.h
M Source/WebKit/UIProcess/WebPageProxy.messages.in
M Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.cpp
M Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.h
M Source/WebKit/WebProcess/WebPage/WebPage.cpp
M Source/WebKit/WebProcess/WebPage/WebPage.h
M Source/WebKit/WebProcess/WebPage/WebPage.messages.in
M Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
A Tools/TestWebKitAPI/Tests/WebKit/AnimationControl.mm
Log Message:
-----------
Add private WKWebView APIs to globally control animation play-state
https://bugs.webkit.org/show_bug.cgi?id=248020
rdar://102450537
Reviewed by Chris Fleizach.
This patch adds three private WKWebView APIs:
- `_pauseAllAnimationsWithCompletionHandler`
- `_playAllAnimationsWithCompletionHandler`
- `_allowsAnyAnimationToPlay`
The first two respectively pause all and play all animations on the
page. `_allowsAnyAnimationToPlay` determines whether any animation on
the page is allowed to play (via `Page::imageAnimationEnabled()`, or if any
animation is playing individually, overriding the page-wide state). This
allows consumers to be smart about the UI they show (i.e. only show
"Pause All Animations" UI if anything is actually allowed to animate).
I made these APIs private for now because they potentially overlap with
the nascent `forced-reduced-motion` CSS proposal:
https://github.com/w3c/csswg-drafts/issues/7440
We don't want to commit this to public API when `forced-reduced-motion`
may evolve in a different direction.
Tested via new API test AnimationControl.mm.
* Source/WebCore/html/HTMLImageElement.cpp:
(WebCore::HTMLImageElement::~HTMLImageElement):
Remove `this` from the Page state tracking individually playing animations.
(WebCore::HTMLImageElement::setAllowsAnimation):
Now updates `Page::m_individuallyPlayingAnimationElements`. A missing
repaint was also added to this method. A repaint is required for an
animation to start playing or to become paused (otherwise it will remain
in its previous playing / paused state).
* Source/WebCore/page/ChromeClient.h:
(WebCore::ChromeClient::isAnyAnimationAllowedToPlayDidChange): Added.
* Source/WebCore/page/Page.h:
* Source/WebCore/page/Page.cpp:
(WebCore::Page::setImageAnimationEnabled):
Update `ChromeClient::isAnyAnimationAllowedToPlayDidChange` if necessary.
(WebCore::Page::addIndividuallyPlayingAnimationElement): Added.
(WebCore::Page::removeIndividuallyPlayingAnimationElement): Added.
* Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h:
* Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _pauseAllAnimationsWithCompletionHandler:]):
(-[WKWebView _playAllAnimationsWithCompletionHandler:]):
(-[WKWebView _allowsAnyAnimationToPlay]):
* Source/WebKit/UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::pauseAllAnimations):
(WebKit::WebPageProxy::playAllAnimations):
* Source/WebKit/UIProcess/WebPageProxy.h:
* Source/WebKit/UIProcess/WebPageProxy.messages.in:
Add `IsAnyAnimationAllowedToPlayDidChange(bool)` message.
* Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.cpp:
(WebKit::WebChromeClient::isAnyAnimationAllowedToPlayDidChange):
* Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.h:
* Source/WebKit/WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::isAnyAnimationAllowedToPlayDidChange):
(WebKit::WebPage::pauseAllAnimations):
(WebKit::WebPage::playAllAnimations):
* Source/WebKit/WebProcess/WebPage/WebPage.h:
* Source/WebKit/WebProcess/WebPage/WebPage.messages.in:
Add new `PauseAllAnimations` and `PlayAllAnimations` messages.
* Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* Tools/TestWebKitAPI/Tests/WebKit/AnimationControl.mm: Added.
Canonical link: https://commits.webkit.org/258671@main
More information about the webkit-changes
mailing list