Bug 748160 - Update the Downloads command to open the Downloads view instead of the Downloads Panel. r=mak
authorPaolo Amadini <paolo.mozmail@amadzone.org>
Sat, 25 Aug 2012 11:37:55 +0200
changeset 105456 3d3e80ee5ec181003376ba5621fe2ace2d89413e
parent 105455 52540206fb9167b7224480906e5184b6d21ab9d1
child 105457 8247f7b038ced1dcbe73187e650dd612fe8ab8b1
push id55
push usershu@rfrn.org
push dateThu, 30 Aug 2012 01:33:09 +0000
reviewersmak
bugs748160
milestone17.0a1
Bug 748160 - Update the Downloads command to open the Downloads view instead of the Downloads Panel. r=mak
browser/base/content/browser.js
browser/base/content/browser.xul
browser/components/downloads/content/downloads.js
browser/components/downloads/content/indicator.js
browser/components/downloads/src/DownloadsUI.js
browser/components/preferences/main.js
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -3121,39 +3121,16 @@ var newWindowButtonObserver = {
     url = getShortcutOrURI(url, postData);
     if (url) {
       // allow third-party services to fixup this URL
       openNewWindowWith(url, null, postData.value, true);
     }
   }
 }
 
-var DownloadsButtonDNDObserver = {
-  onDragOver: function (aEvent)
-  {
-    var types = aEvent.dataTransfer.types;
-    if (types.contains("text/x-moz-url") ||
-        types.contains("text/uri-list") ||
-        types.contains("text/plain"))
-      aEvent.preventDefault();
-  },
-
-  onDragExit: function (aEvent)
-  {
-  },
-
-  onDrop: function (aEvent)
-  {
-    let name = { };
-    let url = browserDragAndDrop.drop(aEvent, name);
-    if (url)
-      saveURL(url, name, null, true, true);
-  }
-}
-
 const DOMLinkHandler = {
   handleEvent: function (event) {
     switch (event.type) {
       case "DOMLinkAdded":
         this.onLinkAdded(event);
         break;
     }
   },
--- a/browser/base/content/browser.xul
+++ b/browser/base/content/browser.xul
@@ -935,21 +935,21 @@
       <toolbarbutton id="print-button" class="toolbarbutton-1 chromeclass-toolbar-additional"
                      label="&printButton.label;" command="cmd_print"
                      tooltiptext="&printButton.tooltip;"/>
 
       <!-- This is a placeholder for the Downloads Indicator.  It is visible
            during the customization of the toolbar, in the palette, and before
            the Downloads Indicator overlay is loaded. -->
       <toolbarbutton id="downloads-button" class="toolbarbutton-1 chromeclass-toolbar-additional"
-                     observes="Tools:Downloads"
-                     ondrop="DownloadsButtonDNDObserver.onDrop(event)"
-                     ondragover="DownloadsButtonDNDObserver.onDragOver(event)"
-                     ondragenter="DownloadsButtonDNDObserver.onDragOver(event)"
-                     ondragexit="DownloadsButtonDNDObserver.onDragExit(event)"
+                     oncommand="DownloadsIndicatorView.onCommand(event);"
+                     ondrop="DownloadsIndicatorView.onDrop(event);"
+                     ondragover="DownloadsIndicatorView.onDragOver(event);"
+                     ondragenter="DownloadsIndicatorView.onDragOver(event);"
+                     ondragleave="DownloadsIndicatorView.onDragLeave(event);"
                      label="&downloads.label;"
                      tooltiptext="&downloads.tooltip;"/>
 
       <toolbarbutton id="history-button" class="toolbarbutton-1 chromeclass-toolbar-additional"
                      observes="viewHistorySidebar" label="&historyButton.label;"
                      tooltiptext="&historyButton.tooltip;"/>
 
       <toolbarbutton id="bookmarks-button" class="toolbarbutton-1 chromeclass-toolbar-additional"
--- a/browser/components/downloads/content/downloads.js
+++ b/browser/components/downloads/content/downloads.js
@@ -255,22 +255,21 @@ const DownloadsPanel = {
   //////////////////////////////////////////////////////////////////////////////
   //// Related operations
 
   /**
    * Shows or focuses the user interface dedicated to downloads history.
    */
   showDownloadsHistory: function DP_showDownloadsHistory()
   {
-    // Hide the panel before invoking the Library window, otherwise focus will
-    // return to the browser window when the panel closes automatically.
+    // Hide the panel before showing another window, otherwise focus will return
+    // to the browser window when the panel closes automatically.
     this.hidePanel();
 
-    // Open the Library window and select the Downloads query.
-    PlacesCommandHook.showPlacesOrganizer("Downloads");
+    BrowserDownloadsUI();
   },
 
   //////////////////////////////////////////////////////////////////////////////
   //// Internal functions
 
   /**
    * Move focus to the main element in the downloads panel, unless another
    * element in the panel is already focused.
--- a/browser/components/downloads/content/indicator.js
+++ b/browser/components/downloads/content/indicator.js
@@ -172,16 +172,28 @@ const DownloadsButton = {
     if (!isElementVisible(placeholder.parentNode)) {
       return null;
     }
 
     return DownloadsIndicatorView.indicatorAnchor;
   },
 
   /**
+   * Indicates whether the indicator is visible in the browser window.
+   */
+  get isVisible()
+  {
+    if (!this._placeholder) {
+      return false;
+    }
+    let element = DownloadsIndicatorView.indicator || this._placeholder;
+    return isElementVisible(element.parentNode);
+  },
+
+  /**
    * Indicates whether we should try and show the indicator temporarily as an
    * anchor for the panel, even if the indicator would be hidden by default.
    */
   _anchorRequested: false,
 
   /**
    * Ensures that there is an anchor available for the panel.
    *
@@ -481,17 +493,17 @@ const DownloadsIndicatorView = {
 
   onCommand: function DIV_onCommand(aEvent)
   {
     if (DownloadsCommon.useToolkitUI) {
       // The panel won't suppress attention for us, we need to clear now.
       DownloadsCommon.indicatorData.attention = false;
     }
 
-    BrowserDownloadsUI();
+    DownloadsPanel.showPanel();
 
     aEvent.stopPropagation();
   },
 
   onDragOver: function DIV_onDragOver(aEvent)
   {
     browserDragAndDrop.dragOver(aEvent);
   },
--- a/browser/components/downloads/src/DownloadsUI.js
+++ b/browser/components/downloads/src/DownloadsUI.js
@@ -63,62 +63,32 @@ DownloadsUI.prototype = {
       return;
     }
 
     if (!aReason) {
       aReason = Ci.nsIDownloadManagerUI.REASON_USER_INTERACTED;
     }
 
     if (aReason == Ci.nsIDownloadManagerUI.REASON_NEW_DOWNLOAD) {
-      // New download notifications are already handled by the panel service.
-      // We don't handle them here because we don't want them to depend on the
-      // "browser.download.manager.showWhenStarting" and
-      // "browser.download.manager.focusWhenStarting" preferences.
-      return;
+      // If the indicator is visible, then new download notifications are
+      // already handled by the panel service.
+      let browserWin = gBrowserGlue.getMostRecentBrowserWindow();
+      if (browserWin &&
+          browserWin.windowState != Ci.nsIDOMChromeWindow.STATE_MINIMIZED &&
+          browserWin.DownloadsButton.isVisible) {
+        return;
+      }
     }
 
-    // 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;
-    }
-
-    // If no browser window is visible and the user requested to show the
-    // current downloads, try and open a new window.  We'll open the panel when
-    // delayed loading is finished.
-    Services.obs.addObserver(function DUIO_observe(aSubject, aTopic, aData) {
-      Services.obs.removeObserver(DUIO_observe, aTopic);
-      aSubject.DownloadsPanel.showPanel();
-    }, "browser-delayed-startup-finished", false);
-
-    // We must really build an empty arguments list for the new window.
-    let windowFirstArg = Cc["@mozilla.org/supports-string;1"]
-                         .createInstance(Ci.nsISupportsString);
-    let windowArgs = Cc["@mozilla.org/supports-array;1"]
-                     .createInstance(Ci.nsISupportsArray);
-    windowArgs.AppendElement(windowFirstArg);
-    Services.ww.openWindow(null, "chrome://browser/content/browser.xul",
-                           null, "chrome,dialog=no,all", windowArgs);
+    this._toolkitUI.show(aWindowContext, aID, aReason);
   },
 
   get visible()
   {
-    if (DownloadsCommon.useToolkitUI) {
-      return this._toolkitUI.visible;
-    }
-
-    let browserWin = gBrowserGlue.getMostRecentBrowserWindow();
-    return browserWin ? browserWin.DownloadsPanel.isPanelShowing : false;
+    return this._toolkitUI.visible;
   },
 
   getAttention: function DUI_getAttention()
   {
     if (DownloadsCommon.useToolkitUI) {
       this._toolkitUI.getAttention();
     }
   }
--- a/browser/components/preferences/main.js
+++ b/browser/components/preferences/main.js
@@ -18,35 +18,22 @@ var gMainPane = {
     this._pane = document.getElementById("paneMain");
 
     // set up the "use current page" label-changing listener
     this._updateUseCurrentButton();
     window.addEventListener("focus", this._updateUseCurrentButton.bind(this), false);
 
     this.updateBrowserStartupLastSession();
 
-    this.setupDownloadsWindowOptions();
-
     // Notify observers that the UI is now ready
     Components.classes["@mozilla.org/observer-service;1"]
               .getService(Components.interfaces.nsIObserverService)
               .notifyObservers(window, "main-pane-loaded", null);
   },
 
-  setupDownloadsWindowOptions: function ()
-  {
-    var showWhenDownloading = document.getElementById("showWhenDownloading");
-    var closeWhenDone = document.getElementById("closeWhenDone");
-
-    // These radio-buttons should not be visible if we have enabled the Downloads Panel.
-    let shouldHide = !DownloadsCommon.useToolkitUI;
-    showWhenDownloading.hidden = shouldHide;
-    closeWhenDone.hidden = shouldHide;
-  },
-
   // HOME PAGE
 
   /*
    * Preferences:
    *
    * browser.startup.homepage
    * - the user's home page, as a string; if the home page is a set of tabs,
    *   this will be those URLs separated by the pipe character "|"