Skip to content

Commit

Permalink
fix webview listener issue and added new test case for webview height…
Browse files Browse the repository at this point in the history
… auto
  • Loading branch information
Jeff Haynie committed Jul 26, 2010
1 parent 3b2531e commit 5404f3b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
9 changes: 8 additions & 1 deletion demos/KitchenSink/Resources/examples/web_views.js
Expand Up @@ -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:'<html><body style="height:200px;width:100px;border:1px solid #ccc;padding:10px">200 px height, 100 px width.</body></html>'});
data.push({title:'Partial Auto', hasChild:true, partial:true, innerHTML:'<html><body><div>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.</div><hr/><div>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.</div></body></html>'});

// this should work on android too, right?
data.push({title:'HTML5 Video', auto:true, hasChild:true, url:'html5video.html'});
Expand Down Expand Up @@ -196,7 +197,13 @@ tableview.addEventListener('click', function(e)
}
});
}


if (rowdata.partial)
{
webview.top = 100;
webview.bottom = 0;
}

w.add(webview);


Expand Down
25 changes: 18 additions & 7 deletions iphone/Classes/AppModule.m
Expand Up @@ -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<TiEvaluator> 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)
Expand All @@ -51,8 +63,6 @@ -(void)addEventListener:(NSArray*)args
[appListeners setObject:l forKey:type];
[l release];
}
id<TiEvaluator> context = [self executionContext]==nil ? [self pageContext] : [self executionContext];
ListenerEntry *entry = [[ListenerEntry alloc] initWithListener:listener context:context proxy:self];
[l addObject:entry];
[entry release];
}
Expand Down Expand Up @@ -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];
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions iphone/Classes/ListenerEntry.h
Expand Up @@ -13,7 +13,10 @@
id listener;
TiProxy *proxy;
BOOL removed;
NSString *type;
}
@property(nonatomic,readwrite,retain) NSString *type;

-(id)initWithListener:(id)listener_ context:(id<TiEvaluator>)context_ proxy:(TiProxy*)proxy;
-(id<TiEvaluator>)context;
-(id)listener;
Expand Down
3 changes: 3 additions & 0 deletions iphone/Classes/ListenerEntry.m
Expand Up @@ -9,6 +9,8 @@

@implementation ListenerEntry

@synthesize type;

-(id)initWithListener:(id)listener_ context:(id<TiEvaluator>)context_ proxy:(TiProxy*)proxy_
{
if (self = [super init])
Expand All @@ -24,6 +26,7 @@ -(id)initWithListener:(id)listener_ context:(id<TiEvaluator>)context_ proxy:(TiP
-(void)dealloc
{
RELEASE_TO_NIL(listener);
RELEASE_TO_NIL(type);
[super dealloc];
}

Expand Down

0 comments on commit 5404f3b

Please sign in to comment.