Add a progress indicator to the preview popover
authorconrad_shultz@apple.com <conrad_shultz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 16 Dec 2014 23:14:55 +0000 (23:14 +0000)
committerconrad_shultz@apple.com <conrad_shultz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 16 Dec 2014 23:14:55 +0000 (23:14 +0000)
https://bugs.webkit.org/show_bug.cgi?id=139699

Reviewed by Tim Horton.

* UIProcess/API/Cocoa/WKViewPrivate.h:
* UIProcess/API/mac/WKView.mm:
(-[WKView _setPreviewLoading:]):
Wrap -[WKImmediateActionController setPreviewLoading:].

* UIProcess/mac/WKImmediateActionController.h:
* UIProcess/mac/WKImmediateActionController.mm:
(-[WKImmediateActionController _createPreviewPopoverIfNeededForURL:]):
Flag the preview view controller as loading before beginning the load.
(-[WKImmediateActionController setPreviewLoading:]):
Wrap -[WKPagePreviewViewController setLoading:].

* UIProcess/mac/WKPagePreviewViewController.h:
* UIProcess/mac/WKPagePreviewViewController.mm:
(-[WKPagePreviewViewController setLoading:]):
Toggle the progress indicator animation state.
(-[WKPagePreviewViewController isLoading]):
Accessor.
(-[WKPagePreviewViewController loadView]):
Create and center an indeterminate progress indicator that won't scale with the preview content.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@177402 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/Cocoa/WKViewPrivate.h
Source/WebKit2/UIProcess/API/mac/WKView.mm
Source/WebKit2/UIProcess/mac/WKImmediateActionController.h
Source/WebKit2/UIProcess/mac/WKImmediateActionController.mm
Source/WebKit2/UIProcess/mac/WKPagePreviewViewController.h
Source/WebKit2/UIProcess/mac/WKPagePreviewViewController.mm

index d1dfc73e9fc37525b6da4d13aa3b894708637714..7fd83273003bc3546548d2789acb4d1f68bace0e 100644 (file)
@@ -1,3 +1,31 @@
+2014-12-16  Conrad Shultz  <conrad_shultz@apple.com>
+
+        Add a progress indicator to the preview popover
+        https://bugs.webkit.org/show_bug.cgi?id=139699
+
+        Reviewed by Tim Horton.
+
+        * UIProcess/API/Cocoa/WKViewPrivate.h:
+        * UIProcess/API/mac/WKView.mm:
+        (-[WKView _setPreviewLoading:]):
+        Wrap -[WKImmediateActionController setPreviewLoading:].
+
+        * UIProcess/mac/WKImmediateActionController.h:
+        * UIProcess/mac/WKImmediateActionController.mm:
+        (-[WKImmediateActionController _createPreviewPopoverIfNeededForURL:]):
+        Flag the preview view controller as loading before beginning the load.
+        (-[WKImmediateActionController setPreviewLoading:]):
+        Wrap -[WKPagePreviewViewController setLoading:].
+
+        * UIProcess/mac/WKPagePreviewViewController.h:
+        * UIProcess/mac/WKPagePreviewViewController.mm:
+        (-[WKPagePreviewViewController setLoading:]):
+        Toggle the progress indicator animation state.
+        (-[WKPagePreviewViewController isLoading]):
+        Accessor.
+        (-[WKPagePreviewViewController loadView]):
+        Create and center an indeterminate progress indicator that won't scale with the preview content.
+
 2014-12-16  Enrica Casucci  <enrica@apple.com>
 
         Fix iOS builders for 8.0
index d7ded04d22e7241a8dcb87dadb5b8762d2187df0..466cd04b935f8f62467de27f5f73eb6725fba2ea 100644 (file)
 - (NSView *)_viewForPreviewingURL:(NSURL *)url initialFrameSize:(NSSize)initialFrameSize;
 - (NSString *)_titleForPreviewOfURL:(NSURL *)url;
 - (void)_setPreviewTitle:(NSString *)previewTitle;
+- (void)_setPreviewLoading:(BOOL)loading;
 - (void)_finishPreviewingURL:(NSURL *)url withPreviewView:(NSView *)previewView;
 - (void)_handleClickInPreviewView:(NSView *)previewView URL:(NSURL *)url;
 - (BOOL)_shouldUseStandardQuickLookPreview;
index 59680997c06ad9cd8828c47ea7d7b069367f0397..70231001cb6354d437501bbc6928c857bd6eb833 100644 (file)
@@ -4356,6 +4356,13 @@ static NSString *pathWithUniqueFilenameForPath(NSString *path)
 #endif
 }
 
+- (void)_setPreviewLoading:(BOOL)loading
+{
+#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000 && WK_API_ENABLED
+    [_data->_immediateActionController setPreviewLoading:loading];
+#endif
+}
+
 - (void)_finishPreviewingURL:(NSURL *)url withPreviewView:(NSView *)previewView
 {
 }
index b06fa935747409ba1008bc3226fc35fe0f90d71c..deb33626f9344a86701e91fc3274bb7708ff4988 100644 (file)
@@ -80,6 +80,7 @@ enum class ImmediateActionState {
 #if WK_API_ENABLED
 - (void)setPreviewTitle:(NSString *)previewTitle;
 - (void)hidePreview;
+- (void)setPreviewLoading:(BOOL)loading;
 #endif // WK_API_ENABLED
 
 @end
index 4e17d957f6f1e5fb9c0a90ad5cbc664eecaeba7f..434288b35f5bdd26a966d2392652259e0b289e8a 100644 (file)
@@ -288,6 +288,7 @@ using namespace WebKit;
 
     _previewViewController = adoptNS([[WKPagePreviewViewController alloc] initWithPageURL:url mainViewSize:_wkView.bounds.size popoverToViewScale:actualPopoverToViewScale]);
     _previewViewController->_delegate = self;
+    [_previewViewController setLoading:YES];
     [_previewViewController loadView];
 
     _previewPopover = adoptNS([[NSPopover alloc] init]);
@@ -316,6 +317,11 @@ using namespace WebKit;
     [_previewViewController setPreviewTitle:previewTitle];
 }
 
+- (void)setPreviewLoading:(BOOL)loading
+{
+    [_previewViewController setLoading:loading];
+}
+
 - (void)popoverWillClose:(NSNotification *)notification
 {
     [self hidePreview];
index 871910d75e3079936a84ced4740954b0c46b1ec3..4e615b315fe2eb3ee5e272117fa648dbebe18dd8 100644 (file)
     RetainPtr<NSView> _previewView;
     RetainPtr<NSTextField> _titleTextField;
     RetainPtr<NSString> _previewTitle;
+    RetainPtr<NSProgressIndicator> _spinner;
+    BOOL _loading;
     id <WKPagePreviewViewControllerDelegate> _delegate;
     CGFloat _popoverToViewScale;
 }
 
 @property (nonatomic, copy) NSString *previewTitle;
+@property (nonatomic, getter=isLoading) BOOL loading;
 
 - (instancetype)initWithPageURL:(NSURL *)URL mainViewSize:(NSSize)size popoverToViewScale:(CGFloat)scale;
 
index 6123914bc5d38e87d328fc45692775b54f29ea04..c2c3f45de300025fcf2ec2680a5f27a97f963a6d 100644 (file)
@@ -67,6 +67,24 @@ static const CGFloat previewViewTitleHeight = 34;
     return NSMakeSize(2 * previewViewInset, previewViewTitleHeight + 2 * previewViewInset);
 }
 
+- (void)setLoading:(BOOL)loading
+{
+    if (_loading == loading)
+        return;
+
+    _loading = loading;
+
+    if (_loading)
+        [_spinner startAnimation:nil];
+    else
+        [_spinner stopAnimation:nil];
+}
+
+- (BOOL)isLoading
+{
+    return _loading;
+}
+
 - (void)loadView
 {
     NSRect defaultFrame = NSMakeRect(0, 0, _mainViewSize.width, _mainViewSize.height);
@@ -126,6 +144,22 @@ static const CGFloat previewViewTitleHeight = 34;
     [_titleTextField setFrame:titleFrame];
     [containerView addSubview:_titleTextField.get()];
 
+    NSSize spinnerSize = NSMakeSize(48, 48);
+    NSRect spinnerFrame = NSMakeRect(NSMidX(containerFrame), NSMidY(containerFrame), 0, 0);
+    spinnerFrame = NSInsetRect(spinnerFrame, -spinnerSize.width * 0.5, -spinnerSize.height * 0.5);
+    spinnerFrame.origin.x = floor(spinnerFrame.origin.x);
+    spinnerFrame.origin.y = floor(spinnerFrame.origin.y);
+
+    _spinner = adoptNS([[NSProgressIndicator alloc] initWithFrame:spinnerFrame]);
+    [_spinner setStyle:NSProgressIndicatorSpinningStyle];
+    [_spinner setDisplayedWhenStopped:NO];
+    [_spinner setAutoresizingMask:NSViewMinXMargin | NSViewMaxXMargin | NSViewMinYMargin | NSViewMaxYMargin];
+    [_spinner setAppearance:[NSAppearance appearanceNamed:NSAppearanceNameAqua]];
+    if (_loading)
+        [_spinner startAnimation:nil];
+
+    [containerView addSubview:_spinner.get()];
+
     // Setting the webView bounds will scale it to 75% of the _mainViewSize.
     [_previewView setBounds:NSMakeRect(0, 0, _mainViewSize.width / _popoverToViewScale, _mainViewSize.height / _popoverToViewScale)];