Bug 1041667 - Fix positioning of the global webrtc sharing indicator if there are multiple screens, r=dolske, a=sledru.
authorFlorian Quèze <florian@queze.net>
Mon, 04 Aug 2014 12:32:59 +0200
changeset 217371 2597220a5926ef85476b09d09f2475956cc32c7c
parent 217370 f6a784dd39871cd2127df3cfbd228fb598ab89d7
child 217372 7c8cf25aa8272c370293e02205a1ac1a78171e50
push id515
push userraliiev@mozilla.com
push dateMon, 06 Oct 2014 12:51:51 +0000
treeherdermozilla-release@267c7a481bef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdolske, sledru
bugs1041667
milestone33.0a2
Bug 1041667 - Fix positioning of the global webrtc sharing indicator if there are multiple screens, r=dolske, a=sledru.
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);