From aa1e190657c229f1fd1c59f0867621dd739379ee Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Wed, 12 Sep 2012 21:12:58 -0700 Subject: [PATCH] Add cydia.registerFrame() to force auto-iframe size. --- CyteKit/WebViewController.h | 5 +++++ CyteKit/WebViewController.mm | 28 ++++++++++++++++++++++++++++ MobileCydia.app/iframe.html | 6 ++++++ MobileCydia.mm | 8 ++++++++ iPhonePrivate.h | 5 +++++ 5 files changed, 52 insertions(+) create mode 100644 MobileCydia.app/iframe.html diff --git a/CyteKit/WebViewController.h b/CyteKit/WebViewController.h index d3ded440..b8270201 100644 --- a/CyteKit/WebViewController.h +++ b/CyteKit/WebViewController.h @@ -78,6 +78,9 @@ _H title_; _H loading_; + _H registered_; + _H timer_; + // XXX: NSString * or UIImage * _H custom_; _H style_; @@ -152,6 +155,8 @@ - (void) setScrollAlwaysBounceVertical:(bool)value; - (void) setScrollIndicatorStyle:(UIScrollViewIndicatorStyle)style; +- (void) registerFrame:(WebFrame *)frame; + @end #endif//CyteKit_WebViewController_H diff --git a/CyteKit/WebViewController.mm b/CyteKit/WebViewController.mm index 5d152139..ccb1823c 100644 --- a/CyteKit/WebViewController.mm +++ b/CyteKit/WebViewController.mm @@ -48,12 +48,24 @@ float CYScrollViewDecelerationRateNormal; - (void) _setAllowsMessaging:(BOOL)allows; @end +@interface WebFrame (Cydia) +- (void) cydia$updateHeight; +@end + @implementation WebFrame (Cydia) - (NSString *) description { return [NSString stringWithFormat:@"<%s: %p, %@>", class_getName([self class]), self, [[[([self provisionalDataSource] ?: [self dataSource]) request] URL] absoluteString]]; } +- (void) cydia$updateHeight { + [[[self frameElement] style] + setProperty:@"height" + value:[NSString stringWithFormat:@"%dpx", + [[[self DOMDocument] body] scrollHeight]] + priority:nil]; +} + @end /* Indirect Delegate {{{ */ @@ -595,6 +607,9 @@ float CYScrollViewDecelerationRateNormal; style_ = nil; function_ = nil; + [registered_ removeAllObjects]; + timer_ = nil; + allowsNavigationAction_ = true; [self setHidesNavigationBar:NO]; @@ -811,6 +826,7 @@ float CYScrollViewDecelerationRateNormal; allowsNavigationAction_ = true; loading_ = [NSMutableSet setWithCapacity:5]; + registered_ = [NSMutableSet setWithCapacity:5]; indirect_ = [[[IndirectDelegate alloc] initWithDelegate:self] autorelease]; reloaditem_ = [[[UIBarButtonItem alloc] @@ -1122,4 +1138,16 @@ float CYScrollViewDecelerationRateNormal; [self dispatchEvent:@"CydiaViewDidDisappear"]; } +- (void) updateHeights:(NSTimer *)timer { + for (WebFrame *frame in (id) registered_) + [frame cydia$updateHeight]; +} + +- (void) registerFrame:(WebFrame *)frame { + [registered_ addObject:frame]; + + if (timer_ == nil) + timer_ = [NSTimer scheduledTimerWithTimeInterval:0.2 target:self selector:@selector(updateHeights:) userInfo:nil repeats:YES]; +} + @end diff --git a/MobileCydia.app/iframe.html b/MobileCydia.app/iframe.html new file mode 100644 index 00000000..f35ef990 --- /dev/null +++ b/MobileCydia.app/iframe.html @@ -0,0 +1,6 @@ + + + + diff --git a/MobileCydia.mm b/MobileCydia.mm index 3b3347f1..e2f1d85d 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -69,6 +69,7 @@ #include #include +#include #include #include @@ -4169,6 +4170,8 @@ static _H Diversions_; return @"popViewController"; else if (selector == @selector(refreshSources)) return @"refreshSources"; + else if (selector == @selector(registerFrame:)) + return @"registerFrame"; else if (selector == @selector(removeButton)) return @"removeButton"; else if (selector == @selector(saveConfig)) @@ -4294,6 +4297,11 @@ static _H Diversions_; return [Values_ allKeys]; } } +- (void) registerFrame:(DOMHTMLIFrameElement *)iframe { + WebFrame *frame([iframe contentFrame]); + [indirect_ registerFrame:frame]; +} + - (void) _setShowPromoted:(NSNumber *)value { [Metadata_ setObject:value forKey:@"ShowPromoted"]; Changed_ = true; diff --git a/iPhonePrivate.h b/iPhonePrivate.h index 98f86b4e..80aed02f 100644 --- a/iPhonePrivate.h +++ b/iPhonePrivate.h @@ -6,6 +6,7 @@ #include // }}} // #import <*> {{{ +#import #import #import // }}} @@ -413,6 +414,10 @@ extern float const UIScrollViewDecelerationRateNormal; @property(nonatomic,readonly) CGFloat scale; @end +@interface DOMHTMLIFrameElement (IDL) +- (WebFrame *) contentFrame; +@end + // extern *; {{{ extern CFStringRef const kGSDisplayIdentifiersCapability; extern float const UIWebViewGrowsAndShrinksToFitHeight; -- 2.45.2