Bug 628887 - When in an expanded stack, arrow keys should only move between those r=tim
authorRaymond Lee <raymond@raysquare.com>
Thu, 18 Aug 2011 10:56:25 +0800
changeset 75878 edeed3c6065ced200cc086d9e171411dd49ed308
parent 75628 9d6e9b1c7807759887c3c2d2d4dc7f2996adbf27
child 75879 f8fbf62f31e8e5b1c63f6c3d19d4bc0dc9f0ec7f
push id3
push userfelipc@gmail.com
push dateFri, 30 Sep 2011 20:09:13 +0000
reviewerstim
bugs628887
milestone9.0a1
Bug 628887 - When in an expanded stack, arrow keys should only move between those r=tim
browser/base/content/tabview/ui.js
browser/base/content/test/tabview/Makefile.in
browser/base/content/test/tabview/browser_tabview_bug628887.js
--- a/browser/base/content/tabview/ui.js
+++ b/browser/base/content/tabview/ui.js
@@ -1125,28 +1125,36 @@ let UI = {
         self.ignoreKeypressForSearch = false;
         processBrowserKeys(event);
         return;
       }
 
       function getClosestTabBy(norm) {
         if (!self.getActiveTab())
           return null;
-        let centers =
-          [[item.bounds.center(), item]
-             for each(item in TabItems.getItems()) if (!item.parent || !item.parent.hidden)];
-        let myCenter = self.getActiveTab().bounds.center();
-        let matches = centers
-          .filter(function(item){return norm(item[0], myCenter)})
-          .sort(function(a,b){
-            return myCenter.distance(a[0]) - myCenter.distance(b[0]);
-          });
-        if (matches.length > 0)
-          return matches[0][1];
-        return null;
+
+        let activeTab = self.getActiveTab();
+        let activeTabGroup = activeTab.parent;
+        let myCenter = activeTab.bounds.center();
+        let match;
+
+        TabItems.getItems().forEach(function (item) {
+          if (!item.parent.hidden &&
+              (!activeTabGroup.expanded || activeTabGroup.id == item.parent.id)) {
+            let itemCenter = item.bounds.center();
+
+            if (norm(itemCenter, myCenter)) {
+              let itemDist = myCenter.distance(itemCenter);
+              if (!match || match[0] > itemDist)
+                match = [itemDist, item];
+            }
+          }
+        });
+
+        return match && match[1];
       }
 
       let preventDefault = true;
       let activeTab;
       let norm = null;
       switch (event.keyCode) {
         case KeyEvent.DOM_VK_RIGHT:
           norm = function(a, me){return a.x > me.x};
--- a/browser/base/content/test/tabview/Makefile.in
+++ b/browser/base/content/test/tabview/Makefile.in
@@ -115,16 +115,17 @@ include $(topsrcdir)/config/rules.mk
                  browser_tabview_bug626525.js \
                  browser_tabview_bug626791.js \
                  browser_tabview_bug627239.js \
                  browser_tabview_bug627288.js \
                  browser_tabview_bug627736.js \
                  browser_tabview_bug628061.js \
                  browser_tabview_bug628165.js \
                  browser_tabview_bug628270.js \
+                 browser_tabview_bug628887.js \
                  browser_tabview_bug629189.js \
                  browser_tabview_bug629195.js \
                  browser_tabview_bug630102.js \
                  browser_tabview_bug630157.js \
                  browser_tabview_bug631662.js \
                  browser_tabview_bug631752.js \
                  browser_tabview_bug633788.js \
                  browser_tabview_bug634077.js \
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/tabview/browser_tabview_bug628887.js
@@ -0,0 +1,50 @@
+/* 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());
+
+    let cw = win.TabView.getContentWindow();
+    let groupItemOne = cw.GroupItems.groupItems[0];
+
+    let groupItemTwo = createGroupItemWithBlankTabs(win, 100, 100, 40, 2);
+    ok(groupItemTwo.isStacked(), "groupItem is now stacked");
+
+    is(win.gBrowser.tabs.length, 3, "There are three tabs");
+
+    // the focus should remain within the group after it's expanded
+    groupItemTwo.addSubscriber("expanded", function onExpanded() {
+      groupItemTwo.removeSubscriber("expanded", onExpanded);
+
+      ok(groupItemTwo.expanded, "groupItemTwo is expanded");
+      is(cw.UI.getActiveTab(), groupItemTwo.getChild(0),
+         "The first tab item in group item two is active in expanded mode");
+
+      EventUtils.synthesizeKey("VK_DOWN", {}, cw);
+      is(cw.UI.getActiveTab(), groupItemTwo.getChild(0),
+         "The first tab item is still active after pressing down key");
+
+      // the focus should goes to other group if the down arrow is pressed
+      groupItemTwo.addSubscriber("collapsed", function onExpanded() {
+        groupItemTwo.removeSubscriber("collapsed", onExpanded);
+
+        ok(!groupItemTwo.expanded, "groupItemTwo is not expanded");
+        is(cw.UI.getActiveTab(), groupItemTwo.getChild(0),
+           "The first tab item is active in group item two in collapsed mode");
+
+        EventUtils.synthesizeKey("VK_DOWN", {}, cw);
+        is(cw.UI.getActiveTab(), groupItemOne.getChild(0),
+           "The first tab item in group item one is active after pressing down key");
+
+        finish();
+      });
+
+      groupItemTwo.collapse();
+    });
+
+    groupItemTwo.expand();
+  });
+}