mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-09-12 05:31:29 +00:00
Key view loop enhancements...
- Nested views are now handled recursively as they are in Cocoa. - Added a nested view test in the test app.
This commit is contained in:
+31
-18
@@ -2853,7 +2853,7 @@ CPTexturedBackgroundWindowMask
|
||||
/*
|
||||
Recursively traverse an array of views (depth last) until we find one that has a next or previous key view set. Return nil if none can be found.
|
||||
|
||||
We don't use _allViews here because it is wasteful to enumerate the entire view hierarchy when we will probably find a key view at the top level.
|
||||
We don't use _viewsSortedByPosition here because it is wasteful to enumerate the entire view hierarchy when we will probably find a key view at the top level.
|
||||
*/
|
||||
- (BOOL)_hasKeyViewLoop:(CPArray)theViews
|
||||
{
|
||||
@@ -2893,12 +2893,40 @@ CPTexturedBackgroundWindowMask
|
||||
|
||||
- (CPArray)_viewsSortedByPosition
|
||||
{
|
||||
var views = [self _allViews];
|
||||
var views = [CPArray arrayWithObject:_contentView];
|
||||
|
||||
views = views.concat([self _subviewsSortedByPosition:[_contentView subviews]]);
|
||||
|
||||
[views sortUsingFunction:keyViewComparator context:nil];
|
||||
return views;
|
||||
}
|
||||
|
||||
- (CPArray)_subviewsSortedByPosition:(CPArray)theSubviews
|
||||
{
|
||||
/*
|
||||
We first sort the subviews according to geometric order.
|
||||
Then we go through each subview, and if it has subviews,
|
||||
they are sorted and inserted after the superview. This
|
||||
is done recursively.
|
||||
*/
|
||||
theSubviews = [theSubviews copy];
|
||||
[theSubviews sortUsingFunction:keyViewComparator context:nil];
|
||||
|
||||
var sortedViews = [];
|
||||
|
||||
for (var i = 0, count = [theSubviews count]; i < count; ++i)
|
||||
{
|
||||
var view = theSubviews[i],
|
||||
subviews = [view subviews];
|
||||
|
||||
sortedViews.push(view);
|
||||
|
||||
if ([subviews count])
|
||||
sortedViews = sortedViews.concat([self _subviewsSortedByPosition:subviews]);
|
||||
}
|
||||
|
||||
return sortedViews;
|
||||
}
|
||||
|
||||
- (void)_doRecalculateKeyViewLoop
|
||||
{
|
||||
var views = [self _viewsSortedByPosition];
|
||||
@@ -3069,21 +3097,6 @@ CPTexturedBackgroundWindowMask
|
||||
[self disableKeyEquivalentForDefaultButton];
|
||||
}
|
||||
|
||||
- (CPArray)_allViews
|
||||
{
|
||||
var contentView = [self contentView],
|
||||
views = [CPArray arrayWithObject:contentView];
|
||||
|
||||
[views addObjectsFromArray:[contentView subviews]];
|
||||
|
||||
// Start from index 1 because index 0 is the contentView
|
||||
// and its subviews have already been added
|
||||
for (var index = 1; index < views.length; ++index)
|
||||
views = views.concat([views[index] subviews]);
|
||||
|
||||
return views;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
var keyViewComparator = function(lhs, rhs, context)
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
{
|
||||
var field = [CPTextField textFieldWithStringValue:@"" placeholder:@"" width:96];
|
||||
|
||||
[field setFrameOrigin:CGPointMake(43, 135)];
|
||||
[field setFrameOrigin:CGPointMake(20, 120)];
|
||||
[[self contentView] addSubview:field];
|
||||
|
||||
[sender setEnabled:NO];
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user