mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-12-04 11:54:59 +00:00
handle tab key as early as possible in CPWindow sendEvent:
This commit is contained in:
1 parent
cf6dc3fa5e
commit
4211abd0b0
2 files changed
+73
-18
No files matched your search
+12
-14
@@ -80,6 +80,7 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
|
||||
BOOL _isEditable;
|
||||
BOOL _isSelectable;
|
||||
BOOL _isSecure;
|
||||
BOOL _willBecomeFirstResponderByClick;
|
||||
|
||||
BOOL _drawsBackground;
|
||||
|
||||
@@ -509,6 +510,13 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
|
||||
window.setTimeout(function()
|
||||
{
|
||||
element.focus();
|
||||
|
||||
// Select the text if the textfield became first responder through keyboard interaction
|
||||
if (!_willBecomeFirstResponderByClick)
|
||||
[self selectText:self];
|
||||
|
||||
_willBecomeFirstResponderByClick = NO;
|
||||
|
||||
[self textDidFocus:[CPNotification notificationWithName:CPTextFieldDidFocusNotification object:self userInfo:nil]];
|
||||
CPTextFieldInputOwner = self;
|
||||
}, 0.0);
|
||||
@@ -600,7 +608,10 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
|
||||
{
|
||||
// Don't track! (ever?)
|
||||
if ([self isEditable] && [self isEnabled])
|
||||
return [[self window] makeFirstResponder:self];
|
||||
{
|
||||
_willBecomeFirstResponderByClick = YES;
|
||||
[[self window] makeFirstResponder:self];
|
||||
}
|
||||
else if ([self isSelectable])
|
||||
{
|
||||
if (document.attachEvent)
|
||||
@@ -677,25 +688,12 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
|
||||
|
||||
[[[self window] platformWindow] _propagateCurrentDOMEvent:NO];
|
||||
}
|
||||
else if ([anEvent keyCode] === CPTabKeyCode)
|
||||
{
|
||||
if ([anEvent modifierFlags] & CPShiftKeyMask)
|
||||
[[self window] selectPreviousKeyView:self];
|
||||
else
|
||||
[[self window] selectNextKeyView:self];
|
||||
|
||||
if ([[[self window] firstResponder] respondsToSelector:@selector(selectText:)])
|
||||
[[[self window] firstResponder] selectText:self];
|
||||
|
||||
[[[self window] platformWindow] _propagateCurrentDOMEvent:NO];
|
||||
}
|
||||
else
|
||||
[[[self window] platformWindow] _propagateCurrentDOMEvent:YES];
|
||||
|
||||
[[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode];
|
||||
}
|
||||
|
||||
|
||||
- (void)textDidBlur:(CPNotification)note
|
||||
{
|
||||
// this looks to prevent false propagation of notifications for other objects
|
||||
|
||||
@@ -1396,12 +1396,31 @@ CPTexturedBackgroundWindowMask
|
||||
|
||||
case CPKeyUp: return [[self firstResponder] keyUp:anEvent];
|
||||
|
||||
case CPKeyDown: [[self firstResponder] keyDown:anEvent];
|
||||
case CPKeyDown: if ([anEvent charactersIgnoringModifiers] === CPTabCharacter)
|
||||
{
|
||||
if ([anEvent modifierFlags] & CPShiftKeyMask)
|
||||
[self selectPreviousKeyView:self];
|
||||
else
|
||||
[self selectNextKeyView:self];
|
||||
|
||||
return;
|
||||
}
|
||||
else if ([anEvent charactersIgnoringModifiers] === CPBackTabCharacter)
|
||||
return [self selectPreviousKeyView:self];
|
||||
|
||||
[[self firstResponder] keyDown:anEvent];
|
||||
|
||||
// Trigger the default button if needed
|
||||
// FIXME: Is this only applicable in a sheet? See isse: #722.
|
||||
if (![self disableKeyEquivalentForDefaultButton])
|
||||
if ([anEvent _triggersKeyEquivalent:[[self defaultButton] keyEquivalent] withModifierMask:[[self defaultButton] keyEquivalentModifierMask]])
|
||||
{
|
||||
var defaultButton = [self defaultButton],
|
||||
keyEquivalent = [defaultButton keyEquivalent],
|
||||
modifierMask = [defaultButton keyEquivalentModifierMask];
|
||||
|
||||
if ([anEvent _triggersKeyEquivalent:keyEquivalent withModifierMask:modifierMask])
|
||||
[[self defaultButton] performClick:self];
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
@@ -2340,9 +2359,47 @@ CPTexturedBackgroundWindowMask
|
||||
}
|
||||
}
|
||||
|
||||
- (void)insertTab:(id)sender
|
||||
/*
|
||||
@ignore
|
||||
Interprets the key event for action messages and sends the action message down the responder chain
|
||||
Cocoa only sends moveDown:, moveUp:, moveLeft:, moveRight:, pageUp:, pageDown: and complete: messages.
|
||||
We deviate from this by sending (the default) scrollPageUp: scrollPageDown: for pageUp and pageDown keys.
|
||||
@param anEvent the event to handle.
|
||||
@return YES if the key event was handled, NO if no responder handled the key event
|
||||
*/
|
||||
- (BOOL)_processKeyboardUIKey:(CPEvent)anEvent
|
||||
{
|
||||
[self selectNextKeyView:nil];
|
||||
var character = [anEvent charactersIgnoringModifiers],
|
||||
uiKeys = [
|
||||
CPLeftArrowFunctionKey,
|
||||
CPRightArrowFunctionKey,
|
||||
CPUpArrowFunctionKey,
|
||||
CPDownArrowFunctionKey,
|
||||
CPPageUpFunctionKey,
|
||||
CPPageDownFunctionKey,
|
||||
CPEscapeFunctionKey
|
||||
];
|
||||
|
||||
if (![uiKeys containsObject:character])
|
||||
return NO;
|
||||
|
||||
var selectors = [CPKeyBinding selectorsForKey:character modifierFlags:0];
|
||||
|
||||
if ([selectors count] <= 0)
|
||||
return NO;
|
||||
|
||||
if (character !== CPEscapeFunctionKey)
|
||||
{
|
||||
var selector = [selectors objectAtIndex:0];
|
||||
return [[self firstResponder] tryToPerform:selector with:self];
|
||||
}
|
||||
else
|
||||
{
|
||||
// Cocoa sends complete: for the escape key (in stead of the default cancelOperation:)
|
||||
// This is also the only action that is not sent directly to the first responder, but through doCommandBySelector.
|
||||
// The difference is that doCommandBySelector: will also send the action to the window and application delegates.
|
||||
[[self firstResponder] doCommandBySelector:@selector(complete:)];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)_dirtyKeyViewLoop
|
||||
|
||||
Reference in new issue
Block a user