Changeset 170361 in webkit


Ignore:
Timestamp:
Jun 24, 2014 7:38:17 AM (10 years ago)
Author:
andersca@apple.com
Message:

WKWebView doesn't respect -[UIScrollView contentInset]
https://bugs.webkit.org/show_bug.cgi?id=134230
<rdar://problem/17429107>

Reviewed by Tim Horton.

  • UIProcess/API/Cocoa/WKWebView.mm:

(-[WKWebView _setHasCustomContentView:loadedMIMEType:WTF::]):
Call initWithFrame and pass the WKWebView along.

(-[WKWebView _adjustedContentOffset:]):
New helper method that takes a content offset as a CGPoint and offsets it by the computed content inset.

(-[WKWebView _computedContentInset]):
New helper method that returns the _obscuredInsets, or if it's zero, the scroll view's content inset.

(-[WKWebView _processDidExit]):
Use _computedContentInset.

(-[WKWebView _didCommitLayerTree:WebKit::]):
use _computedContentInset.

(-[WKWebView _dynamicViewportUpdateChangedTargetToScale:position:]):
Use _computedContentInset.

(-[WKWebView _scrollToContentOffset:WebCore::]):
Use _computedContentInset.

(-[WKWebView _updateVisibleContentRects]):
If we have a custom content view, call web_computedContentInsetDidChange.

(-[WKWebView _setObscuredInsets:]):
Don't call web_setObscuredInsets: if we have a custom content view.

  • UIProcess/API/Cocoa/WKWebViewInternal.h:

Add new methods.

  • UIProcess/Cocoa/WKWebViewContentProvider.h:

Add new methods.

  • UIProcess/ios/WKPDFView.mm:

(-[WKPDFView web_initWithFrame:webView:]):
Set the _webView and _scrollView ivars.

(-[WKPDFView _offsetForPageNumberIndicator]):
Get the computed content offset from the WKWebView.

(-[WKPDFView web_computedContentInsetDidChange]):
Update the page indicator.

(-[WKPDFView initWithFrame:]): Deleted.
(-[WKPDFView web_setObscuredInsets:]): Deleted.

  • UIProcess/ios/WKScrollView.mm:

(-[WKScrollView setContentInset:]):
Call _updateVisibleContentRects.

Location:
trunk/Source/WebKit2
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r170348 r170361  
     12014-06-24  Anders Carlsson  <andersca@apple.com>
     2
     3        WKWebView doesn't respect -[UIScrollView contentInset]
     4        https://bugs.webkit.org/show_bug.cgi?id=134230
     5        <rdar://problem/17429107>
     6
     7        Reviewed by Tim Horton.
     8
     9        * UIProcess/API/Cocoa/WKWebView.mm:
     10        (-[WKWebView _setHasCustomContentView:loadedMIMEType:WTF::]):
     11        Call initWithFrame and pass the WKWebView along.
     12
     13        (-[WKWebView _adjustedContentOffset:]):
     14        New helper method that takes a content offset as a CGPoint and offsets it by the computed content inset.
     15
     16        (-[WKWebView _computedContentInset]):
     17        New helper method that returns the _obscuredInsets, or if it's zero, the scroll view's content inset.
     18
     19        (-[WKWebView _processDidExit]):
     20        Use _computedContentInset.
     21
     22        (-[WKWebView _didCommitLayerTree:WebKit::]):
     23        use _computedContentInset.
     24
     25        (-[WKWebView _dynamicViewportUpdateChangedTargetToScale:position:]):
     26        Use _computedContentInset.
     27
     28        (-[WKWebView _scrollToContentOffset:WebCore::]):
     29        Use _computedContentInset.
     30
     31        (-[WKWebView _updateVisibleContentRects]):
     32        If we have a custom content view, call web_computedContentInsetDidChange.
     33
     34        (-[WKWebView _setObscuredInsets:]):
     35        Don't call web_setObscuredInsets: if we have a custom content view.
     36
     37        * UIProcess/API/Cocoa/WKWebViewInternal.h:
     38        Add new methods.
     39
     40        * UIProcess/Cocoa/WKWebViewContentProvider.h:
     41        Add new methods.
     42
     43        * UIProcess/ios/WKPDFView.mm:
     44        (-[WKPDFView web_initWithFrame:webView:]):
     45        Set the _webView and _scrollView ivars.
     46
     47        (-[WKPDFView _offsetForPageNumberIndicator]):
     48        Get the computed content offset from the WKWebView.
     49
     50        (-[WKPDFView web_computedContentInsetDidChange]):
     51        Update the page indicator.
     52       
     53        (-[WKPDFView initWithFrame:]): Deleted.
     54        (-[WKPDFView web_setObscuredInsets:]): Deleted.
     55
     56        * UIProcess/ios/WKScrollView.mm:
     57        (-[WKScrollView setContentInset:]):
     58        Call _updateVisibleContentRects.
     59
    1602014-06-23  Jaehun Lim  <ljaehun.lim@samsung.com>
    261
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm

    r170335 r170361  
    590590        Class representationClass = [[_configuration _contentProviderRegistry] providerForMIMEType:mimeType];
    591591        ASSERT(representationClass);
    592         _customContentView = adoptNS([[representationClass alloc] init]);
     592        _customContentView = adoptNS([[representationClass alloc] web_initWithFrame:self.bounds webView:self]);
    593593        _customContentFixedOverlayView = adoptNS([[UIView alloc] initWithFrame:self.bounds]);
    594594        [_customContentFixedOverlayView setUserInteractionEnabled:NO];
     
    599599
    600600        [_customContentView web_setMinimumSize:self.bounds.size];
    601         [_customContentView web_setScrollView:_scrollView.get()];
    602         [_customContentView web_setObscuredInsets:_obscuredInsets];
    603601        [_customContentView web_setFixedOverlayView:_customContentFixedOverlayView.get()];
    604602    } else if (_customContentView) {
     
    690688}
    691689
     690- (CGPoint)_adjustedContentOffset:(CGPoint)point
     691{
     692    CGPoint result = point;
     693    UIEdgeInsets contentInset = [self _computedContentInset];
     694
     695    result.x -= contentInset.left;
     696    result.y -= contentInset.top;
     697
     698    return result;
     699}
     700
     701- (UIEdgeInsets)_computedContentInset
     702{
     703    if (!UIEdgeInsetsEqualToEdgeInsets(_obscuredInsets, UIEdgeInsetsZero))
     704        return _obscuredInsets;
     705
     706    return [_scrollView contentInset];
     707}
     708
    692709- (void)_processDidExit
    693710{
     
    703720    [_contentView setFrame:self.bounds];
    704721    [_scrollView setBackgroundColor:[UIColor whiteColor]];
    705     [_scrollView setContentOffset:CGPointMake(-_obscuredInsets.left, -_obscuredInsets.top)];
     722    [_scrollView setContentOffset:[self _adjustedContentOffset:CGPointZero]];
    706723    [_scrollView setZoomScale:1];
    707724
     
    779796    if (_needsResetViewStateAfterCommitLoadForMainFrame && layerTreeTransaction.transactionID() >= _firstPaintAfterCommitLoadTransactionID) {
    780797        _needsResetViewStateAfterCommitLoadForMainFrame = NO;
    781         [_scrollView setContentOffset:CGPointMake(-_obscuredInsets.left, -_obscuredInsets.top)];
     798        [_scrollView setContentOffset:[self _adjustedContentOffset:CGPointZero]];
    782799        [self _updateVisibleContentRects];
    783800    }
     
    820837        _resizeAnimationTransformAdjustments = CATransform3DMakeScale(scale, scale, 0);
    821838
    822         CGPoint newContentOffset = CGPointMake(newScrollPosition.x * newScale, newScrollPosition.y * newScale);
    823         newContentOffset.x -= _obscuredInsets.left;
    824         newContentOffset.y -= _obscuredInsets.top;
     839        CGPoint newContentOffset = [self _adjustedContentOffset:CGPointMake(newScrollPosition.x * newScale, newScrollPosition.y * newScale)];
    825840        CGPoint currentContentOffset = [_scrollView contentOffset];
    826841
     
    943958    scaledOffset.scale(zoomScale, zoomScale);
    944959
    945     scaledOffset -= WebCore::FloatSize(_obscuredInsets.left, _obscuredInsets.top);
    946     [_scrollView setContentOffset:scaledOffset];
     960    [_scrollView setContentOffset:[self _adjustedContentOffset:scaledOffset]];
    947961}
    948962
     
    12681282- (void)_updateVisibleContentRects
    12691283{
    1270     if (![self usesStandardContentView])
    1271         return;
     1284    if (![self usesStandardContentView]) {
     1285        [_customContentView web_computedContentInsetDidChange];
     1286        return
     1287    }
    12721288
    12731289    if (_delayUpdateVisibleContentRects) {
     
    12851301    CGRect visibleRectInContentCoordinates = [self convertRect:fullViewRect toView:_contentView.get()];
    12861302
    1287     CGRect unobscuredRect = UIEdgeInsetsInsetRect(fullViewRect, _obscuredInsets);
     1303    CGRect unobscuredRect = UIEdgeInsetsInsetRect(fullViewRect, [self _computedContentInset]);
    12881304    CGRect unobscuredRectInContentCoordinates = [self convertRect:unobscuredRect toView:_contentView.get()];
    12891305
     
    19241940
    19251941    [self _updateVisibleContentRects];
    1926     [_customContentView web_setObscuredInsets:obscuredInsets];
    19271942}
    19281943
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewInternal.h

    r170325 r170361  
    8989- (void)_willInvokeUIScrollViewDelegateCallback;
    9090- (void)_didInvokeUIScrollViewDelegateCallback;
     91
     92- (void)_updateVisibleContentRects;
     93
     94@property (nonatomic, readonly) UIEdgeInsets _computedContentInset;
     95
    9196#endif
    9297@end
  • trunk/Source/WebKit2/UIProcess/Cocoa/WKWebViewContentProvider.h

    r169290 r170361  
    3333@class UIScrollView;
    3434@class UIView;
     35@class WKWebView;
    3536@protocol NSObject;
    3637@protocol UIScrollViewDelegate;
     
    4142@protocol WKWebViewContentProvider <NSObject, UIScrollViewDelegate>
    4243
     44- (instancetype)web_initWithFrame:(CGRect) frame webView:(WKWebView *)webView;
    4345- (void)web_setContentProviderData:(NSData *)data suggestedFilename:(NSString *)filename;
    4446- (void)web_setMinimumSize:(CGSize)size;
    45 - (void)web_setScrollView:(UIScrollView *)scrollView;
    46 - (void)web_setObscuredInsets:(UIEdgeInsets)insets;
    4747- (void)web_setOverlaidAccessoryViewsInset:(CGSize)inset;
     48- (void)web_computedContentInsetDidChange;
    4849- (void)web_setFixedOverlayView:(UIView *)fixedOverlayView;
    4950
  • trunk/Source/WebKit2/UIProcess/ios/WKPDFView.mm

    r169290 r170361  
    3030
    3131#import "WKPDFPageNumberIndicator.h"
     32#import "WKWebViewInternal.h"
    3233#import <CorePDF/UIPDFDocument.h>
     34#import <CorePDF/UIPDFPage.h>
    3335#import <CorePDF/UIPDFPageView.h>
    3436#import <WebCore/FloatRect.h>
     
    6163    CGSize _minimumSize;
    6264    CGSize _overlaidAccessoryViewsInset;
    63     UIEdgeInsets _obscuredInsets;
     65    WKWebView *_webView;
    6466    UIScrollView *_scrollView;
    6567    UIView *_fixedOverlayView;
    6668}
    6769
    68 - (instancetype)initWithFrame:(CGRect)frame
     70- (instancetype)web_initWithFrame:(CGRect)frame webView:(WKWebView *)webView
    6971{
    7072    if (!(self = [super initWithFrame:frame]))
     
    7274
    7375    self.backgroundColor = [UIColor grayColor];
     76
     77    _webView = webView;
     78
     79    _scrollView = webView.scrollView;
     80    [_scrollView setMinimumZoomScale:pdfMinimumZoomScale];
     81    [_scrollView setMaximumZoomScale:pdfMaximumZoomScale];
     82    [_scrollView setContentSize:_documentFrame.size];
     83    [_scrollView setBackgroundColor:[UIColor grayColor]];
    7484
    7585    return self;
     
    176186- (CGPoint)_offsetForPageNumberIndicator
    177187{
    178     return CGPointMake(_obscuredInsets.left, _obscuredInsets.top + _overlaidAccessoryViewsInset.height);
     188    UIEdgeInsets contentInset = [_webView _computedContentInset];
     189    return CGPointMake(contentInset.left, contentInset.top + _overlaidAccessoryViewsInset.height);
    179190}
    180191
     
    190201}
    191202
    192 - (void)web_setObscuredInsets:(UIEdgeInsets)insets
    193 {
    194     if (UIEdgeInsetsEqualToEdgeInsets(insets, _obscuredInsets))
    195         return;
    196 
    197     _obscuredInsets = insets;
    198 
    199     [self _updatePageNumberIndicator];
    200 }
    201 
    202203- (void)web_setOverlaidAccessoryViewsInset:(CGSize)inset
    203204{
    204205    _overlaidAccessoryViewsInset = inset;
    205206    [_pageNumberIndicator moveToPoint:[self _offsetForPageNumberIndicator] animated:YES];
     207}
     208
     209- (void)web_computedContentInsetDidChange
     210{
     211    [self _updatePageNumberIndicator];
    206212}
    207213
  • trunk/Source/WebKit2/UIProcess/ios/WKScrollView.mm

    r168747 r170361  
    192192}
    193193
     194- (void)setContentInset:(UIEdgeInsets)contentInset
     195{
     196    [super setContentInset:contentInset];
     197
     198    [_internalDelegate _updateVisibleContentRects];
     199}
     200
    194201@end
    195202
Note: See TracChangeset for help on using the changeset viewer.