From 5404f3b281e7bef9a4391215d64aaeb351609b08 Mon Sep 17 00:00:00 2001 From: Jeff Haynie Date: Mon, 26 Jul 2010 11:35:45 -0700 Subject: [PATCH] fix webview listener issue and added new test case for webview height auto --- .../Resources/examples/web_views.js | 9 ++++++- iphone/Classes/AppModule.m | 25 +++++++++++++------ iphone/Classes/ListenerEntry.h | 3 +++ iphone/Classes/ListenerEntry.m | 3 +++ 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/demos/KitchenSink/Resources/examples/web_views.js b/demos/KitchenSink/Resources/examples/web_views.js index 5a48cd70481..f283c5e0ae3 100644 --- a/demos/KitchenSink/Resources/examples/web_views.js +++ b/demos/KitchenSink/Resources/examples/web_views.js @@ -29,6 +29,7 @@ if (Titanium.Platform.name == 'iPhone OS') // The result for this is going to be centered, because that's where layout puts it. // But users can make sure that embedded webviews are anchored in the usual way. data.push({title:'Auto Size', auto:true, hasChild:true, innerHTML:'200 px height, 100 px width.'}); + data.push({title:'Partial Auto', hasChild:true, partial:true, innerHTML:'
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
'}); // this should work on android too, right? data.push({title:'HTML5 Video', auto:true, hasChild:true, url:'html5video.html'}); @@ -196,7 +197,13 @@ tableview.addEventListener('click', function(e) } }); } - + + if (rowdata.partial) + { + webview.top = 100; + webview.bottom = 0; + } + w.add(webview); diff --git a/iphone/Classes/AppModule.m b/iphone/Classes/AppModule.m index d35b9098657..ba49ce5b78c 100644 --- a/iphone/Classes/AppModule.m +++ b/iphone/Classes/AppModule.m @@ -35,14 +35,26 @@ -(void)dealloc -(void)addEventListener:(NSArray*)args { NSString *type = [args objectAtIndex:0]; - KrollCallback* listener = [args objectAtIndex:1]; + id listener = [args objectAtIndex:1]; if (appListeners==nil) { appListeners = [[NSMutableDictionary alloc] init]; } - listener.type = type; + id context = [self executionContext]==nil ? [self pageContext] : [self executionContext]; + ListenerEntry *entry = [[ListenerEntry alloc] initWithListener:listener context:context proxy:self]; + + + if ([listener isKindOfClass:[KrollCallback class]]) + { + ((KrollCallback*)listener).type = type; + } + else + { + entry.type = type; + } + NSMutableArray *l = [appListeners objectForKey:type]; if (l==nil) @@ -51,8 +63,6 @@ -(void)addEventListener:(NSArray*)args [appListeners setObject:l forKey:type]; [l release]; } - id context = [self executionContext]==nil ? [self pageContext] : [self executionContext]; - ListenerEntry *entry = [[ListenerEntry alloc] initWithListener:listener context:context proxy:self]; [l addObject:entry]; [entry release]; } @@ -227,15 +237,16 @@ -(void)willShutdownContext:(NSNotification*)note { if ([entry context] == context) { - [found addObject:[entry listener]]; + [found addObject:[NSArray + arrayWithObjects:[entry type],[entry listener],nil]]; } } } if ([found count]>0) { - for (KrollCallback *callback in found) + for (NSArray *a in found) { - [self removeEventListener:[NSArray arrayWithObjects:callback.type,callback,nil]]; + [self removeEventListener:a]; } } } diff --git a/iphone/Classes/ListenerEntry.h b/iphone/Classes/ListenerEntry.h index 2a5ca0dfe12..b6dada904dd 100644 --- a/iphone/Classes/ListenerEntry.h +++ b/iphone/Classes/ListenerEntry.h @@ -13,7 +13,10 @@ id listener; TiProxy *proxy; BOOL removed; + NSString *type; } +@property(nonatomic,readwrite,retain) NSString *type; + -(id)initWithListener:(id)listener_ context:(id)context_ proxy:(TiProxy*)proxy; -(id)context; -(id)listener; diff --git a/iphone/Classes/ListenerEntry.m b/iphone/Classes/ListenerEntry.m index dc93480124a..85a4360df55 100644 --- a/iphone/Classes/ListenerEntry.m +++ b/iphone/Classes/ListenerEntry.m @@ -9,6 +9,8 @@ @implementation ListenerEntry +@synthesize type; + -(id)initWithListener:(id)listener_ context:(id)context_ proxy:(TiProxy*)proxy_ { if (self = [super init]) @@ -24,6 +26,7 @@ -(id)initWithListener:(id)listener_ context:(id)context_ proxy:(TiP -(void)dealloc { RELEASE_TO_NIL(listener); + RELEASE_TO_NIL(type); [super dealloc]; }