Bug 630157 - double clicking anywhere in a group with any mouse button creates new tabs [r=ian, a=sdwilsh]
authorTim Taubert <tim.taubert@gmx.de>
Thu, 03 Feb 2011 10:51:20 +0100
changeset 61941 e8ad36c57a90e1308bf6141bdc4bc57e54fdf5d6
parent 61940 5e1f1bb2bb8708c552d12b7bccada78d3b736c9c
child 61942 e3ba71476fccf0777281b887759d57fcebb97558
push id1
push userroot
push dateTue, 10 Dec 2013 15:46:25 +0000
reviewersian, sdwilsh
bugs630157
milestone2.0b12pre
Bug 630157 - double clicking anywhere in a group with any mouse button creates new tabs [r=ian, a=sdwilsh]
browser/base/content/tabview/groupitems.js
browser/base/content/tabview/iq.js
browser/base/content/test/tabview/Makefile.in
browser/base/content/test/tabview/browser_tabview_bug630157.js
--- a/browser/base/content/tabview/groupitems.js
+++ b/browser/base/content/tabview/groupitems.js
@@ -1475,16 +1475,23 @@ GroupItem.prototype = Utils.extend(new I
   // ----------
   // Function: _addHandlers
   // Helper routine for the constructor; adds various event handlers to the container.
   _addHandlers: function GroupItem__addHandlers(container) {
     let self = this;
 
     // Create new tab and zoom in on it after a double click
     container.mousedown(function(e) {
+      if (!Utils.isLeftClick(e))
+        return;
+
+      // clicking in the title bar shouldn't create new tabs
+      if (self.$titlebar[0] == e.target || self.$titlebar.contains(e.target))
+        return;
+
       if (Date.now() - self._lastClick <= UI.DBLCLICK_INTERVAL &&
           (self._lastClickPositions.x - UI.DBLCLICK_OFFSET) <= e.clientX &&
           (self._lastClickPositions.x + UI.DBLCLICK_OFFSET) >= e.clientX &&
           (self._lastClickPositions.y - UI.DBLCLICK_OFFSET) <= e.clientY &&
           (self._lastClickPositions.y + UI.DBLCLICK_OFFSET) >= e.clientY) {
         self.newTab();
         self._lastClick = 0;
         self._lastClickPositions = null;
--- a/browser/base/content/tabview/iq.js
+++ b/browser/base/content/tabview/iq.js
@@ -16,16 +16,17 @@
  * The Initial Developer of the Original Code is the Mozilla Foundation.
  * Portions created by the Initial Developer are Copyright (C) 2010
  * the Initial Developer. All Rights Reserved.
  *
  * Contributor(s):
  * Ian Gilman <ian@iangilman.com>
  * Aza Raskin <aza@mozilla.com>
  * Michael Yoshitaka Erlewine <mitcho@mitcho.com>
+ * Tim Taubert <tim.taubert@gmx.de>
  *
  * This file incorporates work from:
  * jQuery JavaScript Library v1.4.2: http://code.jquery.com/jquery-1.4.2.js
  * This incorporated work is covered by the following copyright and
  * permission notice:
  * Copyright 2010, John Resig
  * Dual licensed under the MIT or GPL Version 2 licenses.
  * http://jquery.org/license
@@ -289,16 +290,40 @@ iQClass.prototype = {
         }
       }
     }
 
     return iQ(ret);
   },
 
   // ----------
+  // Function: contains
+  // Check to see if a given DOM node descends from the receiver.
+  contains: function iQClass_contains(selector) {
+    Utils.assert(this.length == 1, 'does not yet support multi-objects (or null objects)');
+
+    // fast path when querySelector() can be used
+    if ('string' == typeof selector)
+      return null != this[0].querySelector(selector);
+
+    let object = iQ(selector);
+    Utils.assert(object.length <= 1, 'does not yet support multi-objects');
+
+    let elem = object[0];
+    if (!elem || !elem.parentNode)
+      return false;
+
+    do {
+      elem = elem.parentNode;
+    } while (elem && this[0] != elem);
+
+    return this[0] == elem;
+  },
+
+  // ----------
   // Function: remove
   // Removes the receiver from the DOM.
   remove: function iQClass_remove() {
     for (let i = 0; this[i] != null; i++) {
       let elem = this[i];
       if (elem.parentNode) {
         elem.parentNode.removeChild(elem);
       }
--- a/browser/base/content/test/tabview/Makefile.in
+++ b/browser/base/content/test/tabview/Makefile.in
@@ -101,16 +101,17 @@ include $(topsrcdir)/config/rules.mk
                  browser_tabview_bug626368.js \
                  browser_tabview_bug626525.js \
                  browser_tabview_bug627288.js \
                  browser_tabview_bug627736.js \
                  browser_tabview_bug628165.js \
                  browser_tabview_bug628270.js \
                  browser_tabview_bug629195.js \
                  browser_tabview_bug630102.js \
+                 browser_tabview_bug630157.js \
                  browser_tabview_dragdrop.js \
                  browser_tabview_exit_button.js \
                  browser_tabview_expander.js \
                  browser_tabview_group.js \
                  browser_tabview_launch.js \
                  browser_tabview_multiwindow_search.js \
                  browser_tabview_orphaned_tabs.js \
                  browser_tabview_privatebrowsing.js \
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/tabview/browser_tabview_bug630157.js
@@ -0,0 +1,84 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+function test() {
+  let cw;
+
+  let createGroupItem = function () {
+    let bounds = new cw.Rect(20, 20, 400, 200);
+    let groupItem = new cw.GroupItem([], {bounds: bounds, immediately: true});
+
+    let groupItemId = groupItem.id;
+    registerCleanupFunction(function() {
+      let groupItem = cw.GroupItems.groupItem(groupItemId);
+      if (groupItem)
+        groupItem.close();
+    });
+
+    return groupItem;
+  }
+
+  let assertNumberOfGroups = function (num) {
+    is(cw.GroupItems.groupItems.length, num, 'there should be ' + num + ' groups');
+  }
+
+  let assertNumberOfTabs = function (num) {
+    is(gBrowser.tabs.length, num, 'there should be ' + num + ' tabs');
+  }
+
+  let simulateDoubleClick = function (target, button) {
+    for (let i=0; i<2; i++)
+      EventUtils.synthesizeMouseAtCenter(target, {button: button || 0}, cw);
+  }
+
+  let finishTest = function () {
+    let tabItem = gBrowser.tabs[0]._tabViewTabItem;
+    cw.GroupItems.updateActiveGroupItemAndTabBar(tabItem);
+
+    gBrowser.removeTab(gBrowser.tabs[1]);
+    assertNumberOfGroups(1);
+    assertNumberOfTabs(1);
+
+    finish();
+  }
+
+  let testDoubleClick = function () {
+    let groupItem = createGroupItem();
+    assertNumberOfGroups(2);
+    assertNumberOfTabs(1);
+
+    // simulate double click on group title
+    let input = groupItem.$title[0];
+    simulateDoubleClick(input);
+    assertNumberOfTabs(1);
+
+    // simulate double click on title bar
+    let titlebar = groupItem.$titlebar[0];
+    simulateDoubleClick(titlebar);
+    assertNumberOfTabs(1);
+
+    // simulate double click with middle mouse button
+    let container = groupItem.container;
+    simulateDoubleClick(container, 1);
+    assertNumberOfTabs(1);
+
+    // simulate double click with right mouse button
+    simulateDoubleClick(container, 2);
+    assertNumberOfTabs(1);
+
+    // simulate double click with left mouse button
+    let container = groupItem.container;
+    simulateDoubleClick(container);
+    assertNumberOfTabs(2);
+
+    whenTabViewIsHidden(finishTest);
+  }
+
+  waitForExplicitFinish();
+  registerCleanupFunction(function () TabView.hide());
+
+  showTabView(function () {
+    cw = TabView.getContentWindow();
+    testDoubleClick();
+  });
+}