From 01ba6ddecd9d33e5ad84c6ecc7be59cd7d56097f Mon Sep 17 00:00:00 2001 From: Alexandre Wilhelm Date: Tue, 7 Apr 2015 17:40:26 -0700 Subject: [PATCH] Fixed: floating windows did not become keyWindow and mainWindow of the application when jumping from platformWindow to another platformWindow Previously, when having several platformWindows, jumping from another platform to another platform did not update the good key window of the application, specially when the expected windows was a panel. Now it does. The CPPlatformWindow keeps a reference to the previous keyWindow when the window browser is about to blur. The we use this reference to update the keyWindow of the application. --- AppKit/CPWindow/CPWindow.j | 1 + AppKit/Platform/CPPlatformWindow.j | 3 +++ AppKit/Platform/DOM/CPPlatformWindow+DOM.j | 22 +++++++++------------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/AppKit/CPWindow/CPWindow.j b/AppKit/CPWindow/CPWindow.j index 9b6dde66b..4bef16ced 100644 --- a/AppKit/CPWindow/CPWindow.j +++ b/AppKit/CPWindow/CPWindow.j @@ -2060,6 +2060,7 @@ CPTexturedBackgroundWindowMask [self _setupFirstResponder]; _hasBecomeKeyWindow = YES; + _platformWindow._currentKeyWindow = self; [_windowView noteKeyWindowStateChanged]; [_contentView _notifyWindowDidBecomeKey]; diff --git a/AppKit/Platform/CPPlatformWindow.j b/AppKit/Platform/CPPlatformWindow.j index cd17fa4a6..41818b13f 100644 --- a/AppKit/Platform/CPPlatformWindow.j +++ b/AppKit/Platform/CPPlatformWindow.j @@ -75,6 +75,9 @@ var PrimaryPlatformWindow = NULL; CPPlatformPasteboard _platformPasteboard; CPString _overriddenEventType; + + CPWindow _currentKeyWindow; + CPWindow _previousKeyWindow; #endif } diff --git a/AppKit/Platform/DOM/CPPlatformWindow+DOM.j b/AppKit/Platform/DOM/CPPlatformWindow+DOM.j index 52a1484ed..6a54d78e7 100644 --- a/AppKit/Platform/DOM/CPPlatformWindow+DOM.j +++ b/AppKit/Platform/DOM/CPPlatformWindow+DOM.j @@ -1057,10 +1057,10 @@ _CPPlatformWindowWillCloseNotification = @"_CPPlatformWindowWillCloseNotificatio */ - (void)blurEvent:(DOMEvent)aDOMEvent { - var location = _lastMouseEventLocation || CGPointMakeZero(), - theWindow = [self _hitTest:location withTest:@selector(_isValidMousePoint:) returnsDefaultWindowIfNull:YES]; + _previousKeyWindow = _currentKeyWindow; + [_previousKeyWindow resignKeyWindow]; - [theWindow resignKeyWindow]; + [[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode]; } /*! @@ -1068,10 +1068,14 @@ _CPPlatformWindowWillCloseNotification = @"_CPPlatformWindowWillCloseNotificatio */ - (void)focusEvent:(DOMEvent)aDOMEvent { - var location = _lastMouseEventLocation || CGPointMakeZero(), - theWindow = [self _hitTest:location withTest:@selector(_isValidMousePoint:) returnsDefaultWindowIfNull:YES]; + var theWindow = _previousKeyWindow; + + if (!theWindow) + theWindow = [[[_windowLayers objectForKey:[_windowLevels firstObject]] orderedWindows] firstObject]; [theWindow makeKeyAndOrderFront:self]; + + [[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode]; } - (void)touchEvent:(DOMEvent)aDOMEvent @@ -1560,11 +1564,6 @@ _CPPlatformWindowWillCloseNotification = @"_CPPlatformWindowWillCloseNotificatio } - (CPWindow)_hitTest:(CGPoint)location withTest:(SEL)aTest -{ - return [self _hitTest:location withTest:aTest returnsDefaultWindowIfNull:NO]; -} - -- (CPWindow)_hitTest:(CGPoint)location withTest:(SEL)aTest returnsDefaultWindowIfNull:(BOOL)returnsDefaultWindowIfNull { if (self._only) return self._only; @@ -1588,9 +1587,6 @@ _CPPlatformWindowWillCloseNotification = @"_CPPlatformWindowWillCloseNotificatio } } - if (!theWindow && returnsDefaultWindowIfNull) - theWindow = [[[layers objectForKey:[levels firstObject]] orderedWindows] firstObject]; - return theWindow; }