<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[170515] trunk/Source/WebKit2</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/170515">170515</a></dd>
<dt>Author</dt> <dd>timothy_horton@apple.com</dd>
<dt>Date</dt> <dd>2014-06-26 19:11:00 -0700 (Thu, 26 Jun 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>[iOS][WK2] Implement WKPDFView smart magnification
https://bugs.webkit.org/show_bug.cgi?id=134269
<rdar://problem/17272825>
Reviewed by Dan Bernstein.
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _currentContentView]):
(contentZoomScale):
Factor _currentContentView out of contentZoomScale.
(-[WKWebView _zoomToRect:WebCore::atScale:origin:WebCore::]):
(-[WKWebView _scrollToRect:WebCore::origin:WebCore::minimumScrollDistance:]):
(-[WKWebView _contentRectForUserInteraction]):
Use it in a bunch more places so we query the right view when zooming/scrolling for smart magnification.
* UIProcess/ios/WKPDFView.h:
* UIProcess/ios/WKPDFView.mm:
(-[WKPDFView scrollViewDidScroll:]):
(-[WKPDFView _revalidateViews]):
(-[WKPDFView zoom:to:atPoint:kind:]):
(-[WKPDFView resetZoom:]):
Implement zoom:to:atPoint:kind: and resetZoom: UIPDFPageViewDelegate methods.
Convert the rects/points and forward them on to the WKWebView to do the zoom.
resetZoom: doesn't provide the gesture origin, so we zoom out using the view center as our origin.
Avoid parenting new UIPDFPageViews while starting a zoom; they'll end up with a bizarre
animation on them and go flying across the screen (even before _isAnimatingZoom is set).</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPICocoaWKWebViewmm">trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm</a></li>
<li><a href="#trunkSourceWebKit2UIProcessiosWKPDFViewh">trunk/Source/WebKit2/UIProcess/ios/WKPDFView.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessiosWKPDFViewmm">trunk/Source/WebKit2/UIProcess/ios/WKPDFView.mm</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (170514 => 170515)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2014-06-27 02:05:15 UTC (rev 170514)
+++ trunk/Source/WebKit2/ChangeLog        2014-06-27 02:11:00 UTC (rev 170515)
</span><span class="lines">@@ -1,3 +1,33 @@
</span><ins>+2014-06-26 Timothy Horton <timothy_horton@apple.com>
+
+ [iOS][WK2] Implement WKPDFView smart magnification
+ https://bugs.webkit.org/show_bug.cgi?id=134269
+ <rdar://problem/17272825>
+
+ Reviewed by Dan Bernstein.
+
+ * UIProcess/API/Cocoa/WKWebView.mm:
+ (-[WKWebView _currentContentView]):
+ (contentZoomScale):
+ Factor _currentContentView out of contentZoomScale.
+
+ (-[WKWebView _zoomToRect:WebCore::atScale:origin:WebCore::]):
+ (-[WKWebView _scrollToRect:WebCore::origin:WebCore::minimumScrollDistance:]):
+ (-[WKWebView _contentRectForUserInteraction]):
+ Use it in a bunch more places so we query the right view when zooming/scrolling for smart magnification.
+
+ * UIProcess/ios/WKPDFView.h:
+ * UIProcess/ios/WKPDFView.mm:
+ (-[WKPDFView scrollViewDidScroll:]):
+ (-[WKPDFView _revalidateViews]):
+ (-[WKPDFView zoom:to:atPoint:kind:]):
+ (-[WKPDFView resetZoom:]):
+ Implement zoom:to:atPoint:kind: and resetZoom: UIPDFPageViewDelegate methods.
+ Convert the rects/points and forward them on to the WKWebView to do the zoom.
+ resetZoom: doesn't provide the gesture origin, so we zoom out using the view center as our origin.
+ Avoid parenting new UIPDFPageViews while starting a zoom; they'll end up with a bizarre
+ animation on them and go flying across the screen (even before _isAnimatingZoom is set).
+
</ins><span class="cx"> 2014-06-26 Tim Horton <timothy_horton@apple.com>
</span><span class="cx">
</span><span class="cx"> [WK2] Pinch-zoom shadows can overlap headers and footers
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPICocoaWKWebViewmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm (170514 => 170515)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm        2014-06-27 02:05:15 UTC (rev 170514)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm        2014-06-27 02:11:00 UTC (rev 170515)
</span><span class="lines">@@ -582,6 +582,11 @@
</span><span class="cx"> return CGSizeMake(floorToDevicePixel(contentSize.width, deviceScaleFactor), floorToDevicePixel(contentSize.height, deviceScaleFactor));
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+- (UIView *)_currentContentView
+{
+ return _customContentView ? _customContentView.get() : _contentView.get();
+}
+
</ins><span class="cx"> - (void)_setHasCustomContentView:(BOOL)pageHasCustomContentView loadedMIMEType:(const WTF::String&)mimeType
</span><span class="cx"> {
</span><span class="cx"> if (pageHasCustomContentView) {
</span><span class="lines">@@ -642,13 +647,7 @@
</span><span class="cx">
</span><span class="cx"> static CGFloat contentZoomScale(WKWebView* webView)
</span><span class="cx"> {
</span><del>- UIView *zoomView;
- if (webView->_customContentView)
- zoomView = webView->_customContentView.get();
- else
- zoomView = webView->_contentView.get();
-
- CGFloat scale = [[zoomView layer] affineTransform].a;
</del><ins>+ CGFloat scale = [[webView._currentContentView layer] affineTransform].a;
</ins><span class="cx"> ASSERT(scale == [webView->_scrollView zoomScale]);
</span><span class="cx"> return scale;
</span><span class="cx"> }
</span><span class="lines">@@ -916,7 +915,7 @@
</span><span class="cx"> {
</span><span class="cx"> // FIMXE: Some of this could be shared with _scrollToRect.
</span><span class="cx"> const double visibleRectScaleChange = contentZoomScale(self) / scale;
</span><del>- const WebCore::FloatRect visibleRect([self convertRect:self.bounds toView:_contentView.get()]);
</del><ins>+ const WebCore::FloatRect visibleRect([self convertRect:self.bounds toView:self._currentContentView]);
</ins><span class="cx"> const WebCore::FloatRect unobscuredRect([self _contentRectForUserInteraction]);
</span><span class="cx">
</span><span class="cx"> const WebCore::FloatSize topLeftObscuredInsetAfterZoom((unobscuredRect.minXMinYCorner() - visibleRect.minXMinYCorner()) * visibleRectScaleChange);
</span><span class="lines">@@ -967,7 +966,7 @@
</span><span class="cx"> {
</span><span class="cx"> WebCore::FloatRect unobscuredContentRect([self _contentRectForUserInteraction]);
</span><span class="cx"> WebCore::FloatPoint unobscuredContentOffset = unobscuredContentRect.location();
</span><del>- WebCore::FloatSize contentSize([_contentView bounds].size);
</del><ins>+ WebCore::FloatSize contentSize([self._currentContentView bounds].size);
</ins><span class="cx">
</span><span class="cx"> // Center the target rect in the scroll view.
</span><span class="cx"> // If the target doesn't fit in the scroll view, center on the gesture location instead.
</span><span class="lines">@@ -1279,7 +1278,7 @@
</span><span class="cx"> UIEdgeInsets obscuredInsets = _obscuredInsets;
</span><span class="cx"> obscuredInsets.bottom = std::max(_obscuredInsets.bottom, _inputViewBounds.size.height);
</span><span class="cx"> CGRect unobscuredRect = UIEdgeInsetsInsetRect(self.bounds, obscuredInsets);
</span><del>- return [self convertRect:unobscuredRect toView:_contentView.get()];
</del><ins>+ return [self convertRect:unobscuredRect toView:self._currentContentView];
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> - (void)_updateVisibleContentRects
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessiosWKPDFViewh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/ios/WKPDFView.h (170514 => 170515)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/ios/WKPDFView.h        2014-06-27 02:05:15 UTC (rev 170514)
+++ trunk/Source/WebKit2/UIProcess/ios/WKPDFView.h        2014-06-27 02:11:00 UTC (rev 170515)
</span><span class="lines">@@ -26,9 +26,10 @@
</span><span class="cx"> #if PLATFORM(IOS)
</span><span class="cx">
</span><span class="cx"> #import "WKWebViewContentProvider.h"
</span><ins>+#import <CorePDF/UIPDFPageView.h>
</ins><span class="cx"> #import <UIKit/UIView.h>
</span><span class="cx">
</span><del>-@interface WKPDFView : UIView <WKWebViewContentProvider>
</del><ins>+@interface WKPDFView : UIView <WKWebViewContentProvider, UIPDFPageViewDelegate>
</ins><span class="cx">
</span><span class="cx"> @property (nonatomic, readonly) NSString *suggestedFilename;
</span><span class="cx"> @property (nonatomic, readonly) CGPDFDocumentRef pdfDocument;
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessiosWKPDFViewmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/ios/WKPDFView.mm (170514 => 170515)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/ios/WKPDFView.mm        2014-06-27 02:05:15 UTC (rev 170514)
+++ trunk/Source/WebKit2/UIProcess/ios/WKPDFView.mm        2014-06-27 02:11:00 UTC (rev 170515)
</span><span class="lines">@@ -33,6 +33,7 @@
</span><span class="cx"> #import <CorePDF/UIPDFDocument.h>
</span><span class="cx"> #import <CorePDF/UIPDFPage.h>
</span><span class="cx"> #import <CorePDF/UIPDFPageView.h>
</span><ins>+#import <UIKit/UIScrollView_Private.h>
</ins><span class="cx"> #import <WebCore/FloatRect.h>
</span><span class="cx"> #import <wtf/RetainPtr.h>
</span><span class="cx"> #import <wtf/Vector.h>
</span><span class="lines">@@ -45,6 +46,8 @@
</span><span class="cx">
</span><span class="cx"> const float overdrawHeightMultiplier = 1.5;
</span><span class="cx">
</span><ins>+static const CGFloat smartMagnificationElementPadding = 0.05;
+
</ins><span class="cx"> typedef struct {
</span><span class="cx"> CGRect frame;
</span><span class="cx"> RetainPtr<UIPDFPageView> view;
</span><span class="lines">@@ -64,6 +67,8 @@
</span><span class="cx"> WKWebView *_webView;
</span><span class="cx"> UIScrollView *_scrollView;
</span><span class="cx"> UIView *_fixedOverlayView;
</span><ins>+
+ BOOL _isStartingZoom;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> - (instancetype)web_initWithFrame:(CGRect)frame webView:(WKWebView *)webView
</span><span class="lines">@@ -85,6 +90,7 @@
</span><span class="cx">
</span><span class="cx"> - (void)dealloc
</span><span class="cx"> {
</span><ins>+ [self _clearPages];
</ins><span class="cx"> [_pageNumberIndicator removeFromSuperview];
</span><span class="cx"> [super dealloc];
</span><span class="cx"> }
</span><span class="lines">@@ -99,15 +105,22 @@
</span><span class="cx"> return [_pdfDocument CGDocument];
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+- (void)_clearPages
+{
+ for (auto& page : _pages) {
+ [page.view removeFromSuperview];
+ [page.view setDelegate:nil];
+ }
+
+ _pages.clear();
+}
+
</ins><span class="cx"> - (void)web_setContentProviderData:(NSData *)data suggestedFilename:(NSString *)filename
</span><span class="cx"> {
</span><span class="cx"> _suggestedFilename = adoptNS([filename copy]);
</span><span class="cx">
</span><del>- for (auto& page : _pages)
- [page.view removeFromSuperview];
</del><ins>+ [self _clearPages];
</ins><span class="cx">
</span><del>- _pages.clear();
-
</del><span class="cx"> RetainPtr<CGDataProvider> dataProvider = adoptCF(CGDataProviderCreateWithCFData((CFDataRef)data));
</span><span class="cx"> RetainPtr<CGPDFDocumentRef> cgPDFDocument = adoptCF(CGPDFDocumentCreateWithProvider(dataProvider.get()));
</span><span class="cx"> _pdfDocument = adoptNS([[UIPDFDocument alloc] initWithCGPDFDocument:cgPDFDocument.get()]);
</span><span class="lines">@@ -126,7 +139,7 @@
</span><span class="cx">
</span><span class="cx"> - (void)scrollViewDidScroll:(UIScrollView *)scrollView
</span><span class="cx"> {
</span><del>- if (scrollView.isZoomBouncing)
</del><ins>+ if (scrollView.isZoomBouncing || scrollView._isAnimatingZoom)
</ins><span class="cx"> return;
</span><span class="cx">
</span><span class="cx"> [self _revalidateViews];
</span><span class="lines">@@ -135,6 +148,9 @@
</span><span class="cx">
</span><span class="cx"> - (void)_revalidateViews
</span><span class="cx"> {
</span><ins>+ if (_isStartingZoom)
+ return;
+
</ins><span class="cx"> CGRect targetRect = [_scrollView convertRect:_scrollView.bounds toView:self];
</span><span class="cx">
</span><span class="cx"> // We apply overdraw after applying scale in order to avoid excessive
</span><span class="lines">@@ -162,6 +178,7 @@
</span><span class="cx">
</span><span class="cx"> pageInfo.view = adoptNS([[UIPDFPageView alloc] initWithPage:pageInfo.page.get() tiledContent:YES]);
</span><span class="cx"> [pageInfo.view setUseBackingLayer:YES];
</span><ins>+ [pageInfo.view setDelegate:self];
</ins><span class="cx"> [self addSubview:pageInfo.view.get()];
</span><span class="cx">
</span><span class="cx"> [pageInfo.view setFrame:pageInfo.frame];
</span><span class="lines">@@ -211,11 +228,9 @@
</span><span class="cx"> {
</span><span class="cx"> NSUInteger pageCount = [_pdfDocument numberOfPages];
</span><span class="cx"> [_pageNumberIndicator setPageCount:pageCount];
</span><ins>+
+ [self _clearPages];
</ins><span class="cx">
</span><del>- for (auto& pageInfo : _pages)
- [pageInfo.view removeFromSuperview];
-
- _pages.clear();
</del><span class="cx"> _pages.reserveCapacity(pageCount);
</span><span class="cx">
</span><span class="cx"> CGRect pageFrame = CGRectMake(0, 0, _minimumSize.width, _minimumSize.height);
</span><span class="lines">@@ -244,6 +259,35 @@
</span><span class="cx"> [_scrollView setContentSize:newFrame.size];
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+
+- (void)zoom:(UIPDFPageView *)pageView to:(CGRect)targetRect atPoint:(CGPoint)origin kind:(UIPDFObjectKind)kind
+{
+ _isStartingZoom = YES;
+
+ BOOL isImage = kind == kUIPDFObjectKindGraphic;
+
+ if (!isImage)
+ targetRect = CGRectInset(targetRect, smartMagnificationElementPadding * targetRect.size.width, smartMagnificationElementPadding * targetRect.size.height);
+
+ CGRect rectInDocumentCoordinates = [pageView convertRect:targetRect toView:self];
+ CGPoint originInDocumentCoordinates = [pageView convertPoint:origin toView:self];
+
+ [_webView _zoomToRect:rectInDocumentCoordinates withOrigin:originInDocumentCoordinates fitEntireRect:isImage minimumScale:pdfMinimumZoomScale maximumScale:pdfMaximumZoomScale minimumScrollDistance:0];
+
+ _isStartingZoom = NO;
+}
+
+- (void)resetZoom:(UIPDFPageView *)pageView
+{
+ _isStartingZoom = YES;
+
+ CGRect scrollViewBounds = _scrollView.bounds;
+ CGPoint centerOfPageInDocumentCoordinates = [_scrollView convertPoint:CGPointMake(CGRectGetMidX(scrollViewBounds), CGRectGetMidY(scrollViewBounds)) toView:self];
+ [_webView _zoomOutWithOrigin:centerOfPageInDocumentCoordinates];
+
+ _isStartingZoom = NO;
+}
+
</ins><span class="cx"> @end
</span><span class="cx">
</span><span class="cx"> #endif /* PLATFORM(IOS) */
</span></span></pre>
</div>
</div>
</body>
</html>