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 //// 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. */ /** The panel is not linked to downloads data yet. */
get kPanelUninitialized() 0, get kStateUninitialized() 0,
/** Download data is loading, but the user interface is invisible. */ /** This object is linked to data, but the panel is invisible. */
get kPanelHidden() 1, get kStateHidden() 1,
/** The panel will be shown as soon as possible. */ /** The panel will be shown as soon as possible. */
get kPanelShowing() 2, get kStateShowing() 2,
/** The panel is open, though download data might still be loading. */ /** The panel is open. */
get kPanelShown() 3, get kStateShown() 3,
/** /**
* Location of the panel overlay. * Location of the panel overlay.
@ -84,12 +85,12 @@ const DownloadsPanel = {
*/ */
initialize: function DP_initialize(aCallback) initialize: function DP_initialize(aCallback)
{ {
if (this._panelState != this.kPanelUninitialized) { if (this._state != this.kStateUninitialized) {
DownloadsOverlayLoader.ensureOverlayLoaded(this.kDownloadsOverlay, DownloadsOverlayLoader.ensureOverlayLoaded(this.kDownloadsOverlay,
aCallback); aCallback);
return; return;
} }
this._panelState = this.kPanelHidden; this._state = this.kStateHidden;
window.addEventListener("unload", this.onWindowUnload, false); window.addEventListener("unload", this.onWindowUnload, false);
@ -115,7 +116,7 @@ const DownloadsPanel = {
*/ */
terminate: function DP_terminate() terminate: function DP_terminate()
{ {
if (this._panelState == this.kPanelUninitialized) { if (this._state == this.kStateUninitialized) {
return; return;
} }
@ -127,7 +128,7 @@ const DownloadsPanel = {
DownloadsViewController.terminate(); DownloadsViewController.terminate();
DownloadsCommon.data.removeView(DownloadsView); DownloadsCommon.data.removeView(DownloadsView);
this._panelState = this.kPanelUninitialized; this._state = this.kStateUninitialized;
}, },
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
@ -163,7 +164,7 @@ const DownloadsPanel = {
setTimeout(function () DownloadsPanel._openPopupIfDataReady(), 0); setTimeout(function () DownloadsPanel._openPopupIfDataReady(), 0);
}.bind(this)); }.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 // 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 // was open, then the onPopupHidden event handler has already updated the
// current state, otherwise we must update the state ourselves. // 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() get isPanelShowing()
{ {
return this._panelState == this.kPanelShowing || return this._state == this.kStateShowing ||
this._panelState == this.kPanelShown; this._state == this.kStateShown;
}, },
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
@ -220,6 +221,8 @@ const DownloadsPanel = {
return; return;
} }
this._state = this.kStateShown;
// Since at most one popup is open at any given time, we can set globally. // Since at most one popup is open at any given time, we can set globally.
DownloadsCommon.indicatorData.attentionSuppressed = true; DownloadsCommon.indicatorData.attentionSuppressed = true;
@ -246,7 +249,7 @@ const DownloadsPanel = {
DownloadsButton.releaseAnchor(); DownloadsButton.releaseAnchor();
// Allow the panel to be reopened. // Allow the panel to be reopened.
this._panelState = this.kPanelHidden; this._state = this.kStateHidden;
}, },
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
@ -275,7 +278,7 @@ const DownloadsPanel = {
_focusPanel: function DP_focusPanel() _focusPanel: function DP_focusPanel()
{ {
// We may be invoked while the panel is still waiting to be shown. // We may be invoked while the panel is still waiting to be shown.
if (this._panelState != this.kPanelShown) { if (this._state != this.kStateShown) {
return; return;
} }
@ -295,12 +298,10 @@ const DownloadsPanel = {
{ {
// We don't want to open the popup if we already displayed it, or if we are // We don't want to open the popup if we already displayed it, or if we are
// still loading data. // still loading data.
if (this._panelState != this.kPanelShowing || DownloadsView.loading) { if (this._state != this.kStateShowing || DownloadsView.loading) {
return; return;
} }
this._panelState = this.kPanelShown;
// Make sure that clicking outside the popup cannot reopen it accidentally. // Make sure that clicking outside the popup cannot reopen it accidentally.
this.panel.popupBoxObject.setConsumeRollupEvent(Ci.nsIPopupBoxObject this.panel.popupBoxObject.setConsumeRollupEvent(Ci.nsIPopupBoxObject
.ROLLUP_CONSUME); .ROLLUP_CONSUME);
@ -308,6 +309,16 @@ const DownloadsPanel = {
// Ensure the anchor is visible. If that is not possible, show the panel // 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. // anchored to the top area of the window, near the default anchor position.
DownloadsButton.getAnchor(function DP_OPIDR_callback(aAnchor) { 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) { if (aAnchor) {
this.panel.openPopup(aAnchor, "bottomcenter topright", 0, 0, false, this.panel.openPopup(aAnchor, "bottomcenter topright", 0, 0, false,
null); null);

View File

@ -78,6 +78,11 @@ DownloadsUI.prototype = {
// Show the panel in the most recent browser window, if present. // Show the panel in the most recent browser window, if present.
let browserWin = gBrowserGlue.getMostRecentBrowserWindow(); let browserWin = gBrowserGlue.getMostRecentBrowserWindow();
if (browserWin) { 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.focus();
browserWin.DownloadsPanel.showPanel(); browserWin.DownloadsPanel.showPanel();
return; return;