From 6ff3fa0e523325c0097b12be5de37611aaeadcec Mon Sep 17 00:00:00 2001 From: Mike Fellows Date: Tue, 27 Jul 2010 17:44:05 -0700 Subject: [PATCH] Fix for issue #769, allow ctrl/cmd keys and F1-F12 keys to propagate to the browser unless they are blacklisted --- AppKit/Platform/DOM/CPPlatformWindow+DOM.j | 43 ++++++++++++++++++++-- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/AppKit/Platform/DOM/CPPlatformWindow+DOM.j b/AppKit/Platform/DOM/CPPlatformWindow+DOM.j index 7af9e9888..ea8badbbe 100644 --- a/AppKit/Platform/DOM/CPPlatformWindow+DOM.j +++ b/AppKit/Platform/DOM/CPPlatformWindow+DOM.j @@ -136,6 +136,7 @@ var CPDOMEventGetClickCount, //might be mac only, we should investigate futher later. var KeyCodesToPrevent = {}, CharacterKeysToPrevent = {}, + KeyCodesToAllow = {}, MozKeyCodeToKeyCodeMap = { 61: 187, // =, equals 59: 186 // ;, semicolon @@ -144,6 +145,19 @@ var KeyCodesToPrevent = {}, KeyCodesToPrevent[CPKeyCodes.A] = YES; +KeyCodesToAllow[CPKeyCodes.F1] = YES; +KeyCodesToAllow[CPKeyCodes.F2] = YES; +KeyCodesToAllow[CPKeyCodes.F3] = YES; +KeyCodesToAllow[CPKeyCodes.F4] = YES; +KeyCodesToAllow[CPKeyCodes.F5] = YES; +KeyCodesToAllow[CPKeyCodes.F6] = YES; +KeyCodesToAllow[CPKeyCodes.F7] = YES; +KeyCodesToAllow[CPKeyCodes.F8] = YES; +KeyCodesToAllow[CPKeyCodes.F9] = YES; +KeyCodesToAllow[CPKeyCodes.F10] = YES; +KeyCodesToAllow[CPKeyCodes.F11] = YES; +KeyCodesToAllow[CPKeyCodes.F12] = YES; + KeyCodesToUnicodeMap[CPKeyCodes.BACKSPACE] = CPDeleteCharacter; KeyCodesToUnicodeMap[CPKeyCodes.DELETE] = CPDeleteFunctionKey; KeyCodesToUnicodeMap[CPKeyCodes.TAB] = CPTabCharacter; @@ -634,10 +648,31 @@ var supportsNativeDragAndDrop = [CPPlatform supportsDragAndDrop]; (aDOMEvent.altKey ? CPAlternateKeyMask : 0) | (aDOMEvent.metaKey ? CPCommandKeyMask : 0); - //We want to stop propagation if this is a command key AND this character or keycode has been added to our blacklist - StopDOMEventPropagation = !!(!(modifierFlags & (CPControlKeyMask | CPCommandKeyMask)) || - CharacterKeysToPrevent[String.fromCharCode(aDOMEvent.keyCode || aDOMEvent.charCode).toLowerCase()] || - KeyCodesToPrevent[aDOMEvent.keyCode]); + // With a few exceptions, all key events are blocked from propagating to + // the browser. Here the following exceptions are being allowed: + // + // - All keys pressed along with a ctrl or cmd key _unless_ they are in + // one of the two blacklists. + // - Any key listed in the whitelist. + // + // The ctrl/cmd keys are used for browser hotkeys as are the keys listed in + // the whitelist (F1-F12 at the time of writing). + // + // If a key is listed in both the blacklist and whitelist, the blacklist is + // checked first. The key will be blocked from propagating in that case. + + StopDOMEventPropagation = YES; + + // Make sure it is not in the blacklists. + if(! (CharacterKeysToPrevent[String.fromCharCode(aDOMEvent.keyCode || aDOMEvent.charCode).toLowerCase()] || KeyCodesToPrevent[aDOMEvent.keyCode])) + { + // It is not in the blacklist, let it through if the ctrl/cmd key is + // also down or it's in the whitelist. + if((modifierFlags & (CPControlKeyMask | CPCommandKeyMask)) || KeyCodesToAllow[aDOMEvent.keyCode]) + { + StopDOMEventPropagation = NO; + } + } var isNativePasteEvent = NO, isNativeCopyOrCutEvent = NO,