35 Components.utils.import(
"resource://app/jsmodules/StringUtils.jsm");
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;
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);
69 .getService(
Ci.nsIConsoleService);
72 .createInstance(
Ci.sbIMediacoreTypeSniffer);
93 var screenManager =
Cc[
"@mozilla.org/gfx/screenmanager;1"]
94 .getService(
Ci.nsIScreenManager);
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);
101 var curScreen = screenManager.screenForRect(curX, curY, curWidth, curHeight);
122 _mIsResizeEventFromZoom:
false,
132 this._windowdragexit =
function(evt) {
133 self._onWindowDragged();
135 this._windowresized =
function(evt) {
136 self._onWindowResized();
138 this._documentunload =
function(evt) {
141 document.addEventListener(
"ondragexit", this._windowdragexit,
false);
142 document.addEventListener(
"resize", this._windowresized,
false);
143 document.addEventListener(
"unload", this._documentunload,
false);
146 _onWindowResized:
function() {
147 if (this._mIsZoomed) {
148 if (this._mIsResizeEventFromZoom) {
149 this._mIsResizeEventFromZoom =
false;
152 else if (!this._isConsideredZoomed()) {
153 this._mIsZoomed =
false;
154 this._saveWindowCoords();
159 _onWindowDragged:
function() {
161 var curX = parseInt(document.documentElement.boxObject.screenX);
162 var curY = parseInt(document.documentElement.boxObject.screenY);
164 if (this._mIsZoomed) {
167 if (curX > (maxScreenRect.x + 10) || curY > (maxScreenRect.y + 10)) {
168 this._mIsZoomed =
false;
169 this._saveWindowCoords();
173 this._mIsZoomed = this._isConsideredZoomed();
178 if (this._mIsZoomed) {
179 window.resizeTo(this._mSavedWidth, this._mSavedHeight);
180 window.moveTo(this._mSavedXPos, this._mSavedYPos);
181 this._mIsZoomed =
false;
184 this._saveWindowCoords();
187 window.moveTo(maxScreenRect.x, maxScreenRect.y);
188 window.resizeTo(maxScreenRect.width, maxScreenRect.height);
190 this._mIsZoomed =
true;
191 this._mIsResizeEventFromZoom =
true;
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;
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);
211 _isConsideredZoomed:
function() {
215 var isZoomed =
false;
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);
222 if (curX < (maxScreenRect.x + 10) &&
223 curY < (maxScreenRect.y + 10) &&
224 curWidth > (maxScreenRect.width - 10) &&
225 curHeight > (maxScreenRect.height - 10))
248 gConsole.logStringMessage( scopeStr +
" : " +
msg );
249 dump( scopeStr +
" : " +
msg +
"\n");
262 function getPref(aFunc, aPreference, aDefaultValue) {
266 return prefs[aFunc](aPreference);
269 return aDefaultValue;
283 return prefs[aFunc](aPreference,
aValue);
292 document.defaultView.minimize();
301 if ( macZoomWindowController !=
null )
303 macZoomWindowController.onZoom();
309 document.defaultView.maximize();
311 document.documentElement.setAttribute(
"sizemode",
"maximized");
315 document.defaultView.restore();
317 document.documentElement.setAttribute(
"sizemode",
"normal");
330 return (
window.windowState == STATE_MAXIMIZED);
339 return (
window.windowState == STATE_MINIMIZED);
357 document.defaultView.close();
368 e = document.createEvent(
"UIEvents");
369 e.initUIEvent(
"hide",
true,
true,
window, 1);
370 document.dispatchEvent(e);
373 Components.classes[
"@songbirdnest.com/Songbird/WindowCloak;1"]
374 .getService(Components.interfaces.sbIWindowCloak);
375 windowCloak.cloak(
window);
378 var windowList = [
"Songbird:Main",
379 "Songbird:TrackEditor",
382 var windowCount = windowList.length;
384 var
wm = Components.classes[
"@mozilla.org/appshell/window-mediator;1"]
385 .getService(Components.interfaces.nsIWindowMediator);
387 for (var index = 0; index < windowCount; index++) {
388 var windowType = windowList[index];
389 var lastWindow = wm.getMostRecentWindow(windowType);
390 if (lastWindow && (lastWindow !=
window)) {
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"); }
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"); }
428 Components.classes[
"@songbirdnest.com/Songbird/WindowCloak;1"]
429 .getService(Components.interfaces.sbIWindowCloak);
430 if (windowCloak.isCloaked(
window))
466 function getStyle(el, styleProp, defaultValue)
470 var v = defaultValue;
472 var s = document.defaultView.getComputedStyle(el,
null);
473 v = s.getPropertyValue(styleProp);
475 return parseInt(v, 10) || defaultValue;
481 var x, oldx = x = parseInt(document.documentElement.boxObject.screenX, 10);
482 var
y, oldy = y = parseInt(document.documentElement.boxObject.screenY, 10);
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)
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)
501 var newWidth = width.xul || 0;
504 newWidth = Math.min(newWidth, width.max);
505 newWidth = Math.min(newWidth, screen.availWidth);
506 newWidth = Math.max(newWidth, width.min);
509 var newHeight = height.xul || 0;
512 newHeight = Math.min(newHeight, height.max);
513 newHeight = Math.min(newHeight, screen.availHeight);
514 newHeight = Math.max(newHeight, height.min);
517 if (newHeight != height.xul || newWidth != width.xul) {
518 window.resizeTo(newWidth, newHeight);
524 if ((x - screenRect.x > screenRect.width) ||
525 (x - screenRect.x + newWidth < 0) ||
526 (y - screenRect.y > screenRect.height) ||
527 (y - screenRect.y + newHeight < 0))
529 x = (screenRect.width / 2) - (
window.outerWidth / 2);
531 y = (screenRect.height / 2) - (
window.outerHeight / 2);
536 if (x < screenRect.x) {
539 if (y < screenRect.y) {
543 if (!document.documentElement.hasAttribute(
"screenX")) {
547 x = Math.min(x, screen.availWidth - newWidth);
549 if (!document.documentElement.hasAttribute(
"screenY")) {
553 y = Math.min(y, screen.availHeight - newHeight);
557 if (x != oldx || y != oldy) {
561 document.documentElement.getAttribute(
"sizemode") ==
"maximized";
567 if (isCurMaximized) {
595 function getXULWindowFromWindow(
win)
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);
618 function SBOpenModalDialog(
url, param1, param2, param3, parentWindow )
621 var
wm = Components.classes[
"@mozilla.org/appshell/window-mediator;1"]
622 .getService(Components.interfaces.nsIWindowMediator);
623 parentWindow = wm.getMostRecentWindow(
"Songbird:Main");
626 var chromeFeatures =
",modal=yes,resizable=no";
628 else chromeFeatures +=
",titlebar=no";
630 param2 += chromeFeatures;
631 var retval = parentWindow.openDialog(
url, param1, param2, param3 );
639 function SBOpenWindow(
url, param1, param2, param3, parentWindow )
642 var wm = Components.classes[
"@mozilla.org/appshell/window-mediator;1"]
643 .getService(Components.interfaces.nsIWindowMediator);
644 parentWindow = wm.getMostRecentWindow(
"Songbird:Main");
649 titlebar +=
",titlebar=yes";
652 titlebar +=
",titlebar=no";
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")
663 param2 = flags.join(
",");
667 var retval =
window.openDialog(
url, param1, param2, param3 );
679 if (gMM.playbackControl)
680 gMM.playbackControl.stop();
682 dump(
"windowUtils.js:quitApp() Error: could not stop playback.\n");
686 return goQuitApplication();
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");
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);
721 function hideElement(e) {
722 var
element = document.getElementById(e);
723 if (element) element.setAttribute(
"hidden",
"true");
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);
751 Components.classes[
"@mozilla.org/system-info;1"]
752 .getService(Components.interfaces.nsIPropertyBag2);
753 return sysInfo.getProperty(
"name");
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)
760 else if (user_agent.indexOf(
"Mac OS X") != -1)
762 else if (user_agent.indexOf(
"Linux") != -1)
764 else if (user_agent.indexOf(
"SunOS") != -1)
774 function checkQuitKey(evt)
777 if (evt.keyCode == 0x73 && evt.altKey)
779 evt.preventDefault();
785 if (platform ==
'Linux' || platform ==
'SunOS') {
787 if ( keyCode ==
'Q' && evt.ctrlKey) {
788 evt.preventDefault();
799 function binaryToHex(input)
803 for (var
i = 0;
i < input.length; ++
i)
805 var hex = input.charCodeAt(
i).toString(16);
821 function newURI(aURLString)
824 Components.classes[
"@mozilla.org/network/io-service;1"]
825 .getService(Components.interfaces.nsIIOService);
828 return ioService.newURI(aURLString,
null,
null);
840 function listProperties(obj, objName)
848 result += objName +
"." +
i +
" = " + obj[
i] +
"\t\t\t";
850 result += objName +
"." +
i +
" = [exception thrown]\t\t\t";
853 if ( count == columns - 1 )
865 function onLayoutLoad(
event) {
867 window.removeEventListener(
'load', onLayoutLoad,
false);
870 Components.classes[
'@songbirdnest.com/songbird/feathersmanager;1']
871 .getService(Components.interfaces.sbIFeathersManager);
873 if (feathersMgr.currentLayoutURL ==
window.location.href) {
876 Components.classes[
"@songbirdnest.com/integration/native-window-manager;1"]
877 .getService(Components.interfaces.sbINativeWindowManager);
881 if (nativeWinMgr && nativeWinMgr.supportsOnTop &&
882 feathersMgr.canOnTop(feathersMgr.currentLayoutURL,
883 feathersMgr.currentSkinName))
885 var isOnTop = feathersMgr.isOnTop(feathersMgr.currentLayoutURL,
886 feathersMgr.currentSkinName);
888 nativeWinMgr.setOnTop(
window, isOnTop);
892 if (nativeWinMgr && nativeWinMgr.supportsShadowing)
894 nativeWinMgr.setShadowing(
window,
true);
898 if (nativeWinMgr.supportsMinimumWindowSize) {
899 var cstyle =
window.getComputedStyle(document.documentElement,
'');
901 var minWidth = parseInt(cstyle.minWidth);
902 var minHeight = parseInt(cstyle.minHeight);
903 if (minWidth > 0 && minHeight > 0) {
904 nativeWinMgr.setMinimumWindowSize(
window, minWidth, minHeight);
907 var maxWidth = parseInt(cstyle.maxWidth);
908 var maxHeight = parseInt(cstyle.maxHeight);
909 if (maxWidth > 0 && maxHeight > 0) {
910 nativeWinMgr.setMaximumWindowSize(
window, maxWidth, maxHeight);
916 window.addEventListener(
'load', onLayoutLoad,
false);
925 function initializeDocumentPlatformAttribute() {
930 document.documentElement.setAttribute(
"platform",platform);
939 function SBGetBrowser()
942 if (typeof gBrowser !=
'undefined') {
948 .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
949 .getInterface(Components.interfaces.nsIWebNavigation)
950 .QueryInterface(Components.interfaces.nsIDocShellTreeItem)
952 .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
953 .getInterface(Components.interfaces.nsIDOMWindow);
956 if (typeof mainWindow.gBrowser !=
'undefined') {
957 return mainWindow.gBrowser;
969 function SBGetApplicationNotificationBox() {
970 return document.getElementById(
"application-notificationbox");
999 let editMenuPopupState = document.getElementById(
"menu_EditPopup").state;
1000 let contextMenuPopupState = document.getElementById(
"contentAreaContextMenu").state;
1005 gEditUIVisible = editMenuPopupState ==
"showing" ||
1006 editMenuPopupState ==
"open" ||
1007 contextMenuPopupState ==
"showing" ||
1008 contextMenuPopupState ==
"open" ?
true :
false;
1012 if (gEditUIVisible) {
1013 goUpdateGlobalEditMenuItems();
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);
1035 function goUpdateGlobalContentMenuItems()
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");
1051 function goUpdateGlobalMetadataMenuItems()
1055 goUpdateCommand(
"cmd_metadata");
1056 goUpdateCommand(
"cmd_editmetadata");
1057 goUpdateCommand(
"cmd_viewmetadata");
1058 goUpdateCommand(
"cmd_reveal");
1064 function toggleNextFeatherLayout()
1066 Components.classes[
'@songbirdnest.com/songbird/feathersmanager;1']
1067 .getService(Components.interfaces.sbIFeathersManager)
1068 .switchToNextLayout();
function onExit(skipSave)
onExit handler, saves window size and position before closing the window.
function onMinimize()
onMinimize handler, minimizes the window in the current context.
function setPref(aFunc, aPreference, aValue)
Set a preference.
var STATE_MINIMIZED
Minimized State value.
function delayedActivate()
Delayed focus of the window in the current context.
function getPlatformString()
Get the name of the platform we are running on.
var PREFS_SERVICE_CONTRACTID
var CORE_WINDOWTYPE
The Songbird Core Window Type.
sbDeviceFirmwareAutoCheckForUpdate prototype flags
function isMaximized()
Is the window in the current context maximized?
function sbMacWindowZoomController()
function updateEditUIVisibility()
function onWindowResizeComplete()
Handles completion of resizing of the window in the current context.
var STATE_MAXIMIZED
Maximized State value.
function SB_LOG(scopeStr, msg)
function SBDataGetBoolValue(aKey)
Get the value of the data in boolean format.
function onHide()
onHide handler, handles hiding the window in the current context.
aWindow setTimeout(function(){_this.restoreHistory(aWindow, aTabs, aTabData, aIdMap);}, 0)
function isMinimized()
Is the window in the current context minimized?
function newURI(aURLString)
BogusChannel prototype owner
function getPref(aFunc, aPreference, aDefaultValue)
Get a preference. Adapted from nsUpdateService.js.in. Need to replace with dataremotes.
function sbScreenRect(inWidth, inHeight, inX, inY)
function windowFocus()
Focus the window in the current context.
function windowPlacementSanityChecks()
See if a window needs to be somehow "fixed" after it is opened.
var macZoomWindowController
_getSelectedPageStyle s i
function getCurMaxScreenRect()
function onMaximize(aMaximize)
onMaximize handler, maximizes the window in the current context.
function onWindowDragComplete()
Handles completion of dragging of the window in the current context.