Bug 954255 - Better window positions at first start.
authorFlorian Quèze <florian@instantbird.org>
Wed, 15 Jun 2011 19:21:58 +0200
changeset 18286 ff0b9f62f161e0bac080af7f914f61f2a463e275
parent 18285 7f0ca039f3e2b04ce0918170af0f0b58952b3d87
child 18287 9bcd621696ac9b58fa032ab04eb9bdd5c130dfc3
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)
bugs954255
Bug 954255 - Better window positions at first start.
im/content/blist.js
im/content/blist.xul
im/content/menus.js
im/content/preferences/main.js
im/modules/ibCore.jsm
--- a/im/content/blist.js
+++ b/im/content/blist.js
@@ -587,16 +587,24 @@ var buddyList = {
       var win = blistWindows.getNext();
       if (win != window) {
         win.QueryInterface(Ci.nsIDOMWindowInternal).focus();
         window.close();
         return;
       }
     }
 
+    // Move the window to the right of the screen on new profiles.
+    let docElt = document.documentElement;
+    if (!docElt.hasAttribute("height")) {
+      docElt.setAttribute("height", screen.availHeight || 600);
+      let width = parseInt(docElt.getAttribute("width"));
+      window.moveTo(screen.availLeft + screen.availWidth - width, 0);
+    }
+
     // TODO remove this once we cleanup the way the menus are inserted
     let menubar = document.getElementById("blistMenubar");
     let statusArea = document.getElementById("statusArea");
     statusArea.parentNode.insertBefore(menubar, statusArea);
 
     buddyList.displayCurrentStatus();
     buddyList.displayUserDisplayName();
     buddyList.displayUserIcon();
--- a/im/content/blist.xul
+++ b/im/content/blist.xul
@@ -49,17 +49,16 @@
   %brandDTD;
 ]>
 
 <window
   id     = "blistWindow"
   windowtype="Messenger:blist"
   title  = "&contacts.title;"
   width  = "200"
-  height = "600"
   persist= "width height screenX screenY"
 #ifndef XP_MACOSX
   onclose= "event.preventDefault(); goQuitApplication();"
 #endif
   xmlns  = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
   <script type="application/javascript" src="chrome://instantbird/content/utilities.js"/>
   <script type="application/javascript" src="chrome://instantbird/content/blist.js"/>
 
--- a/im/content/menus.js
+++ b/im/content/menus.js
@@ -30,62 +30,48 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
-const addonManagerWindow = "chrome://instantbird/content/extensions.xul";
-const accountManagerWindow = "chrome://instantbird/content/accounts.xul";
-const blistWindow = "chrome://instantbird/content/blist.xul";
 const addBuddyWindow = "chrome://instantbird/content/addbuddy.xul";
 const joinChatWindow = "chrome://instantbird/content/joinchat.xul";
 const aboutWindow = "chrome://instantbird/content/aboutDialog.xul";
 const errorConsoleWindow = "chrome://global/content/console.xul";
 const preferencesWindow = "chrome://instantbird/content/preferences/preferences.xul";
 
 if (!("Services" in window))
   Components.utils.import("resource:///modules/imServices.jsm");
 if (!("Core" in window))
   Components.utils.import("resource:///modules/ibCore.jsm");
 
 var menus = {
-  focus: function menu_focus(aWindowType) {
-    var win = Services.wm.getMostRecentWindow(aWindowType);
-    if (win)
-      win.focus();
-    return win;
-  },
-
   about: function menu_about() {
-    if (!this.focus("Messenger:About"))
-      window.open(aboutWindow, "About",
-                  "chrome,resizable=no,minimizable=no,centerscreen");
+    Core.showWindow("Messenger:About", aboutWindow, "About",
+                    "chrome,resizable=no,minimizable=no,centerscreen");
   },
 
   accounts: function menu_accounts() {
     Core.showAccounts();
   },
 
   preferences: function menu_preferences() {
     Core.showPreferences();
   },
 
   addons: function menu_addons() {
-    if (!this.focus("Addons:Manager"))
-      window.open(addonManagerWindow, "Addons",
-                  "chrome,menubar,extra-chrome,toolbar,dialog=no,resizable");
+    Core.showAddons();
   },
 
   errors: function debug_errors() {
-    if (!menus.focus("global:console"))
-      window.open(errorConsoleWindow, "Errors",
-                  "chrome,extrachrome,menubar,resizable,scrollbars,status,toolbar");
+    Core.showWindow("global:console", errorConsoleWindow, "Errors",
+                    "chrome,extrachrome,menubar,resizable,scrollbars,status,toolbar");
   },
 
   updates: function menu_updates() {
     Core.showUpdates();
   },
 
   displayUpdateStatus: function menu_displayUpdateStatus() {
     // copied from buildHelpMenu in mozilla/browser/base/content/utilityOverlay.js
@@ -194,17 +180,19 @@ var menus = {
                                  "statusOffline"]);
   },
 
   setStatus: function menu_setStatus(aEvent) {
     let status = aEvent.originalTarget.getAttribute("status");
     if (!status)
       return; // is this really possible?
 
-    let blist = this.focus("Messenger:blist");
-    if (blist)
+    let blist = Services.wm.getMostRecentWindow("Messenger:blist");
+    if (blist) {
+      blist.focus();
       blist.buddyList.startEditStatus(status);
+    }
     else {
       Services.core.setStatus(Status.toFlag(status),
                               Services.core.currentStatusMessage);
     }
   }
 };
--- a/im/content/preferences/main.js
+++ b/im/content/preferences/main.js
@@ -33,51 +33,38 @@
 # use your version of this file under the terms of the MPL, indicate your
 # decision by deleting the provisions above and replace them with the notice
 # and other provisions required by the GPL or the LGPL. If you do not delete
 # the provisions above, a recipient may use your version of this file under
 # the terms of any one of the MPL, the GPL or the LGPL.
 #
 # ***** END LICENSE BLOCK *****
 
+if (!("Core" in window))
+  Components.utils.import("resource:///modules/ibCore.jsm");
+
 var gMainPane = {
   _pane: null,
 
   /**
    * Initialization of this.
    */
   init: function ()
   {
     this._pane = document.getElementById("paneMain");
   },
 
   /**
-   * Helper to focus an already existing window before opening a new one.
-   */
-  focus: function (aWindowType) {
-    var win = Services.wm.getMostRecentWindow(aWindowType);
-    if (win)
-      win.focus();
-    return win;
-  },
-
-  /**
    * Displays the Add-ons Manager.
    */
   showAccountsMgr: function ()
   {
-    if (!this.focus("Messenger:Accounts"))
-      window.open("chrome://instantbird/content/accounts.xul", "Accounts",
-                  "chrome,resizable");
+    Core.showAccounts();
   },
 
   /**
    * Displays the Add-ons Manager.
    */
   showAddonsMgr: function ()
   {
-    const AMURL = "chrome://instantbird/content/extensions.xul";
-
-    if (!this.focus("Addons:Manager"))
-      window.open(AMURL, "Addons",
-                  "chrome,menubar,extra-chrome,toolbar,dialog=no,resizable");
+    Core.showAddons();
   }
 };
--- a/im/modules/ibCore.jsm
+++ b/im/modules/ibCore.jsm
@@ -125,17 +125,22 @@ var Core = {
     else
       win = Services.ww.openWindow(null, aUrl, aName, aFeatures, null);
     return win;
   },
 
   showAccounts: function() {
     this.showWindow("Messenger:Accounts",
                     "chrome://instantbird/content/accounts.xul", "Accounts",
-                    "chrome,resizable");
+                    "chrome,resizable,centerscreen");
+  },
+  showAddons: function() {
+    this.showWindow("Addons:Manager",
+                    "chrome://instantbird/content/extensions.xul", "Addons",
+                    "chrome,menubar,extrachrome,toolbar,dialog=no,resizable,centerscreen");
   },
   showContacts: function() {
     this.showWindow("Messenger:blist",
                     "chrome://instantbird/content/blist.xul", "Contacts",
                     "chrome,dialog=no,all");
   },
   showPreferences: function() {
     this.showWindow("Messenger:Preferences",