Bug 445573 - Ctrl+Tab: Holding tab should bring up tab-switching panel and repeat. r=gavin
authorDão Gottwald <dao@mozilla.com>
Mon, 11 Aug 2008 11:06:42 +0200
changeset 16550 23a09bfad7cafa11928580663485c857a0348039
parent 16549 48191fdcf8a72d9c256dda6f26a9d7673caa3cb9
child 16551 3d083d9418dc87f5227f6aa0a0698d07baf9731e
push id1124
push userdgottwald@mozilla.com
push dateMon, 11 Aug 2008 09:10:30 +0000
treeherdermozilla-central@3d083d9418dc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgavin
bugs445573
milestone1.9.1a2pre
Bug 445573 - Ctrl+Tab: Holding tab should bring up tab-switching panel and repeat. r=gavin
browser/base/content/browser-tabPreviews.js
--- a/browser/base/content/browser-tabPreviews.js
+++ b/browser/base/content/browser-tabPreviews.js
@@ -172,28 +172,28 @@ var ctrlTab = {
       this.attachTab(tab, tab == gBrowser.selectedTab);
     }, this);
 
     tabContainer.addEventListener("TabOpen", this, false);
     tabContainer.addEventListener("TabSelect", this, false);
     tabContainer.addEventListener("TabClose", this, false);
 
     gBrowser.mTabBox.handleCtrlTab = false;
-    window.addEventListener("keydown", this, true);
+    window.addEventListener("keypress", this, true);
   },
   uninit: function () {
     this.tabs = null;
 
     var tabContainer = gBrowser.tabContainer;
     tabContainer.removeEventListener("TabOpen", this, false);
     tabContainer.removeEventListener("TabSelect", this, false);
     tabContainer.removeEventListener("TabClose", this, false);
 
     this.panel.removeEventListener("popuphiding", this, false);
-    window.removeEventListener("keydown", this, true);
+    window.removeEventListener("keypress", this, true);
   },
   addBox: function (aAtStart) {
     const SVGNS = "http://www.w3.org/2000/svg";
 
     var thumbnail = document.createElementNS(SVGNS, "image");
     thumbnail.setAttribute("class", "ctrlTab-thumbnail");
     thumbnail.setAttribute("height", tabPreviews.height);
     thumbnail.setAttribute("width", tabPreviews.width);
@@ -419,17 +419,17 @@ var ctrlTab = {
     var i = this.tabs.indexOf(aTab);
     if (i >= 0)
       this.tabs.splice(i, 1);
   },
   open: function () {
     this._deferOnTabSelect = [];
 
     window.addEventListener("keyup", this, true);
-    window.addEventListener("keypress", this, true);
+    window.addEventListener("keydown", this, true);
     this.panel.addEventListener("popuphiding", this, false);
     this.panel.hidden = false;
     this.panel.width = tabPreviews.width * this.visibleCount;
     this.panel.openPopupAtScreen(screen.availLeft + (screen.availWidth - this.panel.width) / 2,
                                  screen.availTop + (screen.availHeight - this.svgRoot.getAttribute("height")) / 2,
                                  false);
 
     // display $visibleCount tabs, starting with the first or
@@ -437,17 +437,17 @@ var ctrlTab = {
     for (let index = this.invertDirection ? this.tabs.length - 2 : 0,
              i = this.visibleCount; i > 0; i--)
       this.addPreview(this.addBox(), this.tabs[index++ % this.tabs.length]);
 
     // regardless of visibleCount, highlight the second-visible tab
     this.selected = this.container.childNodes[1];
     this.arrangeBoxes();
   },
-  onKeyDown: function (event) {
+  onKeyPress: function (event) {
     var isOpen = this.isOpen;
     var propagate = !isOpen;
     switch (event.keyCode) {
       case event.DOM_VK_TAB:
         if (event.ctrlKey && !event.altKey && !event.metaKey && this.tabs.length > 1) {
           propagate = false;
           this.invertDirection = event.shiftKey;
           if (isOpen)
@@ -457,16 +457,21 @@ var ctrlTab = {
           else
             this.open();
         }
         break;
       case event.DOM_VK_ESCAPE:
         if (isOpen)
           this.panel.hidePopup();
         break;
+      default:
+        if (isOpen && event.charCode == this.closeCharCode) {
+          this.stopScroll();
+          gBrowser.removeTab(this.selected._tab);
+        }
     }
     if (!propagate) {
       event.stopPropagation();
       event.preventDefault();
     }
   },
   onKeyUp: function (event) {
     if (event.keyCode == event.DOM_VK_CONTROL) {
@@ -474,17 +479,17 @@ var ctrlTab = {
       let selectedTab = this.selected._tab;
       this.panel.hidePopup();
       gBrowser.selectedTab = selectedTab;
     }
   },
   onPopupHiding: function () {
     this.stopScroll();
     window.removeEventListener("keyup", this, true);
-    window.removeEventListener("keypress", this, true);
+    window.removeEventListener("keydown", this, true);
     while (this.container.childNodes.length)
       this.removeBox(this.container.lastChild);
     this.selected = null;
     this.invertDirection = false;
     this._uniqid = 0;
     this.label.value = "";
     this.setStatusbarValue();
     this.container.removeAttribute("transform");
@@ -528,32 +533,25 @@ var ctrlTab = {
                 this.removeBox(box);
                 this.arrangeBoxes();
               }
             }, this);
           }
         }
         this.detachTab(event.target);
         break;
-      case "keydown":
-        this.onKeyDown(event);
+      case "keypress":
+        this.onKeyPress(event);
         break;
-      case "keypress":
-        // the panel is open; don't propagate any key events
-        event.stopPropagation();
-        event.preventDefault();
-        if (event.charCode == this.closeCharCode) {
-          this.stopScroll();
-          gBrowser.removeTab(this.selected._tab);
-        }
-        break;
+      case "keydown":
       case "keyup":
         // the panel is open; don't propagate any key events
         event.stopPropagation();
         event.preventDefault();
-        this.onKeyUp(event);
+        if (event.type == "keyup")
+          this.onKeyUp(event);
         break;
       case "popuphiding":
         this.onPopupHiding();
         break;
     }
   }
 };