[CPView _isVisible] convenience method.

This commit is contained in:
Alexander Ljungberg
2011-05-09 14:37:54 -04:00
parent 1e49072763
commit d5f281320f
2 changed files with 38 additions and 0 deletions
+8
View File
@@ -1284,6 +1284,14 @@ var CPViewFlags = { },
return view !== nil;
}
/*!
Returns YES if the view is not hidden, has no hidden ancestor and doesn't belong to a hidden window.
*/
- (BOOL)_isVisible
{
return ![self isHiddenOrHasHiddenAncestor] && [[self window] isVisible];
}
/*!
Called when the return value of isHiddenOrHasHiddenAncestor becomes YES,
e.g. when this view becomes hidden due to a setHidden:YES message to
+30
View File
@@ -73,4 +73,34 @@
[self assertFalse:[view hasThemeAttribute:@"foobar"] message:[view className] + " should not have theme attribute \"" + firstKey + "\""];
}
- (void)testIsVisible
{
[self assertFalse:[view _isVisible] message:"view must belong to a window to be visible"];
var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask],
contentView = [theWindow contentView];
[self assertFalse:[contentView _isVisible] message:"view must belong to a visible window to be visible"];
[theWindow orderFront:self];
// Fake this because we don't have the DOM in unit tests.
[theWindow._isVisible = YES];
[self assertTrue:[contentView _isVisible] message:"view is the content view of a visible window, hence visible"];
[self assertFalse:[view _isVisible] message:"view must belong to a window to be visible"];
[contentView addSubview:view];
[self assertTrue:[view _isVisible] message:"view is a subview of a visible content view, hence visible"];
[view setHidden:YES];
[self assertFalse:[view _isVisible] message:"view is hidden"];
[view setHidden:NO];
[self assertTrue:[view _isVisible] message:"view is not hidden again"];
[contentView setHidden:YES];
[self assertFalse:[view _isVisible] message:"a superview is hidden"];
[contentView setHidden:NO];
[contentView removeFromSuperview];
[self assertFalse:[view _isVisible] message:"a superview does not belong to a visible window"];
}
@end