Title: [278850] trunk/Source/WebCore
Revision
278850
Author
drou...@apple.com
Date
2021-06-14 15:04:59 -0700 (Mon, 14 Jun 2021)

Log Message

[macOS] TouchBar playback speed controls don't work
https://bugs.webkit.org/show_bug.cgi?id=226987
<rdar://problem/79216098>

Reviewed by Eric Carlson.

Override `setRate:` and `setDefaultPlaybackRate:` instead of just having an ivar so that
TouchBar playback speed controls actually affect the corresponding `<video>`.

* platform/mac/WebPlaybackControlsManager.mm:
(-[WebPlaybackControlsManager defaultPlaybackRate]): Added.
(-[WebPlaybackControlsManager setDefaultPlaybackRate:]): Added.
(-[WebPlaybackControlsManager rate]): Added.
(-[WebPlaybackControlsManager setRate:]): Added.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (278849 => 278850)


--- trunk/Source/WebCore/ChangeLog	2021-06-14 21:36:12 UTC (rev 278849)
+++ trunk/Source/WebCore/ChangeLog	2021-06-14 22:04:59 UTC (rev 278850)
@@ -1,3 +1,20 @@
+2021-06-14  Devin Rousso  <drou...@apple.com>
+
+        [macOS] TouchBar playback speed controls don't work
+        https://bugs.webkit.org/show_bug.cgi?id=226987
+        <rdar://problem/79216098>
+
+        Reviewed by Eric Carlson.
+
+        Override `setRate:` and `setDefaultPlaybackRate:` instead of just having an ivar so that
+        TouchBar playback speed controls actually affect the corresponding `<video>`.
+
+        * platform/mac/WebPlaybackControlsManager.mm:
+        (-[WebPlaybackControlsManager defaultPlaybackRate]): Added.
+        (-[WebPlaybackControlsManager setDefaultPlaybackRate:]): Added.
+        (-[WebPlaybackControlsManager rate]): Added.
+        (-[WebPlaybackControlsManager setRate:]): Added.
+
 2021-06-14  Alex Christensen  <achristen...@webkit.org>
 
         Pass PAL::SessionID by value instead of reference

Modified: trunk/Source/WebCore/platform/mac/WebPlaybackControlsManager.mm (278849 => 278850)


--- trunk/Source/WebCore/platform/mac/WebPlaybackControlsManager.mm	2021-06-14 21:36:12 UTC (rev 278849)
+++ trunk/Source/WebCore/platform/mac/WebPlaybackControlsManager.mm	2021-06-14 22:04:59 UTC (rev 278850)
@@ -48,8 +48,6 @@
 @synthesize seekToTime = _seekToTime;
 @synthesize hasEnabledAudio = _hasEnabledAudio;
 @synthesize hasEnabledVideo = _hasEnabledVideo;
-@synthesize defaultPlaybackRate = _defaultPlaybackRate;
-@synthesize rate = _rate;
 @synthesize canTogglePlayback = _canTogglePlayback;
 @synthesize allowsPictureInPicturePlayback;
 @synthesize pictureInPictureActive;
@@ -331,6 +329,59 @@
     return _playing;
 }
 
+- (double)defaultPlaybackRate
+{
+    return _defaultPlaybackRate;
+}
+
+- (void)setDefaultPlaybackRate:(double)defaultPlaybackRate
+{
+    if (defaultPlaybackRate == _defaultPlaybackRate)
+        return;
+
+    _defaultPlaybackRate = defaultPlaybackRate;
+
+    if (_playbackSessionInterfaceMac) {
+        if (auto* model = _playbackSessionInterfaceMac->playbackSessionModel(); model && model->defaultPlaybackRate() != _defaultPlaybackRate)
+            model->setDefaultPlaybackRate(_defaultPlaybackRate);
+    }
+
+    if ([self isPlaying])
+        [self setRate:_defaultPlaybackRate];
+}
+
+- (float)rate
+{
+    return _rate;
+}
+
+- (void)setRate:(float)rate
+{
+    if (rate == _rate)
+        return;
+
+    _rate = rate;
+
+    // AVKit doesn't have a separate variable for "paused", instead representing it by a `rate` of
+    // `0`. Unfortunately, `HTMLMediaElement::play` doesn't call `HTMLMediaElement::setPlaybackRate`
+    // so if we propagate a `rate` of `0` along to the `HTMLMediaElement` then any attempt to
+    // `HTMLMediaElement::play` will effectively be a no-op since the `playbackRate` will be `0`.
+    if (!_rate)
+        return;
+
+    // In AVKit, the `defaultPlaybackRate` is used when playback starts, such as resuming after
+    // pausing. In WebKit, however, `defaultPlaybackRate` is only used when first loading and after
+    // ending scanning, with the `playbackRate` being used in all other cases, including when
+    // resuming after pausing. As such, WebKit should return the `playbackRate` instead of the
+    // `defaultPlaybackRate` in these cases when communicating with AVKit.
+    [self setDefaultPlaybackRate:_rate];
+
+    if (_playbackSessionInterfaceMac) {
+        if (auto* model = _playbackSessionInterfaceMac->playbackSessionModel(); model && model->playbackRate() != _rate)
+            model->setPlaybackRate(_rate);
+    }
+}
+
 - (void)togglePictureInPicture
 {
     if (auto* model = _playbackSessionInterfaceMac->playbackSessionModel())
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to