]> git.saurik.com Git - cydia.git/commitdiff
Use loadView/releaseSubviews for CyteWebViewController.
authorJay Freeman (saurik) <saurik@saurik.com>
Tue, 8 Mar 2011 21:23:39 +0000 (13:23 -0800)
committerJay Freeman (saurik) <saurik@saurik.com>
Tue, 8 Mar 2011 21:31:59 +0000 (13:31 -0800)
CyteKit/WebViewController.h
CyteKit/WebViewController.mm

index 897a204083a85559da02270f5f75f2522aab76dd..b6cd768ba13589dd3882bfa962c7c402302ad82f 100644 (file)
 
 + (void) _initialize;
 
+- (CyteWebView *) webView;
+
 - (void) setURL:(NSURL *)url;
 
 - (void) loadURL:(NSURL *)url cachePolicy:(NSURLRequestCachePolicy)policy;
index 41ffd1e22ce9730a5b83c72c8a2483f2256e603a..5c34f8582fc76ea964afa5591bdac535c1ffb787 100644 (file)
@@ -147,6 +147,10 @@ float CYScrollViewDecelerationRateNormal;
     [super dealloc];
 }
 
+- (CyteWebView *) webView {
+    return (CyteWebView *) [self view];
+}
+
 - (NSURL *) URLWithURL:(NSURL *)url {
     return url;
 }
@@ -181,7 +185,7 @@ float CYScrollViewDecelerationRateNormal;
     ready_ = true;
 
     WebThreadLocked lock;
-    [webview_ loadRequest:request];
+    [[self webView] loadRequest:request];
 }
 
 - (void) reloadURLWithCache:(BOOL)cache {
@@ -257,7 +261,7 @@ float CYScrollViewDecelerationRateNormal;
 }
 
 - (void) _setViewportWidth {
-    [[webview_ _documentView] setViewportSize:CGSizeMake(width_, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x10];
+    [[[self webView] _documentView] setViewportSize:CGSizeMake(width_, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x10];
 }
 
 - (void) setViewportWidth:(float)width {
@@ -619,7 +623,7 @@ float CYScrollViewDecelerationRateNormal;
         } else if (button == [alert firstOtherButtonIndex]) {
             if (request_ != nil) {
                 WebThreadLocked lock;
-                [webview_ loadRequest:request_];
+                [[self webView] loadRequest:request_];
             }
         }
 
@@ -740,122 +744,130 @@ float CYScrollViewDecelerationRateNormal;
 
 - (id) initWithWidth:(float)width ofClass:(Class)_class {
     if ((self = [super init]) != nil) {
+        width_ = width;
+        class_ = _class;
+
         allowsNavigationAction_ = true;
 
-        class_ = _class;
         loading_ = [NSMutableSet setWithCapacity:5];
-
         indirect_ = [[[IndirectDelegate alloc] initWithDelegate:self] autorelease];
 
-        CGRect bounds([[self view] bounds]);
+        reloaditem_ = [[[UIBarButtonItem alloc]
+            initWithTitle:UCLocalize("RELOAD")
+            style:[self rightButtonStyle]
+            target:self
+            action:@selector(reloadButtonClicked)
+        ] autorelease];
 
-        webview_ = [[[CyteWebView alloc] initWithFrame:bounds] autorelease];
-        [webview_ setDelegate:self];
-        [self setView:webview_];
+        loadingitem_ = [[[UIBarButtonItem alloc]
+            initWithTitle:@" "
+            style:UIBarButtonItemStylePlain
+            target:self
+            action:@selector(reloadButtonClicked)
+        ] autorelease];
 
-        if ([webview_ respondsToSelector:@selector(setDataDetectorTypes:)])
-            [webview_ setDataDetectorTypes:UIDataDetectorTypeAutomatic];
-        else
-            [webview_ setDetectsPhoneNumbers:NO];
+        indicator_ = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite] autorelease];
+        [indicator_ setFrame:CGRectMake(15, 5, [indicator_ frame].size.width, [indicator_ frame].size.height)];
+        [indicator_ setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin];
 
-        [webview_ setScalesPageToFit:YES];
+        [self applyLeftButton];
+        [self applyRightButton];
+    } return self;
+}
 
-        UIWebDocumentView *document([webview_ _documentView]);
+- (void) loadView {
+    CGRect bounds([[UIScreen mainScreen] applicationFrame]);
 
-        // XXX: I think this improves scrolling; the hardcoded-ness sucks
-        [document setTileSize:CGSizeMake(320, 500)];
+    webview_ = [[[CyteWebView alloc] initWithFrame:bounds] autorelease];
+    [webview_ setDelegate:self];
+    [self setView:webview_];
 
-        [document setBackgroundColor:[UIColor clearColor]];
+    if ([webview_ respondsToSelector:@selector(setDataDetectorTypes:)])
+        [webview_ setDataDetectorTypes:UIDataDetectorTypeAutomatic];
+    else
+        [webview_ setDetectsPhoneNumbers:NO];
 
-        // XXX: this is terribly (too?) expensive
-        [document setDrawsBackground:NO];
+    [webview_ setScalesPageToFit:YES];
 
-        WebView *webview([document webView]);
-        WebPreferences *preferences([webview preferences]);
+    UIWebDocumentView *document([webview_ _documentView]);
 
-        // XXX: I have no clue if I actually /want/ this modification
-        if ([webview respondsToSelector:@selector(_setLayoutInterval:)])
-            [webview _setLayoutInterval:0];
-        else if ([preferences respondsToSelector:@selector(_setLayoutInterval:)])
-            [preferences _setLayoutInterval:0];
+    // XXX: I think this improves scrolling; the hardcoded-ness sucks
+    [document setTileSize:CGSizeMake(320, 500)];
 
-        [preferences setCacheModel:WebCacheModelDocumentBrowser];
-        [preferences setJavaScriptCanOpenWindowsAutomatically:YES];
-        [preferences setOfflineWebApplicationCacheEnabled:YES];
+    [document setBackgroundColor:[UIColor clearColor]];
 
-        if ([webview respondsToSelector:@selector(setShouldUpdateWhileOffscreen:)])
-            [webview setShouldUpdateWhileOffscreen:NO];
+    // XXX: this is terribly (too?) expensive
+    [document setDrawsBackground:NO];
 
-#if LogMessages
-        if ([document respondsToSelector:@selector(setAllowsMessaging:)])
-            [document setAllowsMessaging:YES];
-        if ([webview respondsToSelector:@selector(_setAllowsMessaging:)])
-            [webview _setAllowsMessaging:YES];
-#endif
+    WebView *webview([document webView]);
+    WebPreferences *preferences([webview preferences]);
 
-        if ([webview_ respondsToSelector:@selector(_scrollView)]) {
-            scroller_ = [webview_ _scrollView];
+    // XXX: I have no clue if I actually /want/ this modification
+    if ([webview respondsToSelector:@selector(_setLayoutInterval:)])
+        [webview _setLayoutInterval:0];
+    else if ([preferences respondsToSelector:@selector(_setLayoutInterval:)])
+        [preferences _setLayoutInterval:0];
 
-            [scroller_ setDirectionalLockEnabled:YES];
-            [scroller_ setDecelerationRate:CYScrollViewDecelerationRateNormal];
-            [scroller_ setDelaysContentTouches:NO];
+    [preferences setCacheModel:WebCacheModelDocumentBrowser];
+    [preferences setJavaScriptCanOpenWindowsAutomatically:YES];
+    [preferences setOfflineWebApplicationCacheEnabled:YES];
 
-            [scroller_ setCanCancelContentTouches:YES];
-        } else if ([webview_ respondsToSelector:@selector(_scroller)]) {
-            UIScroller *scroller([webview_ _scroller]);
-            scroller_ = (UIScrollView *) scroller;
+    if ([webview respondsToSelector:@selector(setShouldUpdateWhileOffscreen:)])
+        [webview setShouldUpdateWhileOffscreen:NO];
 
-            [scroller setDirectionalScrolling:YES];
-            // XXX: we might be better off /not/ setting this on older systems
-            [scroller setScrollDecelerationFactor:CYScrollViewDecelerationRateNormal]; /* 0.989324 */
-            [scroller setScrollHysteresis:0]; /* 8 */
+#if LogMessages
+    if ([document respondsToSelector:@selector(setAllowsMessaging:)])
+        [document setAllowsMessaging:YES];
+    if ([webview respondsToSelector:@selector(_setAllowsMessaging:)])
+        [webview _setAllowsMessaging:YES];
+#endif
 
-            [scroller setThumbDetectionEnabled:NO];
+    if ([webview_ respondsToSelector:@selector(_scrollView)]) {
+        scroller_ = [webview_ _scrollView];
 
-            // use NO with UIApplicationUseLegacyEvents(YES)
-            [scroller setEventMode:YES];
+        [scroller_ setDirectionalLockEnabled:YES];
+        [scroller_ setDecelerationRate:CYScrollViewDecelerationRateNormal];
+        [scroller_ setDelaysContentTouches:NO];
 
-            // XXX: this is handled by setBounces, right?
-            //[scroller setAllowsRubberBanding:YES];
-        }
+        [scroller_ setCanCancelContentTouches:YES];
+    } else if ([webview_ respondsToSelector:@selector(_scroller)]) {
+        UIScroller *scroller([webview_ _scroller]);
+        scroller_ = (UIScrollView *) scroller;
 
-        [scroller_ setFixedBackgroundPattern:YES];
-        [scroller_ setBackgroundColor:[UIColor clearColor]];
-        [scroller_ setClipsSubviews:YES];
+        [scroller setDirectionalScrolling:YES];
+        // XXX: we might be better off /not/ setting this on older systems
+        [scroller setScrollDecelerationFactor:CYScrollViewDecelerationRateNormal]; /* 0.989324 */
+        [scroller setScrollHysteresis:0]; /* 8 */
 
-        [scroller_ setBounces:YES];
-        [scroller_ setScrollingEnabled:YES];
-        [scroller_ setShowBackgroundShadow:NO];
+        [scroller setThumbDetectionEnabled:NO];
 
-        [self setViewportWidth:width];
+        // use NO with UIApplicationUseLegacyEvents(YES)
+        [scroller setEventMode:YES];
 
-        reloaditem_ = [[[UIBarButtonItem alloc]
-            initWithTitle:UCLocalize("RELOAD")
-            style:[self rightButtonStyle]
-            target:self
-            action:@selector(reloadButtonClicked)
-        ] autorelease];
+        // XXX: this is handled by setBounces, right?
+        //[scroller setAllowsRubberBanding:YES];
+    }
 
-        loadingitem_ = [[[UIBarButtonItem alloc]
-            initWithTitle:@" "
-            style:UIBarButtonItemStylePlain
-            target:self
-            action:@selector(reloadButtonClicked)
-        ] autorelease];
+    [scroller_ setFixedBackgroundPattern:YES];
+    [scroller_ setBackgroundColor:[UIColor clearColor]];
+    [scroller_ setClipsSubviews:YES];
 
-        indicator_ = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite] autorelease];
-        [indicator_ setFrame:CGRectMake(15, 5, [indicator_ frame].size.width, [indicator_ frame].size.height)];
+    [scroller_ setBounces:YES];
+    [scroller_ setScrollingEnabled:YES];
+    [scroller_ setShowBackgroundShadow:NO];
 
-        UITableView *table([[[UITableView alloc] initWithFrame:bounds style:UITableViewStyleGrouped] autorelease]);
-        [webview_ insertSubview:table atIndex:0];
+    [self setViewportWidth:width_];
 
-        [self applyLeftButton];
-        [self applyRightButton];
+    UITableView *table([[[UITableView alloc] initWithFrame:[webview_ bounds] style:UITableViewStyleGrouped] autorelease]);
+    [webview_ insertSubview:table atIndex:0];
 
-        [table setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
-        [webview_ setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
-        [indicator_ setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin];
-    } return self;
+    [table setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
+    [webview_ setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
+}
+
+- (void) releaseSubviews {
+    webview_ = nil;
+    scroller_ = nil;
 }
 
 - (id) initWithWidth:(float)width {
@@ -875,7 +887,7 @@ float CYScrollViewDecelerationRateNormal;
 - (void) callFunction:(WebScriptObject *)function {
     WebThreadLocked lock;
 
-    WebView *webview([[webview_ _documentView] webView]);
+    WebView *webview([[[self webView] _documentView] webView]);
     WebFrame *frame([webview mainFrame]);
 
     JSGlobalContextRef context([frame globalContext]);
@@ -932,7 +944,7 @@ float CYScrollViewDecelerationRateNormal;
 }
 
 - (void) dispatchEvent:(NSString *)event {
-    [(CyteWebView *) webview_ dispatchEvent:event];
+    [[self webView] dispatchEvent:event];
 }
 
 - (bool) hidesNavigationBar {