summaryrefslogtreecommitdiff
path: root/CyteKit
diff options
context:
space:
mode:
authorJay Freeman (saurik) <saurik@saurik.com>2011-03-08 13:23:39 -0800
committerJay Freeman (saurik) <saurik@saurik.com>2011-03-08 13:31:59 -0800
commit6f837280343c42bde0eff1ec9007127f4eb15b4c (patch)
tree0959646e67c4c5edcbb79ac60b4d8da5efd87796 /CyteKit
parent67dd58c7b061d339b70f5fa0f9badc427b1b863f (diff)
Use loadView/releaseSubviews for CyteWebViewController.
Diffstat (limited to 'CyteKit')
-rw-r--r--CyteKit/WebViewController.h2
-rw-r--r--CyteKit/WebViewController.mm188
2 files changed, 102 insertions, 88 deletions
diff --git a/CyteKit/WebViewController.h b/CyteKit/WebViewController.h
index 897a204..b6cd768 100644
--- a/CyteKit/WebViewController.h
+++ b/CyteKit/WebViewController.h
@@ -100,6 +100,8 @@
+ (void) _initialize;
+- (CyteWebView *) webView;
+
- (void) setURL:(NSURL *)url;
- (void) loadURL:(NSURL *)url cachePolicy:(NSURLRequestCachePolicy)policy;
diff --git a/CyteKit/WebViewController.mm b/CyteKit/WebViewController.mm
index 41ffd1e..5c34f85 100644
--- a/CyteKit/WebViewController.mm
+++ b/CyteKit/WebViewController.mm
@@ -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 {