Changeset 254361 in webkit
- Timestamp:
- Jan 10, 2020 11:56:52 AM (4 years ago)
- Location:
- trunk/Source/WebKit
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r254360 r254361 1 2020-01-10 Simon Fraser <simon.fraser@apple.com> 2 3 Clean up -[WKWebView _didCommitLayerTree:] 4 https://bugs.webkit.org/show_bug.cgi?id=206049 5 6 Reviewed by Tim Horton. 7 8 In preparation for sharing more of this code with macOS, factors parts of -[WKWebView _didCommitLayerTree:] 9 into new functions. 10 11 Also pull out part of -[WKWebView _updateVisibleContentRects] into its own function. 12 13 * UIProcess/API/ios/WKWebViewIOS.mm: 14 (-[WKWebView _trackTransactionCommit:]): 15 (-[WKWebView _updateScrollViewForTransaction:]): 16 (-[WKWebView _restoreScrollAndZoomStateForTransaction:]): 17 (-[WKWebView _didCommitLayerTree:]): 18 (-[WKWebView _allowsDoubleTapGestures]): 19 (-[WKWebView currentlyVisibleContentInsetsWithScale:obscuredInsets:]): 20 (-[WKWebView _updateVisibleContentRects]): 21 (areEssentiallyEqualAsFloat): Deleted. 22 1 23 2020-01-10 Simon Fraser <simon.fraser@apple.com> 2 24 -
trunk/Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm
r254315 r254361 723 723 } 724 724 725 // WebCore stores the page scale factor as float instead of double. When we get a scale from WebCore,726 // we need to ignore differences that are within a small rounding error on floats.727 static inline bool areEssentiallyEqualAsFloat(float a, float b)728 {729 return WTF::areEssentiallyEqual(a, b);730 }731 732 725 - (void)_didCommitLayerTreeDuringAnimatedResize:(const WebKit::RemoteLayerTreeTransaction&)layerTreeTransaction 733 726 { … … 773 766 } 774 767 775 - (void)_ didCommitLayerTree:(const WebKit::RemoteLayerTreeTransaction&)layerTreeTransaction768 - (void)_trackTransactionCommit:(const WebKit::RemoteLayerTreeTransaction&)layerTreeTransaction 776 769 { 777 770 if (_didDeferUpdateVisibleContentRectsForUnstableScrollView) { … … 786 779 _timeOfFirstVisibleContentRectUpdateWithPendingCommit = WTF::nullopt; 787 780 } 788 789 _lastTransactionID = layerTreeTransaction.transactionID(); 790 791 if (![self usesStandardContentView]) 792 return; 793 794 LOG_WITH_STREAM(VisibleRects, stream << "-[WKWebView " << _page->identifier() << " _didCommitLayerTree:] transactionID " << layerTreeTransaction.transactionID() << " _dynamicViewportUpdateMode " << (int)_dynamicViewportUpdateMode); 795 796 bool needUpdateVisibleContentRects = _page->updateLayoutViewportParameters(layerTreeTransaction); 797 798 if (_dynamicViewportUpdateMode != WebKit::DynamicViewportUpdateMode::NotResizing) { 799 [self _didCommitLayerTreeDuringAnimatedResize:layerTreeTransaction]; 800 return; 801 } 802 803 if (_resizeAnimationView) 804 RELEASE_LOG_IF_ALLOWED("%p -[WKWebView _didCommitLayerTree:] - dynamicViewportUpdateMode is NotResizing, but still have a live resizeAnimationView (unpaired begin/endAnimatedResize?)", self); 805 781 } 782 783 - (void)_updateScrollViewForTransaction:(const WebKit::RemoteLayerTreeTransaction&)layerTreeTransaction 784 { 806 785 CGSize newContentSize = roundScrollViewContentSize(*_page, [_contentView frame].size); 807 786 [_scrollView _setContentSizePreservingContentOffsetDuringRubberband:newContentSize]; … … 810 789 [_scrollView setMaximumZoomScale:layerTreeTransaction.maximumScaleFactor()]; 811 790 [_scrollView _setZoomEnabledInternal:layerTreeTransaction.allowsUserScaling()]; 812 #if ENABLE(ASYNC_SCROLLING) 791 813 792 bool hasDockedInputView = !CGRectIsEmpty(_inputViewBounds); 814 793 bool isZoomed = layerTreeTransaction.pageScaleFactor() > layerTreeTransaction.initialScaleFactor(); … … 823 802 bool scrollingEnabled = _page->scrollingCoordinatorProxy()->hasScrollableMainFrame() || hasDockedInputView || isZoomed || scrollingNeededToRevealUI; 824 803 [_scrollView _setScrollEnabledInternal:scrollingEnabled]; 825 #endif 804 826 805 if (!layerTreeTransaction.scaleWasSetByUIProcess() && ![_scrollView isZooming] && ![_scrollView isZoomBouncing] && ![_scrollView _isAnimatingZoom] && [_scrollView zoomScale] != layerTreeTransaction.pageScaleFactor()) { 827 806 LOG_WITH_STREAM(VisibleRects, stream << " updating scroll view with pageScaleFactor " << layerTreeTransaction.pageScaleFactor()); 828 807 [_scrollView setZoomScale:layerTreeTransaction.pageScaleFactor()]; 829 808 } 809 } 810 811 - (BOOL)_restoreScrollAndZoomStateForTransaction:(const WebKit::RemoteLayerTreeTransaction&)layerTreeTransaction 812 { 813 if (!_firstTransactionIDAfterPageRestore || layerTreeTransaction.transactionID() < _firstTransactionIDAfterPageRestore.value()) 814 return NO; 815 816 _firstTransactionIDAfterPageRestore = WTF::nullopt; 817 818 BOOL needUpdateVisibleContentRects = NO; 819 820 if (_scrollOffsetToRestore) { 821 WebCore::FloatPoint scaledScrollOffset = _scrollOffsetToRestore.value(); 822 _scrollOffsetToRestore = WTF::nullopt; 823 824 if (WTF::areEssentiallyEqual<float>(contentZoomScale(self), _scaleToRestore)) { 825 scaledScrollOffset.scale(_scaleToRestore); 826 WebCore::FloatPoint contentOffsetInScrollViewCoordinates = scaledScrollOffset - WebCore::FloatSize(_obscuredInsetsWhenSaved.left(), _obscuredInsetsWhenSaved.top()); 827 828 changeContentOffsetBoundedInValidRange(_scrollView.get(), contentOffsetInScrollViewCoordinates); 829 _commitDidRestoreScrollPosition = YES; 830 } 831 832 needUpdateVisibleContentRects = YES; 833 } 834 835 if (_unobscuredCenterToRestore) { 836 WebCore::FloatPoint unobscuredCenterToRestore = _unobscuredCenterToRestore.value(); 837 _unobscuredCenterToRestore = WTF::nullopt; 838 839 if (WTF::areEssentiallyEqual<float>(contentZoomScale(self), _scaleToRestore)) { 840 CGRect unobscuredRect = UIEdgeInsetsInsetRect(self.bounds, _obscuredInsets); 841 WebCore::FloatSize unobscuredContentSizeAtNewScale = WebCore::FloatSize(unobscuredRect.size) / _scaleToRestore; 842 WebCore::FloatPoint topLeftInDocumentCoordinates = unobscuredCenterToRestore - unobscuredContentSizeAtNewScale / 2; 843 844 topLeftInDocumentCoordinates.scale(_scaleToRestore); 845 topLeftInDocumentCoordinates.moveBy(WebCore::FloatPoint(-_obscuredInsets.left, -_obscuredInsets.top)); 846 847 changeContentOffsetBoundedInValidRange(_scrollView.get(), topLeftInDocumentCoordinates); 848 } 849 850 needUpdateVisibleContentRects = YES; 851 } 852 853 if (_gestureController) 854 _gestureController->didRestoreScrollPosition(); 855 856 return needUpdateVisibleContentRects; 857 } 858 859 - (void)_didCommitLayerTree:(const WebKit::RemoteLayerTreeTransaction&)layerTreeTransaction 860 { 861 [self _trackTransactionCommit:layerTreeTransaction]; 862 863 _lastTransactionID = layerTreeTransaction.transactionID(); 864 865 if (![self usesStandardContentView]) 866 return; 867 868 LOG_WITH_STREAM(VisibleRects, stream << "-[WKWebView " << _page->identifier() << " _didCommitLayerTree:] transactionID " << layerTreeTransaction.transactionID() << " _dynamicViewportUpdateMode " << (int)_dynamicViewportUpdateMode); 869 870 bool needUpdateVisibleContentRects = _page->updateLayoutViewportParameters(layerTreeTransaction); 871 872 if (_dynamicViewportUpdateMode != WebKit::DynamicViewportUpdateMode::NotResizing) { 873 [self _didCommitLayerTreeDuringAnimatedResize:layerTreeTransaction]; 874 return; 875 } 876 877 if (_resizeAnimationView) 878 RELEASE_LOG_IF_ALLOWED("%p -[WKWebView _didCommitLayerTree:] - dynamicViewportUpdateMode is NotResizing, but still have a live resizeAnimationView (unpaired begin/endAnimatedResize?)", self); 879 880 [self _updateScrollViewForTransaction:layerTreeTransaction]; 830 881 831 882 _viewportMetaTagWidth = layerTreeTransaction.viewportMetaTagWidth(); … … 833 884 _viewportMetaTagCameFromImageDocument = layerTreeTransaction.viewportMetaTagCameFromImageDocument(); 834 885 _initialScaleFactor = layerTreeTransaction.initialScaleFactor(); 886 835 887 if (_page->inStableState() && layerTreeTransaction.isInStableState() && [_stableStatePresentationUpdateCallbacks count]) { 836 888 for (dispatch_block_t action in _stableStatePresentationUpdateCallbacks.get()) … … 859 911 } 860 912 861 if (_firstTransactionIDAfterPageRestore && layerTreeTransaction.transactionID() >= _firstTransactionIDAfterPageRestore.value()) { 862 if (_scrollOffsetToRestore) { 863 WebCore::FloatPoint scaledScrollOffset = _scrollOffsetToRestore.value(); 864 _scrollOffsetToRestore = WTF::nullopt; 865 866 if (areEssentiallyEqualAsFloat(contentZoomScale(self), _scaleToRestore)) { 867 scaledScrollOffset.scale(_scaleToRestore); 868 WebCore::FloatPoint contentOffsetInScrollViewCoordinates = scaledScrollOffset - WebCore::FloatSize(_obscuredInsetsWhenSaved.left(), _obscuredInsetsWhenSaved.top()); 869 870 changeContentOffsetBoundedInValidRange(_scrollView.get(), contentOffsetInScrollViewCoordinates); 871 _commitDidRestoreScrollPosition = YES; 872 } 873 874 needUpdateVisibleContentRects = true; 875 } 876 877 if (_unobscuredCenterToRestore) { 878 WebCore::FloatPoint unobscuredCenterToRestore = _unobscuredCenterToRestore.value(); 879 _unobscuredCenterToRestore = WTF::nullopt; 880 881 if (areEssentiallyEqualAsFloat(contentZoomScale(self), _scaleToRestore)) { 882 CGRect unobscuredRect = UIEdgeInsetsInsetRect(self.bounds, _obscuredInsets); 883 WebCore::FloatSize unobscuredContentSizeAtNewScale = WebCore::FloatSize(unobscuredRect.size) / _scaleToRestore; 884 WebCore::FloatPoint topLeftInDocumentCoordinates = unobscuredCenterToRestore - unobscuredContentSizeAtNewScale / 2; 885 886 topLeftInDocumentCoordinates.scale(_scaleToRestore); 887 topLeftInDocumentCoordinates.moveBy(WebCore::FloatPoint(-_obscuredInsets.left, -_obscuredInsets.top)); 888 889 changeContentOffsetBoundedInValidRange(_scrollView.get(), topLeftInDocumentCoordinates); 890 } 891 892 needUpdateVisibleContentRects = true; 893 } 894 895 if (_gestureController) 896 _gestureController->didRestoreScrollPosition(); 897 898 _firstTransactionIDAfterPageRestore = WTF::nullopt; 899 } 913 if ([self _restoreScrollAndZoomStateForTransaction:layerTreeTransaction]) 914 needUpdateVisibleContentRects = true; 900 915 901 916 if (needUpdateVisibleContentRects) … … 1423 1438 // if the content's width and height were large, we might have had to shrink it. 1424 1439 // We'll enable double tap zoom whenever we're not at the actual initial scale. 1425 return ! areEssentiallyEqualAsFloat(contentZoomScale(self), _initialScaleFactor);1440 return !WTF::areEssentiallyEqual<float>(contentZoomScale(self), _initialScaleFactor); 1426 1441 } 1427 1442 … … 1885 1900 } 1886 1901 1902 - (UIEdgeInsets)currentlyVisibleContentInsetsWithScale:(CGFloat)scaleFactor obscuredInsets:(UIEdgeInsets)obscuredInsets 1903 { 1904 // The following logic computes the extent to which the bottom, top, left and right content insets are visible. 1905 auto scrollViewInsets = [_scrollView contentInset]; 1906 auto scrollViewBounds = [_scrollView bounds]; 1907 auto scrollViewContentSize = [_scrollView contentSize]; 1908 auto scrollViewOriginIncludingInset = UIEdgeInsetsInsetRect(scrollViewBounds, obscuredInsets).origin; 1909 auto maximumVerticalScrollExtentWithoutRevealingBottomContentInset = scrollViewContentSize.height - CGRectGetHeight(scrollViewBounds); 1910 auto maximumHorizontalScrollExtentWithoutRevealingRightContentInset = scrollViewContentSize.width - CGRectGetWidth(scrollViewBounds); 1911 auto contentInsets = UIEdgeInsetsZero; 1912 1913 if (scrollViewInsets.left > 0 && scrollViewOriginIncludingInset.x < 0) 1914 contentInsets.left = std::min(-scrollViewOriginIncludingInset.x, scrollViewInsets.left) / scaleFactor; 1915 1916 if (scrollViewInsets.top > 0 && scrollViewOriginIncludingInset.y < 0) 1917 contentInsets.top = std::min(-scrollViewOriginIncludingInset.y, scrollViewInsets.top) / scaleFactor; 1918 1919 if (scrollViewInsets.right > 0 && scrollViewOriginIncludingInset.x > maximumHorizontalScrollExtentWithoutRevealingRightContentInset) 1920 contentInsets.right = std::min(scrollViewOriginIncludingInset.x - maximumHorizontalScrollExtentWithoutRevealingRightContentInset, scrollViewInsets.right) / scaleFactor; 1921 1922 if (scrollViewInsets.bottom > 0 && scrollViewOriginIncludingInset.y > maximumVerticalScrollExtentWithoutRevealingBottomContentInset) 1923 contentInsets.bottom = std::min(scrollViewOriginIncludingInset.y - maximumVerticalScrollExtentWithoutRevealingBottomContentInset, scrollViewInsets.bottom) / scaleFactor; 1924 1925 return contentInsets; 1926 } 1927 1887 1928 - (void)_updateVisibleContentRects 1888 1929 { … … 1936 1977 1937 1978 CGFloat scaleFactor = contentZoomScale(self); 1938 1939 1979 CGRect unobscuredRect = UIEdgeInsetsInsetRect(self.bounds, computedContentInsetUnadjustedForKeyboard); 1940 1980 CGRect unobscuredRectInContentCoordinates = _frozenUnobscuredContentRect ? _frozenUnobscuredContentRect.value() : [self convertRect:unobscuredRect toView:_contentView.get()]; 1941 1981 unobscuredRectInContentCoordinates = CGRectIntersection(unobscuredRectInContentCoordinates, [self _contentBoundsExtendedForRubberbandingWithScale:scaleFactor]); 1942 1982 1943 // The following logic computes the extent to which the bottom, top, left and right content insets are visible. 1944 auto scrollViewInsets = [_scrollView contentInset]; 1945 auto scrollViewBounds = [_scrollView bounds]; 1946 auto scrollViewContentSize = [_scrollView contentSize]; 1947 auto scrollViewOriginIncludingInset = UIEdgeInsetsInsetRect(scrollViewBounds, computedContentInsetUnadjustedForKeyboard).origin; 1948 auto maximumVerticalScrollExtentWithoutRevealingBottomContentInset = scrollViewContentSize.height - CGRectGetHeight(scrollViewBounds); 1949 auto maximumHorizontalScrollExtentWithoutRevealingRightContentInset = scrollViewContentSize.width - CGRectGetWidth(scrollViewBounds); 1950 auto contentInsets = UIEdgeInsetsZero; 1951 if (scrollViewInsets.left > 0 && scrollViewOriginIncludingInset.x < 0) 1952 contentInsets.left = std::min(-scrollViewOriginIncludingInset.x, scrollViewInsets.left) / scaleFactor; 1953 1954 if (scrollViewInsets.top > 0 && scrollViewOriginIncludingInset.y < 0) 1955 contentInsets.top = std::min(-scrollViewOriginIncludingInset.y, scrollViewInsets.top) / scaleFactor; 1956 1957 if (scrollViewInsets.right > 0 && scrollViewOriginIncludingInset.x > maximumHorizontalScrollExtentWithoutRevealingRightContentInset) 1958 contentInsets.right = std::min(scrollViewOriginIncludingInset.x - maximumHorizontalScrollExtentWithoutRevealingRightContentInset, scrollViewInsets.right) / scaleFactor; 1959 1960 if (scrollViewInsets.bottom > 0 && scrollViewOriginIncludingInset.y > maximumVerticalScrollExtentWithoutRevealingBottomContentInset) 1961 contentInsets.bottom = std::min(scrollViewOriginIncludingInset.y - maximumVerticalScrollExtentWithoutRevealingBottomContentInset, scrollViewInsets.bottom) / scaleFactor; 1983 auto contentInsets = [self currentlyVisibleContentInsetsWithScale:scaleFactor obscuredInsets:computedContentInsetUnadjustedForKeyboard]; 1962 1984 1963 1985 #if ENABLE(CSS_SCROLL_SNAP) && ENABLE(ASYNC_SCROLLING)
Note: See TracChangeset
for help on using the changeset viewer.