Changeset 232544 in webkit


Ignore:
Timestamp:
Jun 6, 2018 9:32:26 AM (6 years ago)
Author:
timothy_horton@apple.com
Message:

Move animated resize into the layer tree transaction, and make it asynchronous
https://bugs.webkit.org/show_bug.cgi?id=186130
<rdar://problem/38477288>

Reviewed by Simon Fraser.

  • Shared/RemoteLayerTree/RemoteLayerTreeTransaction.h:

(WebKit::RemoteLayerTreeTransaction::setScrollPosition):
(WebKit::RemoteLayerTreeTransaction::dynamicViewportSizeUpdateID const):
(WebKit::RemoteLayerTreeTransaction::setDynamicViewportSizeUpdateID):

  • Shared/RemoteLayerTree/RemoteLayerTreeTransaction.mm:

(WebKit::RemoteLayerTreeTransaction::encode const):
(WebKit::RemoteLayerTreeTransaction::decode):

  • WebProcess/WebPage/WebPage.cpp:

(WebKit::WebPage::willCommitLayerTree):
Add scrollPosition to the transaction on all platforms, not just Mac.
Add the optional dynamicViewportSizeUpdateID to the transaction, representing
the most recent dynamicViewportSizeUpdate that commit contains, if any.

  • Shared/ios/DynamicViewportSizeUpdate.h:

Added a typedef for DynamicViewportSizeUpdateID, and move the mode enum here.

  • UIProcess/ios/PageClientImplIOS.h:
  • UIProcess/ios/PageClientImplIOS.mm:

(WebKit::PageClientImpl::dynamicViewportUpdateChangedTarget): Deleted.

  • UIProcess/PageClient.h:
  • UIProcess/WebPageProxy.cpp:

(WebKit::WebPageProxy::resetState):

  • UIProcess/WebPageProxy.h:
  • UIProcess/WebPageProxy.messages.in:
  • UIProcess/ios/WebPageProxyIOS.mm:

(WebKit::WebPageProxy::dynamicViewportSizeUpdate):
(WebKit::WebPageProxy::didCommitLayerTree):
(WebKit::WebPageProxy::synchronizeDynamicViewportUpdate): Deleted.
(WebKit::WebPageProxy::dynamicViewportUpdateChangedTarget): Deleted.

  • WebProcess/WebPage/WebPage.h:
  • WebProcess/WebPage/WebPage.messages.in:
  • WebProcess/WebPage/ios/WebPageIOS.mm:

(WebKit::WebPage::dynamicViewportSizeUpdate):
(WebKit::WebPage::synchronizeDynamicViewportUpdate): Deleted.
Remove dynamicViewportUpdateChangedTarget and synchronizeDynamicViewportUpdate.
Move dynamicViewportSizeUpdateID maintenance into WKWebView.

  • UIProcess/API/Cocoa/WKWebView.mm:

(-[WKWebView _processDidExit]):
Remove _resizeAnimationTransformTransactionID. We now instead pack
the resize ID inside the transaction, instead of separately sending
back a transaction ID to wait for.

(-[WKWebView _didCommitLayerTreeDuringAnimatedResize:]):
(-[WKWebView _didCommitLayerTree:]):
Added, factored out of _didCommitLayerTree:.
If the transaction includes the result of the most recently-sent resize,
store the requisite adjustments required to counter the new scale and
scroll offset, update the resizeAnimationView, and, if endAnimatedResize
has already been called, call _didCompleteAnimatedResize to tear down
the animation view and put things back together.

Add some code so that if a commit arrives before the resize, we update
the scale of the resize animation view to keep the width fitting.

(activeMaximumUnobscuredSize):
(activeOrientation):
Move these because the code that depends on them moved.

(-[WKWebView _didCompleteAnimatedResize]):
Broken out of _endAnimatedResize. This can now be called from
either endAnimatedResize or _didCommitLayerTreeDuringAnimatedResize,
depending on which is called first.

(-[WKWebView _beginAnimatedResizeWithUpdates:]):
Don't create a new resize view if we still have one. Otherwise, we'll
get the view ordering all wrong when making the second one. This
didn't previously cause trouble, because we don't have a lot of
WKScrollView subviews, but it totally could.

Adopt _initialContentOffsetForScrollView just to make this code more clear.

(-[WKWebView _endAnimatedResize]):
(-[WKWebView _dynamicViewportUpdateChangedTargetToScale:position:nextValidLayerTreeTransactionID:]): Deleted.

  • UIProcess/API/Cocoa/WKWebViewInternal.h:
Location:
trunk/Source/WebKit
Files:
1 added
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r232535 r232544  
     12018-06-06  Tim Horton  <timothy_horton@apple.com>
     2
     3        Move animated resize into the layer tree transaction, and make it asynchronous
     4        https://bugs.webkit.org/show_bug.cgi?id=186130
     5        <rdar://problem/38477288>
     6
     7        Reviewed by Simon Fraser.
     8
     9        * Shared/RemoteLayerTree/RemoteLayerTreeTransaction.h:
     10        (WebKit::RemoteLayerTreeTransaction::setScrollPosition):
     11        (WebKit::RemoteLayerTreeTransaction::dynamicViewportSizeUpdateID const):
     12        (WebKit::RemoteLayerTreeTransaction::setDynamicViewportSizeUpdateID):
     13        * Shared/RemoteLayerTree/RemoteLayerTreeTransaction.mm:
     14        (WebKit::RemoteLayerTreeTransaction::encode const):
     15        (WebKit::RemoteLayerTreeTransaction::decode):
     16        * WebProcess/WebPage/WebPage.cpp:
     17        (WebKit::WebPage::willCommitLayerTree):
     18        Add scrollPosition to the transaction on all platforms, not just Mac.
     19        Add the optional dynamicViewportSizeUpdateID to the transaction, representing
     20        the most recent dynamicViewportSizeUpdate that commit contains, if any.
     21
     22        * Shared/ios/DynamicViewportSizeUpdate.h:
     23        Added a typedef for DynamicViewportSizeUpdateID, and move the mode enum here.
     24
     25        * UIProcess/ios/PageClientImplIOS.h:
     26        * UIProcess/ios/PageClientImplIOS.mm:
     27        (WebKit::PageClientImpl::dynamicViewportUpdateChangedTarget): Deleted.
     28        * UIProcess/PageClient.h:
     29        * UIProcess/WebPageProxy.cpp:
     30        (WebKit::WebPageProxy::resetState):
     31        * UIProcess/WebPageProxy.h:
     32        * UIProcess/WebPageProxy.messages.in:
     33        * UIProcess/ios/WebPageProxyIOS.mm:
     34        (WebKit::WebPageProxy::dynamicViewportSizeUpdate):
     35        (WebKit::WebPageProxy::didCommitLayerTree):
     36        (WebKit::WebPageProxy::synchronizeDynamicViewportUpdate): Deleted.
     37        (WebKit::WebPageProxy::dynamicViewportUpdateChangedTarget): Deleted.
     38        * WebProcess/WebPage/WebPage.h:
     39        * WebProcess/WebPage/WebPage.messages.in:
     40        * WebProcess/WebPage/ios/WebPageIOS.mm:
     41        (WebKit::WebPage::dynamicViewportSizeUpdate):
     42        (WebKit::WebPage::synchronizeDynamicViewportUpdate): Deleted.
     43        Remove dynamicViewportUpdateChangedTarget and synchronizeDynamicViewportUpdate.
     44        Move dynamicViewportSizeUpdateID maintenance into WKWebView.
     45
     46        * UIProcess/API/Cocoa/WKWebView.mm:
     47        (-[WKWebView _processDidExit]):
     48        Remove _resizeAnimationTransformTransactionID. We now instead pack
     49        the resize ID inside the transaction, instead of separately sending
     50        back a transaction ID to wait for.
     51
     52        (-[WKWebView _didCommitLayerTreeDuringAnimatedResize:]):
     53        (-[WKWebView _didCommitLayerTree:]):
     54        Added, factored out of _didCommitLayerTree:.
     55        If the transaction includes the result of the most recently-sent resize,
     56        store the requisite adjustments required to counter the new scale and
     57        scroll offset, update the resizeAnimationView, and, if endAnimatedResize
     58        has already been called, call _didCompleteAnimatedResize to tear down
     59        the animation view and put things back together.
     60
     61        Add some code so that if a commit arrives before the resize, we update
     62        the scale of the resize animation view to keep the width fitting.
     63
     64        (activeMaximumUnobscuredSize):
     65        (activeOrientation):
     66        Move these because the code that depends on them moved.
     67
     68        (-[WKWebView _didCompleteAnimatedResize]):
     69        Broken out of _endAnimatedResize. This can now be called from
     70        either endAnimatedResize or _didCommitLayerTreeDuringAnimatedResize,
     71        depending on which is called first.
     72
     73        (-[WKWebView _beginAnimatedResizeWithUpdates:]):
     74        Don't create a new resize view if we still have one. Otherwise, we'll
     75        get the view ordering all wrong when making the second one. This
     76        didn't previously cause trouble, because we don't have a lot of
     77        WKScrollView subviews, but it totally could.
     78
     79        Adopt _initialContentOffsetForScrollView just to make this code more clear.
     80
     81        (-[WKWebView _endAnimatedResize]):
     82        (-[WKWebView _dynamicViewportUpdateChangedTargetToScale:position:nextValidLayerTreeTransactionID:]): Deleted.
     83        * UIProcess/API/Cocoa/WKWebViewInternal.h:
     84
     85
    1862018-06-05  Per Arne Vollan  <pvollan@apple.com>
    287
  • trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerTreeTransaction.h

    r222233 r232544  
    2626#pragma once
    2727
     28#include "DynamicViewportSizeUpdate.h"
    2829#include "EditorState.h"
    2930#include "GenericCallback.h"
     
    219220    void setPageExtendedBackgroundColor(WebCore::Color color) { m_pageExtendedBackgroundColor = color; }
    220221
    221 #if PLATFORM(MAC)
    222222    WebCore::IntPoint scrollPosition() const { return m_scrollPosition; }
    223223    void setScrollPosition(WebCore::IntPoint p) { m_scrollPosition = p; }
    224 #endif
    225224
    226225    double pageScaleFactor() const { return m_pageScaleFactor; }
     
    273272    const EditorState& editorState() const { return m_editorState.value(); }
    274273    void setEditorState(const EditorState& editorState) { m_editorState = editorState; }
     274
     275    std::optional<DynamicViewportSizeUpdateID> dynamicViewportSizeUpdateID() const { return m_dynamicViewportSizeUpdateID; }
     276    void setDynamicViewportSizeUpdateID(DynamicViewportSizeUpdateID resizeID) { m_dynamicViewportSizeUpdateID = resizeID; }
    275277   
    276278private:
     
    291293    WebCore::LayoutPoint m_minStableLayoutViewportOrigin;
    292294    WebCore::LayoutPoint m_maxStableLayoutViewportOrigin;
    293 #if PLATFORM(MAC)
    294295    WebCore::IntPoint m_scrollPosition;
    295 #endif
    296296    WebCore::Color m_pageExtendedBackgroundColor;
    297297    double m_pageScaleFactor { 1 };
     
    310310    bool m_isInStableState { false };
    311311
    312     std::optional<EditorState> m_editorState { std::nullopt };
     312    std::optional<EditorState> m_editorState;
     313    std::optional<DynamicViewportSizeUpdateID> m_dynamicViewportSizeUpdateID;
    313314};
    314315
  • trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerTreeTransaction.mm

    r232246 r232544  
    534534    encoder << m_maxStableLayoutViewportOrigin;
    535535
    536 #if PLATFORM(MAC)
    537536    encoder << m_scrollPosition;
    538 #endif
     537
    539538    encoder << m_pageExtendedBackgroundColor;
    540539    encoder << m_pageScaleFactor;
     
    564563    if (m_editorState)
    565564        encoder << *m_editorState;
     565
     566    encoder << m_dynamicViewportSizeUpdateID;
    566567}
    567568
     
    625626    if (!decoder.decode(result.m_maxStableLayoutViewportOrigin))
    626627        return false;
    627    
    628 #if PLATFORM(MAC)
     628
    629629    if (!decoder.decode(result.m_scrollPosition))
    630630        return false;
    631 #endif
    632631   
    633632    if (!decoder.decode(result.m_pageExtendedBackgroundColor))
     
    692691        result.setEditorState(editorState);
    693692    }
     693
     694    if (!decoder.decode(result.m_dynamicViewportSizeUpdateID))
     695        return false;
    694696
    695697    return true;
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm

    r232523 r232544  
    3434#import "CompletionHandlerCallChecker.h"
    3535#import "DiagnosticLoggingClient.h"
     36#import "DynamicViewportSizeUpdate.h"
    3637#import "FindClient.h"
    3738#import "FrontBoardServicesSPI.h"
     
    177178@end
    178179
    179 enum class DynamicViewportUpdateMode {
    180     NotResizing,
    181     ResizingWithAnimation,
    182     ResizingWithDocumentHidden,
    183 };
    184 
    185180#endif // PLATFORM(IOS)
    186181
     
    312307    BOOL _needsResetViewStateAfterCommitLoadForMainFrame;
    313308    uint64_t _firstPaintAfterCommitLoadTransactionID;
    314     DynamicViewportUpdateMode _dynamicViewportUpdateMode;
     309    WebKit::DynamicViewportUpdateMode _dynamicViewportUpdateMode;
     310    WebKit::DynamicViewportSizeUpdateID _currentDynamicViewportSizeUpdateID;
    315311    CATransform3D _resizeAnimationTransformAdjustments;
    316     std::optional<uint64_t> _resizeAnimationTransformTransactionID;
     312    CGFloat _animatedResizeOriginalContentWidth;
    317313    RetainPtr<UIView> _resizeAnimationView;
    318314    CGFloat _lastAdjustmentForScroller;
     
    349345
    350346    int _activeAnimatedResizeCount;
     347    BOOL _waitingForEndAnimatedResize;
     348    BOOL _waitingForCommitAfterAnimatedResize;
    351349
    352350    Vector<WTF::Function<void ()>> _snapshotsDeferredDuringResize;
     
    358356    BOOL _visibleContentRectUpdateScheduledFromScrollViewInStableState;
    359357    Vector<BlockPtr<void ()>> _visibleContentRectUpdateCallbacks;
     358
     359    _WKDragInteractionPolicy _dragInteractionPolicy;
    360360#endif
    361361#if PLATFORM(MAC)
    362362    std::unique_ptr<WebKit::WebViewImpl> _impl;
    363363    RetainPtr<WKTextFinderClient> _textFinderClient;
    364 #endif
    365 
    366 #if PLATFORM(IOS)
    367     _WKDragInteractionPolicy _dragInteractionPolicy;
    368364#endif
    369365}
     
    16641660{
    16651661    [self _hidePasswordView];
    1666     if (!_customContentView && _dynamicViewportUpdateMode != DynamicViewportUpdateMode::NotResizing) {
     1662    if (!_customContentView && _dynamicViewportUpdateMode != WebKit::DynamicViewportUpdateMode::NotResizing) {
    16671663        NSUInteger indexOfResizeAnimationView = [[_scrollView subviews] indexOfObject:_resizeAnimationView.get()];
    16681664        [_scrollView insertSubview:_contentView.get() atIndex:indexOfResizeAnimationView];
     
    16821678    _hasCommittedLoadForMainFrame = NO;
    16831679    _needsResetViewStateAfterCommitLoadForMainFrame = NO;
    1684     _dynamicViewportUpdateMode = DynamicViewportUpdateMode::NotResizing;
     1680    _dynamicViewportUpdateMode = WebKit::DynamicViewportUpdateMode::NotResizing;
     1681    _waitingForEndAnimatedResize = NO;
     1682    _waitingForCommitAfterAnimatedResize = NO;
     1683    _animatedResizeOriginalContentWidth = 0;
    16851684    [_contentView setHidden:NO];
    16861685    _scrollOffsetToRestore = std::nullopt;
     
    16981697    _firstPaintAfterCommitLoadTransactionID = 0;
    16991698    _firstTransactionIDAfterPageRestore = std::nullopt;
    1700     _resizeAnimationTransformTransactionID = std::nullopt;
    17011699
    17021700    _hasScheduledVisibleRectUpdate = NO;
     
    17541752}
    17551753
     1754- (void)_didCommitLayerTreeDuringAnimatedResize:(const WebKit::RemoteLayerTreeTransaction&)layerTreeTransaction
     1755{
     1756    auto updateID = layerTreeTransaction.dynamicViewportSizeUpdateID();
     1757    if (updateID && *updateID == _currentDynamicViewportSizeUpdateID) {
     1758        double pageScale = layerTreeTransaction.pageScaleFactor();
     1759        WebCore::IntPoint scrollPosition = layerTreeTransaction.scrollPosition();
     1760
     1761        CGFloat animatingScaleTarget = [[_resizeAnimationView layer] transform].m11;
     1762        double currentTargetScale = animatingScaleTarget * [[_contentView layer] transform].m11;
     1763        double scale = pageScale / currentTargetScale;
     1764        _resizeAnimationTransformAdjustments = CATransform3DMakeScale(scale, scale, 1);
     1765
     1766        CGPoint newContentOffset = [self _contentOffsetAdjustedForObscuredInset:CGPointMake(scrollPosition.x() * pageScale, scrollPosition.y() * pageScale)];
     1767        CGPoint currentContentOffset = [_scrollView contentOffset];
     1768
     1769        _resizeAnimationTransformAdjustments.m41 = (currentContentOffset.x - newContentOffset.x) / animatingScaleTarget;
     1770        _resizeAnimationTransformAdjustments.m42 = (currentContentOffset.y - newContentOffset.y) / animatingScaleTarget;
     1771
     1772        [_resizeAnimationView layer].sublayerTransform = _resizeAnimationTransformAdjustments;
     1773
     1774        // If we've already passed endAnimatedResize, immediately complete
     1775        // the resize when we have an up-to-date layer tree. Otherwise,
     1776        // we will defer completion until endAnimatedResize.
     1777        _waitingForCommitAfterAnimatedResize = NO;
     1778        if (!_waitingForEndAnimatedResize)
     1779            [self _didCompleteAnimatedResize];
     1780
     1781        return;
     1782    }
     1783
     1784    // If a commit arrives during the live part of a resize but before the
     1785    // layer tree takes the current resize into account, it could change the
     1786    // WKContentView's size. Update the resizeAnimationView's scale to ensure
     1787    // we continue to fill the width of the resize target.
     1788
     1789    if (_waitingForEndAnimatedResize)
     1790        return;
     1791
     1792    auto newViewLayoutSize = [self activeViewLayoutSize:self.bounds];
     1793    CGFloat resizeAnimationViewScale = _animatedResizeOriginalContentWidth / newViewLayoutSize.width();
     1794    [[_resizeAnimationView layer] setSublayerTransform:CATransform3DMakeScale(resizeAnimationViewScale, resizeAnimationViewScale, 1)];
     1795}
     1796
    17561797- (void)_didCommitLayerTree:(const WebKit::RemoteLayerTreeTransaction&)layerTreeTransaction
    17571798{
     
    17631804    bool needUpdateVisibleContentRects = _page->updateLayoutViewportParameters(layerTreeTransaction);
    17641805
    1765     if (_dynamicViewportUpdateMode != DynamicViewportUpdateMode::NotResizing) {
    1766         if (_resizeAnimationTransformTransactionID && layerTreeTransaction.transactionID() >= _resizeAnimationTransformTransactionID.value()) {
    1767             _resizeAnimationTransformTransactionID = std::nullopt;
    1768             [_resizeAnimationView layer].sublayerTransform = _resizeAnimationTransformAdjustments;
    1769             if (_dynamicViewportUpdateMode == DynamicViewportUpdateMode::ResizingWithDocumentHidden) {
    1770                 [_contentView setHidden:NO];
    1771                 [self _endAnimatedResize];
    1772             }
    1773         }
     1806    if (_dynamicViewportUpdateMode != WebKit::DynamicViewportUpdateMode::NotResizing) {
     1807        [self _didCommitLayerTreeDuringAnimatedResize:layerTreeTransaction];
    17741808        return;
    17751809    }
     
    18711905}
    18721906
    1873 - (void)_dynamicViewportUpdateChangedTargetToScale:(double)newScale position:(CGPoint)newScrollPosition nextValidLayerTreeTransactionID:(uint64_t)nextValidLayerTreeTransactionID
    1874 {
    1875     LOG_WITH_STREAM(VisibleRects, stream << "-[WKWebView " << _page->pageID() << " _dynamicViewportUpdateChangedTargetToScale:] " <<  newScale << " _dynamicViewportUpdateMode " << (int)_dynamicViewportUpdateMode);
    1876 
    1877     if (_dynamicViewportUpdateMode != DynamicViewportUpdateMode::NotResizing) {
    1878         CGFloat animatingScaleTarget = [[_resizeAnimationView layer] transform].m11;
    1879         double currentTargetScale = animatingScaleTarget * [[_contentView layer] transform].m11;
    1880         double scale = newScale / currentTargetScale;
    1881         _resizeAnimationTransformAdjustments = CATransform3DMakeScale(scale, scale, 1);
    1882 
    1883         CGPoint newContentOffset = [self _contentOffsetAdjustedForObscuredInset:CGPointMake(newScrollPosition.x * newScale, newScrollPosition.y * newScale)];
    1884         CGPoint currentContentOffset = [_scrollView contentOffset];
    1885 
    1886         _resizeAnimationTransformAdjustments.m41 = (currentContentOffset.x - newContentOffset.x) / animatingScaleTarget;
    1887         _resizeAnimationTransformAdjustments.m42 = (currentContentOffset.y - newContentOffset.y) / animatingScaleTarget;
    1888         _resizeAnimationTransformTransactionID = nextValidLayerTreeTransactionID;
    1889     }
    1890 }
    1891 
    18921907- (void)_couldNotRestorePageState
    18931908{
     
    19021917- (void)_restorePageScrollPosition:(std::optional<WebCore::FloatPoint>)scrollPosition scrollOrigin:(WebCore::FloatPoint)scrollOrigin previousObscuredInset:(WebCore::FloatBoxExtent)obscuredInsets scale:(double)scale
    19031918{
    1904     if (_dynamicViewportUpdateMode != DynamicViewportUpdateMode::NotResizing)
     1919    if (_dynamicViewportUpdateMode != WebKit::DynamicViewportUpdateMode::NotResizing)
    19051920        return;
    19061921
     
    19201935- (void)_restorePageStateToUnobscuredCenter:(std::optional<WebCore::FloatPoint>)center scale:(double)scale
    19211936{
    1922     if (_dynamicViewportUpdateMode != DynamicViewportUpdateMode::NotResizing)
     1937    if (_dynamicViewportUpdateMode != WebKit::DynamicViewportUpdateMode::NotResizing)
    19231938        return;
    19241939
     
    20352050- (void)_scrollToContentScrollPosition:(WebCore::FloatPoint)scrollPosition scrollOrigin:(WebCore::IntPoint)scrollOrigin
    20362051{
    2037     if (_commitDidRestoreScrollPosition || _dynamicViewportUpdateMode != DynamicViewportUpdateMode::NotResizing)
     2052    if (_commitDidRestoreScrollPosition || _dynamicViewportUpdateMode != WebKit::DynamicViewportUpdateMode::NotResizing)
    20382053        return;
    20392054
     
    26152630    [_scrollView setFrame:bounds];
    26162631
    2617     if (_dynamicViewportUpdateMode == DynamicViewportUpdateMode::NotResizing) {
     2632    if (_dynamicViewportUpdateMode == WebKit::DynamicViewportUpdateMode::NotResizing) {
    26182633        if (!_overridesViewLayoutSize)
    26192634            [self _dispatchSetViewLayoutSize:[self activeViewLayoutSize:self.bounds]];
     
    27772792    }
    27782793
    2779     if (_dynamicViewportUpdateMode != DynamicViewportUpdateMode::NotResizing
     2794    if (_dynamicViewportUpdateMode != WebKit::DynamicViewportUpdateMode::NotResizing
    27802795        || (_needsResetViewStateAfterCommitLoadForMainFrame && ![_contentView sizeChangedSinceLastVisibleContentRectUpdate])
    27812796        || [_scrollView isZoomBouncing]
     
    28332848    if (_gestureController)
    28342849        _gestureController->didStartProvisionalLoadForMainFrame();
     2850}
     2851
     2852static WebCore::FloatSize activeMaximumUnobscuredSize(WKWebView *webView, const CGRect& bounds)
     2853{
     2854    return WebCore::FloatSize(webView->_overridesMaximumUnobscuredSize ? webView->_maximumUnobscuredSizeOverride : bounds.size);
     2855}
     2856
     2857static int32_t activeOrientation(WKWebView *webView)
     2858{
     2859    return webView->_overridesInterfaceOrientation ? deviceOrientationForUIInterfaceOrientation(webView->_interfaceOrientationOverride) : webView->_page->deviceOrientation();
     2860}
     2861
     2862- (void)_didCompleteAnimatedResize
     2863{
     2864    if (_dynamicViewportUpdateMode == WebKit::DynamicViewportUpdateMode::NotResizing)
     2865        return;
     2866
     2867    [_contentView setHidden:NO];
     2868
     2869    if (!_resizeAnimationView) {
     2870        // Paranoia. If _resizeAnimationView is null we'll end up setting a zero scale on the content view.
     2871        RELEASE_LOG_IF_ALLOWED("%p -[WKWebView _endAnimatedResize:] - _resizeAnimationView is nil", self);
     2872        _dynamicViewportUpdateMode = WebKit::DynamicViewportUpdateMode::NotResizing;
     2873        return;
     2874    }
     2875
     2876    --_activeAnimatedResizeCount;
     2877    NSUInteger indexOfResizeAnimationView = [[_scrollView subviews] indexOfObject:_resizeAnimationView.get()];
     2878    [_scrollView insertSubview:_contentView.get() atIndex:indexOfResizeAnimationView];
     2879    [_scrollView insertSubview:[_contentView unscaledView] atIndex:indexOfResizeAnimationView + 1];
     2880
     2881    CALayer *contentLayer = [_contentView layer];
     2882    CGFloat adjustmentScale = _resizeAnimationTransformAdjustments.m11;
     2883    contentLayer.sublayerTransform = CATransform3DIdentity;
     2884
     2885    CGFloat animatingScaleTarget = [[_resizeAnimationView layer] transform].m11;
     2886    CATransform3D contentLayerTransform = contentLayer.transform;
     2887    CGFloat currentScale = [[_resizeAnimationView layer] transform].m11 * contentLayerTransform.m11;
     2888
     2889    // We cannot use [UIScrollView setZoomScale:] directly because the UIScrollView delegate would get a callback with
     2890    // an invalid contentOffset. The real content offset is only set below.
     2891    // Since there is no public API for setting both the zoomScale and the contentOffset, we set the zoomScale manually
     2892    // on the zoom layer and then only change the contentOffset.
     2893    CGFloat adjustedScale = adjustmentScale * currentScale;
     2894    contentLayerTransform.m11 = adjustedScale;
     2895    contentLayerTransform.m22 = adjustedScale;
     2896    contentLayer.transform = contentLayerTransform;
     2897
     2898    CGPoint currentScrollOffset = [_scrollView contentOffset];
     2899    double horizontalScrollAdjustement = _resizeAnimationTransformAdjustments.m41 * animatingScaleTarget;
     2900    double verticalScrollAdjustment = _resizeAnimationTransformAdjustments.m42 * animatingScaleTarget;
     2901
     2902    [_scrollView setContentSize:roundScrollViewContentSize(*_page, [_contentView frame].size)];
     2903    [_scrollView setContentOffset:CGPointMake(currentScrollOffset.x - horizontalScrollAdjustement, currentScrollOffset.y - verticalScrollAdjustment)];
     2904
     2905    [_resizeAnimationView removeFromSuperview];
     2906    _resizeAnimationView = nil;
     2907    _resizeAnimationTransformAdjustments = CATransform3DIdentity;
     2908
     2909    _dynamicViewportUpdateMode = WebKit::DynamicViewportUpdateMode::NotResizing;
     2910    [self _scheduleVisibleContentRectUpdate];
     2911
     2912    CGRect newBounds = self.bounds;
     2913    auto newViewLayoutSize = [self activeViewLayoutSize:newBounds];
     2914    auto newMaximumUnobscuredSize = activeMaximumUnobscuredSize(self, newBounds);
     2915    int32_t newOrientation = activeOrientation(self);
     2916
     2917    if (!_lastSentViewLayoutSize || newViewLayoutSize != _lastSentViewLayoutSize.value())
     2918        [self _dispatchSetViewLayoutSize:newViewLayoutSize];
     2919
     2920    if (!_lastSentMaximumUnobscuredSize || newMaximumUnobscuredSize != _lastSentMaximumUnobscuredSize.value())
     2921        [self _dispatchSetMaximumUnobscuredSize:WebCore::FloatSize(newMaximumUnobscuredSize)];
     2922
     2923    if (!_lastSentDeviceOrientation || newOrientation != _lastSentDeviceOrientation.value())
     2924        [self _dispatchSetDeviceOrientation:newOrientation];
     2925
     2926    while (!_snapshotsDeferredDuringResize.isEmpty())
     2927        _snapshotsDeferredDuringResize.takeLast()();
    28352928}
    28362929
     
    42174310
    42184311#if PLATFORM(IOS)
    4219 static WebCore::FloatSize activeMaximumUnobscuredSize(WKWebView *webView, const CGRect& bounds)
    4220 {
    4221     return WebCore::FloatSize(webView->_overridesMaximumUnobscuredSize ? webView->_maximumUnobscuredSizeOverride : bounds.size);
    4222 }
    4223 
    4224 static int32_t activeOrientation(WKWebView *webView)
    4225 {
    4226     return webView->_overridesInterfaceOrientation ? deviceOrientationForUIInterfaceOrientation(webView->_interfaceOrientationOverride) : webView->_page->deviceOrientation();
    4227 }
    4228 
    42294312- (void (^)(void))_retainActiveFocusedState
    42304313{
     
    50085091    _viewLayoutSizeOverride = viewLayoutSizeOverride;
    50095092
    5010     if (_dynamicViewportUpdateMode == DynamicViewportUpdateMode::NotResizing)
     5093    if (_dynamicViewportUpdateMode == WebKit::DynamicViewportUpdateMode::NotResizing)
    50115094        [self _dispatchSetViewLayoutSize:WebCore::FloatSize(viewLayoutSizeOverride)];
    50125095
     
    50845167    _interfaceOrientationOverride = interfaceOrientation;
    50855168
    5086     if (_dynamicViewportUpdateMode == DynamicViewportUpdateMode::NotResizing)
     5169    if (_dynamicViewportUpdateMode == WebKit::DynamicViewportUpdateMode::NotResizing)
    50875170        [self _dispatchSetDeviceOrientation:deviceOrientationForUIInterfaceOrientation(_interfaceOrientationOverride)];
    50885171}
     
    51125195    _maximumUnobscuredSizeOverride = size;
    51135196
    5114     if (_dynamicViewportUpdateMode == DynamicViewportUpdateMode::NotResizing)
     5197    if (_dynamicViewportUpdateMode == WebKit::DynamicViewportUpdateMode::NotResizing)
    51155198        [self _dispatchSetMaximumUnobscuredSize:WebCore::FloatSize(size)];
    51165199}
     
    51575240    }
    51585241
    5159     _dynamicViewportUpdateMode = DynamicViewportUpdateMode::ResizingWithAnimation;
     5242    _dynamicViewportUpdateMode = WebKit::DynamicViewportUpdateMode::ResizingWithAnimation;
    51605243
    51615244    auto oldViewLayoutSize = [self activeViewLayoutSize:self.bounds];
     
    51765259    ASSERT_WITH_MESSAGE(!(_overridesViewLayoutSize && newViewLayoutSize.isEmpty()), "Clients controlling the layout size should maintain a valid layout size to minimize layouts.");
    51775260    if (CGRectIsEmpty(newBounds) || newViewLayoutSize.isEmpty() || CGRectIsEmpty(futureUnobscuredRectInSelfCoordinates) || CGRectIsEmpty(contentViewBounds)) {
    5178         _dynamicViewportUpdateMode = DynamicViewportUpdateMode::NotResizing;
     5261        _dynamicViewportUpdateMode = WebKit::DynamicViewportUpdateMode::NotResizing;
    51795262        [self _frameOrBoundsChanged];
    51805263        if (_overridesViewLayoutSize)
     
    51945277        && oldOrientation == newOrientation
    51955278        && UIEdgeInsetsEqualToEdgeInsets(oldObscuredInsets, newObscuredInsets)) {
    5196         _dynamicViewportUpdateMode = DynamicViewportUpdateMode::NotResizing;
     5279        _dynamicViewportUpdateMode = WebKit::DynamicViewportUpdateMode::NotResizing;
    51975280        [self _scheduleVisibleContentRectUpdate];
    51985281        return;
     
    52025285    _resizeAnimationTransformAdjustments = CATransform3DIdentity;
    52035286
    5204     NSUInteger indexOfContentView = [[_scrollView subviews] indexOfObject:_contentView.get()];
    5205     _resizeAnimationView = adoptNS([[UIView alloc] init]);
    5206     [_resizeAnimationView layer].name = @"ResizeAnimation";
    5207     [_scrollView insertSubview:_resizeAnimationView.get() atIndex:indexOfContentView];
    5208     [_resizeAnimationView addSubview:_contentView.get()];
    5209     [_resizeAnimationView addSubview:[_contentView unscaledView]];
     5287    if (!_resizeAnimationView) {
     5288        NSUInteger indexOfContentView = [[_scrollView subviews] indexOfObject:_contentView.get()];
     5289        _resizeAnimationView = adoptNS([[UIView alloc] init]);
     5290        [_resizeAnimationView layer].name = @"ResizeAnimation";
     5291        [_scrollView insertSubview:_resizeAnimationView.get() atIndex:indexOfContentView];
     5292        [_resizeAnimationView addSubview:_contentView.get()];
     5293        [_resizeAnimationView addSubview:[_contentView unscaledView]];
     5294    }
    52105295
    52115296    CGSize contentSizeInContentViewCoordinates = contentViewBounds.size;
     
    52155300    // Compute the new scale to keep the current content width in the scrollview.
    52165301    CGFloat oldWebViewWidthInContentViewCoordinates = oldUnobscuredContentRect.width();
    5217     CGFloat visibleContentViewWidthInContentCoordinates = std::min(contentSizeInContentViewCoordinates.width, oldWebViewWidthInContentViewCoordinates);
    5218     CGFloat targetScale = newViewLayoutSize.width() / visibleContentViewWidthInContentCoordinates;
     5302    _animatedResizeOriginalContentWidth = std::min(contentSizeInContentViewCoordinates.width, oldWebViewWidthInContentViewCoordinates);
     5303    CGFloat targetScale = newViewLayoutSize.width() / _animatedResizeOriginalContentWidth;
    52195304    CGFloat resizeAnimationViewAnimationScale = targetScale / contentZoomScale(self);
    52205305    [_resizeAnimationView setTransform:CGAffineTransformMakeScale(resizeAnimationViewAnimationScale, resizeAnimationViewAnimationScale)];
     
    52445329        contentOffset.y = maxVerticalOffset;
    52455330    if (oldUnobscuredContentRect.y() < 1)
    5246         contentOffset.y = -_obscuredInsets.top;
     5331        contentOffset.y = [self _initialContentOffsetForScrollView].y;
    52475332
    52485333    // FIXME: if we have content centered after double tap to zoom, we should also try to keep that rect in view.
     
    52605345    _lastSentDeviceOrientation = newOrientation;
    52615346
    5262     _page->dynamicViewportSizeUpdate(newViewLayoutSize, newMaximumUnobscuredSize, visibleRectInContentCoordinates, unobscuredRectInContentCoordinates, futureUnobscuredRectInSelfCoordinates, unobscuredSafeAreaInsetsExtent, targetScale, newOrientation);
     5347    _page->dynamicViewportSizeUpdate(newViewLayoutSize, newMaximumUnobscuredSize, visibleRectInContentCoordinates, unobscuredRectInContentCoordinates, futureUnobscuredRectInSelfCoordinates, unobscuredSafeAreaInsetsExtent, targetScale, newOrientation, ++_currentDynamicViewportSizeUpdateID);
    52635348    if (WebKit::DrawingAreaProxy* drawingArea = _page->drawingArea())
    52645349        drawingArea->setSize(WebCore::IntSize(newBounds.size));
     5350
     5351    _waitingForCommitAfterAnimatedResize = YES;
     5352    _waitingForEndAnimatedResize = YES;
    52655353}
    52665354
     
    52725360        [_customContentView web_endAnimatedResize];
    52735361
    5274     if (_dynamicViewportUpdateMode == DynamicViewportUpdateMode::NotResizing)
    5275         return;
    5276 
    5277     _page->synchronizeDynamicViewportUpdate();
    5278 
    5279     // synchronizeDynamicViewportUpdate() may cause this function to re-enter via _didCommitLayerTree, so check _dynamicViewportUpdateMode again.
    5280     if (_dynamicViewportUpdateMode == DynamicViewportUpdateMode::NotResizing)
    5281         return;
    5282 
    5283     if (!_resizeAnimationView) {
    5284         // Paranoia. If _resizeAnimationView is null we'll end up setting a zero scale on the content view.
    5285         RELEASE_LOG_IF_ALLOWED("%p -[WKWebView _endAnimatedResize:] - _resizeAnimationView is nil", self);
    5286         _dynamicViewportUpdateMode = DynamicViewportUpdateMode::NotResizing;
    5287         [_contentView setHidden:NO];
    5288         return;
    5289     }
    5290 
    5291     --_activeAnimatedResizeCount;
    5292     NSUInteger indexOfResizeAnimationView = [[_scrollView subviews] indexOfObject:_resizeAnimationView.get()];
    5293     [_scrollView insertSubview:_contentView.get() atIndex:indexOfResizeAnimationView];
    5294     [_scrollView insertSubview:[_contentView unscaledView] atIndex:indexOfResizeAnimationView + 1];
    5295 
    5296     CALayer *contentViewLayer = [_contentView layer];
    5297     CGFloat adjustmentScale = _resizeAnimationTransformAdjustments.m11;
    5298     contentViewLayer.sublayerTransform = CATransform3DIdentity;
    5299 
    5300     CGFloat animatingScaleTarget = [[_resizeAnimationView layer] transform].m11;
    5301     CALayer *contentLayer = [_contentView layer];
    5302     CATransform3D contentLayerTransform = contentLayer.transform;
    5303     CGFloat currentScale = [[_resizeAnimationView layer] transform].m11 * contentLayerTransform.m11;
    5304 
    5305     // We cannot use [UIScrollView setZoomScale:] directly because the UIScrollView delegate would get a callback with
    5306     // an invalid contentOffset. The real content offset is only set below.
    5307     // Since there is no public API for setting both the zoomScale and the contentOffset, we set the zoomScale manually
    5308     // on the zoom layer and then only change the contentOffset.
    5309     CGFloat adjustedScale = adjustmentScale * currentScale;
    5310     contentLayerTransform.m11 = adjustedScale;
    5311     contentLayerTransform.m22 = adjustedScale;
    5312     contentLayer.transform = contentLayerTransform;
    5313 
    5314     CGPoint currentScrollOffset = [_scrollView contentOffset];
    5315     double horizontalScrollAdjustement = _resizeAnimationTransformAdjustments.m41 * animatingScaleTarget;
    5316     double verticalScrollAdjustment = _resizeAnimationTransformAdjustments.m42 * animatingScaleTarget;
    5317 
    5318     [_scrollView setContentSize:roundScrollViewContentSize(*_page, [_contentView frame].size)];
    5319     [_scrollView setContentOffset:CGPointMake(currentScrollOffset.x - horizontalScrollAdjustement, currentScrollOffset.y - verticalScrollAdjustment)];
    5320 
    5321     [_resizeAnimationView removeFromSuperview];
    5322     _resizeAnimationView = nil;
    5323     _resizeAnimationTransformAdjustments = CATransform3DIdentity;
    5324 
    5325     _dynamicViewportUpdateMode = DynamicViewportUpdateMode::NotResizing;
    5326     [_contentView setHidden:NO];
    5327     [self _scheduleVisibleContentRectUpdate];
    5328 
    5329     CGRect newBounds = self.bounds;
    5330     auto newViewLayoutSize = [self activeViewLayoutSize:newBounds];
    5331     auto newMaximumUnobscuredSize = activeMaximumUnobscuredSize(self, newBounds);
    5332     int32_t newOrientation = activeOrientation(self);
    5333 
    5334     if (!_lastSentViewLayoutSize || newViewLayoutSize != _lastSentViewLayoutSize.value())
    5335         [self _dispatchSetViewLayoutSize:newViewLayoutSize];
    5336     if (!_lastSentMaximumUnobscuredSize || newMaximumUnobscuredSize != _lastSentMaximumUnobscuredSize.value())
    5337         [self _dispatchSetMaximumUnobscuredSize:WebCore::FloatSize(newMaximumUnobscuredSize)];
    5338     if (!_lastSentDeviceOrientation || newOrientation != _lastSentDeviceOrientation.value())
    5339         [self _dispatchSetDeviceOrientation:newOrientation];
    5340 
    5341     while (!_snapshotsDeferredDuringResize.isEmpty())
    5342         _snapshotsDeferredDuringResize.takeLast()();
     5362    // If we already have an up-to-date layer tree, immediately complete
     5363    // the resize. Otherwise, we will defer completion until we do.
     5364    _waitingForEndAnimatedResize = NO;
     5365    if (!_waitingForCommitAfterAnimatedResize)
     5366        [self _didCompleteAnimatedResize];
    53435367}
    53445368
     
    53475371    LOG_WITH_STREAM(VisibleRects, stream << "-[WKWebView " << _page->pageID() << " _resizeWhileHidingContentWithUpdates:]");
    53485372    [self _beginAnimatedResizeWithUpdates:updateBlock];
    5349     if (_dynamicViewportUpdateMode == DynamicViewportUpdateMode::ResizingWithAnimation) {
     5373    if (_dynamicViewportUpdateMode == WebKit::DynamicViewportUpdateMode::ResizingWithAnimation) {
    53505374        [_contentView setHidden:YES];
    5351         _dynamicViewportUpdateMode = DynamicViewportUpdateMode::ResizingWithDocumentHidden;
     5375        _dynamicViewportUpdateMode = WebKit::DynamicViewportUpdateMode::ResizingWithDocumentHidden;
    53525376    }
    53535377}
     
    53605384- (void)_snapshotRect:(CGRect)rectInViewCoordinates intoImageOfWidth:(CGFloat)imageWidth completionHandler:(void(^)(CGImageRef))completionHandler
    53615385{
    5362     if (_dynamicViewportUpdateMode != DynamicViewportUpdateMode::NotResizing) {
     5386    if (_dynamicViewportUpdateMode != WebKit::DynamicViewportUpdateMode::NotResizing) {
    53635387        // Defer snapshotting until after the current resize completes.
    53645388        void (^copiedCompletionHandler)(CGImageRef) = [completionHandler copy];
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewInternal.h

    r232416 r232544  
    8383- (void)_layerTreeCommitComplete;
    8484
    85 - (void)_dynamicViewportUpdateChangedTargetToScale:(double)newScale position:(CGPoint)newScrollPosition nextValidLayerTreeTransactionID:(uint64_t)nextValidLayerTreeTransactionID;
    8685- (void)_couldNotRestorePageState;
    8786- (void)_restorePageScrollPosition:(std::optional<WebCore::FloatPoint>)scrollPosition scrollOrigin:(WebCore::FloatPoint)scrollOrigin previousObscuredInset:(WebCore::FloatBoxExtent)insets scale:(double)scale;
     
    105104
    106105- (void)_scheduleVisibleContentRectUpdate;
     106
     107- (void)_didCompleteAnimatedResize;
    107108
    108109- (void)_didStartProvisionalLoadForMainFrame;
  • trunk/Source/WebKit/UIProcess/PageClient.h

    r231242 r232544  
    285285    virtual void layerTreeCommitComplete() = 0;
    286286
    287     virtual void dynamicViewportUpdateChangedTarget(double newScale, const WebCore::FloatPoint& newScrollPosition, uint64_t transactionID) = 0;
    288287    virtual void couldNotRestorePageState() = 0;
    289288    virtual void restorePageState(std::optional<WebCore::FloatPoint> scrollPosition, const WebCore::FloatPoint& scrollOrigin, const WebCore::FloatBoxExtent& obscuredInsetsOnSave, double scale) = 0;
  • trunk/Source/WebKit/UIProcess/WebPageProxy.cpp

    r232535 r232544  
    59645964    m_firstLayerTreeTransactionIdAfterDidCommitLoad = 0;
    59655965    m_lastVisibleContentRectUpdate = VisibleContentRectUpdateInfo();
    5966     m_dynamicViewportSizeUpdateWaitingForTarget = false;
    5967     m_dynamicViewportSizeUpdateWaitingForLayerTreeCommit = false;
    5968     m_dynamicViewportSizeUpdateLayerTreeTransactionID = 0;
    59695966    m_hasNetworkRequestsOnSuspended = false;
    59705967    m_isKeyboardAnimatingIn = false;
  • trunk/Source/WebKit/UIProcess/WebPageProxy.h

    r232437 r232544  
    108108
    109109#if PLATFORM(COCOA)
     110#include "DynamicViewportSizeUpdate.h"
    110111#include "LayerRepresentation.h"
    111112#include "TouchBarMenuData.h"
     
    552553    void overflowScrollDidEndScroll();
    553554
    554     void dynamicViewportSizeUpdate(const WebCore::FloatSize& viewLayoutSize, const WebCore::FloatSize& maximumUnobscuredSize, const WebCore::FloatRect& targetExposedContentRect, const WebCore::FloatRect& targetUnobscuredRect, const WebCore::FloatRect& targetUnobscuredRectInScrollViewCoordinates, const WebCore::FloatBoxExtent& unobscuredSafeAreaInsets, double targetScale, int32_t deviceOrientation);
    555     void synchronizeDynamicViewportUpdate();
     555    void dynamicViewportSizeUpdate(const WebCore::FloatSize& viewLayoutSize, const WebCore::FloatSize& maximumUnobscuredSize, const WebCore::FloatRect& targetExposedContentRect, const WebCore::FloatRect& targetUnobscuredRect, const WebCore::FloatRect& targetUnobscuredRectInScrollViewCoordinates, const WebCore::FloatBoxExtent& unobscuredSafeAreaInsets, double targetScale, int32_t deviceOrientation, DynamicViewportSizeUpdateID);
    556556
    557557    void setViewportConfigurationViewLayoutSize(const WebCore::FloatSize&);
     
    16641664    float textAutosizingWidth();
    16651665
    1666     void dynamicViewportUpdateChangedTarget(double newTargetScale, const WebCore::FloatPoint& newScrollPosition, uint64_t dynamicViewportSizeUpdateID);
    16671666    void couldNotRestorePageState();
    16681667    void restorePageState(std::optional<WebCore::FloatPoint> scrollPosition, const WebCore::FloatPoint& scrollOrigin, const WebCore::FloatBoxExtent& obscuredInsetsOnSave, double scale);
     
    18451844    uint64_t m_firstLayerTreeTransactionIdAfterDidCommitLoad { 0 };
    18461845    int32_t m_deviceOrientation { 0 };
    1847     uint64_t m_dynamicViewportSizeUpdateLayerTreeTransactionID { 0 };
    1848     uint64_t m_currentDynamicViewportSizeUpdateID { 0 };
    18491846    bool m_hasReceivedLayerTreeTransactionAfterDidCommitLoad { true };
    1850     bool m_dynamicViewportSizeUpdateWaitingForTarget { false };
    1851     bool m_dynamicViewportSizeUpdateWaitingForLayerTreeCommit { false };
    18521847    bool m_hasNetworkRequestsOnSuspended { false };
    18531848    bool m_isKeyboardAnimatingIn { false };
  • trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in

    r231510 r232544  
    390390
    391391#if PLATFORM(IOS)
    392     DynamicViewportUpdateChangedTarget(double newTargetScale, WebCore::FloatPoint newScrollPosition, uint64_t dynamicViewportSizeUpdateID)
    393392    CouldNotRestorePageState()
    394393    RestorePageState(std::optional<WebCore::FloatPoint> scrollPosition, WebCore::FloatPoint scrollOrigin, WebCore::RectEdges<float> obscuredInsetsOnSave, double scale)
  • trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.h

    r231242 r232544  
    121121    void layerTreeCommitComplete() override;
    122122
    123     void dynamicViewportUpdateChangedTarget(double newScale, const WebCore::FloatPoint& newScrollPosition, uint64_t transactionID) override;
    124123    void couldNotRestorePageState() override;
    125124    void restorePageState(std::optional<WebCore::FloatPoint>, const WebCore::FloatPoint&, const WebCore::FloatBoxExtent&, double) override;
  • trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.mm

    r232416 r232544  
    516516}
    517517
    518 void PageClientImpl::dynamicViewportUpdateChangedTarget(double newScale, const WebCore::FloatPoint& newScrollPosition, uint64_t nextValidLayerTreeTransactionID)
    519 {
    520     [m_webView _dynamicViewportUpdateChangedTargetToScale:newScale position:newScrollPosition nextValidLayerTreeTransactionID:nextValidLayerTreeTransactionID];
    521 }
    522 
    523518void PageClientImpl::couldNotRestorePageState()
    524519{
  • trunk/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm

    r231676 r232544  
    307307}
    308308
    309 void WebPageProxy::dynamicViewportSizeUpdate(const FloatSize& viewLayoutSize, const WebCore::FloatSize& maximumUnobscuredSize, const FloatRect& targetExposedContentRect, const FloatRect& targetUnobscuredRect, const FloatRect& targetUnobscuredRectInScrollViewCoordinates, const WebCore::FloatBoxExtent& unobscuredSafeAreaInsets, double targetScale, int32_t deviceOrientation)
     309void WebPageProxy::dynamicViewportSizeUpdate(const FloatSize& viewLayoutSize, const WebCore::FloatSize& maximumUnobscuredSize, const FloatRect& targetExposedContentRect, const FloatRect& targetUnobscuredRect, const FloatRect& targetUnobscuredRectInScrollViewCoordinates, const WebCore::FloatBoxExtent& unobscuredSafeAreaInsets, double targetScale, int32_t deviceOrientation, DynamicViewportSizeUpdateID dynamicViewportSizeUpdateID)
    310310{
    311311    if (!isValid())
     
    314314    hideValidationMessage();
    315315
    316     m_dynamicViewportSizeUpdateWaitingForTarget = true;
    317     m_dynamicViewportSizeUpdateWaitingForLayerTreeCommit = true;
    318     m_process->send(Messages::WebPage::DynamicViewportSizeUpdate(viewLayoutSize, maximumUnobscuredSize, targetExposedContentRect, targetUnobscuredRect, targetUnobscuredRectInScrollViewCoordinates, unobscuredSafeAreaInsets, targetScale, deviceOrientation, ++m_currentDynamicViewportSizeUpdateID), m_pageID);
    319 }
    320 
    321 void WebPageProxy::synchronizeDynamicViewportUpdate()
    322 {
    323     if (!isValid())
    324         return;
    325 
    326     if (m_dynamicViewportSizeUpdateWaitingForTarget) {
    327         // We do not want the UIProcess to finish animated resize with the old content size, scale, etc.
    328         // If that happens, the UIProcess would start pushing new VisibleContentRectUpdateInfo to the WebProcess with
    329         // invalid informations.
    330         //
    331         // Ideally, the animated resize should just be transactional, and the UIProcess would remain in the "resize" state
    332         // until both DynamicViewportUpdateChangedTarget and the associated commitLayerTree are finished.
    333         // The tricky part with such implementation is if a second animated resize starts before the end of the previous one.
    334         // In that case, the values used for the target state needs to be computed from the output of the previous animated resize.
    335         //
    336         // The following is a workaround to have the UIProcess in a consistent state.
    337         // Instead of handling nested resize, we block the UIProcess until the animated resize finishes.
    338         double newScale;
    339         FloatPoint newScrollPosition;
    340         uint64_t nextValidLayerTreeTransactionID;
    341         if (m_process->sendSync(Messages::WebPage::SynchronizeDynamicViewportUpdate(), Messages::WebPage::SynchronizeDynamicViewportUpdate::Reply(newScale, newScrollPosition, nextValidLayerTreeTransactionID), m_pageID, 2_s)) {
    342             m_dynamicViewportSizeUpdateWaitingForTarget = false;
    343             m_dynamicViewportSizeUpdateLayerTreeTransactionID = nextValidLayerTreeTransactionID;
    344             m_pageClient.dynamicViewportUpdateChangedTarget(newScale, newScrollPosition, nextValidLayerTreeTransactionID);
    345         }
    346 
    347     }
    348 
    349     // If m_dynamicViewportSizeUpdateWaitingForTarget is false, we are waiting for the next valid frame with the hope it is the one for the new target.
    350     // If m_dynamicViewportSizeUpdateWaitingForTarget is still true, this is a desperate attempt to get the valid frame before finishing the animation.
    351     if (m_dynamicViewportSizeUpdateWaitingForLayerTreeCommit)
    352         m_drawingArea->waitForDidUpdateActivityState();
    353 
    354     m_dynamicViewportSizeUpdateWaitingForTarget = false;
    355     m_dynamicViewportSizeUpdateWaitingForLayerTreeCommit = false;
     316    m_process->send(Messages::WebPage::DynamicViewportSizeUpdate(viewLayoutSize,
     317        maximumUnobscuredSize, targetExposedContentRect, targetUnobscuredRect,
     318        targetUnobscuredRectInScrollViewCoordinates, unobscuredSafeAreaInsets,
     319        targetScale, deviceOrientation, dynamicViewportSizeUpdateID), m_pageID);
    356320}
    357321
     
    408372    }
    409373
    410     if (!m_dynamicViewportSizeUpdateWaitingForTarget && m_dynamicViewportSizeUpdateWaitingForLayerTreeCommit) {
    411         if (layerTreeTransaction.transactionID() >= m_dynamicViewportSizeUpdateLayerTreeTransactionID)
    412             m_dynamicViewportSizeUpdateWaitingForLayerTreeCommit = false;
    413     }
    414 
    415374    m_pageClient.didCommitLayerTree(layerTreeTransaction);
    416375
     
    903862{
    904863    return WebCore::screenSize().width();
    905 }
    906 
    907 void WebPageProxy::dynamicViewportUpdateChangedTarget(double newScale, const WebCore::FloatPoint& newScrollPosition, uint64_t dynamicViewportSizeUpdateID)
    908 {
    909     if (dynamicViewportSizeUpdateID != m_currentDynamicViewportSizeUpdateID)
    910         return;
    911 
    912     if (m_dynamicViewportSizeUpdateWaitingForTarget) {
    913         m_dynamicViewportSizeUpdateLayerTreeTransactionID = downcast<RemoteLayerTreeDrawingAreaProxy>(*drawingArea()).nextLayerTreeTransactionID();
    914         m_dynamicViewportSizeUpdateWaitingForTarget = false;
    915         m_pageClient.dynamicViewportUpdateChangedTarget(newScale, newScrollPosition, m_dynamicViewportSizeUpdateLayerTreeTransactionID);
    916     }
    917864}
    918865
  • trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj

    r232491 r232544  
    678678                2DA1E4FE18C02B6A00DBC929 /* WKLegacyPDFView.h in Headers */ = {isa = PBXBuildFile; fileRef = 2DA1E4FC18C02B6A00DBC929 /* WKLegacyPDFView.h */; };
    679679                2DA1E4FF18C02B6A00DBC929 /* WKLegacyPDFView.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2DA1E4FD18C02B6A00DBC929 /* WKLegacyPDFView.mm */; };
     680                2DA6731A20C754B1003CB401 /* DynamicViewportSizeUpdate.h in Headers */ = {isa = PBXBuildFile; fileRef = 2DA6731920C754B1003CB401 /* DynamicViewportSizeUpdate.h */; };
    680681                2DA9449E1884E4F000ED86DB /* NativeWebKeyboardEventIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2DA944971884E4F000ED86DB /* NativeWebKeyboardEventIOS.mm */; };
    681682                2DA9449F1884E4F000ED86DB /* NativeWebTouchEventIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2DA944981884E4F000ED86DB /* NativeWebTouchEventIOS.mm */; };
     
    30563057                2DA1E4FC18C02B6A00DBC929 /* WKLegacyPDFView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WKLegacyPDFView.h; path = ios/WKLegacyPDFView.h; sourceTree = "<group>"; };
    30573058                2DA1E4FD18C02B6A00DBC929 /* WKLegacyPDFView.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = WKLegacyPDFView.mm; path = ios/WKLegacyPDFView.mm; sourceTree = "<group>"; };
     3059                2DA6731920C754B1003CB401 /* DynamicViewportSizeUpdate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DynamicViewportSizeUpdate.h; path = ios/DynamicViewportSizeUpdate.h; sourceTree = "<group>"; };
    30583060                2DA7FDCB18F88625008DDED0 /* FindIndicatorOverlayClientIOS.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = FindIndicatorOverlayClientIOS.h; path = ios/FindIndicatorOverlayClientIOS.h; sourceTree = "<group>"; };
    30593061                2DA944971884E4F000ED86DB /* NativeWebKeyboardEventIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = NativeWebKeyboardEventIOS.mm; path = ios/NativeWebKeyboardEventIOS.mm; sourceTree = "<group>"; };
     
    57805782                        children = (
    57815783                                A7E93CEB192531AA00A1DC48 /* ChildProcessIOS.mm */,
     5784                                2DA6731920C754B1003CB401 /* DynamicViewportSizeUpdate.h */,
    57825785                                2DA9449D1884E4F000ED86DB /* GestureTypes.h */,
    57835786                                C5BCE5DA1C50761D00CDE3FA /* InteractionInformationAtPosition.h */,
     
    89428945                                BC2652171182608100243E12 /* DrawingAreaProxy.h in Headers */,
    89438946                                1A64230912DD09EB00CAAE2C /* DrawingAreaProxyMessages.h in Headers */,
     8947                                2DA6731A20C754B1003CB401 /* DynamicViewportSizeUpdate.h in Headers */,
    89448948                                E105FE5418D7B9DE008F57A8 /* EditingRange.h in Headers */,
    89458949                                1AA41AB512C02EC4002BE67B /* EditorState.h in Headers */,
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp

    r232535 r232544  
    32233223    layerTransaction.setIsInStableState(m_isInStableState);
    32243224    layerTransaction.setAllowsUserScaling(allowsUserScaling());
    3225 #endif
    3226 
    3227 #if PLATFORM(MAC)
     3225    if (m_pendingDynamicViewportSizeUpdateID) {
     3226        layerTransaction.setDynamicViewportSizeUpdateID(*m_pendingDynamicViewportSizeUpdateID);
     3227        m_pendingDynamicViewportSizeUpdateID = std::nullopt;
     3228    }
     3229#endif
     3230
    32283231    layerTransaction.setScrollPosition(frameView->scrollPosition());
    3229 #endif
    32303232
    32313233    if (m_hasPendingEditorStateUpdate) {
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.h

    r232535 r232544  
    108108
    109109#if PLATFORM(COCOA)
     110#include "DynamicViewportSizeUpdate.h"
    110111#include <WebCore/VisibleSelection.h>
    111112#include <wtf/RetainPtr.h>
     
    883884    void setMaximumUnobscuredSize(const WebCore::FloatSize&);
    884885    void setDeviceOrientation(int32_t);
    885     void dynamicViewportSizeUpdate(const WebCore::FloatSize& viewLayoutSize, const WebCore::FloatSize& maximumUnobscuredSize, const WebCore::FloatRect& targetExposedContentRect, const WebCore::FloatRect& targetUnobscuredRect, const WebCore::FloatRect& targetUnobscuredRectInScrollViewCoordinates, const WebCore::FloatBoxExtent& targetUnobscuredSafeAreaInsets, double scale, int32_t deviceOrientation, uint64_t dynamicViewportSizeUpdateID);
    886     void synchronizeDynamicViewportUpdate(double& newTargetScale, WebCore::FloatPoint& newScrollPosition, uint64_t& nextValidLayerTreeTransactionID);
     886    void dynamicViewportSizeUpdate(const WebCore::FloatSize& viewLayoutSize, const WebCore::FloatSize& maximumUnobscuredSize, const WebCore::FloatRect& targetExposedContentRect, const WebCore::FloatRect& targetUnobscuredRect, const WebCore::FloatRect& targetUnobscuredRectInScrollViewCoordinates, const WebCore::FloatBoxExtent& targetUnobscuredSafeAreaInsets, double scale, int32_t deviceOrientation, DynamicViewportSizeUpdateID);
    887887    std::optional<float> scaleFromUIProcess(const VisibleContentRectUpdateInfo&) const;
    888888    void updateVisibleContentRects(const VisibleContentRectUpdateInfo&, MonotonicTime oldestTimestamp);
     
    16511651    WebCore::FloatRect m_previousExposedContentRect;
    16521652    uint64_t m_currentAssistedNodeIdentifier { 0 };
     1653    std::optional<DynamicViewportSizeUpdateID> m_pendingDynamicViewportSizeUpdateID;
    16531654#endif
    16541655
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in

    r232535 r232544  
    5050    SetDeviceOrientation(int32_t deviceOrientation)
    5151    DynamicViewportSizeUpdate(WebCore::FloatSize viewLayoutSize, WebCore::FloatSize maximumUnobscuredSize, WebCore::FloatRect targetExposedContentRect, WebCore::FloatRect targetUnobscuredRect, WebCore::FloatRect targetUnobscuredRectInScrollViewCoordinates, WebCore::RectEdges<float> targetUnobscuredSafeAreaInsets, double scale, int32_t deviceOrientation, uint64_t dynamicViewportSizeUpdateID)
    52     SynchronizeDynamicViewportUpdate() -> (double newTargetScale, WebCore::FloatPoint newScrollPosition, uint64_t nextValidLayerTreeTransactionID)
    5352
    5453    HandleTap(WebCore::IntPoint point, uint64_t lastLayerTreeTransactionId)
  • trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm

    r232479 r232544  
    24962496}
    24972497
    2498 void WebPage::dynamicViewportSizeUpdate(const FloatSize& viewLayoutSize, const WebCore::FloatSize& maximumUnobscuredSize, const FloatRect& targetExposedContentRect, const FloatRect& targetUnobscuredRect, const WebCore::FloatRect& targetUnobscuredRectInScrollViewCoordinates, const WebCore::FloatBoxExtent& targetUnobscuredSafeAreaInsets, double targetScale, int32_t deviceOrientation, uint64_t dynamicViewportSizeUpdateID)
     2498void WebPage::dynamicViewportSizeUpdate(const FloatSize& viewLayoutSize, const WebCore::FloatSize& maximumUnobscuredSize, const FloatRect& targetExposedContentRect, const FloatRect& targetUnobscuredRect, const WebCore::FloatRect& targetUnobscuredRectInScrollViewCoordinates, const WebCore::FloatBoxExtent& targetUnobscuredSafeAreaInsets, double targetScale, int32_t deviceOrientation, DynamicViewportSizeUpdateID dynamicViewportSizeUpdateID)
    24992499{
    25002500    SetForScope<bool> dynamicSizeUpdateGuard(m_inDynamicSizeUpdate, true);
     
    26732673    m_drawingArea->scheduleCompositingLayerFlush();
    26742674
    2675     send(Messages::WebPageProxy::DynamicViewportUpdateChangedTarget(pageScaleFactor(), frameView.scrollPosition(), dynamicViewportSizeUpdateID));
    2676 }
    2677 
    2678 void WebPage::synchronizeDynamicViewportUpdate(double& newTargetScale, FloatPoint& newScrollPosition, uint64_t& nextValidLayerTreeTransactionID)
    2679 {
    2680     newTargetScale = pageScaleFactor();
    2681     newScrollPosition = m_page->mainFrame().view()->scrollPosition();
    2682     nextValidLayerTreeTransactionID = downcast<RemoteLayerTreeDrawingArea>(*m_drawingArea).nextTransactionID();
     2675    m_pendingDynamicViewportSizeUpdateID = dynamicViewportSizeUpdateID;
    26832676}
    26842677
Note: See TracChangeset for help on using the changeset viewer.