Bug 1029501 - Opening the awesometab and then pressing Escape should return to the previous conversation. r=florian
authorNihanth Subramanya <nhnt11@gmail.com>
Tue, 01 Jul 2014 15:21:27 +0530
changeset 20415 b82a9f18921f1929323ad154807a53d93e645b4d
parent 20414 82fdf36eab593bdb093e33ae461ce94bd62a1313
child 20416 3fdd4044a6e194fb3f5e4638c4dacd4b2173019f
push id1209
push usermbanner@mozilla.com
push dateTue, 02 Sep 2014 16:59:36 +0000
treeherdercomm-beta@842e0fd167ee [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersflorian
bugs1029501
Bug 1029501 - Opening the awesometab and then pressing Escape should return to the previous conversation. r=florian
im/content/newtab.xml
--- a/im/content/newtab.xml
+++ b/im/content/newtab.xml
@@ -53,28 +53,35 @@
         <getter>
           return document.getAnonymousElementByAttribute(this, "anonid", "newtab-listbox");
         </getter>
       </property>
 
       <!-- Array version of this.listbox.childNodes. -->
       <field name="listItems">[]</field>
 
+      <!-- If a new conversation tab is opened and then closed without
+           switching away, we restore focus to the previous tab. -->
+      <field name="previousTab">null</field>
+
       <property name="tab">
         <getter>
         <![CDATA[
           return this._tab;
         ]]>
         </getter>
         <setter>
         <![CDATA[
           this._tab = val;
           this._tab.setAttribute("label",
             Services.strings.createBundle("chrome://instantbird/locale/newtab.properties")
                     .GetStringFromName("newtab.label"));
+          // When our tab is set, the tab browser has not yet updated its
+          // current tab to ours, so we can use it to store the previous tab.
+          this.previousTab = window.getTabBrowser().mCurrentTab;
         ]]>
         </setter>
       </property>
 
       <destructor>
       <![CDATA[
         this.destroy();
       ]]>
@@ -99,16 +106,24 @@
       <method name="onSelect">
         <body>
         <![CDATA[
           this.refresh();
         ]]>
         </body>
       </method>
 
+      <method name="switchingAwayFromPanel">
+        <body>
+        <![CDATA[
+          this.previousTab = null;
+        ]]>
+        </body>
+      </method>
+
       <!-- Maintains computed number of items to display. Incremented when the user
            scrolls near the bottom of the list if we have more conversations. -->
       <field name="numberOfItemsToDisplay">0</field>
       <property name="hasMoreConversations" readonly="true">
         <getter>
         <![CDATA[
           return this.filteredConvs && this.filteredConvs.hasMoreElements();
         ]]>
@@ -152,16 +167,20 @@
         ]]>
         </body>
       </method>
 
       <!-- Remove observers when closing tab. -->
       <method name="destroy">
         <body>
         <![CDATA[
+          if (this._destroyed)
+            return;
+          if (this.previousTab && !window.getTabBrowser()._windowIsClosing)
+            window.getTabBrowser().selectedTab = this.previousTab;
           this.statsService.removeObserver(this);
           this._destroyed = true;
         ]]>
         </body>
       </method>
 
       <method name="finishImport">
         <parameter name="aOtherNewTab"/>
@@ -308,16 +327,18 @@
 
       <method name="startConversation">
         <parameter name="aNewtabItem"/>
         <body>
         <![CDATA[
           let conv = aNewtabItem.target.createConversation();
           if (conv)
             Conversations.focusConversation(conv);
+          // Ensure we don't focus the previous tab after removing ours.
+          this.previousTab = null;
         ]]>
         </body>
       </method>
 
       <!-- nsIObserver implementation -->
       <method name="observe">
         <parameter name="aSubject"/>
         <parameter name="aTopic"/>