Bug 649319 - tab focus when resizing or moving a group in panorama; f=raymond, r=ian
authorTim Taubert <tim.taubert@gmx.de>
Fri, 10 Jun 2011 11:40:20 +0200
changeset 71383 cb2a5954a5b48931b2016ae6f9a333927bece296
parent 71382 7232c7714d8195e52ce64ffdd551d1d9ba21141e
child 71384 0c47cb07f6894c26b8cd96f991d0ee5ae6955df5
push id159
push usereakhgari@mozilla.com
push dateTue, 16 Aug 2011 17:53:11 +0000
treeherdermozilla-beta@8786e3e49240 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersian
bugs649319
milestone7.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 649319 - tab focus when resizing or moving a group in panorama; f=raymond, r=ian
browser/base/content/tabview/drag.js
browser/base/content/tabview/groupitems.js
browser/base/content/tabview/items.js
browser/base/content/test/tabview/Makefile.in
browser/base/content/test/tabview/browser_tabview_bug649319.js
--- a/browser/base/content/tabview/drag.js
+++ b/browser/base/content/tabview/drag.js
@@ -80,29 +80,16 @@ function Drag(item, event, isFauxDrag) {
   this.startTime = Date.now();
 
   this.item.isDragging = true;
   this.item.setZ(999999);
 
   this.safeWindowBounds = Items.getSafeWindowBounds();
 
   Trenches.activateOthersTrenches(this.el);
-
-  if (!isFauxDrag) {
-    // When a tab drag starts, make it the focused tab.
-    if (this.item.isAGroupItem) {
-      var tab = UI.getActiveTab();
-      if (!tab || tab.parent != this.item) {
-        if (this.item._children.length)
-          UI.setActive(this.item._children[0]);
-      }
-    } else if (this.item.isATabItem) {
-      UI.setActive(this.item);
-    }
-  }
 };
 
 Drag.prototype = {
   // ----------
   // Function: toString
   // Prints [Drag (item)] for debug use
   toString: function Drag_toString() {
     return "[Drag (" + this.item + ")]";
--- a/browser/base/content/tabview/groupitems.js
+++ b/browser/base/content/tabview/groupitems.js
@@ -1009,18 +1009,17 @@ GroupItem.prototype = Utils.extend(new I
             UI.setActive(self);
         });
 
         item.setParent(this);
 
         if (typeof item.setResizable == 'function')
           item.setResizable(false, options.immediately);
 
-        // if it is visually active, set it as the active tab.
-        if (iQ(item.container).hasClass("focus"))
+        if (item == UI.getActiveTab() || !this._activeTab)
           this.setActiveTab(item);
 
         // if it matches the selected tab or no active tab and the browser
         // tab is hidden, the active group item would be set.
         if (item.tab == gBrowser.selectedTab ||
             (!GroupItems.getActiveGroupItem() && !item.tab.hidden))
           UI.setActive(this);
       }
--- a/browser/base/content/tabview/items.js
+++ b/browser/base/content/tabview/items.js
@@ -146,20 +146,19 @@ Item.prototype = {
     this.$container = iQ(container);
 
     iQ(this.container).data('item', this);
 
     // ___ drag
     this.dragOptions = {
       cancelClass: 'close stackExpander',
       start: function(e, ui) {
-        if (this.isAGroupItem) {
-          UI.setActive(this);
+        UI.setActive(this);
+        if (this.isAGroupItem)
           this._unfreezeItemSize();
-        }
         // if we start dragging a tab within a group, start with dropSpace on.
         else if (this.parent != null)
           this.parent._dropSpaceActive = true;
         drag.info = new Drag(this, e);
       },
       drag: function(e) {
         drag.info.drag(e);
       },
@@ -196,18 +195,17 @@ Item.prototype = {
 
     // ___ resize
     var self = this;
     this.resizeOptions = {
       aspectRatio: self.keepProportional,
       minWidth: 90,
       minHeight: 90,
       start: function(e,ui) {
-        if (this.isAGroupItem)
-          UI.setActive(this);
+        UI.setActive(this);
         resize.info = new Drag(this, e);
       },
       resize: function(e,ui) {
         resize.info.snap(UI.rtl ? 'topright' : 'topleft', false, self.keepProportional);
       },
       stop: function() {
         self.setUserSize();
         self.pushAway();
--- a/browser/base/content/test/tabview/Makefile.in
+++ b/browser/base/content/test/tabview/Makefile.in
@@ -135,16 +135,17 @@ include $(topsrcdir)/config/rules.mk
                  browser_tabview_bug641802.js \
                  browser_tabview_bug642793.js \
                  browser_tabview_bug643392.js \
                  browser_tabview_bug644097.js \
                  browser_tabview_bug645653.js \
                  browser_tabview_bug648882.js \
                  browser_tabview_bug649006.js \
                  browser_tabview_bug649307.js \
+                 browser_tabview_bug649319.js \
                  browser_tabview_bug650573.js \
                  browser_tabview_bug651311.js \
                  browser_tabview_bug654941.js \
                  browser_tabview_bug655269.js \
                  browser_tabview_bug656778.js \
                  browser_tabview_bug656913.js \
                  browser_tabview_dragdrop.js \
                  browser_tabview_exit_button.js \
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/tabview/browser_tabview_bug649319.js
@@ -0,0 +1,88 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+function test() {
+  waitForExplicitFinish();
+
+  newWindowWithTabView(function (win) {
+    registerCleanupFunction(function () win.close());
+    waitForFocus(function () testScenarios(win));
+  });
+}
+
+function testScenarios(win) {
+  let simulateDragDrop = function (target) {
+    EventUtils.synthesizeMouseAtCenter(target, {type: "mousedown"}, cw);
+    EventUtils.synthesizeMouse(target, 40, 20, {type: "mousemove"}, cw);
+    EventUtils.synthesizeMouse(target, 80, 20, {type: "mouseup"}, cw);
+  }
+
+  let dragOutOfGroup = function (target) {
+    EventUtils.synthesizeMouseAtCenter(target, {type: "mousedown"}, cw);
+    EventUtils.synthesizeMouse(target, 600, 5, {type: "mousemove"}, cw);
+    EventUtils.synthesizeMouse(target, 600, 5, {type: "mouseup"}, cw);
+  }
+
+  let dragIntoGroup = function (target) {
+    EventUtils.synthesizeMouseAtCenter(target, {type: "mousedown"}, cw);
+    EventUtils.synthesizeMouse(target, -200, 5, {type: "mousemove"}, cw);
+    EventUtils.synthesizeMouse(target, -200, 5, {type: "mouseup"}, cw);
+  }
+
+  let assertActiveOrphan = function (tabItem) {
+    ok(!cw.GroupItems.getActiveGroupItem(), "no groupItem is active");
+    is(cw.UI.getActiveTab(), tabItem, "orphan tab is active");
+    is(cw.UI.getActiveOrphanTab(), tabItem, "orphan tab is active");
+  }
+
+  let cw = win.TabView.getContentWindow();
+  let groupItem = cw.GroupItems.groupItems[0];
+  let groupItem2 = createGroupItemWithBlankTabs(win, 400, 300, 20, 4);
+
+  // move group
+  cw.UI.setActive(groupItem);
+  simulateDragDrop(groupItem2.container);
+  is(cw.GroupItems.getActiveGroupItem(), groupItem2, "second groupItem is active");
+  is(cw.UI.getActiveTab(), groupItem2.getChild(0), "second groupItem's first tab is active");
+
+  // resize group
+  cw.UI.setActive(groupItem);
+  let tabItem = groupItem2.getChild(2);
+  groupItem2.setActiveTab(tabItem);
+  simulateDragDrop(groupItem2.$resizer[0]);
+  is(cw.GroupItems.getActiveGroupItem(), groupItem2, "second groupItem is active");
+  is(cw.UI.getActiveTab(), tabItem, "second groupItem's third tab is active");
+
+  // create orphan
+  tabItem = groupItem2.getChild(0);
+  dragOutOfGroup(tabItem.container);
+
+  // move orphan
+  cw.UI.setActive(groupItem2);
+  simulateDragDrop(tabItem.container);
+  assertActiveOrphan(tabItem);
+
+  // resize orphan
+  cw.UI.setActive(groupItem2);
+  let $resizer = cw.iQ('.iq-resizable-handle', tabItem.container);
+  simulateDragDrop($resizer[0]);
+  assertActiveOrphan(tabItem);
+
+  // drag back into group
+  dragIntoGroup(tabItem.container);
+  cw.UI.setActive(groupItem);
+  cw.UI.setActive(groupItem2);
+  is(cw.UI.getActiveTab(), tabItem, "the dropped tab is active");
+
+  // hide + unhide groupItem
+  hideGroupItem(groupItem2, function () {
+    is(cw.GroupItems.getActiveGroupItem(), groupItem, "first groupItem is active");
+
+    unhideGroupItem(groupItem2, function () {
+      is(cw.GroupItems.getActiveGroupItem(), groupItem2, "second groupItem is active");
+      is(cw.UI.getActiveTab(), tabItem, "the dropped tab is active");
+
+      finish();
+    });
+  });
+}