Changeset 168560 in webkit


Ignore:
Timestamp:
May 9, 2014 5:11:26 PM (10 years ago)
Author:
Simon Fraser
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.

Location:
trunk/Source/WebKit2
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r168559 r168560  
     12014-05-09  Simon Fraser  <simon.fraser@apple.com>
     2
     3        [iOS WK2] Fixed elements can go outside the document on pinching
     4        https://bugs.webkit.org/show_bug.cgi?id=132759
     5        <rdar://problem/16870835>
     6
     7        Reviewed by Benjamin Poulain.
     8       
     9        Constrain the rect used to position fixed position objects when pinching (when
     10        the scale goes below the minimumScale). Do so in such a way that there's a smooth
     11        transition between rubber-banding and pinching.
     12
     13        * UIProcess/API/Cocoa/WKWebView.mm:
     14        (-[WKWebView _updateScrollViewBackground]): Use a nicer form for std::max<>.
     15        (-[WKWebView _updateVisibleContentRects]): Pass the minimum scale.
     16        * UIProcess/API/ios/WKViewIOS.mm:
     17        (-[WKView _updateVisibleContentRects]): Ditto.
     18        * UIProcess/ios/WKContentView.h:
     19        * UIProcess/ios/WKContentView.mm:
     20        (adjustedUnexposedEdge): Helper to adjust the left/top.
     21        (adjustedUnexposedMaxEdge): Helper to adjust the right/bottom.
     22        (fixedPositionRectFromExposedRect):
     23        (-[WKContentView didUpdateVisibleRect:unobscuredRect:scale:minimumScale:inStableState:]):
     24        (-[WKContentView didUpdateVisibleRect:unobscuredRect:scale:inStableState:]): Deleted.
     25
    1262014-05-09  Zalan Bujtas  <zalan@apple.com>
    227
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm

    r168556 r168560  
    448448    if (zoomScale < minimumZoomScale) {
    449449        CGFloat slope = 12;
    450         CGFloat opacity = std::max(1 - slope * (minimumZoomScale - zoomScale), static_cast<CGFloat>(0));
     450        CGFloat opacity = std::max<CGFloat>(1 - slope * (minimumZoomScale - zoomScale), 0);
    451451        cgColor = adoptCF(CGColorCreateCopyWithAlpha(cgColor.get(), opacity));
    452452    }
     
    780780
    781781    BOOL isStableState = !(_isChangingObscuredInsetsInteractively || [_scrollView isDragging] || [_scrollView isDecelerating] || [_scrollView isZooming] || [_scrollView isZoomBouncing] || [_scrollView _isAnimatingZoom]);
    782     [_contentView didUpdateVisibleRect:visibleRectInContentCoordinates unobscuredRect:unobscuredRectInContentCoordinates unobscuredRectInScrollViewCoordinates:unobscuredRect scale:scaleFactor inStableState:isStableState isChangingObscuredInsetsInteractively:_isChangingObscuredInsetsInteractively];
     782    [_contentView didUpdateVisibleRect:visibleRectInContentCoordinates
     783        unobscuredRect:unobscuredRectInContentCoordinates
     784        unobscuredRectInScrollViewCoordinates:unobscuredRect
     785        scale:scaleFactor minimumScale:[_scrollView minimumZoomScale]
     786        inStableState:isStableState isChangingObscuredInsetsInteractively:_isChangingObscuredInsetsInteractively];
    783787}
    784788
  • trunk/Source/WebKit2/UIProcess/API/ios/WKViewIOS.mm

    r168556 r168560  
    262262    CGRect unobscuredRectInContentCoordinates = [self convertRect:unobscuredRect toView:_contentView.get()];
    263263
    264     CGFloat scaleFactor = [_scrollView zoomScale];
    265 
    266     [_contentView didUpdateVisibleRect:visibleRectInContentCoordinates unobscuredRect:unobscuredRectInContentCoordinates unobscuredRectInScrollViewCoordinates:unobscuredRect scale:scaleFactor inStableState:YES isChangingObscuredInsetsInteractively:NO];
     264    [_contentView didUpdateVisibleRect:visibleRectInContentCoordinates
     265        unobscuredRect:unobscuredRectInContentCoordinates
     266        unobscuredRectInScrollViewCoordinates:unobscuredRect
     267        scale:[_scrollView zoomScale] minimumScale:[_scrollView minimumZoomScale]
     268        inStableState:YES isChangingObscuredInsetsInteractively:NO];
    267269}
    268270
  • trunk/Source/WebKit2/UIProcess/ios/WKContentView.h

    r168556 r168560  
    6161
    6262- (void)setMinimumSize:(CGSize)size;
    63 - (void)didUpdateVisibleRect:(CGRect)visibleRect unobscuredRect:(CGRect)unobscuredRect unobscuredRectInScrollViewCoordinates:(CGRect)unobscuredRectInScrollViewCoordinates scale:(CGFloat)scale inStableState:(BOOL)isStableState isChangingObscuredInsetsInteractively:(BOOL)isChangingObscuredInsetsInteractively;
     63- (void)didUpdateVisibleRect:(CGRect)visibleRect unobscuredRect:(CGRect)unobscuredRect
     64    unobscuredRectInScrollViewCoordinates:(CGRect)unobscuredRectInScrollViewCoordinates
     65    scale:(CGFloat)scale minimumScale:(CGFloat)minimumScale
     66    inStableState:(BOOL)isStableState isChangingObscuredInsetsInteractively:(BOOL)isChangingObscuredInsetsInteractively;
    6467
    6568- (void)didFinishScrolling;
  • trunk/Source/WebKit2/UIProcess/ios/WKContentView.mm

    r168556 r168560  
    293293}
    294294
    295 static inline FloatRect fixedPositionRectFromExposedRect(CGRect unobscuredRect, CGSize documentSize, CGFloat scale)
    296 {
    297     return FrameView::rectForViewportConstrainedObjects(enclosingLayoutRect(unobscuredRect), roundedLayoutSize(FloatSize(documentSize)), scale, false, StickToViewportBounds);
    298 }
    299 
    300 - (void)didUpdateVisibleRect:(CGRect)visibleRect unobscuredRect:(CGRect)unobscuredRect unobscuredRectInScrollViewCoordinates:(CGRect)unobscuredRectInScrollViewCoordinates scale:(CGFloat)zoomScale inStableState:(BOOL)isStableState isChangingObscuredInsetsInteractively:(BOOL)isChangingObscuredInsetsInteractively
     295static inline float adjustedUnexposedEdge(float documentEdge, float exposedRectEdge, float factor)
     296{
     297    if (exposedRectEdge < documentEdge)
     298        return documentEdge - factor * (documentEdge - exposedRectEdge);
     299   
     300    return exposedRectEdge;
     301}
     302
     303static inline float adjustedUnexposedMaxEdge(float documentEdge, float exposedRectEdge, float factor)
     304{
     305    if (exposedRectEdge > documentEdge)
     306        return documentEdge + factor * (exposedRectEdge - documentEdge);
     307   
     308    return exposedRectEdge;
     309}
     310
     311static inline FloatRect fixedPositionRectFromExposedRect(CGRect unobscuredRect, CGSize documentSize, CGFloat scale, CGFloat minimumScale)
     312{
     313    FloatRect constrainedUnobscuredRect = unobscuredRect;
     314    FloatRect documentRect = FloatRect(FloatPoint(), FloatSize(documentSize));
     315   
     316    if (scale < minimumScale) {
     317        const CGFloat slope = 12;
     318        CGFloat factor = std::max<CGFloat>(1 - slope * (minimumScale - scale), 0);
     319           
     320        constrainedUnobscuredRect.setX(adjustedUnexposedEdge(documentRect.x(), constrainedUnobscuredRect.x(), factor));
     321        constrainedUnobscuredRect.setY(adjustedUnexposedEdge(documentRect.y(), constrainedUnobscuredRect.y(), factor));
     322        constrainedUnobscuredRect.setWidth(adjustedUnexposedMaxEdge(documentRect.maxX(), constrainedUnobscuredRect.maxX(), factor) - constrainedUnobscuredRect.x());
     323        constrainedUnobscuredRect.setHeight(adjustedUnexposedMaxEdge(documentRect.maxY(), constrainedUnobscuredRect.maxY(), factor) - constrainedUnobscuredRect.y());
     324    }
     325   
     326    return FrameView::rectForViewportConstrainedObjects(enclosingLayoutRect(constrainedUnobscuredRect), roundedLayoutSize(FloatSize(documentSize)), scale, false, StickToViewportBounds);
     327}
     328
     329- (void)didUpdateVisibleRect:(CGRect)visibleRect unobscuredRect:(CGRect)unobscuredRect unobscuredRectInScrollViewCoordinates:(CGRect)unobscuredRectInScrollViewCoordinates
     330    scale:(CGFloat)zoomScale minimumScale:(CGFloat)minimumScale inStableState:(BOOL)isStableState isChangingObscuredInsetsInteractively:(BOOL)isChangingObscuredInsetsInteractively
    301331{
    302332    double timestamp = monotonicallyIncreasingTime();
     
    315345    }
    316346
    317     FloatRect customFixedPositionRect = fixedPositionRectFromExposedRect(unobscuredRect, [self bounds].size, zoomScale);
     347    FloatRect customFixedPositionRect = fixedPositionRectFromExposedRect(unobscuredRect, [self bounds].size, zoomScale, minimumScale);
    318348    _page->updateVisibleContentRects(VisibleContentRectUpdateInfo(_page->nextVisibleContentRectUpdateID(), visibleRect, unobscuredRect, unobscuredRectInScrollViewCoordinates, customFixedPositionRect, filteredScale, isStableState, isChangingObscuredInsetsInteractively, timestamp, velocityData.horizontalVelocity, velocityData.verticalVelocity, velocityData.scaleChangeRate));
    319349   
    320350    RemoteScrollingCoordinatorProxy* scrollingCoordinator = _page->scrollingCoordinatorProxy();
    321     scrollingCoordinator->viewportChangedViaDelegatedScrolling(scrollingCoordinator->rootScrollingNodeID(), unobscuredRect, zoomScale);
     351    scrollingCoordinator->viewportChangedViaDelegatedScrolling(scrollingCoordinator->rootScrollingNodeID(), customFixedPositionRect, zoomScale);
    322352
    323353    if (auto drawingArea = _page->drawingArea())
Note: See TracChangeset for help on using the changeset viewer.