From e6bd9217461e412977659512f0e41b5220d2b01e Mon Sep 17 00:00:00 2001 From: Klaas Pieter Annema Date: Fri, 24 Sep 2010 14:04:21 +0200 Subject: [PATCH] fix CPWindow to only sent certain not handled keys as actions In Cocoa CPWindow will only send moveDown: (down arrow), moveUp: (up arrow), moveLeft: (left arrow), moveRight: (right arrow), pageUp: (page up), pageDown: (page down) and complete: (escape) down the responder chain. This commits makes us fully compatible with Cocoa except that we send scrollPageDown: and scrollPageUp: in stead of pageUp: and pageDown:. --- AppKit/CPWindow/CPWindow.j | 42 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/AppKit/CPWindow/CPWindow.j b/AppKit/CPWindow/CPWindow.j index a3816c870..3a57fc4c7 100644 --- a/AppKit/CPWindow/CPWindow.j +++ b/AppKit/CPWindow/CPWindow.j @@ -2298,8 +2298,46 @@ CPTexturedBackgroundWindowMask if ([anEvent _couldBeKeyEquivalent] && [self performKeyEquivalent:anEvent]) return; - // Interpret the key events - [self interpretKeyEvents:[anEvent]]; + // Apple's documentation is inconsistent with their behavior here. According to the docs + // an event going of the responder chain is passed to the input system as a last resort. + // However, the only methods I could get Cocoa to call automatically are + // moveUp: moveDown: moveLeft: moveRight: pageUp: pageDown: and complete: + [self _processKeyboardUIKey:anEvent]; +} + +/* + @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 +{ + 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)insertTab:(id)sender