From d0875e422010b6252fd3d4f11623b993734ff9c7 Mon Sep 17 00:00:00 2001 From: Michael Yoshitaka Erlewine Date: Tue, 22 Jun 2010 23:16:49 -0400 Subject: [PATCH] don't snap to anything (except edges) if you're on top of another group (fixes bug reported by Aza: snapping onto another group) --- browser/base/content/tabcandy/app/drag.js | 4 +++- browser/base/content/tabcandy/app/items.js | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/browser/base/content/tabcandy/app/drag.js b/browser/base/content/tabcandy/app/drag.js index c982ae1abbd..b35b3364a24 100644 --- a/browser/base/content/tabcandy/app/drag.js +++ b/browser/base/content/tabcandy/app/drag.js @@ -100,7 +100,9 @@ Drag.prototype = { var newRect; // OH SNAP! - if (!Keys.meta) { // if we aren't holding down the meta key... + if ( !Keys.meta // if we aren't holding down the meta key... + && !this.item.overlapsWithOtherItems() // and we aren't on top of anything else... + ) { newRect = Trenches.snap(bounds,assumeConstantSize,keepProportional); if (newRect) { // might be false if no changes were made update = true; diff --git a/browser/base/content/tabcandy/app/items.js b/browser/base/content/tabcandy/app/items.js index 52838c0dd9c..ecda43b6f0a 100644 --- a/browser/base/content/tabcandy/app/items.js +++ b/browser/base/content/tabcandy/app/items.js @@ -237,6 +237,21 @@ window.Item.prototype = { Utils.assert('this.bounds', isRect(this.bounds)); return new Rect(this.bounds); }, + + // ---------- + // Function: overlapsWithOtherItems + // Returns true if this Item overlaps with any other Item on the screen. + overlapsWithOtherItems: function() { + var self = this; + var items = Items.getTopLevelItems(); + var bounds = this.getBounds(); + return items.some(function(item) { + if (item == self) // can't overlap with yourself. + return false; + var myBounds = item.getBounds(); + return myBounds.intersects(bounds); + } ); + }, // ---------- // Function: setPosition