mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-09-14 22:51:28 +00:00
support for autorecalculateskeyviewloop
This commit is contained in:
+11
-1
@@ -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];
|
||||
}
|
||||
|
||||
/*!
|
||||
|
||||
@@ -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<count; i++)
|
||||
[keyViewOrder[i] setNextKeyView:keyViewOrder[(i+1)%count]];
|
||||
|
||||
_keyViewLoopIsDirty = NO;
|
||||
}
|
||||
|
||||
- (void)_appendSubviewsOf:(CPView)aView toArray:(CPArray)anArray
|
||||
{
|
||||
var subviews = [aView subviews],
|
||||
count = [subviews count];
|
||||
|
||||
while (count--)
|
||||
[self _appendSubviewsOf:subviews[count] toArray:anArray];
|
||||
|
||||
[anArray addObject:aView];
|
||||
}
|
||||
|
||||
- (void)setAutorecalculatesKeyViewLoop:(BOOL)shouldRecalculate
|
||||
{
|
||||
if (_autorecalculatesKeyViewLoop === shouldRecalculate)
|
||||
return;
|
||||
|
||||
_autorecalculatesKeyViewLoop = shouldRecalculate;
|
||||
_keyViewLoopIsDirty = YES;
|
||||
}
|
||||
|
||||
- (BOOL)autorecalculatesKeyViewLoop
|
||||
{
|
||||
return _autorecalculatesKeyViewLoop;
|
||||
}
|
||||
|
||||
- (void)selectNextKeyView:(id)sender
|
||||
{
|
||||
if ([_firstResponder isKindOfClass:[CPView class]])
|
||||
@@ -1728,11 +1776,17 @@ CPTexturedBackgroundWindowMask
|
||||
|
||||
- (void)selectKeyViewFollowingView:(CPView)aView
|
||||
{
|
||||
if (_keyViewLoopIsDirty && _autorecalculatesKeyViewLoop)
|
||||
[self recalculateKeyViewLoop];
|
||||
|
||||
[self makeFirstResponder:[aView nextValidKeyView]];
|
||||
}
|
||||
|
||||
- (void)selectKeyViewPrecedingView:(CPView)aView
|
||||
{
|
||||
if (_keyViewLoopIsDirty && _autorecalculatesKeyViewLoop)
|
||||
[self recalculateKeyViewLoop];
|
||||
|
||||
[self makeFirstResponder:[aView previousValidKeyView]];
|
||||
}
|
||||
|
||||
@@ -1782,6 +1836,21 @@ CPTexturedBackgroundWindowMask
|
||||
|
||||
@end
|
||||
|
||||
var keyViewComparator = function(a, b, context)
|
||||
{
|
||||
var viewBounds = [a convertRect:[a bounds] toView:nil],
|
||||
otherBounds = [b convertRect:[b bounds] toView:nil];
|
||||
|
||||
if (CGRectGetMinY(viewBounds) < CGRectGetMinY(otherBounds))
|
||||
return -1;
|
||||
else if (CGRectGetMinY(viewBounds) == CGRectGetMinY(otherBounds) && CGRectGetMinX(viewBounds) < CGRectGetMinX(otherBounds))
|
||||
return -1;
|
||||
else if (CGRectGetMinX(viewBounds) == CGRectGetMinX(otherBounds) && CGRectGetMinX(viewBounds) == CGRectGetMinX(otherBounds))
|
||||
return 0;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
|
||||
@implementation CPWindow (MenuBar)
|
||||
|
||||
- (void)_synchronizeMenuBarTitleWithWindowTitle
|
||||
|
||||
Reference in New Issue
Block a user