]> git.saurik.com Git - cydia.git/blobdiff - UICaboodle/BrowserView.mm
Use UIApplication::networkActivityIndicator to indicate network activity.
[cydia.git] / UICaboodle / BrowserView.mm
index 705c7e176d7f11c85866e069e6f8450f1992b196..f1053f85e65f5c5fa76185f6c4900ca510adb104 100644 (file)
@@ -335,8 +335,10 @@ static NSURLRequest *$UIWebViewWebViewDelegate$webView$resource$willSendRequest$
 - (void) webView:(WebView *)view runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame {
     id<CYWebViewDelegate> delegate([self delegate]);
     if ([UIWebView instancesRespondToSelector:@selector(webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:)])
-        // XXX: check delegate
-        if ([delegate webView:view shouldRunJavaScriptAlertPanelWithMessage:message initiatedByFrame:frame])
+        if (
+            ![delegate respondsToSelector:@selector(webView:shouldRunJavaScriptAlertPanelWithMessage:initiatedByFrame:)] ||
+            [delegate webView:view shouldRunJavaScriptAlertPanelWithMessage:message initiatedByFrame:frame]
+        )
             [super webView:view runJavaScriptAlertPanelWithMessage:message initiatedByFrame:frame];
 }
 // }}}
@@ -344,8 +346,10 @@ static NSURLRequest *$UIWebViewWebViewDelegate$webView$resource$willSendRequest$
 - (BOOL) webView:(WebView *)view runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame {
     id<CYWebViewDelegate> delegate([self delegate]);
     if ([UIWebView instancesRespondToSelector:@selector(webView:runJavaScriptConfirmPanelWithMessage:initiatedByFrame:)])
-        // XXX: check delegate
-        if ([delegate webView:view shouldRunJavaScriptConfirmPanelWithMessage:message initiatedByFrame:frame])
+        if (
+            ![delegate respondsToSelector:@selector(webView:shouldRunJavaScriptConfirmPanelWithMessage:initiatedByFrame:)] ||
+            [delegate webView:view shouldRunJavaScriptConfirmPanelWithMessage:message initiatedByFrame:frame]
+        )
             return [super webView:view runJavaScriptConfirmPanelWithMessage:message initiatedByFrame:frame];
     return NO;
 }
@@ -354,8 +358,10 @@ static NSURLRequest *$UIWebViewWebViewDelegate$webView$resource$willSendRequest$
 - (NSString *) webView:(WebView *)view runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(NSString *)text initiatedByFrame:(WebFrame *)frame {
     id<CYWebViewDelegate> delegate([self delegate]);
     if ([UIWebView instancesRespondToSelector:@selector(webView:runJavaScriptTextInputPanelWithPrompt:defaultText:initiatedByFrame:)])
-        // XXX: check delegate
-        if ([delegate webView:view shouldRunJavaScriptTextInputPanelWithPrompt:prompt defaultText:text initiatedByFrame:frame])
+        if (
+            ![delegate respondsToSelector:@selector(webView:shouldRunJavaScriptTextInputPanelWithPrompt:defaultText:initiatedByFrame:)] ||
+            [delegate webView:view shouldRunJavaScriptTextInputPanelWithPrompt:prompt defaultText:text initiatedByFrame:frame]
+        )
             return [super webView:view runJavaScriptTextInputPanelWithPrompt:prompt defaultText:text initiatedByFrame:frame];
     return nil;
 }
@@ -432,8 +438,6 @@ static void $UIWebViewWebViewDelegate$webViewClose$(UIWebViewWebViewDelegate *se
     if (request_ != nil)
         [request_ release];
 
-    //NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
-
     if (custom_ != nil)
         [custom_ release];
     if (style_ != nil)
@@ -447,6 +451,8 @@ static void $UIWebViewWebViewDelegate$webViewClose$(UIWebViewWebViewDelegate *se
     if (title_ != nil)
         [title_ release];
 
+    if ([loading_ count] != 0)
+        [delegate_ releaseNetworkActivityIndicator];
     [loading_ release];
 
     [reloaditem_ release];
@@ -877,26 +883,39 @@ static void $UIWebViewWebViewDelegate$webViewClose$(UIWebViewWebViewDelegate *se
     [[self navigationItem] setTitle:UCLocalize("LOADING")];
 }
 
+- (void) layoutRightButton {
+    [[loadingitem_ view] addSubview:indicator_];
+    [[loadingitem_ view] bringSubviewToFront:indicator_];
+}
+
 - (void) applyRightButton {
     if ([self isLoading]) {
         [[self navigationItem] setRightBarButtonItem:loadingitem_ animated:YES];
-        // XXX: why do we do this again here? (if we don't, just remove indicator_)
-        [[loadingitem_ view] addSubview:indicator_];
+        [self performSelector:@selector(layoutRightButton) withObject:nil afterDelay:0];
+
+        [indicator_ startAnimating];
         [self applyLoadingTitle];
-    } else if (custom_ != nil) {
-        [[self navigationItem] setRightBarButtonItem:[self customButton] animated:YES];
     } else {
-        [[self navigationItem] setRightBarButtonItem:[self rightButton] animated:YES];
+        [indicator_ stopAnimating];
+
+        [[self navigationItem] setRightBarButtonItem:(
+            custom_ != nil ? [self customButton] : [self rightButton]
+        ) animated:YES];
     }
 }
 
 - (void) _didStartLoading {
     [self applyRightButton];
+
+    if ([loading_ count] != 1)
+        return;
+    [delegate_ retainNetworkActivityIndicator];
 }
 
 - (void) _didFinishLoading {
     if ([loading_ count] != 0)
         return;
+    [delegate_ releaseNetworkActivityIndicator];
 
     [self applyRightButton];
 
@@ -933,6 +952,8 @@ static void $UIWebViewWebViewDelegate$webViewClose$(UIWebViewWebViewDelegate *se
         [document setTileSize:CGSizeMake(320, 500)];
 
         [document setBackgroundColor:[UIColor clearColor]];
+
+        // XXX: this is terribly (too?) expensive
         [document setDrawsBackground:NO];
 
         WebView *webview([document webView]);
@@ -997,11 +1018,8 @@ static void $UIWebViewWebViewDelegate$webViewClose$(UIWebViewWebViewDelegate *se
             action:@selector(reloadButtonClicked)
         ];
 
-        CGSize indsize = [UIProgressIndicator defaultSizeForStyle:UIProgressIndicatorStyleMediumWhite];
-        indicator_ = [[UIProgressIndicator alloc] initWithFrame:CGRectMake(15, 5, indsize.width, indsize.height)];
-        [indicator_ setStyle:UIProgressIndicatorStyleMediumWhite];
-        [indicator_ startAnimation];
-        [[loadingitem_ view] addSubview:indicator_];
+        indicator_ = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite]; 
+        [indicator_ setFrame:CGRectMake(15, 5, [indicator_ frame].size.width, [indicator_ frame].size.height)];
 
         [webview_ setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
         [indicator_ setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin];