Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Unified Diff: ui/webui/resources/js/cr/ui/menu.js

Issue 1358893003: Ignore mouseup shortly after showing cr.ui.Menu (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/webui/resources/js/cr/ui/context_menu_handler.js ('k') | ui/webui/resources/js/cr/ui/menu_button.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/webui/resources/js/cr/ui/menu.js
diff --git a/ui/webui/resources/js/cr/ui/menu.js b/ui/webui/resources/js/cr/ui/menu.js
index d54f5430f855a9239caaa9ba9af714054acae0db..d900496022e9b4f6f07e91f57958071e4eb8c11c 100644
--- a/ui/webui/resources/js/cr/ui/menu.js
+++ b/ui/webui/resources/js/cr/ui/menu.js
@@ -32,6 +32,7 @@ cr.define('cr.ui', function() {
decorate: function() {
this.addEventListener('mouseover', this.handleMouseOver_);
this.addEventListener('mouseout', this.handleMouseOut_);
+ this.addEventListener('mouseup', this.handleMouseUp_, true);
this.classList.add('decorated');
this.setAttribute('role', 'menu');
@@ -113,6 +114,28 @@ cr.define('cr.ui', function() {
this.selectedItem = null;
},
+ /**
+ * @param {Event} e
mustaq 2015/09/22 14:20:36 Please add a brief doc.
Dan Beam 2015/09/22 15:51:31 Done.
+ */
+ handleMouseUp_: function(e) {
+ assert(this.contains(/** @type {Element} */(e.target)));
+
+ var mouseDownPos = this.shown_.mouseDownPos;
+ if (!mouseDownPos)
+ return;
+
+ if (Date.now() - this.shown_.time > 200)
+ return;
+
+ var xDelta = mouseDownPos.x - e.screenX;
+ var yDelta = mouseDownPos.y - e.screenY;
+ if (Math.sqrt(Math.pow(xDelta, 2) + Math.pow(yDelta, 2)) > 4)
mustaq 2015/09/22 14:20:36 What about a faster+simpler math? This is a heuris
Dan Beam 2015/09/22 15:51:30 Done.
+ return;
+
+ e.preventDefault();
+ e.stopPropagation();
+ },
+
get menuItems() {
return this.querySelectorAll(this.menuItemSelector || '*');
},
@@ -238,6 +261,17 @@ cr.define('cr.ui', function() {
return false;
},
+ hide: function() {
+ this.hidden = true;
+ delete this.shown_;
+ },
+
+ /** @param {{x: number, y: number}=} opt_mouseDownPos */
+ show: function(opt_mouseDownPos) {
+ this.shown_ = {mouseDownPos: opt_mouseDownPos, time: Date.now()};
+ this.hidden = false;
+ },
+
/**
* Updates menu items command according to context.
* @param {Node=} node Node for which to actuate commands state.
« no previous file with comments | « ui/webui/resources/js/cr/ui/context_menu_handler.js ('k') | ui/webui/resources/js/cr/ui/menu_button.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698