NEW: Closing a platform window will correctly close its main CPWindow

Previously, when closing a platform window using the browser close
button, the represented `CPWindow` was not correctly closed.

This patch ensure `-(void)close` is called correctly by using the DOM
`unload` event. Also, delegate method `- (void)windowWillClose:` is
correctly called.
This commit is contained in:
Antoine Mercadal
2015-03-10 16:35:03 -07:00
parent 14349cb583
commit 1dc060123d
5 changed files with 104 additions and 35 deletions
+15
View File
@@ -959,6 +959,11 @@ CPTexturedBackgroundWindowMask
*/
- (void)_windowWillBeAddedToTheDOM
{
[[CPNotificationCenter defaultCenter] addObserver:self
selector:@selector(_didReceivePlatformWindowWillCloseNotification:)
name:_CPPlatformWindowWillCloseNotification
object:_platformWindow];
[[self contentView] _addObservers];
}
@@ -967,6 +972,8 @@ CPTexturedBackgroundWindowMask
*/
- (void)_windowWillBeRemovedFromTheDOM
{
[[CPNotificationCenter defaultCenter] removeObserver:self name:_CPPlatformWindowWillCloseNotification object:nil];
[[self contentView] _removeObservers];
}
@@ -3368,6 +3375,14 @@ CPTexturedBackgroundWindowMask
[super setValue:aValue forKey:aKey];
}
- (void)_didReceivePlatformWindowWillCloseNotification:(CPNotification)aNotification
{
if ([aNotification object] != _platformWindow)
return;
[self close];
}
@end
var keyViewComparator = function(lhs, rhs, context)
+16 -4
View File
@@ -203,6 +203,9 @@ var ModifierKeyCodes = [
var resizeTimer = nil;
var PreventScroll = true;
_CPPlatformWindowWillCloseNotification = @"_CPPlatformWindowWillCloseNotification";
// When scrolling with an old-style scroll wheel with discete steps ('clicks'), the scroll amount can indicate how many "lines" to
// scroll.
#define SCROLLWHEEL_LINE_PIXELS 6.0
@@ -429,6 +432,9 @@ var PreventScroll = true;
_DOMWindow.addEventListener("unload", function()
{
_DOMWindow.removeEventListener("unload", arguments.callee, NO);
[self _notifyPlatformWindowWillClose];
[self updateFromNativeContentRect];
[self _removeLayers];
@@ -452,8 +458,6 @@ var PreventScroll = true;
_DOMWindow.removeEventListener("wheel", scrollEventCallback, NO);
_DOMWindow.removeEventListener("mousewheel", scrollEventCallback, NO);
//_DOMWindow.removeEventListener("beforeunload", this, NO);
[PlatformWindows removeObject:self];
[_platformPasteboard setDOMWindow:nil];
@@ -483,6 +487,9 @@ var PreventScroll = true;
_DOMWindow.attachEvent("onunload", function()
{
_DOMWindow.detachEvent("unload", arguments.callee);
[self _notifyPlatformWindowWillClose];
[self updateFromNativeContentRect];
[self _removeLayers];
@@ -504,8 +511,6 @@ var PreventScroll = true;
_DOMBodyElement.ondrag = NULL;
_DOMBodyElement.onselectstart = NULL;
//_DOMWindow.removeEvent("beforeunload", this);
[PlatformWindows removeObject:self];
[_platformPasteboard setDOMWindow:nil];
@@ -1632,6 +1637,13 @@ var PreventScroll = true;
KeyCodesToPrevent = {};
}
- (void)_notifyPlatformWindowWillClose
{
[[CPNotificationCenter defaultCenter] postNotificationName:_CPPlatformWindowWillCloseNotification
object:self
userInfo:nil];
}
@end
#endif
+51 -6
View File
@@ -13,7 +13,7 @@
@implementation AppController : CPObject
{
@outlet CPWindow theWindow;
@outlet CPWindow windowPlatformWindow;
@outlet CPWindow externalWindow;
CPPlatformWindow platformWindow;
@@ -22,7 +22,8 @@
- (void)applicationDidFinishLaunching:(CPNotification)aNotification
{
// This is called when the application is done loading.
[[CPPlatformWindow alloc] initWithWindow:windowPlatformWindow];
[[CPPlatformWindow alloc] initWithWindow:externalWindow];
[externalWindow setDelegate:self];
}
- (void)awakeFromCib
@@ -37,23 +38,67 @@
- (IBAction)showWindow:(id)sender
{
[windowPlatformWindow orderFront:sender];
[externalWindow orderFront:sender];
}
- (IBAction)closeWindow:(id)sender
{
[windowPlatformWindow orderOut:sender];
[externalWindow orderOut:sender];
}
- (IBAction)changeFrame:(id)sender
{
[windowPlatformWindow setFrame:CGRectMake(250, 250, 200, 200)];
[externalWindow setFrame:CGRectMake(250, 250, 200, 200)];
}
- (IBAction)showAlert:(id)sender
{
var alert = [CPAlert alertWithMessageText:@"rer" defaultButton:"OK" alternateButton:nil otherButton:nil informativeTextWithFormat:"Multiple login failures may result in blocked access to the system."];
[alert beginSheetModalForWindow:windowPlatformWindow];
[alert beginSheetModalForWindow:externalWindow];
}
#pragma mark -
#pragma mark Delegate
- (void)windowDidBecomeKey:(CPNotification)aNotification
{
CPLog.debug("windowDidBecomeKey:");
}
- (void)windowDidBecomeMain:(CPNotification)aNotification
{
CPLog.debug("windowDidBecomeMain:");
}
- (void)windowDidEndSheet:(CPNotification)aNotification
{
CPLog.debug("windowDidEndSheet:");
}
- (void)windowDidMove:(CPNotification)aNotification
{
CPLog.debug("windowDidMove:");
}
- (void)windowDidResignKey:(CPNotification)aNotification
{
CPLog.debug("windowDidResignKey:");
}
- (void)windowDidResignMain:(CPNotification)aNotification
{
CPLog.debug("windowDidResignMain:");
}
- (void)windowDidResize:(CPNotification)aNotification
{
CPLog.debug("windowDidResize:");
}
- (void)windowWillClose:(CPWindow)aWindow
{
CPLog.debug("windowWillClose:");
}
@end
File diff suppressed because one or more lines are too long
@@ -2,13 +2,13 @@
<archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="8.00">
<data>
<int key="IBDocument.SystemTarget">1050</int>
<string key="IBDocument.SystemVersion">14A389</string>
<string key="IBDocument.InterfaceBuilderVersion">6250</string>
<string key="IBDocument.AppKitVersion">1343.14</string>
<string key="IBDocument.HIToolboxVersion">755.00</string>
<string key="IBDocument.SystemVersion">14D87h</string>
<string key="IBDocument.InterfaceBuilderVersion">6751</string>
<string key="IBDocument.AppKitVersion">1347.23</string>
<string key="IBDocument.HIToolboxVersion">758.40</string>
<object class="NSMutableDictionary" key="IBDocument.PluginVersions">
<string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="NS.object.0">6250</string>
<string key="NS.object.0">6751</string>
</object>
<array key="IBDocument.IntegratedClassDependencies">
<string>NSButton</string>
@@ -704,7 +704,6 @@
<string key="NSFrame">{{25, 215}, {131, 32}}</string>
<reference key="NSSuperview" ref="439893737"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<bool key="NSEnabled">YES</bool>
<object class="NSButtonCell" key="NSCell" id="791299498">
@@ -729,7 +728,7 @@
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="1038331095"/>
</object>
<string key="NSScreenRect">{{0, 0}, {1440, 877}}</string>
<string key="NSScreenRect">{{0, 0}, {1440, 900}}</string>
<string key="NSMaxSize">{10000000000000, 10000000000000}</string>
<bool key="NSWindowIsRestorable">YES</bool>
</object>
@@ -805,7 +804,6 @@
<string key="NSFrame">{{353, 199}, {107, 32}}</string>
<reference key="NSSuperview" ref="989016706"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<bool key="NSEnabled">YES</bool>
<object class="NSButtonCell" key="NSCell" id="82365316">
@@ -828,10 +826,9 @@
<string key="NSFrameSize">{562, 270}</string>
<reference key="NSSuperview"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView"/>
<string key="NSReuseIdentifierKey">_NS:20</string>
</object>
<string key="NSScreenRect">{{0, 0}, {1440, 877}}</string>
<string key="NSScreenRect">{{0, 0}, {1440, 900}}</string>
<string key="NSMaxSize">{10000000000000, 10000000000000}</string>
<bool key="NSWindowIsRestorable">YES</bool>
</object>
@@ -1158,14 +1155,6 @@
</object>
<int key="connectionID">478</int>
</object>
<object class="IBConnectionRecord">
<object class="IBOutletConnection" key="connection">
<string key="label">windowPlatformWindow</string>
<reference key="source" ref="635946545"/>
<reference key="destination" ref="223875758"/>
</object>
<int key="connectionID">480</int>
</object>
<object class="IBConnectionRecord">
<object class="IBActionConnection" key="connection">
<string key="label">showAlert:</string>
@@ -1174,6 +1163,14 @@
</object>
<int key="connectionID">484</int>
</object>
<object class="IBConnectionRecord">
<object class="IBOutletConnection" key="connection">
<string key="label">externalWindow</string>
<reference key="source" ref="635946545"/>
<reference key="destination" ref="223875758"/>
</object>
<int key="connectionID">486</int>
</object>
</array>
<object class="IBMutableOrderedSet" key="objectRecords">
<array key="orderedObjects">
@@ -1862,7 +1859,7 @@
<nil key="activeLocalization"/>
<dictionary class="NSMutableDictionary" key="localizations"/>
<nil key="sourceID"/>
<int key="maxID">484</int>
<int key="maxID">486</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<array class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -1894,16 +1891,16 @@
</object>
</dictionary>
<dictionary class="NSMutableDictionary" key="outlets">
<string key="externalWindow">NSWindow</string>
<string key="theWindow">NSWindow</string>
<string key="windowPlatformWindow">NSWindow</string>
</dictionary>
<dictionary class="NSMutableDictionary" key="toOneOutletInfosByName">
<object class="IBToOneOutletInfo" key="theWindow">
<string key="name">theWindow</string>
<object class="IBToOneOutletInfo" key="externalWindow">
<string key="name">externalWindow</string>
<string key="candidateClassName">NSWindow</string>
</object>
<object class="IBToOneOutletInfo" key="windowPlatformWindow">
<string key="name">windowPlatformWindow</string>
<object class="IBToOneOutletInfo" key="theWindow">
<string key="name">theWindow</string>
<string key="candidateClassName">NSWindow</string>
</object>
</dictionary>