Teardown and recreate WebView (not the entire controller) on reload.

This commit is contained in:
Corey Johnson
2011-12-14 10:46:57 -08:00
parent fc81baa372
commit 89c00ec8a6
5 changed files with 46 additions and 136 deletions

View File

@@ -12,9 +12,14 @@
@synthesize controllers = _controllers;
- (AtomController *)createController:(NSString *)path {
AtomController *controller = [(AtomController *)[AtomController alloc] initWithURL:path];
AtomController *controller = [[AtomController alloc] initWithURL:path];
[self.controllers addObject:controller];
return controller;
}
- (AtomController *)createSpecController {
AtomController *controller = [[AtomController alloc] initForSpecs];
[self.controllers addObject:controller];
return controller;
}
@@ -23,16 +28,8 @@
[controller.jscocoa callJSFunctionNamed:@"triggerEvent" withArguments:@"window:close", nil, false, nil];
}
- (void)runSpecs {
AtomController *controller = [(AtomController *)[AtomController alloc] initForSpecs];
[self.controllers addObject:controller];
}
- (void)reloadController:(AtomController *)controller {
CGRect frame = [[controller window] frame];
AtomController *newController = [self createController:controller.url];
[controller close];
[[newController window] setFrame:frame display:YES animate:NO];
[controller createWebView];
}
- (void)open:(NSString *)path {

View File

@@ -6,13 +6,15 @@
@interface AtomController : NSWindowController <NSWindowDelegate> {
}
@property (retain) WebView *webView;
@property (assign) WebView *webView;
@property (nonatomic, retain) JSCocoa *jscocoa;
@property (nonatomic, retain, readonly) NSString *url;
@property (nonatomic, retain, readonly) NSString *bootstrapPage;
@property (nonatomic, retain, readonly) NSString *bootstrapScript;
- (id)initForSpecs;
- (AtomController *)initWithURL:(NSString *)url;
- (id)initWithURL:(NSString *)url;
- (void)createWebView;
@end

View File

@@ -7,7 +7,7 @@
@interface AtomController ()
@property (nonatomic, retain, readwrite) NSString *url;
@property (nonatomic, retain, readwrite) NSString *bootstrapPage;
@property (nonatomic, retain, readwrite) NSString *bootstrapScript;
@end
@@ -17,36 +17,54 @@
webView = _webView,
jscocoa = _jscocoa,
url = _url,
bootstrapPage = _bootstrapPage;
bootstrapScript = _bootstrapScript;
- (void)dealloc {
[self.jscocoa unlinkAllReferences];
[self.jscocoa garbageCollect];
self.jscocoa = nil;
self.webView = nil;
self.bootstrapPage = nil;
self.webView = nil;;
self.bootstrapScript = nil;
self.url = nil;
[super dealloc];
}
- (id)initWithBootstrapPage:(NSString *)bootstrapPage url:(NSString *)url {
- (id)initWithBootstrapScript:(NSString *)bootstrapScript url:(NSString *)url {
self = [super initWithWindowNibName:@"AtomWindow"];
self.bootstrapPage = bootstrapPage;
self.bootstrapScript = bootstrapScript;
self.url = url;
[self.window makeKeyWindow];
return self;
}
- (id)initForSpecs {
return [self initWithBootstrapPage:@"spec-suite.html" url:nil];
- (id)initSpecs {
return [self initWithBootstrapScript:@"spec-startup" url:nil];
}
- (id)initWithURL:(NSString *)url {
return [self initWithBootstrapPage:@"index.html" url:url];
return [self initWithBootstrapScript:@"startup" url:url];
}
- (void)createWebView {
[self.webView removeFromSuperview];
self.webView = [[WebView alloc] initWithFrame:[self.window.contentView frame]];
[self.webView setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
[self.window.contentView addSubview:self.webView];
[self.webView setUIDelegate:self];
self.jscocoa = [[JSCocoa alloc] initWithGlobalContext:[[self.webView mainFrame] globalContext]];
[self.jscocoa setObject:self withName:@"$atomController"];
[self.jscocoa setObject:self.bootstrapScript withName:@"$bootstrapScript"];
NSURL *resourceDirURL = [[NSBundle mainBundle] resourceURL];
NSURL *indexURL = [resourceDirURL URLByAppendingPathComponent:@"index.html"];
NSURLRequest *request = [NSURLRequest requestWithURL:indexURL];
[[self.webView mainFrame] loadRequest:request];
}
- (void)windowDidLoad {
@@ -55,22 +73,12 @@
[self.window setDelegate:self];
[self.window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
[self.webView setUIDelegate:self];
[self setShouldCascadeWindows:YES];
[self setWindowFrameAutosaveName:@"atomController"];
self.jscocoa = [[JSCocoa alloc] initWithGlobalContext:[[self.webView mainFrame] globalContext]];
[self.jscocoa setObject:self withName:@"$atomController"];
NSURL *resourceURL = [[NSBundle mainBundle] resourceURL];
NSURL *bootstrapPageURL = [resourceURL URLByAppendingPathComponent:self.bootstrapPage];
NSURLRequest *request = [NSURLRequest requestWithURL:bootstrapPageURL];
[[self.webView mainFrame] loadRequest:request];
[self createWebView];
}
- (void)close {
[(AtomApp *)NSApp removeController:self];
[super close];

View File

@@ -7,29 +7,18 @@
<string key="IBDocument.AppKitVersion">1138.23</string>
<string key="IBDocument.HIToolboxVersion">567.00</string>
<object class="NSMutableDictionary" key="IBDocument.PluginVersions">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.WebKitIBPlugin</string>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>1938</string>
<string>822</string>
</object>
<string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="NS.object.0">1938</string>
</object>
<object class="NSArray" key="IBDocument.IntegratedClassDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>NSWindowTemplate</string>
<string>NSView</string>
<string>NSCustomObject</string>
<string>WebView</string>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.WebKitIBPlugin</string>
</object>
<object class="NSMutableDictionary" key="IBDocument.Metadata">
<string key="NS.key.0">PluginDependencyRecalculationVersion</string>
@@ -58,62 +47,10 @@
<object class="NSView" key="NSWindowView" id="610964987">
<reference key="NSNextResponder"/>
<int key="NSvFlags">256</int>
<object class="NSMutableArray" key="NSSubviews">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="WebView" id="615135301">
<reference key="NSNextResponder" ref="610964987"/>
<int key="NSvFlags">274</int>
<object class="NSMutableSet" key="NSDragTypes">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSArray" key="set.sortedObjects">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>Apple HTML pasteboard type</string>
<string>Apple PDF pasteboard type</string>
<string>Apple PICT pasteboard type</string>
<string>Apple URL pasteboard type</string>
<string>Apple Web Archive pasteboard type</string>
<string>NSColor pasteboard type</string>
<string>NSFilenamesPboardType</string>
<string>NSStringPboardType</string>
<string>NeXT RTFD pasteboard type</string>
<string>NeXT Rich Text Format v1.0 pasteboard type</string>
<string>NeXT TIFF v4.0 pasteboard type</string>
<string>WebURLsWithTitlesPboardType</string>
<string>public.png</string>
<string>public.url</string>
<string>public.url-name</string>
</object>
</object>
<string key="NSFrameSize">{725, 723}</string>
<reference key="NSSuperview" ref="610964987"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView"/>
<string key="FrameName"/>
<string key="GroupName"/>
<object class="WebPreferences" key="Preferences">
<string key="Identifier">atomController</string>
<object class="NSMutableDictionary" key="Values">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>atomControllerWebKitJavaEnabled</string>
<string>atomControllerWebKitPluginsEnabled</string>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<boolean value="NO"/>
<boolean value="NO"/>
</object>
</object>
</object>
<bool key="UseBackForwardList">NO</bool>
<bool key="AllowsUndo">YES</bool>
</object>
</object>
<string key="NSFrameSize">{725, 723}</string>
<reference key="NSSuperview"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="615135301"/>
<reference key="NSNextKeyView"/>
</object>
<string key="NSScreenRect">{{0, 0}, {1440, 878}}</string>
<string key="NSMaxSize">{10000000000000, 10000000000000}</string>
@@ -124,14 +61,6 @@
<object class="IBObjectContainer" key="IBDocument.Objects">
<object class="NSMutableArray" key="connectionRecords">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBConnectionRecord">
<object class="IBOutletConnection" key="connection">
<string key="label">webView</string>
<reference key="source" ref="1001"/>
<reference key="destination" ref="615135301"/>
</object>
<int key="connectionID">6</int>
</object>
<object class="IBConnectionRecord">
<object class="IBOutletConnection" key="connection">
<string key="label">window</string>
@@ -184,15 +113,9 @@
<reference key="object" ref="610964987"/>
<object class="NSMutableArray" key="children">
<bool key="EncodedWithXMLCoder">YES</bool>
<reference ref="615135301"/>
</object>
<reference key="parent" ref="773759719"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">5</int>
<reference key="object" ref="615135301"/>
<reference key="parent" ref="610964987"/>
</object>
</object>
</object>
<object class="NSMutableDictionary" key="flattenedProperties">
@@ -206,7 +129,6 @@
<string>3.IBWindowTemplateEditedContentRect</string>
<string>3.NSWindowTemplate.visibleAtLaunch</string>
<string>4.IBPluginDependency</string>
<string>5.IBPluginDependency</string>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -217,7 +139,6 @@
<string>{{324, 121}, {725, 723}}</string>
<integer value="1"/>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.WebKitIBPlugin</string>
</object>
</object>
<object class="NSMutableDictionary" key="unlocalizedProperties">
@@ -245,24 +166,6 @@
<string key="minorKey">./Classes/AtomController.h</string>
</object>
</object>
<object class="IBPartialClassDescription">
<string key="className">WebView</string>
<object class="NSMutableDictionary" key="actions">
<string key="NS.key.0">reloadFromOrigin:</string>
<string key="NS.object.0">id</string>
</object>
<object class="NSMutableDictionary" key="actionInfosByName">
<string key="NS.key.0">reloadFromOrigin:</string>
<object class="IBActionInfo" key="NS.object.0">
<string key="name">reloadFromOrigin:</string>
<string key="candidateClassName">id</string>
</object>
</object>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
<string key="minorKey">./Classes/WebView.h</string>
</object>
</object>
</object>
</object>
<int key="IBDocument.localizationMode">0</int>

View File

@@ -13,7 +13,7 @@
<script src='src/stdlib/require.js'></script>
<script>
window.onload = function() {
require('startup');
require($bootstrapScript);
}
</script>