From a1d9275d7fbeb3871ec7026bb363ba2e744c4c51 Mon Sep 17 00:00:00 2001 From: Tim Taubert Date: Tue, 25 Jan 2011 22:13:21 +0100 Subject: [PATCH] Bug 626368 - Empty space left between tabs when closing multiple pages in Panorama view [r=ian, a=beltzner] --HG-- extra : rebase_source : 4f10915c108923889536ef159c223c6091f3bf49 --- browser/base/content/tabview/groupitems.js | 4 +- browser/base/content/tabview/items.js | 4 +- .../base/content/tabview/modules/utils.jsm | 14 +++ browser/base/content/tabview/tabitems.js | 2 +- browser/base/content/test/tabview/Makefile.in | 1 + .../test/tabview/browser_tabview_bug626368.js | 85 +++++++++++++++++++ 6 files changed, 105 insertions(+), 5 deletions(-) create mode 100644 browser/base/content/test/tabview/browser_tabview_bug626368.js diff --git a/browser/base/content/tabview/groupitems.js b/browser/base/content/tabview/groupitems.js index 72d8477109ab..50e1091f68dc 100644 --- a/browser/base/content/tabview/groupitems.js +++ b/browser/base/content/tabview/groupitems.js @@ -207,7 +207,7 @@ function GroupItem(listOfEls, options) { else { this.$titleShield .mousedown(function(e) { - self.lastMouseDownTarget = (Utils.isRightClick(e) ? null : e.target); + self.lastMouseDownTarget = (Utils.isLeftClick(e) ? e.target : null); }) .mouseup(function(e) { var same = (e.target == self.lastMouseDownTarget); @@ -1019,7 +1019,7 @@ GroupItem.prototype = Utils.extend(new Item(), new Subscribable(), { .data("xulTab", xulTab) .appendTo(this.$appTabTray) .click(function(event) { - if (Utils.isRightClick(event)) + if (!Utils.isLeftClick(event)) return; GroupItems.setActiveGroupItem(self); diff --git a/browser/base/content/tabview/items.js b/browser/base/content/tabview/items.js index 4e2615ba47b2..75c0c16f8092 100644 --- a/browser/base/content/tabview/items.js +++ b/browser/base/content/tabview/items.js @@ -703,7 +703,7 @@ Item.prototype = { // ___ mousedown $container.mousedown(function(e) { - if (Utils.isRightClick(e)) + if (!Utils.isLeftClick(e)) return; var cancel = false; @@ -835,7 +835,7 @@ Item.prototype = { .addClass('iq-resizable-handle iq-resizable-se') .appendTo($container) .mousedown(function(e) { - if (Utils.isRightClick(e)) + if (!Utils.isLeftClick(e)) return; startMouse = new Point(e.pageX, e.pageY); diff --git a/browser/base/content/tabview/modules/utils.jsm b/browser/base/content/tabview/modules/utils.jsm index cdeed4892fc8..4555192c80f9 100644 --- a/browser/base/content/tabview/modules/utils.jsm +++ b/browser/base/content/tabview/modules/utils.jsm @@ -580,6 +580,20 @@ let Utils = { // ___ Misc + // ---------- + // Function: isLeftClick + // Given a DOM mouse event, returns true if it was for the left mouse button. + isLeftClick: function Utils_isLeftClick(event) { + return event.button == 0; + }, + + // ---------- + // Function: isMiddleClick + // Given a DOM mouse event, returns true if it was for the middle mouse button. + isMiddleClick: function Utils_isMiddleClick(event) { + return event.button == 1; + }, + // ---------- // Function: isRightClick // Given a DOM mouse event, returns true if it was for the right mouse button. diff --git a/browser/base/content/tabview/tabitems.js b/browser/base/content/tabview/tabitems.js index c9e483c0ea0f..6ae5513d0af3 100644 --- a/browser/base/content/tabview/tabitems.js +++ b/browser/base/content/tabview/tabitems.js @@ -200,7 +200,7 @@ function TabItem(tab, options) { return; // press close button or middle mouse click - if (iQ(e.target).hasClass("close") || e.button == 1) { + if (iQ(e.target).hasClass("close") || Utils.isMiddleClick(e)) { self.close(); } else { if (!Items.item(this).isDragging) diff --git a/browser/base/content/test/tabview/Makefile.in b/browser/base/content/test/tabview/Makefile.in index d585be486835..89411c76dae1 100644 --- a/browser/base/content/test/tabview/Makefile.in +++ b/browser/base/content/test/tabview/Makefile.in @@ -90,6 +90,7 @@ _BROWSER_FILES = \ browser_tabview_bug624265.js \ browser_tabview_bug624953.js \ browser_tabview_bug625269.js \ + browser_tabview_bug626368.js \ browser_tabview_bug627736.js \ browser_tabview_dragdrop.js \ browser_tabview_exit_button.js \ diff --git a/browser/base/content/test/tabview/browser_tabview_bug626368.js b/browser/base/content/test/tabview/browser_tabview_bug626368.js new file mode 100644 index 000000000000..aaa2bc4f4f02 --- /dev/null +++ b/browser/base/content/test/tabview/browser_tabview_bug626368.js @@ -0,0 +1,85 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is a test for bug 626368. + * + * The Initial Developer of the Original Code is + * Mozilla Foundation. + * Portions created by the Initial Developer are Copyright (C) 2011 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Tim Taubert + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +function test() { + let cw; + + let createGroupItem = function () { + let bounds = new cw.Rect(20, 20, 150, 150); + let groupItem = new cw.GroupItem([], {bounds: bounds, immediately: true}); + + cw.GroupItems.setActiveGroupItem(groupItem); + gBrowser.loadOneTab('about:blank', {inBackground: true}); + + return groupItem; + } + + let synthesizeMiddleMouseDrag = function (tabContainer, width) { + EventUtils.synthesizeMouseAtCenter(tabContainer, + {type: 'mousedown', button: 1}, cw); + let rect = tabContainer.getBoundingClientRect(); + EventUtils.synthesizeMouse(tabContainer, rect.width / 2 + width, + rect.height / 2, {type: 'mousemove', button: 1}, cw); + EventUtils.synthesizeMouse(tabContainer, rect.width / 2 + width, + rect.height / 2, {type: 'mouseup', button: 1}, cw); + } + + let testDragAndDropWithMiddleMouseButton = function () { + let groupItem = createGroupItem(); + let tabItem = groupItem.getChild(0); + let tabContainer = tabItem.container; + let bounds = tabItem.getBounds(); + + // try to drag and move the mouse out of the tab + synthesizeMiddleMouseDrag(tabContainer, 200); + is(groupItem.getChild(0), tabItem, 'tabItem was not closed'); + ok(bounds.equals(tabItem.getBounds()), 'bounds did not change'); + + // try to drag and let the mouse stay within tab bounds + synthesizeMiddleMouseDrag(tabContainer, 10); + ok(!groupItem.getChild(0), 'tabItem was closed'); + + hideTabView(finish); + } + + waitForExplicitFinish(); + + showTabView(function () { + cw = TabView.getContentWindow(); + afterAllTabsLoaded(testDragAndDropWithMiddleMouseButton); + }); +}