Bug 746787 - Ensure the browser window is not minimized when opening the Downloads panel. r=mak

This commit is contained in:
Paolo Amadini 2012-04-27 15:05:04 +02:00
parent 39be939aa0
commit 695359ee3c
2 changed files with 38 additions and 22 deletions

View File

@ -56,18 +56,19 @@ const DownloadsPanel = {
//// Initialization and termination
/**
* State of the downloads panel, based on one of the kPanel constants.
* Internal state of the downloads panel, based on one of the kState
* constants. This is not the same state as the XUL panel element.
*/
_panelState: 0,
_state: 0,
/** Download data has not been loaded. */
get kPanelUninitialized() 0,
/** Download data is loading, but the user interface is invisible. */
get kPanelHidden() 1,
/** The panel is not linked to downloads data yet. */
get kStateUninitialized() 0,
/** This object is linked to data, but the panel is invisible. */
get kStateHidden() 1,
/** The panel will be shown as soon as possible. */
get kPanelShowing() 2,
/** The panel is open, though download data might still be loading. */
get kPanelShown() 3,
get kStateShowing() 2,
/** The panel is open. */
get kStateShown() 3,
/**
* Location of the panel overlay.
@ -84,12 +85,12 @@ const DownloadsPanel = {
*/
initialize: function DP_initialize(aCallback)
{
if (this._panelState != this.kPanelUninitialized) {
if (this._state != this.kStateUninitialized) {
DownloadsOverlayLoader.ensureOverlayLoaded(this.kDownloadsOverlay,
aCallback);
return;
}
this._panelState = this.kPanelHidden;
this._state = this.kStateHidden;
window.addEventListener("unload", this.onWindowUnload, false);
@ -115,7 +116,7 @@ const DownloadsPanel = {
*/
terminate: function DP_terminate()
{
if (this._panelState == this.kPanelUninitialized) {
if (this._state == this.kStateUninitialized) {
return;
}
@ -127,7 +128,7 @@ const DownloadsPanel = {
DownloadsViewController.terminate();
DownloadsCommon.data.removeView(DownloadsView);
this._panelState = this.kPanelUninitialized;
this._state = this.kStateUninitialized;
},
//////////////////////////////////////////////////////////////////////////////
@ -163,7 +164,7 @@ const DownloadsPanel = {
setTimeout(function () DownloadsPanel._openPopupIfDataReady(), 0);
}.bind(this));
this._panelState = this.kPanelShowing;
this._state = this.kStateShowing;
},
/**
@ -181,7 +182,7 @@ const DownloadsPanel = {
// Ensure that we allow the panel to be reopened. Note that, if the popup
// was open, then the onPopupHidden event handler has already updated the
// current state, otherwise we must update the state ourselves.
this._panelState = this.kPanelHidden;
this._state = this.kStateHidden;
},
/**
@ -189,8 +190,8 @@ const DownloadsPanel = {
*/
get isPanelShowing()
{
return this._panelState == this.kPanelShowing ||
this._panelState == this.kPanelShown;
return this._state == this.kStateShowing ||
this._state == this.kStateShown;
},
//////////////////////////////////////////////////////////////////////////////
@ -220,6 +221,8 @@ const DownloadsPanel = {
return;
}
this._state = this.kStateShown;
// Since at most one popup is open at any given time, we can set globally.
DownloadsCommon.indicatorData.attentionSuppressed = true;
@ -246,7 +249,7 @@ const DownloadsPanel = {
DownloadsButton.releaseAnchor();
// Allow the panel to be reopened.
this._panelState = this.kPanelHidden;
this._state = this.kStateHidden;
},
//////////////////////////////////////////////////////////////////////////////
@ -275,7 +278,7 @@ const DownloadsPanel = {
_focusPanel: function DP_focusPanel()
{
// We may be invoked while the panel is still waiting to be shown.
if (this._panelState != this.kPanelShown) {
if (this._state != this.kStateShown) {
return;
}
@ -295,12 +298,10 @@ const DownloadsPanel = {
{
// We don't want to open the popup if we already displayed it, or if we are
// still loading data.
if (this._panelState != this.kPanelShowing || DownloadsView.loading) {
if (this._state != this.kStateShowing || DownloadsView.loading) {
return;
}
this._panelState = this.kPanelShown;
// Make sure that clicking outside the popup cannot reopen it accidentally.
this.panel.popupBoxObject.setConsumeRollupEvent(Ci.nsIPopupBoxObject
.ROLLUP_CONSUME);
@ -308,6 +309,16 @@ const DownloadsPanel = {
// Ensure the anchor is visible. If that is not possible, show the panel
// anchored to the top area of the window, near the default anchor position.
DownloadsButton.getAnchor(function DP_OPIDR_callback(aAnchor) {
// At this point, if the window is minimized, opening the panel could fail
// without any notification, and there would be no way to either open or
// close the panel anymore. To prevent this, check if the window is
// minimized and in that case force the panel to the closed state.
if (window.windowState == Ci.nsIDOMChromeWindow.STATE_MINIMIZED) {
DownloadsButton.releaseAnchor();
this._state = this.kStateHidden;
return;
}
if (aAnchor) {
this.panel.openPopup(aAnchor, "bottomcenter topright", 0, 0, false,
null);

View File

@ -78,6 +78,11 @@ DownloadsUI.prototype = {
// Show the panel in the most recent browser window, if present.
let browserWin = gBrowserGlue.getMostRecentBrowserWindow();
if (browserWin) {
// The most recent browser window could have been minimized, in that case
// it must be restored to allow the panel to open properly.
if (browserWin.windowState == Ci.nsIDOMChromeWindow.STATE_MINIMIZED) {
browserWin.restore();
}
browserWin.focus();
browserWin.DownloadsPanel.showPanel();
return;