mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-08-25 21:17:03 +00:00
[CPView _isVisible] convenience method.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user