Bug 1300556 - Adjust the height of the Downloads Panel if downloads are removed while the panel is hidden. r=jaws
MozReview-Commit-ID: JpW9G6MAGwM
--- a/browser/components/downloads/content/downloads.js
+++ b/browser/components/downloads/content/downloads.js
@@ -306,16 +306,30 @@ const DownloadsPanel = {
switch (aEvent.type) {
case "mousemove":
this.keyFocusing = false;
break;
case "keydown":
return this._onKeyDown(aEvent);
case "keypress":
return this._onKeyPress(aEvent);
+ case "popupshown":
+ if (this.setHeightToFitOnShow) {
+ this.setHeightToFitOnShow = false;
+ this.setHeightToFit();
+ }
+ break;
+ }
+ },
+
+ setHeightToFit() {
+ if (this._state == this.kStateShown) {
+ DownloadsBlockedSubview.view.setHeightToFit();
+ } else {
+ this.setHeightToFitOnShow = true;
}
},
//////////////////////////////////////////////////////////////////////////////
//// Callback functions from DownloadsView
/**
* Called after data loading finished.
@@ -424,25 +438,28 @@ const DownloadsPanel = {
* panel has successfully loaded.
*/
_attachEventListeners() {
// Handle keydown to support accel-V.
this.panel.addEventListener("keydown", this, false);
// Handle keypress to be able to preventDefault() events before they reach
// the richlistbox, for keyboard navigation.
this.panel.addEventListener("keypress", this, false);
+ // Handle height adjustment on show.
+ this.panel.addEventListener("popupshown", this, false);
},
/**
* Unattach event listeners that were added in _attachEventListeners. This
* is called automatically on panel termination.
*/
_unattachEventListeners() {
this.panel.removeEventListener("keydown", this, false);
this.panel.removeEventListener("keypress", this, false);
+ this.panel.removeEventListener("popupshown", this, false);
},
_onKeyPress(aEvent) {
// Handle unmodified keys only.
if (aEvent.altKey || aEvent.ctrlKey || aEvent.shiftKey || aEvent.metaKey) {
return;
}
@@ -737,18 +754,16 @@ const DownloadsView = {
if (count > 0) {
DownloadsCommon.log("Setting the panel's hasdownloads attribute to true.");
DownloadsPanel.panel.setAttribute("hasdownloads", "true");
} else {
DownloadsCommon.log("Removing the panel's hasdownloads attribute.");
DownloadsPanel.panel.removeAttribute("hasdownloads");
}
- DownloadsBlockedSubview.view.setHeightToFit();
-
// If we've got some hidden downloads, we should activate the
// DownloadsSummary. The DownloadsSummary will determine whether or not
// it's appropriate to actually display the summary.
DownloadsSummary.active = hiddenCount > 0;
},
/**
* Element corresponding to the list of downloads.
@@ -869,16 +884,19 @@ const DownloadsView = {
this._removeViewItem(download);
if (this._downloads.length >= this.kItemCountLimit) {
// Reinsert the next item into the panel.
this._addViewItem(this._downloads[this.kItemCountLimit - 1], false);
}
}
this._itemCountChanged();
+
+ // Adjust the panel height if we removed items.
+ DownloadsPanel.setHeightToFit();
},
/**
* Associates each richlistitem for a download with its corresponding
* DownloadsViewItem object.
*/
_itemsForElements: new Map(),
@@ -1523,17 +1541,17 @@ const DownloadsFooter = {
if (this._footerNode) {
if (aValue) {
this._footerNode.setAttribute("showingsummary", "true");
} else {
this._footerNode.removeAttribute("showingsummary");
}
if (!aValue && this._showingSummary) {
// Make sure the panel's height shrinks when the summary is hidden.
- DownloadsBlockedSubview.view.setHeightToFit();
+ DownloadsPanel.setHeightToFit();
}
this._showingSummary = aValue;
}
return aValue;
},
/**
* Element corresponding to the footer of the downloads panel.