summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorarv@chromium.org <arv@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-25 17:29:52 +0000
committerarv@chromium.org <arv@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-25 17:29:52 +0000
commit75393a5c79f92b579ff9535f6a22ee88f03365f5 (patch)
treed01792796f04e8eac10e0a96abf43c6a4ca89212
parenta955860ece843c2a7c9f628ab1a9fda85e96964d (diff)
downloadchromium_src-75393a5c79f92b579ff9535f6a22ee88f03365f5.zip
chromium_src-75393a5c79f92b579ff9535f6a22ee88f03365f5.tar.gz
chromium_src-75393a5c79f92b579ff9535f6a22ee88f03365f5.tar.bz2
TBR:
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42632 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/resources/bookmark_manager/js/cr/ui/command.js94
-rw-r--r--chrome/browser/resources/bookmark_manager/main.html15
2 files changed, 63 insertions, 46 deletions
diff --git a/chrome/browser/resources/bookmark_manager/js/cr/ui/command.js b/chrome/browser/resources/bookmark_manager/js/cr/ui/command.js
index d1a0677..184e091 100644
--- a/chrome/browser/resources/bookmark_manager/js/cr/ui/command.js
+++ b/chrome/browser/resources/bookmark_manager/js/cr/ui/command.js
@@ -18,6 +18,53 @@
cr.define('cr.ui', function() {
/**
+ * This is used to identify keyboard shortcuts.
+ * @param {string} shortcut The text used to describe the keys for this
+ * keyboard shortcut.
+ * @constructor
+ */
+ function KeyboardShortcut(shortcut) {
+ var mods = {};
+ var ident = '';
+ shortcut.split('-').forEach(function(part) {
+ var partLc = part.toLowerCase();
+ switch (partLc) {
+ case 'alt':
+ case 'ctrl':
+ case 'meta':
+ case 'shift':
+ mods[partLc + 'Key'] = true;
+ break;
+ default:
+ if (ident)
+ throw Error('Invalid shortcut');
+ ident = part;
+ }
+ });
+
+ this.ident_ = ident;
+ this.mods_ = mods;
+ }
+
+ KeyboardShortcut.prototype = {
+ /**
+ * Wether the keyboard shortcut object mathes a keyboard event.
+ * @param {!Event} e The keyboard event object.
+ * @return {boolean} Whether we found a match or not.
+ */
+ matchesEvent: function(e) {
+ if (e.keyIdentifier == this.ident_) {
+ // All keyboard modifiers needs to match.
+ var mods = this.mods_;
+ return ['altKey', 'ctrlKey', 'metaKey', 'shiftKey'].every(function(k) {
+ return e[k] == !!mods[k];
+ });
+ }
+ return false;
+ }
+ };
+
+ /**
* Creates a new command element.
* @constructor
* @extends {HTMLElement}
@@ -61,45 +108,31 @@ cr.define('cr.ui', function() {
* The keyboard shortcut that triggers the command. This is a string
* consisting of a keyIdentifier (as reported by WebKit in keydown) as
* well as optional key modifiers joinded with a '-'.
+ *
+ * Multiple keyboard shortcuts can be provided by separating them by
+ * whitespace.
+ *
* For example:
* "F1"
* "U+0008-Meta" for Apple command backspace.
* "U+0041-Ctrl" for Control A
+ * "U+007F U+0008-Meta" for Delete and Command Backspace
*
* @type {string}
*/
- shortcut_: null,
+ shortcut_: '',
get shortcut() {
return this.shortcut_;
},
set shortcut(shortcut) {
var oldShortcut = this.shortcut_;
if (shortcut !== oldShortcut) {
- this.shortcut_ = shortcut;
-
- // TODO(arv): Multiple shortcuts?
-
- var mods = {};
- var ident = '';
- shortcut.split('-').forEach(function(part) {
- var partLc = part.toLowerCase();
- switch (partLc) {
- case 'alt':
- case 'ctrl':
- case 'meta':
- case 'shift':
- mods[partLc + 'Key'] = true;
- break;
- default:
- if (ident)
- throw Error('Multiple keyboard shortcuts are not supported');
- ident = part;
- }
-
- this.keyIdentifier_ = ident;
- this.keyModifiers_ = mods;
- }, this);
+ this.keyboardShortcuts_ = shortcut.split(/\s+/).map(function(shortcut) {
+ return new KeyboardShortcut(shortcut);
+ });
+ // Set this after the keyboardShortcuts_ since that might throw.
+ this.shortcut_ = shortcut;
cr.dispatchPropertyChange(this, 'shortcut', this.shortcut_,
oldShortcut);
}
@@ -111,18 +144,13 @@ cr.define('cr.ui', function() {
* @return {boolean} Whether it matched or not.
*/
matchesEvent: function(e) {
- if (!this.keyIdentifier_)
+ if (!this.keyboardShortcuts_)
return false;
- if (e.keyIdentifier == this.keyIdentifier_) {
- // All keyboard modifiers needs to match.
- var mods = this.keyModifiers_;
- return ['altKey', 'ctrlKey', 'metaKey', 'shiftKey'].every(function(k) {
- return e[k] == !!mods[k];
+ return this.keyboardShortcuts_.some(function(keyboardShortcut) {
+ return keyboardShortcut.matchesEvent(e);
});
}
- return false;
- }
};
/**
diff --git a/chrome/browser/resources/bookmark_manager/main.html b/chrome/browser/resources/bookmark_manager/main.html
index c420617..e2ec832 100644
--- a/chrome/browser/resources/bookmark_manager/main.html
+++ b/chrome/browser/resources/bookmark_manager/main.html
@@ -6,15 +6,6 @@ Copyright (c) 2010 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-
-This is work in progress:
-
-Favicons: chrome-extension: is not allowed to access chrome://favicon. We need
-to whitelist it or expose a way to get the data URI for the favicon (slow and
-sucky).
-
-Favicon of bmm does not work. No icon is showed.
-
-->
<head>
<title i18n-content="title"></title>
@@ -1523,10 +1514,8 @@ function handleCommand(e) {
}
}
-// TODO(arv): Move shortcut to HTML?
-
-// Meta+Backspace on Mac, Del on other platforms.
-$('delete-command').shortcut = cr.isMac ? 'U+0008-meta' : 'U+007F';
+// Delete on all platforms. On Mac we also allow Meta+Backspace.
+$('delete-command').shortcut = 'U+007F' + (cr.isMac ? ' U+0008-meta' : '');
list.addEventListener('command', handleCommand);
tree.addEventListener('command', handleCommand);