diff options
author | yurys@google.com <yurys@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-01 08:09:26 +0000 |
---|---|---|
committer | yurys@google.com <yurys@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-01 08:09:26 +0000 |
commit | e6efae3fd1d47fdf47d790208e66e257e9af275e (patch) | |
tree | c60900877c823eaee312cde42fad41c8cdf1f8b0 /webkit/glue | |
parent | 10fb687b87f5fde62b3df3e2dd5c5d6f5533d715 (diff) | |
download | chromium_src-e6efae3fd1d47fdf47d790208e66e257e9af275e.zip chromium_src-e6efae3fd1d47fdf47d790208e66e257e9af275e.tar.gz chromium_src-e6efae3fd1d47fdf47d790208e66e257e9af275e.tar.bz2 |
DevTols: add KeyboardShortcuts.js t Chromium so that when WebKit change for https://bugs.webkit.org/show_bug.cgi?id=23849 is landed in Chromium it doesn't break devtools.
Review URL: http://codereview.chromium.org/149064
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19714 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue')
-rw-r--r-- | webkit/glue/devtools/js/KeyboardShortcut.js | 108 | ||||
-rw-r--r-- | webkit/glue/devtools/js/devtools.html | 1 |
2 files changed, 109 insertions, 0 deletions
diff --git a/webkit/glue/devtools/js/KeyboardShortcut.js b/webkit/glue/devtools/js/KeyboardShortcut.js new file mode 100644 index 0000000..ed28a48 --- /dev/null +++ b/webkit/glue/devtools/js/KeyboardShortcut.js @@ -0,0 +1,108 @@ +/* + * Copyright (C) 2009 Apple Inc. All rights reserved. + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +WebInspector.KeyboardShortcut = function() +{ +}; + +/** + * Constants for encoding modifier key set as a bit mask. + * @see #_makeKeyFromCodeAndModifiers + */ +WebInspector.KeyboardShortcut.Modifiers = { + None: 0, // Constant for empty modifiers set. + Shift: 1, + Ctrl: 2, + Alt: 4, + Meta: 8 // Command key on Mac, Win key on other platforms. +}; + +WebInspector.KeyboardShortcut.KeyCodes = { + Esc: 27, + Space: 32, + PageUp: 33, // also NUM_NORTH_EAST + PageDown: 34, // also NUM_SOUTH_EAST + End: 35, // also NUM_SOUTH_WEST + Home: 36, // also NUM_NORTH_WEST + Left: 37, // also NUM_WEST + Up: 38, // also NUM_NORTH + Right: 39, // also NUM_EAST + Down: 40, // also NUM_SOUTH + F1: 112, + F2: 113, + F3: 114, + F4: 115, + F5: 116, + F6: 117, + F7: 118, + F8: 119, + F9: 120, + F10: 121, + F11: 122, + F12: 123, + Semicolon: 186, // ; + Comma: 188, // , + Period: 190, // . + Slash: 191, // / + Apostrophe: 192, // ` + SingleQuote: 222, // ' +}; + +/** + * Creates a number encoding keyCode in the lower 8 bits and modifiers mask in the higher 8 bits. + * It is usefull for matching pressed keys. + * @param {number} keyCode Code of the key. + * @param {number} optModifiers Optional list of modifiers passed as additional paramerters. + */ +WebInspector.KeyboardShortcut.makeKey = function(keyCode, optModifiers) +{ + var modifiers = WebInspector.KeyboardShortcut.Modifiers.None; + for (var i = 1; i < arguments.length; i++) + modifiers |= arguments[i]; + return WebInspector.KeyboardShortcut._makeKeyFromCodeAndModifiers(keyCode, modifiers); +}; + +WebInspector.KeyboardShortcut.makeKeyFromEvent = function(keyboardEvent) +{ + var modifiers = WebInspector.KeyboardShortcut.Modifiers.None; + if (keyboardEvent.shiftKey) + modifiers |= WebInspector.KeyboardShortcut.Modifiers.Shift; + if (keyboardEvent.ctrlKey) + modifiers |= WebInspector.KeyboardShortcut.Modifiers.Ctrl; + if (keyboardEvent.altKey) + modifiers |= WebInspector.KeyboardShortcut.Modifiers.Alt; + if (keyboardEvent.metaKey) + modifiers |= WebInspector.KeyboardShortcut.Modifiers.Meta; + return WebInspector.KeyboardShortcut._makeKeyFromCodeAndModifiers(keyboardEvent.keyCode, modifiers); +}; + +WebInspector.KeyboardShortcut._makeKeyFromCodeAndModifiers = function(keyCode, modifiers) +{ + return (keyCode & 255) | (modifiers << 8); +}; diff --git a/webkit/glue/devtools/js/devtools.html b/webkit/glue/devtools/js/devtools.html index 842d9d8..3ca50fb 100644 --- a/webkit/glue/devtools/js/devtools.html +++ b/webkit/glue/devtools/js/devtools.html @@ -62,6 +62,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. <script type="text/javascript" src="profiler_processor.js"></script> <script type="text/javascript" src="splaytree.js"></script> <script type="text/javascript" src="Object.js"></script> + <script type="text/javascript" src="KeyboardShortcut.js"></script> <script type="text/javascript" src="TextPrompt.js"></script> <script type="text/javascript" src="Placard.js"></script> <script type="text/javascript" src="View.js"></script> |