Title: [168560] trunk/Source/WebKit2
Revision
168560
Author
simon.fra...@apple.com
Date
2014-05-09 17:11:26 -0700 (Fri, 09 May 2014)

Log Message

[iOS WK2] Fixed elements can go outside the document on pinching
https://bugs.webkit.org/show_bug.cgi?id=132759
<rdar://problem/16870835>

Reviewed by Benjamin Poulain.

Constrain the rect used to position fixed position objects when pinching (when
the scale goes below the minimumScale). Do so in such a way that there's a smooth
transition between rubber-banding and pinching.

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _updateScrollViewBackground]): Use a nicer form for std::max<>.
(-[WKWebView _updateVisibleContentRects]): Pass the minimum scale.
* UIProcess/API/ios/WKViewIOS.mm:
(-[WKView _updateVisibleContentRects]): Ditto.
* UIProcess/ios/WKContentView.h:
* UIProcess/ios/WKContentView.mm:
(adjustedUnexposedEdge): Helper to adjust the left/top.
(adjustedUnexposedMaxEdge): Helper to adjust the right/bottom.
(fixedPositionRectFromExposedRect):
(-[WKContentView didUpdateVisibleRect:unobscuredRect:scale:minimumScale:inStableState:]):
(-[WKContentView didUpdateVisibleRect:unobscuredRect:scale:inStableState:]): Deleted.

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (168559 => 168560)


--- trunk/Source/WebKit2/ChangeLog	2014-05-10 00:08:28 UTC (rev 168559)
+++ trunk/Source/WebKit2/ChangeLog	2014-05-10 00:11:26 UTC (rev 168560)
@@ -1,3 +1,28 @@
+2014-05-09  Simon Fraser  <simon.fra...@apple.com>
+
+        [iOS WK2] Fixed elements can go outside the document on pinching
+        https://bugs.webkit.org/show_bug.cgi?id=132759
+        <rdar://problem/16870835>
+
+        Reviewed by Benjamin Poulain.
+        
+        Constrain the rect used to position fixed position objects when pinching (when
+        the scale goes below the minimumScale). Do so in such a way that there's a smooth
+        transition between rubber-banding and pinching.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _updateScrollViewBackground]): Use a nicer form for std::max<>.
+        (-[WKWebView _updateVisibleContentRects]): Pass the minimum scale.
+        * UIProcess/API/ios/WKViewIOS.mm:
+        (-[WKView _updateVisibleContentRects]): Ditto.
+        * UIProcess/ios/WKContentView.h:
+        * UIProcess/ios/WKContentView.mm:
+        (adjustedUnexposedEdge): Helper to adjust the left/top.
+        (adjustedUnexposedMaxEdge): Helper to adjust the right/bottom.
+        (fixedPositionRectFromExposedRect):
+        (-[WKContentView didUpdateVisibleRect:unobscuredRect:scale:minimumScale:inStableState:]):
+        (-[WKContentView didUpdateVisibleRect:unobscuredRect:scale:inStableState:]): Deleted.
+
 2014-05-09  Zalan Bujtas  <za...@apple.com>
 
         Subpixel rendering[iOS]: Top bar on apple.com/support jiggles when the swoosh animates.

Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm (168559 => 168560)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm	2014-05-10 00:08:28 UTC (rev 168559)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm	2014-05-10 00:11:26 UTC (rev 168560)
@@ -447,7 +447,7 @@
     CGFloat minimumZoomScale = [_scrollView minimumZoomScale];
     if (zoomScale < minimumZoomScale) {
         CGFloat slope = 12;
-        CGFloat opacity = std::max(1 - slope * (minimumZoomScale - zoomScale), static_cast<CGFloat>(0));
+        CGFloat opacity = std::max<CGFloat>(1 - slope * (minimumZoomScale - zoomScale), 0);
         cgColor = adoptCF(CGColorCreateCopyWithAlpha(cgColor.get(), opacity));
     }
     RetainPtr<UIColor*> uiBackgroundColor = adoptNS([[UIColor alloc] initWithCGColor:cgColor.get()]);
@@ -779,7 +779,11 @@
     CGFloat scaleFactor = contentZoomScale(self);
 
     BOOL isStableState = !(_isChangingObscuredInsetsInteractively || [_scrollView isDragging] || [_scrollView isDecelerating] || [_scrollView isZooming] || [_scrollView isZoomBouncing] || [_scrollView _isAnimatingZoom]);
-    [_contentView didUpdateVisibleRect:visibleRectInContentCoordinates unobscuredRect:unobscuredRectInContentCoordinates unobscuredRectInScrollViewCoordinates:unobscuredRect scale:scaleFactor inStableState:isStableState isChangingObscuredInsetsInteractively:_isChangingObscuredInsetsInteractively];
+    [_contentView didUpdateVisibleRect:visibleRectInContentCoordinates
+        unobscuredRect:unobscuredRectInContentCoordinates
+        unobscuredRectInScrollViewCoordinates:unobscuredRect
+        scale:scaleFactor minimumScale:[_scrollView minimumZoomScale]
+        inStableState:isStableState isChangingObscuredInsetsInteractively:_isChangingObscuredInsetsInteractively];
 }
 
 - (void)_keyboardChangedWithInfo:(NSDictionary *)keyboardInfo adjustScrollView:(BOOL)adjustScrollView

Modified: trunk/Source/WebKit2/UIProcess/API/ios/WKViewIOS.mm (168559 => 168560)


--- trunk/Source/WebKit2/UIProcess/API/ios/WKViewIOS.mm	2014-05-10 00:08:28 UTC (rev 168559)
+++ trunk/Source/WebKit2/UIProcess/API/ios/WKViewIOS.mm	2014-05-10 00:11:26 UTC (rev 168560)
@@ -261,9 +261,11 @@
     CGRect unobscuredRect = UIEdgeInsetsInsetRect(fullViewRect, _obscuredInsets);
     CGRect unobscuredRectInContentCoordinates = [self convertRect:unobscuredRect toView:_contentView.get()];
 
-    CGFloat scaleFactor = [_scrollView zoomScale];
-
-    [_contentView didUpdateVisibleRect:visibleRectInContentCoordinates unobscuredRect:unobscuredRectInContentCoordinates unobscuredRectInScrollViewCoordinates:unobscuredRect scale:scaleFactor inStableState:YES isChangingObscuredInsetsInteractively:NO];
+    [_contentView didUpdateVisibleRect:visibleRectInContentCoordinates
+        unobscuredRect:unobscuredRectInContentCoordinates
+        unobscuredRectInScrollViewCoordinates:unobscuredRect
+        scale:[_scrollView zoomScale] minimumScale:[_scrollView minimumZoomScale]
+        inStableState:YES isChangingObscuredInsetsInteractively:NO];
 }
 
 - (void)_keyboardChangedWithInfo:(NSDictionary *)keyboardInfo adjustScrollView:(BOOL)adjustScrollView

Modified: trunk/Source/WebKit2/UIProcess/ios/WKContentView.h (168559 => 168560)


--- trunk/Source/WebKit2/UIProcess/ios/WKContentView.h	2014-05-10 00:08:28 UTC (rev 168559)
+++ trunk/Source/WebKit2/UIProcess/ios/WKContentView.h	2014-05-10 00:11:26 UTC (rev 168560)
@@ -60,7 +60,10 @@
 - (instancetype)initWithFrame:(CGRect)frame context:(WebKit::WebContext&)context configuration:(WebKit::WebPageConfiguration)webPageConfiguration webView:(WKWebView *)webView;
 
 - (void)setMinimumSize:(CGSize)size;
-- (void)didUpdateVisibleRect:(CGRect)visibleRect unobscuredRect:(CGRect)unobscuredRect unobscuredRectInScrollViewCoordinates:(CGRect)unobscuredRectInScrollViewCoordinates scale:(CGFloat)scale inStableState:(BOOL)isStableState isChangingObscuredInsetsInteractively:(BOOL)isChangingObscuredInsetsInteractively;
+- (void)didUpdateVisibleRect:(CGRect)visibleRect unobscuredRect:(CGRect)unobscuredRect
+    unobscuredRectInScrollViewCoordinates:(CGRect)unobscuredRectInScrollViewCoordinates
+    scale:(CGFloat)scale minimumScale:(CGFloat)minimumScale
+    inStableState:(BOOL)isStableState isChangingObscuredInsetsInteractively:(BOOL)isChangingObscuredInsetsInteractively;
 
 - (void)didFinishScrolling;
 - (void)didZoomToScale:(CGFloat)scale;

Modified: trunk/Source/WebKit2/UIProcess/ios/WKContentView.mm (168559 => 168560)


--- trunk/Source/WebKit2/UIProcess/ios/WKContentView.mm	2014-05-10 00:08:28 UTC (rev 168559)
+++ trunk/Source/WebKit2/UIProcess/ios/WKContentView.mm	2014-05-10 00:11:26 UTC (rev 168560)
@@ -292,13 +292,43 @@
     }
 }
 
-static inline FloatRect fixedPositionRectFromExposedRect(CGRect unobscuredRect, CGSize documentSize, CGFloat scale)
+static inline float adjustedUnexposedEdge(float documentEdge, float exposedRectEdge, float factor)
 {
-    return FrameView::rectForViewportConstrainedObjects(enclosingLayoutRect(unobscuredRect), roundedLayoutSize(FloatSize(documentSize)), scale, false, StickToViewportBounds);
+    if (exposedRectEdge < documentEdge)
+        return documentEdge - factor * (documentEdge - exposedRectEdge);
+    
+    return exposedRectEdge;
 }
 
-- (void)didUpdateVisibleRect:(CGRect)visibleRect unobscuredRect:(CGRect)unobscuredRect unobscuredRectInScrollViewCoordinates:(CGRect)unobscuredRectInScrollViewCoordinates scale:(CGFloat)zoomScale inStableState:(BOOL)isStableState isChangingObscuredInsetsInteractively:(BOOL)isChangingObscuredInsetsInteractively
+static inline float adjustedUnexposedMaxEdge(float documentEdge, float exposedRectEdge, float factor)
 {
+    if (exposedRectEdge > documentEdge)
+        return documentEdge + factor * (exposedRectEdge - documentEdge);
+    
+    return exposedRectEdge;
+}
+
+static inline FloatRect fixedPositionRectFromExposedRect(CGRect unobscuredRect, CGSize documentSize, CGFloat scale, CGFloat minimumScale)
+{
+    FloatRect constrainedUnobscuredRect = unobscuredRect;
+    FloatRect documentRect = FloatRect(FloatPoint(), FloatSize(documentSize));
+    
+    if (scale < minimumScale) {
+        const CGFloat slope = 12;
+        CGFloat factor = std::max<CGFloat>(1 - slope * (minimumScale - scale), 0);
+            
+        constrainedUnobscuredRect.setX(adjustedUnexposedEdge(documentRect.x(), constrainedUnobscuredRect.x(), factor));
+        constrainedUnobscuredRect.setY(adjustedUnexposedEdge(documentRect.y(), constrainedUnobscuredRect.y(), factor));
+        constrainedUnobscuredRect.setWidth(adjustedUnexposedMaxEdge(documentRect.maxX(), constrainedUnobscuredRect.maxX(), factor) - constrainedUnobscuredRect.x());
+        constrainedUnobscuredRect.setHeight(adjustedUnexposedMaxEdge(documentRect.maxY(), constrainedUnobscuredRect.maxY(), factor) - constrainedUnobscuredRect.y());
+    }
+    
+    return FrameView::rectForViewportConstrainedObjects(enclosingLayoutRect(constrainedUnobscuredRect), roundedLayoutSize(FloatSize(documentSize)), scale, false, StickToViewportBounds);
+}
+
+- (void)didUpdateVisibleRect:(CGRect)visibleRect unobscuredRect:(CGRect)unobscuredRect unobscuredRectInScrollViewCoordinates:(CGRect)unobscuredRectInScrollViewCoordinates
+    scale:(CGFloat)zoomScale minimumScale:(CGFloat)minimumScale inStableState:(BOOL)isStableState isChangingObscuredInsetsInteractively:(BOOL)isChangingObscuredInsetsInteractively
+{
     double timestamp = monotonicallyIncreasingTime();
     HistoricalVelocityData::VelocityData velocityData;
     if (!isStableState)
@@ -314,11 +344,11 @@
         filteredScale = _page->displayedContentScale();
     }
 
-    FloatRect customFixedPositionRect = fixedPositionRectFromExposedRect(unobscuredRect, [self bounds].size, zoomScale);
+    FloatRect customFixedPositionRect = fixedPositionRectFromExposedRect(unobscuredRect, [self bounds].size, zoomScale, minimumScale);
     _page->updateVisibleContentRects(VisibleContentRectUpdateInfo(_page->nextVisibleContentRectUpdateID(), visibleRect, unobscuredRect, unobscuredRectInScrollViewCoordinates, customFixedPositionRect, filteredScale, isStableState, isChangingObscuredInsetsInteractively, timestamp, velocityData.horizontalVelocity, velocityData.verticalVelocity, velocityData.scaleChangeRate));
     
     RemoteScrollingCoordinatorProxy* scrollingCoordinator = _page->scrollingCoordinatorProxy();
-    scrollingCoordinator->viewportChangedViaDelegatedScrolling(scrollingCoordinator->rootScrollingNodeID(), unobscuredRect, zoomScale);
+    scrollingCoordinator->viewportChangedViaDelegatedScrolling(scrollingCoordinator->rootScrollingNodeID(), customFixedPositionRect, zoomScale);
 
     if (auto drawingArea = _page->drawingArea())
         drawingArea->updateDebugIndicator();
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to