summaryrefslogtreecommitdiffstats
path: root/application/palemoon/components/downloads/content/downloads.js
diff options
context:
space:
mode:
authorjanekptacijarabaci <janekptacijarabaci@seznam.cz>2018-07-29 07:23:54 +0200
committerjanekptacijarabaci <janekptacijarabaci@seznam.cz>2018-07-29 07:23:54 +0200
commita970e88a1753101d2d55139bd7ae44d005c33f44 (patch)
treefc2a06ce42e69e58bf2c3d4810f7a943e9f29283 /application/palemoon/components/downloads/content/downloads.js
parent43cebecade19978f231253b221cb36bc7039661b (diff)
downloadUXP-a970e88a1753101d2d55139bd7ae44d005c33f44.tar
UXP-a970e88a1753101d2d55139bd7ae44d005c33f44.tar.gz
UXP-a970e88a1753101d2d55139bd7ae44d005c33f44.tar.lz
UXP-a970e88a1753101d2d55139bd7ae44d005c33f44.tar.xz
UXP-a970e88a1753101d2d55139bd7ae44d005c33f44.zip
[PALEMOON] Bug 1115369 - Use notifications instead of getViewItem for DownloadsView
Diffstat (limited to 'application/palemoon/components/downloads/content/downloads.js')
-rw-r--r--application/palemoon/components/downloads/content/downloads.js56
1 files changed, 22 insertions, 34 deletions
diff --git a/application/palemoon/components/downloads/content/downloads.js b/application/palemoon/components/downloads/content/downloads.js
index 833d7d72f..44457e711 100644
--- a/application/palemoon/components/downloads/content/downloads.js
+++ b/application/palemoon/components/downloads/content/downloads.js
@@ -570,7 +570,7 @@ const DownloadsPanel = {
// still exist, and update the allowed items interactions accordingly. We
// do these checks on a background thread, and don't prevent the panel to
// be displayed while these checks are being performed.
- for each (let viewItem in DownloadsView._viewItems) {
+ for (let viewItem of DownloadsView._visibleViewItems.values()) {
viewItem.verifyTargetExists();
}
@@ -711,11 +711,11 @@ const DownloadsView = {
_dataItems: [],
/**
- * Object containing the available DownloadsViewItem objects, indexed by their
- * numeric download identifier. There is a limited number of view items in
- * the panel at any given time.
+ * Associates the visible DownloadsDataItem objects with their corresponding
+ * DownloadsViewItem object. There is a limited number of view items in the
+ * panel at any given time.
*/
- _viewItems: {},
+ _visibleViewItems: new Map(),
/**
* Called when the number of items in the list changes.
@@ -879,31 +879,21 @@ const DownloadsView = {
this._itemCountChanged();
},
- /**
- * Returns the view item associated with the provided data item for this view.
- *
- * @param aDataItem
- * DownloadsDataItem object for which the view item is requested.
- *
- * @return Object that can be used to notify item status events.
- */
- getViewItem: function DV_getViewItem(aDataItem)
- {
- // If the item is visible, just return it, otherwise return a mock object
- // that doesn't react to notifications.
- if (aDataItem.downloadGuid in this._viewItems) {
- return this._viewItems[aDataItem.downloadGuid];
+ // DownloadsView
+ onDataItemStateChanged(aDataItem, aOldState) {
+ let viewItem = this._visibleViewItems.get(aDataItem);
+ if (viewItem) {
+ viewItem.onStateChanged(aOldState);
}
- return this._invisibleViewItem;
},
- /**
- * Mock DownloadsDataItem object that doesn't react to notifications.
- */
- _invisibleViewItem: Object.freeze({
- onStateChange: function () { },
- onProgressChange: function () { }
- }),
+ // DownloadsView
+ onDataItemChanged(aDataItem) {
+ let viewItem = this._visibleViewItems.get(aDataItem);
+ if (viewItem) {
+ viewItem.onChanged();
+ }
+ },
/**
* Creates a new view item associated with the specified data item, and adds
@@ -916,7 +906,7 @@ const DownloadsView = {
let element = document.createElement("richlistitem");
let viewItem = new DownloadsViewItem(aDataItem, element);
- this._viewItems[aDataItem.downloadGuid] = viewItem;
+ this._visibleViewItems.set(aDataItem, viewItem);
if (aNewest) {
this.richListBox.insertBefore(element, this.richListBox.firstChild);
} else {
@@ -930,14 +920,14 @@ const DownloadsView = {
_removeViewItem: function DV_removeViewItem(aDataItem)
{
DownloadsCommon.log("Removing a DownloadsViewItem from the downloads list.");
- let element = this.getViewItem(aDataItem)._element;
+ let element = this._visibleViewItems.get(aDataItem)._element;
let previousSelectedIndex = this.richListBox.selectedIndex;
this.richListBox.removeChild(element);
if (previousSelectedIndex != -1) {
this.richListBox.selectedIndex = Math.min(previousSelectedIndex,
this.richListBox.itemCount - 1);
}
- delete this._viewItems[aDataItem.downloadGuid];
+ this._visibleViewItems.delete(aDataItem);
},
//////////////////////////////////////////////////////////////////////////////
@@ -1134,7 +1124,7 @@ DownloadsViewItem.prototype = {
* the download might be the same as before, if the data layer received
* multiple events for the same download.
*/
- onStateChange: function DVI_onStateChange(aOldState)
+ onStateChanged(aOldState) {
{
// If a download just finished successfully, it means that the target file
// now exists and we can extract its specific icon. To ensure that the icon
@@ -1155,14 +1145,12 @@ DownloadsViewItem.prototype = {
// Update the user interface after switching states.
this._element.setAttribute("state", this.dataItem.state);
- this._updateProgress();
- this._updateStatusLine();
},
/**
* Called when the download progress has changed.
*/
- onProgressChange: function DVI_onProgressChange() {
+ onChanged() {
this._updateProgress();
this._updateStatusLine();
},