Bug 814961 - Hide the summary in the Downloads Panel if there are no hidden downloads in progress or paused. r=mak.
authorMike Conley <mconley@mozilla.com>
Wed, 05 Dec 2012 12:12:00 -0500
changeset 115103 51cbdd0f1ba456f204acb55eee400bb0a008e108
parent 115102 dbb56727c829a90ace6ca2d7725ccfcacfa6237b
child 115104 5488aa7e3fc3855cb481addac7e8f9532e277d72
push id23973
push useremorley@mozilla.com
push dateThu, 06 Dec 2012 10:04:18 +0000
treeherdermozilla-central@ddda5400c826 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs814961
milestone20.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 814961 - Hide the summary in the Downloads Panel if there are no hidden downloads in progress or paused. r=mak.
browser/components/downloads/content/downloads.css
browser/components/downloads/content/downloads.js
browser/components/downloads/content/downloadsOverlay.xul
--- a/browser/components/downloads/content/downloads.css
+++ b/browser/components/downloads/content/downloads.css
@@ -91,12 +91,15 @@ richlistitem[type="download"]:not([selec
                                    [counter],
                                    [paused]))
                                            #downloads-indicator-progress-area
 
 {
   visibility: hidden;
 }
 
-#downloadsSummary:not([inprogress="true"]) > vbox > #downloadsSummaryProgress,
-#downloadsSummary:not([inprogress="true"]) > vbox > #downloadsSummaryDetails {
+#downloadsSummary:not([inprogress]) > vbox > #downloadsSummaryProgress,
+#downloadsSummary:not([inprogress]) > vbox > #downloadsSummaryDetails,
+#downloadsFooter[showingsummary] > #downloadsHistory,
+#downloadsFooter:not([showingsummary]) > #downloadsSummary
+{
   display: none;
 }
--- a/browser/components/downloads/content/downloads.js
+++ b/browser/components/downloads/content/downloads.js
@@ -535,20 +535,20 @@ const DownloadsView = {
     let hiddenCount = count - this.kItemCountLimit;
 
     if (count > 0) {
       DownloadsPanel.panel.setAttribute("hasdownloads", "true");
     } else {
       DownloadsPanel.panel.removeAttribute("hasdownloads");
     }
 
-    // If we've got some hidden downloads, we should show the summary just
-    // below the list.
-    this.downloadsHistory.collapsed = hiddenCount > 0;
-    DownloadsSummary.visible = this.downloadsHistory.collapsed;
+    // 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.
    */
   get richListBox()
   {
     delete this.richListBox;
@@ -1440,61 +1440,61 @@ DownloadsViewItemController.prototype = 
 
 /**
  * Manages the summary at the bottom of the downloads panel list if the number
  * of items in the list exceeds the panels limit.
  */
 const DownloadsSummary = {
 
   /**
-   * Sets the collapsed state of the summary, and automatically subscribes or
-   * unsubscribes from the DownloadsCommon DownloadsSummaryData singleton.
+   * Sets the active state of the summary. When active, the sumamry subscribes
+   * to the DownloadsCommon DownloadsSummaryData singleton.
    *
-   * @param aVisible
-   *        True if the summary should be shown.
+   * @param aActive
+   *        Set to true to activate the summary.
    */
-  set visible(aVisible)
+  set active(aActive)
   {
-    if (aVisible == this._visible || !this._summaryNode) {
-      return this._visible;
+    if (aActive == this._active || !this._summaryNode) {
+      return this._active;
     }
-    if (aVisible) {
+    if (aActive) {
       DownloadsCommon.getSummary(DownloadsView.kItemCountLimit)
                      .addView(this);
     } else {
       DownloadsCommon.getSummary(DownloadsView.kItemCountLimit)
                      .removeView(this);
+      DownloadsFooter.showingSummary = false;
     }
-    this._summaryNode.collapsed = !aVisible;
-    return this._visible = aVisible;
+
+    return this._active = aActive;
   },
 
   /**
-   * Returns the collapsed state of the downloads summary.
+   * Returns the active state of the downloads summary.
    */
-  get visible()
-  {
-    return this._visible;
-  },
+  get active() this._active,
 
-  _visible: false,
+  _active: false,
 
   /**
    * Sets whether or not we show the progress bar.
    *
    * @param aShowingProgress
    *        True if we should show the progress bar.
    */
   set showingProgress(aShowingProgress)
   {
     if (aShowingProgress) {
       this._summaryNode.setAttribute("inprogress", "true");
     } else {
       this._summaryNode.removeAttribute("inprogress");
     }
+    // If progress isn't being shown, then we simply do not show the summary.
+    return DownloadsFooter.showingSummary = aShowingProgress;
   },
 
   /**
    * Sets the amount of progress that is visible in the progress bar.
    *
    * @param aValue
    *        A value between 0 and 100 to represent the progress of the
    *        summarized downloads.
@@ -1662,10 +1662,39 @@ const DownloadsFooter = {
     // If the up key is pressed, and the downloads list has at least 1 element
     // in it, focus the last element in the list.
     if (aEvent.keyCode == KeyEvent.DOM_VK_UP &&
         DownloadsView.richListBox.itemCount > 0) {
       DownloadsView.richListBox.focus();
       DownloadsView.richListBox.selectedIndex =
         (DownloadsView.richListBox.itemCount - 1);
     }
+  },
+
+  /**
+   * Sets whether or not the Downloads Summary should be displayed in the
+   * footer. If not, the "Show All Downloads" button is shown instead.
+   */
+  set showingSummary(aValue)
+  {
+    if (this._footerNode) {
+      if (aValue) {
+        this._footerNode.setAttribute("showingsummary", "true");
+      } else {
+        this._footerNode.removeAttribute("showingsummary");
+      }
+    }
+    return aValue;
+  },
+
+  /**
+   * Element corresponding to the footer of the downloads panel.
+   */
+  get _footerNode()
+  {
+    let node = document.getElementById("downloadsFooter");
+    if (!node) {
+      return null;
+    }
+    delete this._footerNode;
+    return this._footerNode = node;
   }
 };
--- a/browser/components/downloads/content/downloadsOverlay.xul
+++ b/browser/components/downloads/content/downloadsOverlay.xul
@@ -103,17 +103,16 @@
                    context="downloadsContextMenu"
                    onkeypress="DownloadsView.onDownloadKeyPress(event);"
                    oncontextmenu="DownloadsView.onDownloadContextMenu(event);"
                    ondragstart="DownloadsView.onDownloadDragStart(event);"/>
 
       <vbox id="downloadsFooter"
             onkeypress="DownloadsFooter.onKeyPress(event);">
         <hbox id="downloadsSummary"
-              collapsed="true"
               align="center"
               orient="horizontal"
               onkeypress="DownloadsSummary.onKeyPress(event);"
               onclick="DownloadsSummary.onClick(event);">
           <image class="downloadTypeIcon" />
           <vbox>
             <description id="downloadsSummaryDescription"
                          class="downloadTarget"