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. |