Bug 248020 - Add private WKWebView APIs to globally control animation play-state
Summary: Add private WKWebView APIs to globally control animation play-state
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Animations (show other bugs)
Version: Other
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Tyler Wilcock
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2022-11-16 21:21 PST by Tyler Wilcock
Modified: 2023-01-09 10:13 PST (History)
13 users (show)

See Also:


Attachments
Patch (16.84 KB, patch)
2022-11-16 23:41 PST, Tyler Wilcock
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (16.80 KB, patch)
2022-11-16 23:58 PST, Tyler Wilcock
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (16.87 KB, patch)
2022-11-17 00:33 PST, Tyler Wilcock
no flags Details | Formatted Diff | Diff
Patch (24.29 KB, patch)
2022-11-28 11:29 PST, Tyler Wilcock
no flags Details | Formatted Diff | Diff
Patch (30.00 KB, patch)
2022-12-12 20:10 PST, Tyler Wilcock
no flags Details | Formatted Diff | Diff
Patch (29.81 KB, patch)
2022-12-12 23:56 PST, Tyler Wilcock
no flags Details | Formatted Diff | Diff
Patch (29.51 KB, patch)
2023-01-06 22:53 PST, Tyler Wilcock
no flags Details | Formatted Diff | Diff
Patch (29.51 KB, patch)
2023-01-07 20:08 PST, Tyler Wilcock
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tyler Wilcock 2022-11-16 21:21:00 PST
Add private iOS WKWebView API to pause all and play all animations on the page
Comment 1 Tyler Wilcock 2022-11-16 23:41:35 PST
Created attachment 463574 [details]
Patch
Comment 2 Tyler Wilcock 2022-11-16 23:58:02 PST
Created attachment 463576 [details]
Patch
Comment 3 Tyler Wilcock 2022-11-17 00:33:21 PST
Created attachment 463577 [details]
Patch
Comment 4 Antoine Quint 2022-11-18 01:11:38 PST
The title of this bug is not specific to animated images, but the patch is.
Comment 5 Radar WebKit Bug Importer 2022-11-23 21:21:17 PST
<rdar://problem/102638732>
Comment 6 Tyler Wilcock 2022-11-28 11:29:07 PST
Created attachment 463766 [details]
Patch
Comment 7 Tyler Wilcock 2022-11-28 11:30:50 PST
(In reply to Antoine Quint from comment #4)
> The title of this bug is not specific to animated images, but the patch is.
We talked about this in Slack, but posting here too for posterity.

The intention of these APIs is to pause and play all types of animations, not just animated images. So it will include SVG animations, Web Animations, model element animations, etc (the latter two are yet to be implemented). Here's a test exercising the core functionality for SVG and image animations: https://github.com/WebKit/WebKit/blob/main/LayoutTests/fast/images/pagewide-play-pause-offscreen-animations.html
Comment 8 Darin Adler 2022-11-29 09:28:26 PST
Comment on attachment 463766 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=463766&action=review

> COMMIT_MESSAGE:1
> +Add private iOS WKWebView APIs: _pauseAllAnimations, _playAllAnimations, _isAnyAnimationAllowedToPlay
 

Why private?
Comment 9 Tyler Wilcock 2022-11-29 10:00:49 PST
(In reply to Darin Adler from comment #8)
> Comment on attachment 463766 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=463766&action=review
> 
> > COMMIT_MESSAGE:1
> > +Add private iOS WKWebView APIs: _pauseAllAnimations, _playAllAnimations, _isAnyAnimationAllowedToPlay
>  
> 
> Why private?
As of now, there will only be one internal consumer. I think we could consider promoting it to a public API later on, but I figured making it private to start is a good first step.
Comment 10 Darin Adler 2022-11-29 10:03:54 PST
(In reply to Tyler Wilcock from comment #9)
> As of now, there will only be one internal consumer. I think we could
> consider promoting it to a public API later on, but I figured making it
> private to start is a good first step.

I don’t agree with this general principle. We should discuss our approach so we don’t build up an even longer list of private API.
Comment 11 Said Abou-Hallawa 2022-11-29 10:41:28 PST
Comment on attachment 463766 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=463766&action=review

> COMMIT_MESSAGE:28
> +tests in AnimationControl.mm to pass consistently.

Can you explain why this change is needed to make the tests pass consistently?

> Source/WebCore/platform/graphics/BitmapImage.cpp:446
> +        m_animationIsRunning = !!m_frameTimer;

This is a weird place to set this flag.

> Source/WebCore/platform/graphics/BitmapImage.h:241
> +    bool m_animationIsRunning { false };

What is the meaning of this flag? And what is the difference between its value and the value of canAnimate()?

I think you are changing its meaning. It is currently true when we are displaying a frame, waiting for its interval to elapse to draw the next frame. With your change it I think it will mean whether the image is animating or still since it is not cleared in BitmapImage::clearTimer().

Also it is weird to have two flags m_animationIsRunning and m_animationFinished although each of them means the opposite to the other. How can we guarantee they are not both set to true? Actually having both of them initialized with false is confusing. If m_animationIsRunning is false then m_animationFinished should be true.
Comment 12 Said Abou-Hallawa 2022-11-29 15:50:03 PST
Comment on attachment 463766 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=463766&action=review

>> Source/WebCore/platform/graphics/BitmapImage.h:241
>> +    bool m_animationIsRunning { false };
> 
> What is the meaning of this flag? And what is the difference between its value and the value of canAnimate()?
> 
> I think you are changing its meaning. It is currently true when we are displaying a frame, waiting for its interval to elapse to draw the next frame. With your change it I think it will mean whether the image is animating or still since it is not cleared in BitmapImage::clearTimer().
> 
> Also it is weird to have two flags m_animationIsRunning and m_animationFinished although each of them means the opposite to the other. How can we guarantee they are not both set to true? Actually having both of them initialized with false is confusing. If m_animationIsRunning is false then m_animationFinished should be true.

I meant to say you are changing the meaning of BitmapImage::isAnimating() since it is now returning m_animationIsRunning.
Comment 13 James Craig 2022-12-12 11:01:39 PST
It may  be wise to keep the new API private until CSS has a resolution on Issue #7440? https://github.com/w3c/csswg-drafts/issues/7440
Comment 14 Tyler Wilcock 2022-12-12 20:10:37 PST
Created attachment 464018 [details]
Patch
Comment 15 Tyler Wilcock 2022-12-12 20:15:19 PST
(In reply to Said Abou-Hallawa from comment #11)
> Comment on attachment 463766 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=463766&action=review
> 
> > COMMIT_MESSAGE:28
> > +tests in AnimationControl.mm to pass consistently.
> 
> Can you explain why this change is needed to make the tests pass
> consistently?
> 
> > Source/WebCore/platform/graphics/BitmapImage.cpp:446
> > +        m_animationIsRunning = !!m_frameTimer;
> 
> This is a weird place to set this flag.
> 
> > Source/WebCore/platform/graphics/BitmapImage.h:241
> > +    bool m_animationIsRunning { false };
> 
> What is the meaning of this flag? And what is the difference between its
> value and the value of canAnimate()?
> 
> I think you are changing its meaning. It is currently true when we are
> displaying a frame, waiting for its interval to elapse to draw the next
> frame. With your change it I think it will mean whether the image is
> animating or still since it is not cleared in BitmapImage::clearTimer().
> 
> Also it is weird to have two flags m_animationIsRunning and
> m_animationFinished although each of them means the opposite to the other.
> How can we guarantee they are not both set to true? Actually having both of
> them initialized with false is confusing. If m_animationIsRunning is false
> then m_animationFinished should be true.
Thanks for the insight! I was able to write the test such that the changes to BitmapImage::isAnimating are unnecessary.
Comment 16 Tyler Wilcock 2022-12-12 23:56:20 PST
Created attachment 464021 [details]
Patch
Comment 17 chris fleizach 2022-12-27 23:48:14 PST
(In reply to Tyler Wilcock from comment #16)
> Created attachment 464021 [details]
> Patch

Looks like feedback has been addressed and public API has been pended for good reasons. I'm inclined to approve this.
Comment 18 Tyler Wilcock 2023-01-06 22:53:43 PST
Created attachment 464393 [details]
Patch
Comment 19 Tyler Wilcock 2023-01-07 20:08:11 PST
Created attachment 464409 [details]
Patch
Comment 20 EWS 2023-01-09 10:13:52 PST
Committed 258671@main (c6458455e6da): <https://commits.webkit.org/258671@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 464409 [details].