 Issue 29329786:
  Issue 3258 - Blockable items: fix Size column  (Closed)
    
  
    Issue 29329786:
  Issue 3258 - Blockable items: fix Size column  (Closed) 
  | Left: | ||
| Right: | 
| LEFT | RIGHT | 
|---|---|
| 1 /* | 1 /* | 
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 
| 3 * Copyright (C) 2006-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2015 Eyeo GmbH | 
| 4 * | 4 * | 
| 5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify | 
| 6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as | 
| 7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. | 
| 8 * | 8 * | 
| 9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, | 
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 299 if (subscriptions.length) | 299 if (subscriptions.length) | 
| 300 { | 300 { | 
| 301 let sourceElement = E("tooltipFilterSource"); | 301 let sourceElement = E("tooltipFilterSource"); | 
| 302 while (sourceElement.firstChild) | 302 while (sourceElement.firstChild) | 
| 303 sourceElement.removeChild(sourceElement.firstChild); | 303 sourceElement.removeChild(sourceElement.firstChild); | 
| 304 for (let i = 0; i < subscriptions.length; i++) | 304 for (let i = 0; i < subscriptions.length; i++) | 
| 305 setMultilineContent(sourceElement, subscriptions[i].title, true); | 305 setMultilineContent(sourceElement, subscriptions[i].title, true); | 
| 306 } | 306 } | 
| 307 } | 307 } | 
| 308 | 308 | 
| 309 let updateSize = function() | 309 E("tooltipSizeRow").hidden = true; | 
| 310 { | 310 if (!("tooltip" in item)) | 
| 311 let size = ("tooltip" in item ? null : getItemSize(item, updateSize)); | 311 { | 
| 312 E("tooltipSizeRow").hidden = !size; | 312 getItemSize(item, (size) => | 
| 313 if (size) | 313 { | 
| 314 E("tooltipSize").setAttribute("value", size.join(" x ")); | 314 if (size) | 
| 315 }; | 315 { | 
| 316 updateSize(); | 316 E("tooltipSizeRow").hidden = false; | 
| 
Thomas Greiner
2015/11/24 14:02:19
`getItemSize` no longer returns the result synchro
 
Wladimir Palant
2015/11/25 22:22:49
Sorting and tree view don't work asynchronously, t
 | |
| 317 E("tooltipSize").setAttribute("value", size.join(" x ")); | |
| 318 } | |
| 319 }); | |
| 320 } | |
| 317 | 321 | 
| 318 var showPreview = Prefs.previewimages && !("tooltip" in item); | 322 var showPreview = Prefs.previewimages && !("tooltip" in item); | 
| 319 showPreview = showPreview && item.type == "IMAGE"; | 323 showPreview = showPreview && item.type == "IMAGE"; | 
| 320 showPreview = showPreview && (!filter || filter.disabled || filter instanceof WhitelistFilter); | 324 showPreview = showPreview && (!filter || filter.disabled || filter instanceof WhitelistFilter); | 
| 321 E("tooltipPreviewBox").hidden = true; | 325 E("tooltipPreviewBox").hidden = true; | 
| 322 if (showPreview) | 326 if (showPreview) | 
| 323 { | 327 { | 
| 324 if (!cacheStorage) | 328 if (!cacheStorage) | 
| 325 { | 329 { | 
| 326 let {Services} = Cu.import("resource://gre/modules/Services.jsm", null); | 330 let {Services} = Cu.import("resource://gre/modules/Services.jsm", null); | 
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 661 // Store variables locally, global variables will go away when we are closed | 665 // Store variables locally, global variables will go away when we are closed | 
| 662 let myPrefs = Prefs; | 666 let myPrefs = Prefs; | 
| 663 let myMainWin = mainWin; | 667 let myMainWin = mainWin; | 
| 664 | 668 | 
| 665 // Close sidebar and open detached window | 669 // Close sidebar and open detached window | 
| 666 myMainWin.document.getElementById("abp-command-sidebar").doCommand(); | 670 myMainWin.document.getElementById("abp-command-sidebar").doCommand(); | 
| 667 myPrefs.detachsidebar = doDetach; | 671 myPrefs.detachsidebar = doDetach; | 
| 668 myMainWin.document.getElementById("abp-command-sidebar").doCommand(); | 672 myMainWin.document.getElementById("abp-command-sidebar").doCommand(); | 
| 669 } | 673 } | 
| 670 | 674 | 
| 671 // Returns items size in the document if available | 675 // Returns item's size if already known, otherwise undefined | 
| 672 function getItemSize(item, retryCallback) | 676 function getCachedItemSize(item) | 
| 673 { | 677 { | 
| 674 if ("size" in item) | 678 if ("size" in item) | 
| 675 return item.size; | 679 return item.size; | 
| 676 | 680 | 
| 677 let filter = getFilter(item); | 681 let filter = getFilter(item); | 
| 678 if (filter && !filter.disabled && filter instanceof BlockingFilter) | 682 if (filter && !filter.disabled && filter instanceof BlockingFilter) | 
| 679 return null; | 683 return null; | 
| 680 | 684 | 
| 681 if (requestNotifier) | 685 return undefined; | 
| 682 { | 686 } | 
| 683 requestNotifier.retrieveNodeSize(item.ids, function(size) | 687 | 
| 684 { | 688 // Retrieves item's size in the document if available | 
| 689 function getItemSize(item, callback) | |
| 690 { | |
| 691 let size = getCachedItemSize(item); | |
| 692 if (typeof size != "undefined" || !requestNotifier) | |
| 693 { | |
| 694 callback(size); | |
| 695 return; | |
| 696 } | |
| 697 | |
| 698 requestNotifier.retrieveNodeSize(item.ids, function(size) | |
| 699 { | |
| 700 if (size) | |
| 685 item.size = size; | 701 item.size = size; | 
| 686 if (retryCallback) | 702 callback(size); | 
| 687 retryCallback(); | 703 }); | 
| 688 }); | |
| 689 } | |
| 690 return null; | |
| 691 } | 704 } | 
| 692 | 705 | 
| 693 // Sort functions for the item list | 706 // Sort functions for the item list | 
| 694 function sortByAddress(item1, item2) { | 707 function sortByAddress(item1, item2) { | 
| 695 if (item1.location < item2.location) | 708 if (item1.location < item2.location) | 
| 696 return -1; | 709 return -1; | 
| 697 else if (item1.location > item2.location) | 710 else if (item1.location > item2.location) | 
| 698 return 1; | 711 return 1; | 
| 699 else | 712 else | 
| 700 return 0; | 713 return 0; | 
| (...skipping 29 matching lines...) Expand all Loading... | |
| 730 | 743 | 
| 731 function compareState(item1, item2) | 744 function compareState(item1, item2) | 
| 732 { | 745 { | 
| 733 let filter1 = getFilter(item1); | 746 let filter1 = getFilter(item1); | 
| 734 let filter2 = getFilter(item2); | 747 let filter2 = getFilter(item2); | 
| 735 let state1 = (!filter1 ? 0 : (filter1.disabled ? 1 : (filter1 instanceof White listFilter ? 2 : 3))); | 748 let state1 = (!filter1 ? 0 : (filter1.disabled ? 1 : (filter1 instanceof White listFilter ? 2 : 3))); | 
| 736 let state2 = (!filter2 ? 0 : (filter2.disabled ? 1 : (filter2 instanceof White listFilter ? 2 : 3))); | 749 let state2 = (!filter2 ? 0 : (filter2.disabled ? 1 : (filter2 instanceof White listFilter ? 2 : 3))); | 
| 737 return state1 - state2; | 750 return state1 - state2; | 
| 738 } | 751 } | 
| 739 | 752 | 
| 740 function compareSize(item1, item2) { | 753 function compareSize(item1, item2) | 
| 741 var size1 = getItemSize(item1); | 754 { | 
| 755 let size1 = getCachedItemSize(item1); | |
| 756 let size2 = getCachedItemSize(item2); | |
| 757 | |
| 742 size1 = size1 ? size1[0] * size1[1] : 0; | 758 size1 = size1 ? size1[0] * size1[1] : 0; | 
| 743 | |
| 744 var size2 = getItemSize(item2); | |
| 745 size2 = size2 ? size2[0] * size2[1] : 0; | 759 size2 = size2 ? size2[0] * size2[1] : 0; | 
| 746 return size1 - size2; | 760 return size1 - size2; | 
| 747 } | 761 } | 
| 748 | 762 | 
| 749 function compareDocDomain(item1, item2) | 763 function compareDocDomain(item1, item2) | 
| 750 { | 764 { | 
| 751 if (item1.docDomain < item2.docDomain) | 765 if (item1.docDomain < item2.docDomain) | 
| 752 return -1; | 766 return -1; | 
| 753 else if (item1.docDomain > item2.docDomain) | 767 else if (item1.docDomain > item2.docDomain) | 
| 754 return 1; | 768 return 1; | 
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 878 return ""; | 892 return ""; | 
| 879 if (this.data && this.data.length) { | 893 if (this.data && this.data.length) { | 
| 880 if (row >= this.data.length) | 894 if (row >= this.data.length) | 
| 881 return ""; | 895 return ""; | 
| 882 if (col == "type") | 896 if (col == "type") | 
| 883 return localizedTypes.get(this.data[row].type); | 897 return localizedTypes.get(this.data[row].type); | 
| 884 else if (col == "filter") | 898 else if (col == "filter") | 
| 885 return (this.data[row].filter || ""); | 899 return (this.data[row].filter || ""); | 
| 886 else if (col == "size") | 900 else if (col == "size") | 
| 887 { | 901 { | 
| 888 let size = getItemSize(this.data[row], () => | 902 let size = getCachedItemSize(this.data[row]); | 
| 903 if (typeof size == "undefined") | |
| 889 { | 904 { | 
| 890 this.boxObject.invalidateRow(row); | 905 getItemSize(this.data[row], (size) => | 
| 891 }); | 906 { | 
| 907 if (size) | |
| 908 this.boxObject.invalidateRow(row) | |
| 909 }); | |
| 910 } | |
| 892 return (size ? size.join(" x ") : ""); | 911 return (size ? size.join(" x ") : ""); | 
| 893 } | 912 } | 
| 894 else if (col == "docDomain") | 913 else if (col == "docDomain") | 
| 895 return this.data[row].docDomain + " " + (this.data[row].thirdParty ? doc DomainThirdParty : docDomainFirstParty); | 914 return this.data[row].docDomain + " " + (this.data[row].thirdParty ? doc DomainThirdParty : docDomainFirstParty); | 
| 896 else if (col == "filterSource") | 915 else if (col == "filterSource") | 
| 897 { | 916 { | 
| 898 let filter = getFilter(this.data[row]) | 917 let filter = getFilter(this.data[row]) | 
| 899 if (!filter) | 918 if (!filter) | 
| 900 return ""; | 919 return ""; | 
| 901 | 920 | 
| (...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1290 return {tooltip: this.itemsDummyTooltip}; | 1309 return {tooltip: this.itemsDummyTooltip}; | 
| 1291 }, | 1310 }, | 
| 1292 | 1311 | 
| 1293 invalidateItem: function(item) | 1312 invalidateItem: function(item) | 
| 1294 { | 1313 { | 
| 1295 let row = this.data.indexOf(item); | 1314 let row = this.data.indexOf(item); | 
| 1296 if (row >= 0) | 1315 if (row >= 0) | 
| 1297 this.boxObject.invalidateRow(row); | 1316 this.boxObject.invalidateRow(row); | 
| 1298 } | 1317 } | 
| 1299 } | 1318 } | 
| LEFT | RIGHT |