summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorarv@chromium.org <arv@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-07 21:41:06 +0000
committerarv@chromium.org <arv@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-07 21:41:06 +0000
commit66b29992dcbe65fe31dea866dbb9ac31edcb01f4 (patch)
tree68457297b1a319c526e09abc9b37ffbc01e4c9cf /chrome
parent658cc62f9c2257f91e2600b2895aabd6b8462308 (diff)
downloadchromium_src-66b29992dcbe65fe31dea866dbb9ac31edcb01f4.zip
chromium_src-66b29992dcbe65fe31dea866dbb9ac31edcb01f4.tar.gz
chromium_src-66b29992dcbe65fe31dea866dbb9ac31edcb01f4.tar.bz2
Bookmarks: Fix position of context menu when opened using the keyboard.
After fixing the contextmenu event in WebKit we can no longer rely on the bug/hack/feature that screenX was 0 when the event was generated using the keyboard. We now keep track of keydown and keyup and if the right key was down then we know it was a context menu generated by the keyboard. BUG= 40073 TEST=Select an bookmark item (or a folder in the bookmark tree). Press Shift+F10. The context menu should be positioned relative to the selected item. Review URL: http://codereview.chromium.org/2845042 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51779 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/resources/shared/js/cr/ui/context_menu_handler.js27
1 files changed, 24 insertions, 3 deletions
diff --git a/chrome/browser/resources/shared/js/cr/ui/context_menu_handler.js b/chrome/browser/resources/shared/js/cr/ui/context_menu_handler.js
index 6b86808..f033a80 100644
--- a/chrome/browser/resources/shared/js/cr/ui/context_menu_handler.js
+++ b/chrome/browser/resources/shared/js/cr/ui/context_menu_handler.js
@@ -76,7 +76,7 @@ cr.define('cr.ui', function() {
var x, y;
// When the user presses the context menu key (on the keyboard) we need
// to detect this.
- if (e.screenX == 0 && e.screenY == 0) {
+ if (this.keyIsDown_) {
var rect = element.getRectForContextMenu ?
element.getRectForContextMenu() :
element.getBoundingClientRect();
@@ -96,6 +96,21 @@ cr.define('cr.ui', function() {
* @param {!Event} e The event object.
*/
handleEvent: function(e) {
+ // Keep track of keydown state so that we can use that to determine the
+ // reason for the contextmenu event.
+ switch (e.type) {
+ case 'keydown':
+ this.keyIsDown_ = !e.ctrlKey && !e.altKey &&
+ // context menu key or Shift-F10
+ (e.keyCode == 93 && !e.shiftKey ||
+ e.keyIdentifier == 'F10' && e.shiftKey);
+ break;
+
+ case 'keyup':
+ this.keyIsDown_ = false;
+ break;
+ }
+
// Context menu is handled even when we have no menu.
if (e.type != 'contextmenu' && !this.menu)
return;
@@ -159,10 +174,16 @@ cr.define('cr.ui', function() {
if (menu === oldContextMenu)
return;
- if (oldContextMenu && !menu)
+ if (oldContextMenu && !menu) {
this.removeEventListener('contextmenu', contextMenuHandler);
- if (menu && !oldContextMenu)
+ this.removeEventListener('keydown', contextMenuHandler);
+ this.removeEventListener('keyup', contextMenuHandler);
+ }
+ if (menu && !oldContextMenu) {
this.addEventListener('contextmenu', contextMenuHandler);
+ this.addEventListener('keydown', contextMenuHandler);
+ this.addEventListener('keyup', contextMenuHandler);
+ }
this.contextMenu_ = menu;