Bug 1300556 - Adjust the height of the Downloads Panel if downloads are removed while the panel is hidden. r=jaws, a=ritu
authorPaolo Amadini <paolo.mozmail@amadzone.org>
Wed, 07 Sep 2016 15:00:46 +0100
changeset 350211 dab56348f0ea8fec6574639c0a1c88f727c297d2
parent 350210 7db6b94ebda431eb880fb958ebbcd6a9ec3b3eab
child 350212 ade8492b568004bc3fbd9e02bd7e0bcf3d469f2f
push id1230
push userjlund@mozilla.com
push dateMon, 31 Oct 2016 18:13:35 +0000
treeherdermozilla-release@5e06e3766db2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws, ritu
bugs1300556
milestone50.0a2
Bug 1300556 - Adjust the height of the Downloads Panel if downloads are removed while the panel is hidden. r=jaws, a=ritu MozReview-Commit-ID: JpW9G6MAGwM
browser/components/downloads/content/downloads.js
--- a/browser/components/downloads/content/downloads.js
+++ b/browser/components/downloads/content/downloads.js
@@ -298,16 +298,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.
@@ -391,25 +405,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;
     }
 
@@ -704,18 +721,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.
@@ -836,16 +851,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(),
 
@@ -1487,17 +1505,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.