mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-10-28 02:48:49 +00:00
Fix for issue #769, allow ctrl/cmd keys and F1-F12 keys to propagate to the browser unless they are blacklisted
This commit is contained in:
1 parent
c3c996f1f7
commit
6ff3fa0e52
1 file changed
+39
-4
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user