Bug 955449 - Add method to select and focus a panel in tabbrowser, r=aleth.
authorNihanth Subramanya <nhnt11@gmail.com>
Mon, 24 Jun 2013 21:05:26 +0530
changeset 19048 1b734a2c4994634af34ab70d320e6e3d2c9194ea
parent 19047 1e72434937ef1a2ab24d5d5e7574cb60ff5768c4
child 19049 e3f7e6924f846e5469e294d8899ca6382dbcc864
push id1103
push usermbanner@mozilla.com
push dateTue, 18 Mar 2014 07:44:06 +0000
treeherdercomm-beta@50c6279a0af0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaleth
bugs955449
Bug 955449 - Add method to select and focus a panel in tabbrowser, r=aleth.
im/content/tabbrowser.xml
im/modules/ibCore.jsm
im/modules/imWindows.jsm
--- a/im/content/tabbrowser.xml
+++ b/im/content/tabbrowser.xml
@@ -803,16 +803,30 @@
               var e = document.createEvent("Events");
               e.initEvent("NewTab", true, true);
               this.dispatchEvent(e);
             }
           ]]>
         </body>
       </method>
 
+      <method name="selectPanel">
+        <parameter name="aPanel"/>
+        <body>
+        <![CDATA[
+          if (aPanel.parentNode != this.mPanelContainer)
+            throw "Trying to select a panel that's not in this tabbrowser?";
+          this.selectedTab = aPanel.tab;
+          aPanel.focus();
+          if ("onSelect" in aPanel)
+            aPanel.onSelect();
+        ]]>
+        </body>
+      </method>
+
       <method name="selectTabAtIndex">
         <parameter name="aIndex"/>
         <parameter name="aEvent"/>
         <body>
         <![CDATA[
           // count backwards for aIndex < 0
           if (aIndex < 0)
             aIndex += this.mTabs.length;
--- a/im/modules/ibCore.jsm
+++ b/im/modules/ibCore.jsm
@@ -101,18 +101,17 @@ var Core = {
           let panel = aWindow.document.createElementNS(
             "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul",
             "aboutPanel");
           // Try to add the panel, and return false if the window couldn't accept
           // it (e.g. tabbed conversations are disabled).
           if (!aWindow.getTabBrowser().addPanel(panel))
             return false;
           panel.showAboutPage(aPage);
-          aWindow.getTabBrowser().selectedTab = panel.tab;
-          panel.focus();
+          aWindow.getTabBrowser().selectPanel(panel);
           return true;
         }
         // Try to show the page in win, and open a new window if it didn't work.
         if (!showPage(win, page)) {
           win = Services.ww.openWindow(null, "chrome://instantbird/content/instantbird.xul",
                                        "_blank", "chrome,toolbar,resizable", null);
           win.addEventListener("load", showPage.bind(null, win, page));
           return true;
--- a/im/modules/imWindows.jsm
+++ b/im/modules/imWindows.jsm
@@ -70,20 +70,17 @@ var Conversations = {
     if (!this.isUIConversationDisplayed(uiConv))
       this.showConversation(uiConv);
     // The conversation may still not be displayed if we are waiting
     // for a new window. In this case the conversation will be focused
     // automatically anyway.
     if (this.isUIConversationDisplayed(uiConv)) {
       let conv = this._uiConv[uiConv.id];
       let doc = conv.ownerDocument;
-      doc.getElementById("conversations").selectedTab = conv.tab;
-      conv.focus();
-      // Tell it to mark itself as read.
-      conv.onSelect();
+      doc.getElementById("conversations").selectPanel(conv);
       doc.defaultView.focus();
 #ifdef XP_MACOSX
       Components.classes["@mozilla.org/widget/macdocksupport;1"]
                 .getService(Components.interfaces.nsIMacDockSupport)
                 .activateApplication(true);
 #endif
     }
     return uiConv;