windowUtils.js
Go to the documentation of this file.
1 /*
2 // BEGIN SONGBIRD GPL
3 //
4 //
5 // This file is part of the Songbird web player.
6 //
7 // Copyright(c) 2005-2008 POTI, Inc.
8 // http://songbirdnest.com
9 //
10 // This file may be licensed under the terms of of the
11 // GNU General Public License Version 2 (the "GPL").
12 //
13 // Software distributed under the License is distributed
14 // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
15 // express or implied. See the GPL for the specific language
16 // governing rights and limitations.
17 //
18 // You should have received a copy of the GPL along with this
19 // program. If not, go to http://www.gnu.org/licenses/gpl.html
20 // or write to the Free Software Foundation, Inc.,
21 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 //
23 // END SONGBIRD GPL
24 //
25  */
26 
35 Components.utils.import("resource://app/jsmodules/StringUtils.jsm");
36 
37 if (typeof(Cc) == "undefined")
38  window.Cc = Components.classes;
39 if (typeof(Ci) == "undefined")
40  window.Ci = Components.interfaces;
41 if (typeof(Cu) == "undefined")
42  window.Cu = Components.utils;
43 if (typeof(Cr) == "undefined")
44  window.Cr = Components.results;
45 
46 
50 var CORE_WINDOWTYPE = "Songbird:Core";
51 
55 var STATE_MAXIMIZED = Ci.nsIDOMChromeWindow.STATE_MAXIMIZED;
56 
60 var STATE_MINIMIZED = Ci.nsIDOMChromeWindow.STATE_MINIMIZED;
61 
62 var gMM = Cc["@songbirdnest.com/Songbird/Mediacore/Manager;1"]
63  .getService(Ci.sbIMediacoreManager);
64 var gPrompt = Cc["@mozilla.org/embedcomp/prompt-service;1"]
65  .getService(Ci.nsIPromptService);
66 var gPrefs = Cc["@mozilla.org/preferences-service;1"]
67  .getService(Ci.nsIPrefBranch);
68 var gConsole = Cc["@mozilla.org/consoleservice;1"]
69  .getService(Ci.nsIConsoleService);
70 
71 var gTypeSniffer = Cc["@songbirdnest.com/Songbird/Mediacore/TypeSniffer;1"]
72  .createInstance(Ci.sbIMediacoreTypeSniffer);
73 
74 
79 function sbScreenRect(inWidth, inHeight, inX, inY) {
80  this.width = inWidth;
81  this.height = inHeight;
82  this.x = inX;
83  this.y = inY;
84 }
85 
92 function getCurMaxScreenRect() {
93  var screenManager = Cc["@mozilla.org/gfx/screenmanager;1"]
94  .getService(Ci.nsIScreenManager);
95 
96  var curX = parseInt(document.documentElement.boxObject.screenX);
97  var curY = parseInt(document.documentElement.boxObject.screenY);
98  var curWidth = parseInt(document.documentElement.boxObject.width);
99  var curHeight = parseInt(document.documentElement.boxObject.height);
100 
101  var curScreen = screenManager.screenForRect(curX, curY, curWidth, curHeight);
102  var x = {}, y = {}, width = {}, height = {};
103  curScreen.GetAvailRect(x, y, width, height);
104 
105  return new sbScreenRect(width.value, height.value, x.value, y.value);
106 }
107 
108 
117  this._init();
118 }
119 
121  _mIsZoomed: false,
122  _mIsResizeEventFromZoom: false,
123  _mSavedXPos: 0,
124  _mSavedYPos: 0,
125  _mSavedWidth: 0,
126  _mSavedHeight: 0,
127 
128  _init: function() {
129  // Listen to document dragging events, we need a closure when a message
130  // is dispatched directly through the document object.
131  var self = this;
132  this._windowdragexit = function(evt) {
133  self._onWindowDragged();
134  };
135  this._windowresized = function(evt) {
136  self._onWindowResized();
137  };
138  this._documentunload = function(evt) {
139  self._onUnload();
140  };
141  document.addEventListener("ondragexit", this._windowdragexit, false);
142  document.addEventListener("resize", this._windowresized, false);
143  document.addEventListener("unload", this._documentunload, false);
144  },
145 
146  _onWindowResized: function() {
147  if (this._mIsZoomed) {
148  if (this._mIsResizeEventFromZoom) {
149  this._mIsResizeEventFromZoom = false;
150  }
151  // Only save window coordinates if the window is out of the 'zoomed' area..
152  else if (!this._isConsideredZoomed()) {
153  this._mIsZoomed = false;
154  this._saveWindowCoords();
155  }
156  }
157  },
158 
159  _onWindowDragged: function() {
160  var maxScreenRect = getCurMaxScreenRect();
161  var curX = parseInt(document.documentElement.boxObject.screenX);
162  var curY = parseInt(document.documentElement.boxObject.screenY);
163 
164  if (this._mIsZoomed) {
165  // If the window was moved more than 10 pixels either way - this
166  // window is no longer considered "zoomed".
167  if (curX > (maxScreenRect.x + 10) || curY > (maxScreenRect.y + 10)) {
168  this._mIsZoomed = false;
169  this._saveWindowCoords();
170  }
171  }
172  else {
173  this._mIsZoomed = this._isConsideredZoomed();
174  }
175  },
176 
177  onZoom: function() {
178  if (this._mIsZoomed) {
179  window.resizeTo(this._mSavedWidth, this._mSavedHeight);
180  window.moveTo(this._mSavedXPos, this._mSavedYPos);
181  this._mIsZoomed = false;
182  }
183  else {
184  this._saveWindowCoords();
185 
186  var maxScreenRect = getCurMaxScreenRect();
187  window.moveTo(maxScreenRect.x, maxScreenRect.y);
188  window.resizeTo(maxScreenRect.width, maxScreenRect.height);
189 
190  this._mIsZoomed = true;
191  this._mIsResizeEventFromZoom = true;
192  }
193  },
194 
195  _onUnload: function() {
196  document.removeEventListener("ondragexit", this._windowdragexit, false);
197  document.removeEventListener("resize", this._windowresized, false);
198  document.removeEventListener("unload", this._documentunload, false);
199  this._windowdragexit = null;
200  this._windowresized = null;
201  this._documentunload = null;
202  },
203 
204  _saveWindowCoords: function() {
205  this._mSavedYPos = parseInt(document.documentElement.boxObject.screenY);
206  this._mSavedXPos = parseInt(document.documentElement.boxObject.screenX);
207  this._mSavedWidth = parseInt(document.documentElement.boxObject.width);
208  this._mSavedHeight = parseInt(document.documentElement.boxObject.height);
209  },
210 
211  _isConsideredZoomed: function() {
212  // If the window was moved into the "zoom" zone
213  // (10 pixel square in top-left corner) then it should be considered
214  // "zoomed" and be set as so.
215  var isZoomed = false;
216  var maxScreenRect = getCurMaxScreenRect();
217  var curX = parseInt(document.documentElement.boxObject.screenX);
218  var curY = parseInt(document.documentElement.boxObject.screenY);
219  var curWidth = parseInt(document.documentElement.boxObject.width);
220  var curHeight = parseInt(document.documentElement.boxObject.height);
221 
222  if (curX < (maxScreenRect.x + 10) &&
223  curY < (maxScreenRect.y + 10) &&
224  curWidth > (maxScreenRect.width - 10) &&
225  curHeight > (maxScreenRect.height - 10))
226  {
227  isZoomed = true;
228  }
229 
230  return isZoomed;
231  }
232 };
233 
234 // Only use our mac zoom controller on the mac:
236 if (getPlatformString() == "Darwin")
237  macZoomWindowController = new sbMacWindowZoomController();
238 
239 
240 // Strings are cool.
241 var theSongbirdStrings = document.getElementById( "songbird_strings" );
242 
243 // log to JS console AND to the command line (in case of crashes)
244 function SB_LOG (scopeStr, msg) {
245  msg = msg ? msg : "";
246  //This works, but adds everything as an Error
247  //Components.utils.reportError( scopeStr + " : " + msg);
248  gConsole.logStringMessage( scopeStr + " : " + msg );
249  dump( scopeStr + " : " + msg + "\n");
250 }
251 
252 var PREFS_SERVICE_CONTRACTID = "@mozilla.org/preferences-service;1";
253 var nsIPrefBranch2 = Components.interfaces.nsIPrefBranch2;
262 function getPref(aFunc, aPreference, aDefaultValue) {
263  var prefs =
264  Components.classes[PREFS_SERVICE_CONTRACTID].getService(nsIPrefBranch2);
265  try {
266  return prefs[aFunc](aPreference);
267  }
268  catch (e) { }
269  return aDefaultValue;
270 }
271 
280 function setPref(aFunc, aPreference, aValue) {
281  var prefs =
282  Components.classes[PREFS_SERVICE_CONTRACTID].getService(nsIPrefBranch2);
283  return prefs[aFunc](aPreference, aValue);
284 }
285 
290 function onMinimize()
291 {
292  document.defaultView.minimize();
293 }
294 
299 function onMaximize(aMaximize)
300 {
301  if ( macZoomWindowController != null )
302  {
303  macZoomWindowController.onZoom();
304  }
305  else
306  {
307  if ( aMaximize )
308  {
309  document.defaultView.maximize();
310  // Force sizemode attribute, due to mozbug 409095.
311  document.documentElement.setAttribute("sizemode", "maximized");
312  }
313  else
314  {
315  document.defaultView.restore();
316  // Force sizemode attribute, due to mozbug 409095.
317  document.documentElement.setAttribute("sizemode", "normal");
318  }
319  }
320  // TODO
321  //syncResizers();
322 }
323 
329 function isMaximized() {
330  return (window.windowState == STATE_MAXIMIZED);
331 }
332 
338 function isMinimized() {
339  return (window.windowState == STATE_MINIMIZED);
340 }
341 
342 /* TODO: These broke circa 0.2. The logic needs to be moved into sys-outer-frame
343 function syncResizers()
344 {
345  // TODO?
346  if (isMaximized()) disableResizers();
347  else enableResizers();
348 }
349 */
350 
355 function onExit( skipSave )
356 {
357  document.defaultView.close();
358 }
359 
364 function onHide()
365 {
366  // Fire custom DOM event so that potential listeners interested in
367  // the fact that the window is about to hide can do something about it.
368  e = document.createEvent("UIEvents");
369  e.initUIEvent("hide", true, true, window, 1);
370  document.dispatchEvent(e);
371 
372  var windowCloak =
373  Components.classes["@songbirdnest.com/Songbird/WindowCloak;1"]
374  .getService(Components.interfaces.sbIWindowCloak);
375  windowCloak.cloak(window);
376 
377  // And try to focus another of our windows. We'll try to focus in this order:
378  var windowList = ["Songbird:Main",
379  "Songbird:TrackEditor",
380  "Songbird:Firstrun",
381  "Songbird:EULA"];
382  var windowCount = windowList.length;
383 
384  var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
385  .getService(Components.interfaces.nsIWindowMediator);
386 
387  for (var index = 0; index < windowCount; index++) {
388  var windowType = windowList[index];
389  var lastWindow = wm.getMostRecentWindow(windowType);
390  if (lastWindow && (lastWindow != window)) {
391  try {
392  lastWindow.focus();
393  } catch (e) {}
394  break;
395  }
396  }
397 
398 }
399 
400 
405  var d = window.document;
406  var dE = window.document.documentElement;
407  if (dE.getAttribute("persist").match("width")) { d.persist(dE.id, "width"); }
408  if (dE.getAttribute("persist").match("height")) { d.persist(dE.id, "height"); }
409 }
410 
415  var d = window.document;
416  var dE = window.document.documentElement;
417  if (dE.getAttribute("persist").match("screenX")) { d.persist(dE.id, "screenX"); }
418  if (dE.getAttribute("persist").match("screenY")) { d.persist(dE.id, "screenY"); }
419 }
420 
424 function windowFocus()
425 {
426  // Try to activate the window if it isn't cloaked.
427  var windowCloak =
428  Components.classes["@songbirdnest.com/Songbird/WindowCloak;1"]
429  .getService(Components.interfaces.sbIWindowCloak);
430  if (windowCloak.isCloaked(window))
431  return;
432 
433  try {
434  window.focus();
435  } catch(e) {
436  }
437 }
438 
442 function delayedActivate()
443 {
444  setTimeout( windowFocus, 50 );
445 }
446 
458 {
466  function getStyle(el, styleProp, defaultValue)
467  {
468  if (!defaultValue)
469  defaultValue = 0;
470  var v = defaultValue;
471  if (el) {
472  var s = document.defaultView.getComputedStyle(el,null);
473  v = s.getPropertyValue(styleProp);
474  }
475  return parseInt(v, 10) || defaultValue;
476  }
477 
478  delayedActivate();
479 
480  // Grab all the values we'll need.
481  var x, oldx = x = parseInt(document.documentElement.boxObject.screenX, 10);
482  var y, oldy = y = parseInt(document.documentElement.boxObject.screenY, 10);
483 
484  /*
485  * xul: the property as set on XUL, or via persist=
486  * min: the property minimum as computed by CSS. Has a fallback minimum.
487  * max: the property maximum as computed by CSS.
488  */
489  var width = {
490  xul: parseInt(document.documentElement.getAttribute("width"), 10),
491  min: Math.max(getStyle(document.documentElement, "min-width"), 16),
492  max: getStyle(document.documentElement, "max-width", Number.POSITIVE_INFINITY)
493  };
494  var height = {
495  xul: parseInt(document.documentElement.getAttribute("height"), 10),
496  min: Math.max(getStyle(document.documentElement, "min-height"), 16),
497  max: getStyle(document.documentElement, "max-height", Number.POSITIVE_INFINITY)
498  };
499 
500  // correct width
501  var newWidth = width.xul || 0;
502 
503  // correct for maximum and minimum sizes (including not larger than the screen)
504  newWidth = Math.min(newWidth, width.max);
505  newWidth = Math.min(newWidth, screen.availWidth);
506  newWidth = Math.max(newWidth, width.min);
507 
508  // correct height
509  var newHeight = height.xul || 0;
510 
511  // correct for maximum and minimum sizes (including not larger than the screen)
512  newHeight = Math.min(newHeight, height.max);
513  newHeight = Math.min(newHeight, screen.availHeight);
514  newHeight = Math.max(newHeight, height.min);
515 
516  // resize the window if necessary
517  if (newHeight != height.xul || newWidth != width.xul) {
518  window.resizeTo(newWidth, newHeight);
519  }
520 
521  // check if we need to move the window, and
522  // move fully offscreen windows back onto the center of the screen
523  var screenRect = getCurMaxScreenRect();
524  if ((x - screenRect.x > screenRect.width) || // offscreen right
525  (x - screenRect.x + newWidth < 0) || // offscreen left
526  (y - screenRect.y > screenRect.height) || // offscreen bottom
527  (y - screenRect.y + newHeight < 0)) // offscreen top
528  {
529  x = (screenRect.width / 2) - (window.outerWidth / 2);
530  x = Math.max(x, 0); // don't move window left of zero.
531  y = (screenRect.height / 2) - (window.outerHeight / 2);
532  y = Math.max(y, 0); // don't move window above zero.
533  }
534 
535  // Make sure our (x, y) coordinate is at least on screen.
536  if (x < screenRect.x) {
537  x = screenRect.x;
538  }
539  if (y < screenRect.y) {
540  y = screenRect.y;
541  }
542 
543  if (!document.documentElement.hasAttribute("screenX")) {
544  // no persisted x, move the window back into the screen
545  // (we allow the user to persist having the window be partially off screen)
546  x = Math.max(x, 0);
547  x = Math.min(x, screen.availWidth - newWidth);
548  }
549  if (!document.documentElement.hasAttribute("screenY")) {
550  // no persisted y, move the window back into the screen
551  // (we allow the user to persist having the window be partially off screen)
552  y = Math.max(y, 0);
553  y = Math.min(y, screen.availHeight - newHeight);
554  }
555 
556  // Move the window if necessary
557  if (x != oldx || y != oldy) {
558  // Moving a maximized window will break the maximized state, so save
559  // the current state so that the window can be re-maximized.
560  var isCurMaximized =
561  document.documentElement.getAttribute("sizemode") == "maximized";
562 
563  // Move
564  window.moveTo(x, y);
565 
566  // Re-maximize
567  if (isCurMaximized) {
568  onMaximize(true);
569  }
570  }
571 
572 /*
573  // debugging dumps
574  Components.utils.reportError(<>
575  {arguments.callee.name}:
576  location: {location.href}
577  persisted position: ({document.documentElement.getAttribute("screenX")}, {document.documentElement.getAttribute("screenY")})
578  previous position: ({oldx}, {oldy})
579  computed position: ({x}, {y})
580 
581  new dimensions: {newWidth} x {newHeight}
582  current dimensions: {width.actual} x {height.actual}
583  min dimensions: {width.min} x {height.min}
584  max dimensions: {width.max} x {height.max}
585 </>);
586 /* */
587 
588 }
589 
595 function getXULWindowFromWindow(win) // taken from venkman source
596 {
597  var rv;
598  try
599  {
600  var requestor = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor);
601  var nav = requestor.getInterface(Components.interfaces.nsIWebNavigation);
602  var dsti = nav.QueryInterface(Components.interfaces.nsIDocShellTreeItem);
603  var owner = dsti.treeOwner;
604  requestor = owner.QueryInterface(Components.interfaces.nsIInterfaceRequestor);
605  rv = requestor.getInterface(Components.interfaces.nsIXULWindow);
606  }
607  catch (ex)
608  {
609  rv = null;
610  }
611  return rv;
612 }
613 
618 function SBOpenModalDialog( url, param1, param2, param3, parentWindow )
619 {
620  if (!parentWindow) {
621  var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
622  .getService(Components.interfaces.nsIWindowMediator);
623  parentWindow = wm.getMostRecentWindow("Songbird:Main");
624  }
625  // bonus stuff to shut the mac up.
626  var chromeFeatures = ",modal=yes,resizable=no";
627  if (SBDataGetBoolValue("accessibility.enabled")) chromeFeatures += ",titlebar=yes";
628  else chromeFeatures += ",titlebar=no";
629 
630  param2 += chromeFeatures;
631  var retval = parentWindow.openDialog( url, param1, param2, param3 );
632  return retval;
633 }
634 
639 function SBOpenWindow( url, param1, param2, param3, parentWindow )
640 {
641  if (!parentWindow) {
642  var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
643  .getService(Components.interfaces.nsIWindowMediator);
644  parentWindow = wm.getMostRecentWindow("Songbird:Main");
645  }
646 
647  var titlebar = ",modal=no";
648  if (SBDataGetBoolValue("accessibility.enabled")) {
649  titlebar += ",titlebar=yes";
650  // if in accessible mode, resizable flag determines whether or not the window is resizable
651  } else {
652  titlebar += ",titlebar=no";
653  // if not in accessible mode, resizable flag does not determine if the window is resizable
654  // or not, that's determined by the presence or absence of resizers in the xul.
655  // on the other hand, if resizable=yes is present in the flags, that create a border
656  // around the window in OSX, so remove it
657  var flags = param2.split(",");
658  for (var i = flags.length - 1 ; i >= 0; --i) {
659  if (flags[i] == "resizable=yes" ||
660  flags[i] == "resizable")
661  flags.splice(i, 1);
662  }
663  param2 = flags.join(",");
664  }
665 
666  param2 += titlebar;
667  var retval = window.openDialog( url, param1, param2, param3 );
668 
669  return retval;
670 }
671 
675 function quitApp( )
676 {
677  // Why not stop playback, too?
678  try {
679  if (gMM.playbackControl)
680  gMM.playbackControl.stop();
681  } catch (e) {
682  dump("windowUtils.js:quitApp() Error: could not stop playback.\n");
683  }
684 
685  // Defer to toolkit/globalOverlay.js
686  return goQuitApplication();
687 }
688 
689 
693 function restartApp( )
694 {
695 
696  // Notify all windows that an application quit has been requested.
697  var os = Components.classes["@mozilla.org/observer-service;1"]
698  .getService(Components.interfaces.nsIObserverService);
699  var cancelQuit = Components.classes["@mozilla.org/supports-PRBool;1"]
700  .createInstance(Components.interfaces.nsISupportsPRBool);
701  os.notifyObservers(cancelQuit, "quit-application-requested", "restart");
702 
703  // Something aborted the quit process.
704  if (cancelQuit.data)
705  return;
706 
707  // attempt to restart
708  var as = Components.classes["@mozilla.org/toolkit/app-startup;1"]
709  .getService(Components.interfaces.nsIAppStartup);
710  as.quit(Components.interfaces.nsIAppStartup.eRestart |
711  Components.interfaces.nsIAppStartup.eAttemptQuit);
712 
713  onExit( );
714 }
715 
716 
721 function hideElement(e) {
722  var element = document.getElementById(e);
723  if (element) element.setAttribute("hidden", "true");
724 }
725 
730 function moveElement(e, before) {
731  var element = document.getElementById(e);
732  var beforeElement = document.getElementById(before);
733  if (element && beforeElement) {
734  element.parentNode.removeChild(element);
735  beforeElement.parentNode.insertBefore(element, beforeElement);
736  }
737 }
738 
747 function getPlatformString()
748 {
749  try {
750  var sysInfo =
751  Components.classes["@mozilla.org/system-info;1"]
752  .getService(Components.interfaces.nsIPropertyBag2);
753  return sysInfo.getProperty("name");
754  }
755  catch (e) {
756  dump("System-info not available, trying the user agent string.\n");
757  var user_agent = navigator.userAgent;
758  if (user_agent.indexOf("Windows") != -1)
759  return "Windows_NT";
760  else if (user_agent.indexOf("Mac OS X") != -1)
761  return "Darwin";
762  else if (user_agent.indexOf("Linux") != -1)
763  return "Linux";
764  else if (user_agent.indexOf("SunOS") != -1)
765  return "SunOS";
766  return "";
767  }
768 }
769 
774 function checkQuitKey(evt)
775 {
776  // handle alt-F4 on all platforms
777  if (evt.keyCode == 0x73 && evt.altKey)
778  {
779  evt.preventDefault();
780  quitApp();
781  }
782 
783  // handle ctrl-Q on UNIX
784  let platform = getPlatformString();
785  if (platform == 'Linux' || platform == 'SunOS') {
786  let keyCode = String.fromCharCode(evt.which).toUpperCase();
787  if ( keyCode == 'Q' && evt.ctrlKey) {
788  evt.preventDefault();
789  quitApp();
790  }
791  }
792 }
793 
799 function binaryToHex(input)
800 {
801  var result = "";
802 
803  for (var i = 0; i < input.length; ++i)
804  {
805  var hex = input.charCodeAt(i).toString(16);
806 
807  if (hex.length == 1)
808  hex = "0" + hex;
809 
810  result += hex;
811  }
812 
813  return result;
814 }
815 
821 function newURI(aURLString)
822 {
823  var ioService =
824  Components.classes["@mozilla.org/network/io-service;1"]
825  .getService(Components.interfaces.nsIIOService);
826 
827  try {
828  return ioService.newURI(aURLString, null, null);
829  }
830  catch (e) { }
831 
832  return null;
833 }
834 
840 function listProperties(obj, objName)
841 {
842  var columns = 3;
843  var count = 0;
844  var result = "";
845  for (var i in obj)
846  {
847  try {
848  result += objName + "." + i + " = " + obj[i] + "\t\t\t";
849  } catch (e) {
850  result += objName + "." + i + " = [exception thrown]\t\t\t";
851  }
852  count = ++count % columns;
853  if ( count == columns - 1 )
854  {
855  result += "\n";
856  }
857  }
858  alert(result);
859 }
860 
861 
865 function onLayoutLoad(event) {
866  // don't leak, plz
867  window.removeEventListener('load', onLayoutLoad, false);
868 
869  var feathersMgr =
870  Components.classes['@songbirdnest.com/songbird/feathersmanager;1']
871  .getService(Components.interfaces.sbIFeathersManager);
872 
873  if (feathersMgr.currentLayoutURL == window.location.href) {
874  // this is the primary window for the current layout
875  var nativeWinMgr =
876  Components.classes["@songbirdnest.com/integration/native-window-manager;1"]
877  .getService(Components.interfaces.sbINativeWindowManager);
878 
879  // Check to see if "ontop" is supported with the current window manager
880  // and the current layout:
881  if (nativeWinMgr && nativeWinMgr.supportsOnTop &&
882  feathersMgr.canOnTop(feathersMgr.currentLayoutURL,
883  feathersMgr.currentSkinName))
884  {
885  var isOnTop = feathersMgr.isOnTop(feathersMgr.currentLayoutURL,
886  feathersMgr.currentSkinName);
887 
888  nativeWinMgr.setOnTop(window, isOnTop);
889  }
890 
891  // Check to see if shadowing is supported and enable it.
892  if (nativeWinMgr && nativeWinMgr.supportsShadowing)
893  {
894  nativeWinMgr.setShadowing(window, true);
895  }
896 
897  // Set the min-window size if the window supports it
898  if (nativeWinMgr.supportsMinimumWindowSize) {
899  var cstyle = window.getComputedStyle(document.documentElement, '');
900  if (cstyle) {
901  var minWidth = parseInt(cstyle.minWidth);
902  var minHeight = parseInt(cstyle.minHeight);
903  if (minWidth > 0 && minHeight > 0) {
904  nativeWinMgr.setMinimumWindowSize(window, minWidth, minHeight);
905  }
906 
907  var maxWidth = parseInt(cstyle.maxWidth);
908  var maxHeight = parseInt(cstyle.maxHeight);
909  if (maxWidth > 0 && maxHeight > 0) {
910  nativeWinMgr.setMaximumWindowSize(window, maxWidth, maxHeight);
911  }
912  }
913  }
914  }
915 }
916 window.addEventListener('load', onLayoutLoad, false);
917 
918 
925 function initializeDocumentPlatformAttribute() {
926  // Perform platform specific customization
927  var platform = getPlatformString();
928 
929  // Set attributes on the document element so we can use them in CSS.
930  document.documentElement.setAttribute("platform",platform);
931 }
932 
939 function SBGetBrowser()
940 {
941  // Return global browser if defined.
942  if (typeof gBrowser != 'undefined') {
943  return gBrowser;
944  }
945 
946  // Get the main window.
947  var mainWindow = window
948  .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
949  .getInterface(Components.interfaces.nsIWebNavigation)
950  .QueryInterface(Components.interfaces.nsIDocShellTreeItem)
951  .rootTreeItem
952  .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
953  .getInterface(Components.interfaces.nsIDOMWindow);
954 
955  // Return the main window browser.
956  if (typeof mainWindow.gBrowser != 'undefined') {
957  return mainWindow.gBrowser;
958  }
959 
960  return null;
961 }
962 
969 function SBGetApplicationNotificationBox() {
970  return document.getElementById("application-notificationbox");
971 }
972 
995 var gEditUIVisible = true;
996 function updateEditUIVisibility()
997 {
998  if ( getPlatformString() != "Darwin" ) {
999  let editMenuPopupState = document.getElementById("menu_EditPopup").state;
1000  let contextMenuPopupState = document.getElementById("contentAreaContextMenu").state;
1001 
1002  // The UI is visible if the Edit menu is opening or open, if the context menu
1003  // is open, or if the toolbar has been customized to include the Cut, Copy,
1004  // or Paste toolbar buttons.
1005  gEditUIVisible = editMenuPopupState == "showing" ||
1006  editMenuPopupState == "open" ||
1007  contextMenuPopupState == "showing" ||
1008  contextMenuPopupState == "open" ? true : false;
1009 
1010  // If UI is visible, update the edit commands' enabled state to reflect
1011  // whether or not they are actually enabled for the current focus/selection.
1012  if (gEditUIVisible) {
1013  goUpdateGlobalEditMenuItems();
1014  } else {
1015  // Otherwise, enable all commands, so that keyboard shortcuts still work,
1016  // then lazily determine their actual enabled state when the user presses
1017  // a keyboard shortcut.
1018  goSetCommandEnabled("cmd_undo", true);
1019  goSetCommandEnabled("cmd_redo", true);
1020  goSetCommandEnabled("cmd_cut", true);
1021  goSetCommandEnabled("cmd_copy", true);
1022  goSetCommandEnabled("cmd_paste", true);
1023  goSetCommandEnabled("cmd_selectAll", true);
1024  goSetCommandEnabled("cmd_delete", true);
1025  goSetCommandEnabled("cmd_switchTextDirection", true);
1026  }
1027  }
1028 }
1029 
1030 
1035 function goUpdateGlobalContentMenuItems()
1036 {
1037  goUpdateCommand("cmd_find");
1038  goUpdateCommand("cmd_findAgain");
1039  goUpdateCommand("cmd_print");
1040  goUpdateCommand("cmd_getartwork");
1041  goUpdateCommand("cmd_control_previous");
1042  goUpdateCommand("cmd_control_next");
1043  goUpdateCommand("cmd_exportmedia");
1044 }
1045 
1051 function goUpdateGlobalMetadataMenuItems()
1052 {
1053  // This will call gSongbirdWindowController.isCommandEnabled in
1054  // mainPlayerWindow.js with the command id as the parameter
1055  goUpdateCommand("cmd_metadata");
1056  goUpdateCommand("cmd_editmetadata");
1057  goUpdateCommand("cmd_viewmetadata");
1058  goUpdateCommand("cmd_reveal");
1059 }
1060 
1064 function toggleNextFeatherLayout()
1065 {
1066  Components.classes['@songbirdnest.com/songbird/feathersmanager;1']
1067  .getService(Components.interfaces.sbIFeathersManager)
1068  .switchToNextLayout();
1069 }
1070 
const Cu
function onExit(skipSave)
onExit handler, saves window size and position before closing the window.
Definition: windowUtils.js:355
const Cc
function onMinimize()
onMinimize handler, minimizes the window in the current context.
Definition: windowUtils.js:290
var gMM
Definition: windowUtils.js:62
function setPref(aFunc, aPreference, aValue)
Set a preference.
Definition: windowUtils.js:280
var STATE_MINIMIZED
Minimized State value.
Definition: windowUtils.js:60
function delayedActivate()
Delayed focus of the window in the current context.
Definition: windowUtils.js:442
function restartApp()
Definition: safeMode.js:40
onPageChanged aValue
Definition: FeedWriter.js:1395
function getPlatformString()
Get the name of the platform we are running on.
var nsIPrefBranch2
Definition: windowUtils.js:253
var PREFS_SERVICE_CONTRACTID
Definition: windowUtils.js:252
var CORE_WINDOWTYPE
The Songbird Core Window Type.
Definition: windowUtils.js:50
sbDeviceFirmwareAutoCheckForUpdate prototype flags
var gEditUIVisible
Definition: browser.js:92
var event
function isMaximized()
Is the window in the current context maximized?
Definition: windowUtils.js:329
function sbMacWindowZoomController()
Definition: windowUtils.js:116
function updateEditUIVisibility()
Definition: browser.js:3493
function onWindowResizeComplete()
Handles completion of resizing of the window in the current context.
Definition: windowUtils.js:404
var ioService
var titlebar
Definition: mainwin.js:127
var STATE_MAXIMIZED
Maximized State value.
Definition: windowUtils.js:55
function SB_LOG(scopeStr, msg)
Definition: windowUtils.js:244
function width(ele) rect(ele).width
let window
function d(s)
var gPrefs
Definition: windowUtils.js:66
function SBDataGetBoolValue(aKey)
Get the value of the data in boolean format.
var count
Definition: test_bug7406.js:32
function onHide()
onHide handler, handles hiding the window in the current context.
Definition: windowUtils.js:364
aWindow setTimeout(function(){_this.restoreHistory(aWindow, aTabs, aTabData, aIdMap);}, 0)
var columns
return null
Definition: FeedWriter.js:1143
_updateDatepicker height
function isMinimized()
Is the window in the current context minimized?
Definition: windowUtils.js:338
function newURI(aURLString)
BogusChannel prototype owner
var os
function getPref(aFunc, aPreference, aDefaultValue)
Get a preference. Adapted from nsUpdateService.js.in. Need to replace with dataremotes.
Definition: windowUtils.js:262
function url(spec)
var gTypeSniffer
Definition: windowUtils.js:71
var prefs
Definition: FeedWriter.js:1169
var gPrompt
Definition: windowUtils.js:64
const Cr
function sbScreenRect(inWidth, inHeight, inX, inY)
Definition: windowUtils.js:79
const Ci
function windowFocus()
Focus the window in the current context.
Definition: windowUtils.js:424
function msg
var theSongbirdStrings
Definition: windowUtils.js:241
function windowPlacementSanityChecks()
See if a window needs to be somehow "fixed" after it is opened.
Definition: windowUtils.js:457
#define min(a, b)
var macZoomWindowController
Definition: windowUtils.js:235
_getSelectedPageStyle s i
function getCurMaxScreenRect()
Definition: windowUtils.js:92
function onMaximize(aMaximize)
onMaximize handler, maximizes the window in the current context.
Definition: windowUtils.js:299
function onWindowDragComplete()
Handles completion of dragging of the window in the current context.
Definition: windowUtils.js:414
var gConsole
Definition: windowUtils.js:68