diff --git a/AppKit/CPView.j b/AppKit/CPView.j index 14bb9c413..894cb547b 100644 --- a/AppKit/CPView.j +++ b/AppKit/CPView.j @@ -324,7 +324,10 @@ var DOMElementPrototype = nil, { // We will have to adjust the z-index of all views starting at this index. var count = _subviews.length; - + + // dirty the key view loop, in case the window wants to auto recalculate it + [[self window] _dirtyKeyViewLoop]; + // If this is already one of our subviews, remove it. if (aSubview._superview == self) { @@ -403,6 +406,9 @@ var DOMElementPrototype = nil, if (!_superview) return; + // dirty the key view loop, in case the window wants to auto recalculate it + [[self window] _dirtyKeyViewLoop]; + [_superview willRemoveSubview:self]; [[_superview subviews] removeObject:self]; @@ -438,6 +444,8 @@ var DOMElementPrototype = nil, if (_window === aWindow) return; + [[self window] _dirtyKeyViewLoop]; + // Clear out first responder if we're the first responder and leaving. if ([_window firstResponder] === self) [_window makeFirstResponder:nil]; @@ -461,6 +469,8 @@ var DOMElementPrototype = nil, [_subviews[count] _setWindow:aWindow]; [self viewDidMoveToWindow]; + + [[self window] _dirtyKeyViewLoop]; } /*! diff --git a/AppKit/CPWindow/CPWindow.j b/AppKit/CPWindow/CPWindow.j index d01a069a4..73bf4172f 100644 --- a/AppKit/CPWindow/CPWindow.j +++ b/AppKit/CPWindow/CPWindow.j @@ -279,6 +279,9 @@ var CPWindowSaveImage = nil, CPButton _defaultButton; BOOL _defaultButtonEnabled; + BOOL _autorecalculatesKeyViewLoop; + BOOL _keyViewLoopIsDirty; + // Bridge Support #if PLATFORM(DOM) DOMElement _DOMElement; @@ -1714,6 +1717,51 @@ CPTexturedBackgroundWindowMask [self selectNextKeyView:nil]; } +- (void)_dirtyKeyViewLoop +{ + _keyViewLoopIsDirty = YES; +} + +- (void)recalculateKeyViewLoop +{ + var subviews = []; + + [self _appendSubviewsOf:_contentView toArray:subviews]; + + var keyViewOrder = [subviews sortedArrayUsingFunction:keyViewComparator context:_contentView], + count = [keyViewOrder count]; + + for (var i=0; i