Bug 1041667 - Fix positioning of the global webrtc sharing indicator if there are multiple screens, r=dolske.
authorFlorian Quèze <florian@queze.net>
Mon, 04 Aug 2014 12:32:59 +0200
changeset 197492 a4c0a19cf1cf0c7b00bb46eedd60a8119c294647
parent 197418 e6614d8d85f9cae8cc1343743154f0f98eb34a9e
child 197493 0053279a09b4ab97ccb7a049cef1ad70d9b5cf69
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersdolske
bugs1041667
milestone34.0a1
Bug 1041667 - Fix positioning of the global webrtc sharing indicator if there are multiple screens, r=dolske.
browser/base/content/webrtcIndicator.js
--- a/browser/base/content/webrtcIndicator.js
+++ b/browser/base/content/webrtcIndicator.js
@@ -1,13 +1,13 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-const Cu = Components.utils;
+const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource:///modules/webrtcUI.jsm");
 
 const BUNDLE_URL = "chrome://browser/locale/webrtcIndicator.properties";
 let gStringBundle;
 
 function init(event) {
   gStringBundle = Services.strings.createBundle(BUNDLE_URL);
@@ -124,17 +124,22 @@ function onFirefoxButtonClick(event) {
 }
 
 let PositionHandler = {
   positionCustomized: false,
   threshold: 10,
   adjustPosition: function() {
     if (!this.positionCustomized) {
       // Center the window horizontally on the screen (not the available area).
-      window.moveTo((screen.width - document.documentElement.clientWidth) / 2, 0);
+      // Until we have moved the window to y=0, 'screen.width' may give a value
+      // for a secondary screen, so use values from the screen manager instead.
+      let width = {};
+      Cc["@mozilla.org/gfx/screenmanager;1"].getService(Ci.nsIScreenManager)
+        .primaryScreen.GetRectDisplayPix({}, {}, width, {});
+      window.moveTo((width.value - document.documentElement.clientWidth) / 2, 0);
     } else {
       // This will ensure we're at y=0.
       this.setXPosition(window.screenX);
     }
   },
   setXPosition: function(desiredX) {
     // Ensure the indicator isn't moved outside the available area of the screen.
     let desiredX = Math.max(desiredX, screen.availLeft);