<!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>[162886] 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/162886">162886</a></dd>
<dt>Author</dt> <dd>andersca@apple.com</dd>
<dt>Date</dt> <dd>2014-01-27 16:24:56 -0800 (Mon, 27 Jan 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>Copy relevant code from the iOS version of WKView to WKWebView
https://bugs.webkit.org/show_bug.cgi?id=127721
Reviewed by Dan Bernstein.
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView initWithFrame:configuration:]):
(-[WKWebView setFrame:]):
(-[WKWebView setBounds:]):
(-[WKWebView scrollView]):
(-[WKWebView browsingContextController]):
(-[WKWebView contentView:contentsSizeDidChange:]):
(-[WKWebView contentViewDidCommitLoadForMainFrame:]):
(-[WKWebView contentViewDidReceiveMobileDocType:]):
(-[WKWebView contentView:didChangeViewportArgumentsSize:initialScale:minimumScale:maximumScale:allowsUserScaling:]):
(-[WKWebView viewportHandlerDidChangeScales:]):
(-[WKWebView viewportHandler:didChangeViewportSize:]):
(-[WKWebView viewForZoomingInScrollView:]):
(-[WKWebView scrollViewWillBeginZooming:withView:]):
(-[WKWebView _didFinishScroll]):
(-[WKWebView scrollViewDidEndDragging:willDecelerate:]):
(-[WKWebView scrollViewDidEndDecelerating:]):
(-[WKWebView scrollViewDidScrollToTop:]):
(-[WKWebView scrollViewDidScroll:]):
(-[WKWebView scrollViewDidEndZooming:withView:atScale:]):
(-[WKWebView _frameOrBoundsChanged]):
(-[WKWebView _setDocumentScale:]):</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>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (162885 => 162886)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2014-01-28 00:20:58 UTC (rev 162885)
+++ trunk/Source/WebKit2/ChangeLog        2014-01-28 00:24:56 UTC (rev 162886)
</span><span class="lines">@@ -1,3 +1,33 @@
</span><ins>+2014-01-27 Anders Carlsson <andersca@apple.com>
+
+ Copy relevant code from the iOS version of WKView to WKWebView
+ https://bugs.webkit.org/show_bug.cgi?id=127721
+
+ Reviewed by Dan Bernstein.
+
+ * UIProcess/API/Cocoa/WKWebView.mm:
+ (-[WKWebView initWithFrame:configuration:]):
+ (-[WKWebView setFrame:]):
+ (-[WKWebView setBounds:]):
+ (-[WKWebView scrollView]):
+ (-[WKWebView browsingContextController]):
+ (-[WKWebView contentView:contentsSizeDidChange:]):
+ (-[WKWebView contentViewDidCommitLoadForMainFrame:]):
+ (-[WKWebView contentViewDidReceiveMobileDocType:]):
+ (-[WKWebView contentView:didChangeViewportArgumentsSize:initialScale:minimumScale:maximumScale:allowsUserScaling:]):
+ (-[WKWebView viewportHandlerDidChangeScales:]):
+ (-[WKWebView viewportHandler:didChangeViewportSize:]):
+ (-[WKWebView viewForZoomingInScrollView:]):
+ (-[WKWebView scrollViewWillBeginZooming:withView:]):
+ (-[WKWebView _didFinishScroll]):
+ (-[WKWebView scrollViewDidEndDragging:willDecelerate:]):
+ (-[WKWebView scrollViewDidEndDecelerating:]):
+ (-[WKWebView scrollViewDidScrollToTop:]):
+ (-[WKWebView scrollViewDidScroll:]):
+ (-[WKWebView scrollViewDidEndZooming:withView:atScale:]):
+ (-[WKWebView _frameOrBoundsChanged]):
+ (-[WKWebView _setDocumentScale:]):
+
</ins><span class="cx"> 2014-01-27 Tim Horton <timothy_horton@apple.com>
</span><span class="cx">
</span><span class="cx"> Revert the parts of r162629 that add a new pluginLoadPolicy and the context menu item.
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPICocoaWKWebViewmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm (162885 => 162886)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm        2014-01-28 00:20:58 UTC (rev 162885)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm        2014-01-28 00:24:56 UTC (rev 162886)
</span><span class="lines">@@ -28,11 +28,38 @@
</span><span class="cx">
</span><span class="cx"> #if WK_API_ENABLED
</span><span class="cx">
</span><ins>+#import "WKProcessClass.h"
</ins><span class="cx"> #import "WKWebViewConfiguration.h"
</span><ins>+#import "WebPageProxy.h"
</ins><span class="cx"> #import <wtf/RetainPtr.h>
</span><span class="cx">
</span><ins>+#if PLATFORM(IOS)
+#import "WKContentViewInternal.h"
+#import "WKScrollView.h"
+#import <UIKit/UIScrollView_Private.h>
+#import <UIKit/_UIWebViewportHandler.h>
+
+static const float minWebViewScale = 0.25;
+static const float maxWebViewScale = 5;
+static _UIWebViewportConfiguration standardViewportConfiguration = { { UIWebViewportStandardViewportWidth, UIWebViewportGrowsAndShrinksToFitHeight }, UIWebViewportScaleForScalesToFit, minWebViewScale, maxWebViewScale, true
+};
+
+@interface WKWebView () <UIScrollViewDelegate, WKContentViewDelegate, _UIWebViewportHandlerDelegate>
+@end
+#endif
+
</ins><span class="cx"> @implementation WKWebView {
</span><span class="cx"> RetainPtr<WKWebViewConfiguration> _configuration;
</span><ins>+ RefPtr<WebKit::WebPageProxy> _page;
+
+#if PLATFORM(IOS)
+ RetainPtr<WKScrollView> _scrollView;
+ RetainPtr<WKContentView> _contentView;
+ RetainPtr<_UIWebViewportHandler> _viewportHandler;
+
+ BOOL _userHasChangedPageScale;
+ BOOL _hasStaticMinimumLayoutSize;
+#endif
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> - (instancetype)initWithFrame:(CGRect)frame
</span><span class="lines">@@ -45,11 +72,34 @@
</span><span class="cx"> if (!(self = [super initWithFrame:frame]))
</span><span class="cx"> return nil;
</span><span class="cx">
</span><del>- // FIXME: Fill in nil properties with concrete properties.
</del><span class="cx"> _configuration = adoptNS([configuration copy]);
</span><span class="cx">
</span><del>- // FIXME: Initialize the WKWebView object.
</del><ins>+ if (![_configuration processClass])
+ [_configuration setProcessClass:adoptNS([[WKProcessClass alloc] init]).get()];
</ins><span class="cx">
</span><ins>+#if PLATFORM(IOS)
+ CGRect bounds = self.bounds;
+
+ _scrollView = adoptNS([[WKScrollView alloc] initWithFrame:bounds]);
+ [_scrollView setInternalDelegate:self];
+ [_scrollView setBouncesZoom:YES];
+
+ [self addSubview:_scrollView.get()];
+
+ _contentView = adoptNS([[WKContentView alloc] initWithFrame:bounds configuration:_configuration.get()]);
+ _page = _contentView->_page;
+ [_contentView setDelegate:self];
+ [_contentView layer].anchorPoint = CGPointZero;
+ [_contentView setFrame:bounds];
+ [_scrollView addSubview:_contentView.get()];
+
+ _viewportHandler = adoptNS([[_UIWebViewportHandler alloc] init]);
+ [_viewportHandler setDelegate:self];
+
+ [self _frameOrBoundsChanged];
+
+#endif
+
</ins><span class="cx"> return self;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -58,6 +108,187 @@
</span><span class="cx"> return [[_configuration copy] autorelease];
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+#pragma mark iOS-specific methods
+
+#if PLATFORM(IOS)
+- (void)setFrame:(CGRect)frame
+{
+ CGRect oldFrame = self.frame;
+ [super setFrame:frame];
+
+ if (!CGSizeEqualToSize(oldFrame.size, frame.size))
+ [self _frameOrBoundsChanged];
+}
+
+- (void)setBounds:(CGRect)bounds
+{
+ CGRect oldBounds = self.bounds;
+ [super setBounds:bounds];
+
+ if (!CGSizeEqualToSize(oldBounds.size, bounds.size))
+ [self _frameOrBoundsChanged];
+}
+
+- (UIScrollView *)scrollView
+{
+ return _scrollView.get();
+}
+
+- (WKBrowsingContextController *)browsingContextController
+{
+ return [_contentView browsingContextController];
+}
+
+#pragma mark WKContentViewDelegate
+
+- (void)contentView:(WKContentView *)contentView contentsSizeDidChange:(CGSize)newSize
+{
+ CGFloat zoomScale = [_scrollView zoomScale];
+ CGSize contentsSizeInScrollViewCoordinates = CGSizeMake(newSize.width * zoomScale, newSize.height * zoomScale);
+ [_scrollView setContentSize:contentsSizeInScrollViewCoordinates];
+
+ [_viewportHandler update:^{
+ [_viewportHandler setDocumentBounds:{CGPointZero, newSize}];
+ }];
+}
+
+- (void)contentViewDidCommitLoadForMainFrame:(WKContentView *)contentView
+{
+ _userHasChangedPageScale = NO;
+
+ WKContentType contentType = [_contentView contentType];
+ [_viewportHandler update:^{
+ [_viewportHandler clearWebKitViewportConfigurationFlags];
+ _UIWebViewportConfiguration configuration = standardViewportConfiguration;
+
+ if (contentType == PlainText) {
+ CGFloat screenWidth = [[UIScreen mainScreen] bounds].size.width;
+ configuration.size.width = screenWidth;
+ } else if (contentType == WKContentType::Image)
+ configuration.minimumScale = 0.01;
+
+ [_viewportHandler resetViewportConfiguration:&configuration];
+ }];
+}
+
+- (void)contentViewDidReceiveMobileDocType:(WKContentView *)contentView
+{
+ [_viewportHandler update:^{
+ _UIWebViewportConfiguration configuration = standardViewportConfiguration;
+ configuration.minimumScale = 1;
+ configuration.size = CGSizeMake(320, UIWebViewportGrowsAndShrinksToFitHeight);
+ [_viewportHandler resetViewportConfiguration:&configuration];
+ }];
+}
+
+- (void)contentView:(WKContentView *)contentView didChangeViewportArgumentsSize:(CGSize)newSize initialScale:(float)initialScale minimumScale:(float)minimumScale maximumScale:(float)maximumScale allowsUserScaling:(float)allowsUserScaling
+{
+ [_viewportHandler update:^{
+ [_viewportHandler applyWebKitViewportArgumentsSize:newSize initialScale:initialScale minimumScale:minimumScale maximumScale:maximumScale allowsUserScaling:allowsUserScaling];
+ }];
+}
+
+#pragma mark - _UIWebViewportHandlerDelegate
+
+- (void)viewportHandlerDidChangeScales:(_UIWebViewportHandler *)viewportHandler
+{
+ ASSERT(viewportHandler == _viewportHandler);
+ [_scrollView setMinimumZoomScale:viewportHandler.minimumScale];
+ [_scrollView setMaximumZoomScale:viewportHandler.maximumScale];
+ [_scrollView setZoomEnabled:viewportHandler.allowsUserScaling];
+
+ if (!_userHasChangedPageScale)
+ [self _setDocumentScale:viewportHandler.initialScale];
+ else {
+ CGFloat currentScale = [_scrollView zoomScale];
+ CGFloat validScale = std::max(std::min(currentScale, static_cast<CGFloat>(viewportHandler.maximumScale)), static_cast<CGFloat>(viewportHandler.minimumScale));
+ [self _setDocumentScale:validScale];
+ }
+}
+
+- (void)viewportHandler:(_UIWebViewportHandler *)viewportHandler didChangeViewportSize:(CGSize)newSize
+{
+ ASSERT(viewportHandler == _viewportHandler);
+ [_contentView setViewportSize:newSize];
+}
+
+#pragma mark - UIScrollViewDelegate
+
+- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
+{
+ ASSERT(_scrollView == scrollView);
+ return _contentView.get();
+}
+
+- (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(UIView *)view
+{
+ if (scrollView.pinchGestureRecognizer.state == UIGestureRecognizerStateBegan)
+ _userHasChangedPageScale = YES;
+}
+
+- (void)_didFinishScroll
+{
+ CGPoint position = [_scrollView convertPoint:[_scrollView contentOffset] toView:_contentView.get()];
+ [_contentView didFinishScrollTo:position];
+}
+
+- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
+{
+ // If we're decelerating, scroll offset will be updated when scrollViewDidFinishDecelerating: is called.
+ if (!decelerate)
+ [self _didFinishScroll];
+}
+
+- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
+{
+ [self _didFinishScroll];
+}
+
+- (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView
+{
+ [self _didFinishScroll];
+}
+
+- (void)scrollViewDidScroll:(UIScrollView *)scrollView
+{
+ CGPoint position = [_scrollView convertPoint:[_scrollView contentOffset] toView:_contentView.get()];
+ [_contentView didScrollTo:position];
+}
+
+- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(CGFloat)scale
+{
+ ASSERT(scrollView == _scrollView);
+ [_contentView didZoomToScale:scale];
+}
+
+#pragma mark Internal
+
+- (void)_frameOrBoundsChanged
+{
+ CGRect bounds = self.bounds;
+
+ if (!_hasStaticMinimumLayoutSize) {
+ [_viewportHandler update:^{
+ [_viewportHandler setAvailableViewSize:bounds.size];
+ }];
+ }
+ [_scrollView setFrame:bounds];
+ [_contentView setMinimumSize:bounds.size];
+}
+
+- (void)_setDocumentScale:(CGFloat)newScale
+{
+ CGPoint contentOffsetInDocumentCoordinates = [_scrollView convertPoint:[_scrollView contentOffset] toView:_contentView.get()];
+
+ [_scrollView setZoomScale:newScale];
+ [_contentView didZoomToScale:newScale];
+
+ CGPoint contentOffset = [_scrollView convertPoint:contentOffsetInDocumentCoordinates fromView:_contentView.get()];
+ [_scrollView setContentOffset:contentOffset];
+}
+
+#endif
+
</ins><span class="cx"> @end
</span><span class="cx">
</span><span class="cx"> #endif // WK_API_ENABLED
</span></span></pre>
</div>
</div>
</body>
</html>