Bug 628918 Make CTRL-F4 work in tabbmail (but not in OSX) and better keyboard tab navigation on Mac. r=Neil ui-r=stefanh
authorPhilip Chee <philip.chee@gmail.com>
Sun, 30 Jan 2011 23:27:48 +0800
changeset 7037 f15efb863e07ad4be337bc6e2c7ef13534fb0e62
parent 7036 c45978ee2f61ad3b70f04092b9cd617ae91b605a
child 7038 f361ab8e5d3bcb8c1a403a54a2cc883c6f2668c2
push idunknown
push userunknown
push dateunknown
reviewersNeil, stefanh
bugs628918
Bug 628918 Make CTRL-F4 work in tabbmail (but not in OSX) and better keyboard tab navigation on Mac. r=Neil ui-r=stefanh
suite/browser/tabbrowser.xml
--- a/suite/browser/tabbrowser.xml
+++ b/suite/browser/tabbrowser.xml
@@ -193,23 +193,46 @@
       <field name="mMissedIconCache">
         null
       </field>
       <field name="mContextTab">
         null
       </field>
       <field name="_keyEventHandler" readonly="true">
       <![CDATA[({
-        tabbrowser: this,
         handleEvent: function handleEvent(aEvent) {
-          if (aEvent.ctrlKey && aEvent.keyCode == KeyEvent.DOM_VK_F4 &&
-              this.tabbrowser.mTabBox.handleCtrlPageUpDown &&
-              this.tabbrowser.getStripVisibility())
-            this.tabbrowser.removeCurrentTab();
-        }
+          if (aEvent.altKey)
+            return;
+
+          if (/Mac/.test(navigator.platform)) {
+            if (!aEvent.metaKey)
+              return;
+
+            var offset = 1;
+            switch (aEvent.charCode) {
+              case '}'.charCodeAt(0):
+                offset = -1;
+              case '{'.charCodeAt(0):
+                if (window.getComputedStyle(this, null).direction == "ltr")
+                  offset *= -1;
+                this.tabContainer.advanceSelectedTab(offset, true);
+                aEvent.stopPropagation();
+                aEvent.preventDefault();
+            }
+          }
+          else {
+            if (aEvent.ctrlKey && !aEvent.shiftKey && !aEvent.metaKey &&
+                aEvent.keyCode == KeyEvent.DOM_VK_F4 &&
+                this.getStripVisibility()) {
+              this.removeCurrentTab();
+              aEvent.stopPropagation();
+              aEvent.preventDefault();
+            }
+          }
+        }.bind(this)
       })]]>
       </field>
       <field name="arrowKeysShouldWrap">
         null
       </field>
       <field name="nextTabNumber">
         0
       </field>
@@ -2683,21 +2706,24 @@
           }
           return this._fastFind;
         ]]>
         </getter>
       </property>
 
       <constructor>
         <![CDATA[
+          document.addEventListener("keypress", this._keyEventHandler, false);
+          this.arrowKeysShouldWrap = /Mac/.test(navigator.platform);
+          // Bail out early if we are in tabmail. See Bug 521803.
+          if (!this.mPanelContainer)
+            return;
+
           this.mCurrentBrowser = this.mPanelContainer.firstChild.firstChild;
           this.mCurrentTab = this.tabContainer.firstChild;
-          document.addEventListener("keypress", this._keyEventHandler, false);
-          this.mTabBox.handleCtrlTab = !/Mac/.test(navigator.platform);
-          this.arrowKeysShouldWrap = /Mac/.test(navigator.platform);
 
           var uniqueId = "panel" + this.nextTabNumber++;
           this.mPanelContainer.childNodes[0].id = uniqueId;
           this.tabs[0].linkedPanel = uniqueId;
           this.tabs[0].linkedBrowser = this.mCurrentBrowser;
 
           // Wire up the first title change listener.
           this.mCurrentBrowser.addEventListener("DOMTitleChanged", this.onTitleChanged, true);
@@ -2741,26 +2767,29 @@
           var os = Components.classes["@mozilla.org/observer-service;1"]
                              .getService(Components.interfaces.nsIObserverService);
           os.addObserver(this, "browser:purge-session-history", false);
         ]]>
       </constructor>
 
       <destructor>
         <![CDATA[
+          document.removeEventListener("keypress", this._keyEventHandler, false);
+          // Bail out early if we are in tabmail. See Bug 521803.
+          if (!this.mPanelContainer)
+            return;
+
           for (var i = 0; i < this.mTabListeners.length; ++i) {
             this.browsers[i].webProgress.removeProgressListener(this.mTabFilters[i]);
             this.mTabFilters[i].removeProgressListener(this.mTabListeners[i]);
             this.mTabFilters[i] = null;
             this.mTabListeners[i] = null;
             // eventListeners are removed from the browsers in display order of the browsers
             this.browsers[i].removeEventListener("DOMTitleChanged", this.onTitleChanged, true);
           }
-          document.removeEventListener("keypress", this._keyEventHandler, false);
-
           var os = Components.classes["@mozilla.org/observer-service;1"]
                              .getService(Components.interfaces.nsIObserverService);
           os.removeObserver(this, "browser:purge-session-history");
           this.savedBrowsers.forEach(function(aTabData) {
             delete aTabData._tab;
             delete aTabData._browser;
             delete aTabData._history;
           });