X-Git-Url: https://git.saurik.com/cydia.git/blobdiff_plain/b5e7eebb25026afcb8052552a5fedb7984c08a38..3b7fcecd1d1d10c596f73bd499cd71d9eeef68f6:/UICaboodle/BrowserView.mm diff --git a/UICaboodle/BrowserView.mm b/UICaboodle/BrowserView.mm index 9bfeb790..7c123f97 100644 --- a/UICaboodle/BrowserView.mm +++ b/UICaboodle/BrowserView.mm @@ -148,12 +148,36 @@ static Class $UIWebBrowserView; @end +@interface BrowserView : UIView { +@private + UIWebDocumentView *documentView; +} +@property (nonatomic, retain) UIWebDocumentView *documentView; +@end + +@implementation BrowserView + +@synthesize documentView; + +- (void)dealloc { + [documentView release]; + [super dealloc]; +} + +- (void)layoutSubviews { + [super layoutSubviews]; + if ([documentView respondsToSelector:@selector(setMinimumSize:)]) + [documentView setMinimumSize:documentView.bounds.size]; +} + +@end + #define ShowInternals 0 #define LogBrowser 1 #define lprintf(args...) fprintf(stderr, args) -@implementation BrowserView +@implementation BrowserController #if ShowInternals #include "UICaboodle/UCInternal.h" @@ -183,7 +207,7 @@ static Class $UIWebBrowserView; - (void) dealloc { #if LogBrowser - NSLog(@"[BrowserView dealloc]"); + NSLog(@"[BrowserController dealloc]"); #endif if (challenge_ != nil) @@ -255,6 +279,11 @@ static Class $UIWebBrowserView; [sensitive_ release]; if (title_ != nil) [title_ release]; + if (reloaditem_ != nil) + [reloaditem_ release]; + if (loadingitem_ != nil) + [loadingitem_ release]; + [super dealloc]; } @@ -531,7 +560,7 @@ static Class $UIWebBrowserView; [function_ autorelease]; function_ = function == nil ? nil : [function retain]; - [self reloadButtons]; + [self applyRightButton]; } - (void) setButtonTitle:(NSString *)button withStyle:(NSString *)style toFunction:(id)function { @@ -547,7 +576,7 @@ static Class $UIWebBrowserView; [function_ autorelease]; function_ = function == nil ? nil : [function retain]; - [self reloadButtons]; + [self applyRightButton]; } - (void) setFinishHook:(id)function { @@ -621,7 +650,7 @@ static Class $UIWebBrowserView; if (page == nil) { /* XXX: call createWebViewWithRequest instead? */ - BrowserView *browser([[[class_ alloc] init] autorelease]); + BrowserController *browser([[[class_ alloc] init] autorelease]); [browser loadURL:url]; page = browser; } @@ -890,7 +919,7 @@ static Class $UIWebBrowserView; UCNavigationController *navigation(!popup_ ? [self navigationController] : [[[UCNavigationController alloc] init] autorelease]); /* XXX: deal with cydia:// pages */ - BrowserView *browser([[[class_ alloc] initWithWidth:width] autorelease]); + BrowserController *browser([[[class_ alloc] initWithWidth:width] autorelease]); if (features != nil && popup_) { [navigation setDelegate:delegate_]; @@ -1007,10 +1036,53 @@ static Class $UIWebBrowserView; } } - [self reloadButtons]; + [self _startLoading]; +} + +- (UINavigationButtonStyle) rightButtonStyle { + if (style_ == nil) normal: + return UINavigationButtonStyleNormal; + else if ([style_ isEqualToString:@"Normal"]) + return UINavigationButtonStyleNormal; + else if ([style_ isEqualToString:@"Back"]) + return UINavigationButtonStyleBack; + else if ([style_ isEqualToString:@"Highlighted"]) + return UINavigationButtonStyleHighlighted; + else if ([style_ isEqualToString:@"Destructive"]) + return UINavigationButtonStyleDestructive; + else goto normal; +} + +- (UIBarButtonItem *) customButton { + UIBarButtonItem *customItem = [[UIBarButtonItem alloc] + initWithTitle:button_ + style:[self rightButtonStyle] + target:self + action:@selector(customButtonClicked) + ]; + + return [customItem autorelease]; +} + +- (void) applyLoadingTitle { + [[self navigationItem] setTitle:UCLocalize("LOADING")]; +} + +- (void) applyRightButton { + if ([self isLoading]) { + [[self navigationItem] setRightBarButtonItem:loadingitem_ animated:YES]; + [[loadingitem_ view] addSubview:indicator_]; + [self applyLoadingTitle]; + } else if (button_) { + [[self navigationItem] setRightBarButtonItem:[self customButton] animated:YES]; + } else { + [[self navigationItem] setRightBarButtonItem:reloaditem_ animated:YES]; + } } -- (void) didFinishLoading { } +- (void) _startLoading { + [self applyRightButton]; +} - (void) _finishLoading { size_t count([loading_ count]); @@ -1021,7 +1093,8 @@ static Class $UIWebBrowserView; if (finish_ != nil) [self callFunction:finish_]; - [self reloadButtons]; + [self applyRightButton]; + if (![self isLoading]) [[self navigationItem] setTitle:title_]; } - (bool) isLoading { @@ -1258,6 +1331,9 @@ static Class $UIWebBrowserView; loading_ = [[NSMutableSet alloc] initWithCapacity:3]; popup_ = false; + BrowserView *actualView = [[BrowserView alloc] initWithFrame:CGRectZero]; + [self setView:actualView]; + struct CGRect bounds = [[self view] bounds]; scroller_ = [[objc_getClass(Wildcat_ ? "UIScrollView" : "UIScroller") alloc] initWithFrame:bounds]; @@ -1377,6 +1453,9 @@ static Class $UIWebBrowserView; else [preferences _setLayoutInterval:0]; } + + actualView.documentView = document_; + [actualView release]; [self setViewportWidth:width]; @@ -1408,10 +1487,25 @@ static Class $UIWebBrowserView; indicator_ = [[UIProgressIndicator alloc] initWithFrame:CGRectMake(15, 5, indsize.width, indsize.height)]; [indicator_ setStyle:UIProgressIndicatorStyleMediumWhite]; [indicator_ startAnimation]; + + reloaditem_ = [[UIBarButtonItem alloc] + initWithTitle:UCLocalize("RELOAD") + style:[self rightButtonStyle] + target:self + action:@selector(reloadButtonClicked) + ]; + + loadingitem_ = [[UIBarButtonItem alloc] + initWithTitle:@" " + style:UIBarButtonItemStylePlain + target:self + action:@selector(reloadButtonClicked) + ]; + [[loadingitem_ view] addSubview:indicator_]; [scroller_ setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)]; [indicator_ setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin]; - [document_ setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)]; + [document_ setAutoresizingMask:UIViewAutoresizingFlexibleWidth]; /*UIWebView *test([[[UIWebView alloc] initWithFrame:[[self view] bounds]] autorelease]); [test loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.saurik.com/"]]]; @@ -1472,59 +1566,18 @@ static Class $UIWebBrowserView; [self callFunction:closer_]; } -- (void) __rightButtonClicked { +- (void) reloadButtonClicked { reloading_ = true; [self reloadURL]; } -- (void) _rightButtonClicked { +- (void) customButtonClicked { #if !AlwaysReload if (function_ != nil) [self callFunction:function_]; else #endif - [self __rightButtonClicked]; -} - -- (UINavigationButtonStyle) rightButtonStyle { - if (style_ == nil) normal: - return UINavigationButtonStyleNormal; - else if ([style_ isEqualToString:@"Normal"]) - return UINavigationButtonStyleNormal; - else if ([style_ isEqualToString:@"Back"]) - return UINavigationButtonStyleBack; - else if ([style_ isEqualToString:@"Highlighted"]) - return UINavigationButtonStyleHighlighted; - else if ([style_ isEqualToString:@"Destructive"]) - return UINavigationButtonStyleDestructive; - else goto normal; -} - -- (void) reloadButtons { - if ([self isLoading]) { - UIBarButtonItem *reloadItem = [[UIBarButtonItem alloc] - initWithTitle:@" " - style:UIBarButtonItemStylePlain - target:self - action:@selector(_rightButtonClicked) - ]; - [[self navigationItem] setRightBarButtonItem:reloadItem]; - [[reloadItem view] addSubview:indicator_]; - [[self navigationItem] setTitle:UCLocalize("LOADING")]; - [reloadItem release]; - } else { - UIBarButtonItem *reloadItem = [[UIBarButtonItem alloc] - initWithTitle:button_ ?: UCLocalize("RELOAD") - style:[self rightButtonStyle] - target:self - action:@selector(_rightButtonClicked) - ]; - [[self navigationItem] setRightBarButtonItem:reloadItem animated:YES]; - [[self navigationItem] setTitle:title_]; - [reloadItem release]; - - if (function_ == nil) [self didFinishLoading]; - } + [self reloadButtonClicked]; } - (void) setPageActive:(BOOL)active {