diff --git a/AppKit/CPView.j b/AppKit/CPView.j index f03282cdc..fd1576753 100644 --- a/AppKit/CPView.j +++ b/AppKit/CPView.j @@ -2961,6 +2961,25 @@ setBoundsOrigin: while (count--) [_subviews[count] _notifyViewDidResignFirstResponder]; } + +- (void)_notifyWindowDidBecomeKey +{ + [self setThemeState:CPThemeStateKeyWindow]; + + var count = [_subviews count]; + while (count--) + [_subviews[count] _notifyWindowDidBecomeKey]; +} + +- (void)_notifyWindowDidResignKey +{ + [self unsetThemeState:CPThemeStateKeyWindow]; + + var count = [_subviews count]; + while (count--) + [_subviews[count] _notifyWindowDidResignKey]; +} + #pragma mark Theme Attributes + (CPString)defaultThemeClass diff --git a/AppKit/CPWindow/CPWindow.j b/AppKit/CPWindow/CPWindow.j index 4066e28f5..86cfa393d 100644 --- a/AppKit/CPWindow/CPWindow.j +++ b/AppKit/CPWindow/CPWindow.j @@ -1965,6 +1965,7 @@ CPTexturedBackgroundWindowMask _hasBecomeKeyWindow = YES; [_windowView noteKeyWindowStateChanged]; + [_contentView _notifyWindowDidBecomeKey]; [[CPNotificationCenter defaultCenter] postNotificationName:CPWindowDidBecomeKeyNotification @@ -2033,6 +2034,7 @@ CPTexturedBackgroundWindowMask CPApp._keyWindow = nil; [_windowView noteKeyWindowStateChanged]; + [_contentView _notifyWindowDidResignKey]; [[CPNotificationCenter defaultCenter] postNotificationName:CPWindowDidResignKeyNotification diff --git a/Tests/AppKit/CPViewTest.j b/Tests/AppKit/CPViewTest.j index aefd611a0..8d23e379c 100644 --- a/Tests/AppKit/CPViewTest.j +++ b/Tests/AppKit/CPViewTest.j @@ -244,6 +244,7 @@ [self assertTrue:CGPointEqualToPoint(CGPointMake(4, 6), [subView0 convertPoint:CGPointMake(7, 11) fromView:tView0])] } + + (CPArray)createResponderView:(/*@ref */CPView)viewOut siblingView:(/*@ref */CPView)siblingViewOut inWindow:(/*@ref */CPWindow)windowOut { var aView = [CPResponderView new], @@ -392,6 +393,31 @@ [self assertFalse:[subview hasThemeState:CPThemeStateFirstResponder]]; } +- (void)testWhenAndOnlyWhenWindowIsKeyEveryViewShouldHaveThemeStateKeyWindow +{ + var aView, siblingView, aWindow; + [CPViewTest createResponderView:@ref(aView) siblingView:@ref(siblingView) inWindow:@ref(aWindow)]; + + var subview = [CPView new]; + [aView addSubview:subview]; + + var aView2, siblingView2, aWindow2; + [CPViewTest createResponderView:@ref(aView2) siblingView:@ref(siblingView2) inWindow:@ref(aWindow2)]; + + [aWindow makeKeyWindow]; + [self assertTrue:[aView hasThemeState:CPThemeStateKeyWindow]]; + [self assertTrue:[siblingView hasThemeState:CPThemeStateKeyWindow]]; + [self assertTrue:[subview hasThemeState:CPThemeStateKeyWindow]]; + [self assertFalse:[aView2 hasThemeState:CPThemeStateKeyWindow]]; + [self assertFalse:[siblingView2 hasThemeState:CPThemeStateKeyWindow]]; + + [aWindow2 makeKeyWindow]; + [self assertFalse:[aView hasThemeState:CPThemeStateKeyWindow]]; + [self assertFalse:[siblingView hasThemeState:CPThemeStateKeyWindow]]; + [self assertFalse:[subview hasThemeState:CPThemeStateKeyWindow]]; + [self assertTrue:[aView2 hasThemeState:CPThemeStateKeyWindow]]; + [self assertTrue:[siblingView2 hasThemeState:CPThemeStateKeyWindow]]; +} @end