OLD | NEW |
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 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 else | 251 else |
252 item = treeView.getItemAt(e.clientX, e.clientY); | 252 item = treeView.getItemAt(e.clientX, e.clientY); |
253 | 253 |
254 if (!item) | 254 if (!item) |
255 { | 255 { |
256 e.preventDefault(); | 256 e.preventDefault(); |
257 return; | 257 return; |
258 } | 258 } |
259 | 259 |
260 let filter = getFilter(item); | 260 let filter = getFilter(item); |
261 let size = ("tooltip" in item ? null : getItemSize(item)); | |
262 let subscriptions = (filter ? filter.subscriptions.filter(function(subscriptio
n) { return !subscription.disabled; }) : []); | 261 let subscriptions = (filter ? filter.subscriptions.filter(function(subscriptio
n) { return !subscription.disabled; }) : []); |
263 | 262 |
264 E("tooltipDummy").hidden = !("tooltip" in item); | 263 E("tooltipDummy").hidden = !("tooltip" in item); |
265 E("tooltipAddressRow").hidden = ("tooltip" in item); | 264 E("tooltipAddressRow").hidden = ("tooltip" in item); |
266 E("tooltipTypeRow").hidden = ("tooltip" in item); | 265 E("tooltipTypeRow").hidden = ("tooltip" in item); |
267 E("tooltipSizeRow").hidden = !size; | |
268 E("tooltipDocDomainRow").hidden = ("tooltip" in item || !item.docDomain); | 266 E("tooltipDocDomainRow").hidden = ("tooltip" in item || !item.docDomain); |
269 E("tooltipFilterRow").hidden = !filter; | 267 E("tooltipFilterRow").hidden = !filter; |
270 E("tooltipFilterSourceRow").hidden = !subscriptions.length; | 268 E("tooltipFilterSourceRow").hidden = !subscriptions.length; |
271 | 269 |
272 if ("tooltip" in item) | 270 if ("tooltip" in item) |
273 E("tooltipDummy").setAttribute("value", item.tooltip); | 271 E("tooltipDummy").setAttribute("value", item.tooltip); |
274 else | 272 else |
275 { | 273 { |
276 E("tooltipAddress").parentNode.hidden = (item.type == "ELEMHIDE"); | 274 E("tooltipAddress").parentNode.hidden = (item.type == "ELEMHIDE"); |
277 setMultilineContent(E("tooltipAddress"), item.location); | 275 setMultilineContent(E("tooltipAddress"), item.location); |
278 | 276 |
279 var type = localizedTypes.get(item.type); | 277 var type = localizedTypes.get(item.type); |
280 if (filter && filter instanceof WhitelistFilter) | 278 if (filter && filter instanceof WhitelistFilter) |
281 type += " " + E("tooltipType").getAttribute("whitelisted"); | 279 type += " " + E("tooltipType").getAttribute("whitelisted"); |
282 else if (filter && item.type != "ELEMHIDE") | 280 else if (filter && item.type != "ELEMHIDE") |
283 type += " " + E("tooltipType").getAttribute("filtered"); | 281 type += " " + E("tooltipType").getAttribute("filtered"); |
284 E("tooltipType").setAttribute("value", type); | 282 E("tooltipType").setAttribute("value", type); |
285 | 283 |
286 if (size) | |
287 E("tooltipSize").setAttribute("value", size.join(" x ")); | |
288 | |
289 E("tooltipDocDomain").setAttribute("value", item.docDomain + " " + (item.thi
rdParty ? docDomainThirdParty : docDomainFirstParty)); | 284 E("tooltipDocDomain").setAttribute("value", item.docDomain + " " + (item.thi
rdParty ? docDomainThirdParty : docDomainFirstParty)); |
290 } | 285 } |
291 | 286 |
292 if (filter) | 287 if (filter) |
293 { | 288 { |
294 let filterField = E("tooltipFilter"); | 289 let filterField = E("tooltipFilter"); |
295 setMultilineContent(filterField, filter.text); | 290 setMultilineContent(filterField, filter.text); |
296 if (filter.disabled) | 291 if (filter.disabled) |
297 { | 292 { |
298 let disabledText = document.createElement("description"); | 293 let disabledText = document.createElement("description"); |
299 disabledText.className = "disabledTextLabel"; | 294 disabledText.className = "disabledTextLabel"; |
300 disabledText.textContent = filterField.getAttribute("disabledText"); | 295 disabledText.textContent = filterField.getAttribute("disabledText"); |
301 filterField.appendChild(disabledText); | 296 filterField.appendChild(disabledText); |
302 } | 297 } |
303 | 298 |
304 if (subscriptions.length) | 299 if (subscriptions.length) |
305 { | 300 { |
306 let sourceElement = E("tooltipFilterSource"); | 301 let sourceElement = E("tooltipFilterSource"); |
307 while (sourceElement.firstChild) | 302 while (sourceElement.firstChild) |
308 sourceElement.removeChild(sourceElement.firstChild); | 303 sourceElement.removeChild(sourceElement.firstChild); |
309 for (let i = 0; i < subscriptions.length; i++) | 304 for (let i = 0; i < subscriptions.length; i++) |
310 setMultilineContent(sourceElement, subscriptions[i].title, true); | 305 setMultilineContent(sourceElement, subscriptions[i].title, true); |
311 } | 306 } |
312 } | 307 } |
313 | 308 |
| 309 E("tooltipSizeRow").hidden = true; |
| 310 if (!("tooltip" in item)) |
| 311 { |
| 312 getItemSize(item, (size) => |
| 313 { |
| 314 if (size) |
| 315 { |
| 316 E("tooltipSizeRow").hidden = false; |
| 317 E("tooltipSize").setAttribute("value", size.join(" x ")); |
| 318 } |
| 319 }); |
| 320 } |
| 321 |
314 var showPreview = Prefs.previewimages && !("tooltip" in item); | 322 var showPreview = Prefs.previewimages && !("tooltip" in item); |
315 showPreview = showPreview && item.type == "IMAGE"; | 323 showPreview = showPreview && item.type == "IMAGE"; |
316 showPreview = showPreview && (!filter || filter.disabled || filter instanceof
WhitelistFilter); | 324 showPreview = showPreview && (!filter || filter.disabled || filter instanceof
WhitelistFilter); |
317 E("tooltipPreviewBox").hidden = true; | 325 E("tooltipPreviewBox").hidden = true; |
318 if (showPreview) | 326 if (showPreview) |
319 { | 327 { |
320 if (!cacheStorage) | 328 if (!cacheStorage) |
321 { | 329 { |
322 let {Services} = Cu.import("resource://gre/modules/Services.jsm", null); | 330 let {Services} = Cu.import("resource://gre/modules/Services.jsm", null); |
323 // Cache v2 API is enabled by default starting with Gecko 32 | 331 // Cache v2 API is enabled by default starting with Gecko 32 |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
657 // 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 |
658 let myPrefs = Prefs; | 666 let myPrefs = Prefs; |
659 let myMainWin = mainWin; | 667 let myMainWin = mainWin; |
660 | 668 |
661 // Close sidebar and open detached window | 669 // Close sidebar and open detached window |
662 myMainWin.document.getElementById("abp-command-sidebar").doCommand(); | 670 myMainWin.document.getElementById("abp-command-sidebar").doCommand(); |
663 myPrefs.detachsidebar = doDetach; | 671 myPrefs.detachsidebar = doDetach; |
664 myMainWin.document.getElementById("abp-command-sidebar").doCommand(); | 672 myMainWin.document.getElementById("abp-command-sidebar").doCommand(); |
665 } | 673 } |
666 | 674 |
667 // Returns items size in the document if available | 675 // Retrieves items size in the document if available |
668 function getItemSize(item) | 676 function getItemSize(item, callback) |
669 { | 677 { |
| 678 if ("size" in item) |
| 679 return callback(item.size); |
| 680 |
670 let filter = getFilter(item); | 681 let filter = getFilter(item); |
671 if (filter && !filter.disabled && filter instanceof BlockingFilter) | 682 if (filter && !filter.disabled && filter instanceof BlockingFilter) |
672 return null; | 683 return callback(null); |
673 | 684 |
674 for (let node of item.nodes) | 685 if (requestNotifier) |
675 { | 686 { |
676 if (node instanceof HTMLImageElement && (node.naturalWidth || node.naturalHe
ight)) | 687 requestNotifier.retrieveNodeSize(item.ids, function(size) |
677 return [node.naturalWidth, node.naturalHeight]; | 688 { |
678 else if (node instanceof HTMLElement && (node.offsetWidth || node.offsetHeig
ht)) | 689 item.size = size; |
679 return [node.offsetWidth, node.offsetHeight]; | 690 callback(size); |
| 691 }); |
680 } | 692 } |
681 return null; | |
682 } | 693 } |
683 | 694 |
684 // Sort functions for the item list | 695 // Sort functions for the item list |
685 function sortByAddress(item1, item2) { | 696 function sortByAddress(item1, item2) { |
686 if (item1.location < item2.location) | 697 if (item1.location < item2.location) |
687 return -1; | 698 return -1; |
688 else if (item1.location > item2.location) | 699 else if (item1.location > item2.location) |
689 return 1; | 700 return 1; |
690 else | 701 else |
691 return 0; | 702 return 0; |
(...skipping 30 matching lines...) Expand all Loading... |
722 function compareState(item1, item2) | 733 function compareState(item1, item2) |
723 { | 734 { |
724 let filter1 = getFilter(item1); | 735 let filter1 = getFilter(item1); |
725 let filter2 = getFilter(item2); | 736 let filter2 = getFilter(item2); |
726 let state1 = (!filter1 ? 0 : (filter1.disabled ? 1 : (filter1 instanceof White
listFilter ? 2 : 3))); | 737 let state1 = (!filter1 ? 0 : (filter1.disabled ? 1 : (filter1 instanceof White
listFilter ? 2 : 3))); |
727 let state2 = (!filter2 ? 0 : (filter2.disabled ? 1 : (filter2 instanceof White
listFilter ? 2 : 3))); | 738 let state2 = (!filter2 ? 0 : (filter2.disabled ? 1 : (filter2 instanceof White
listFilter ? 2 : 3))); |
728 return state1 - state2; | 739 return state1 - state2; |
729 } | 740 } |
730 | 741 |
731 function compareSize(item1, item2) { | 742 function compareSize(item1, item2) { |
732 var size1 = getItemSize(item1); | 743 let size1; |
| 744 let size2; |
| 745 getItemSize(item1, (size) => size1 = size); |
| 746 getItemSize(item2, (size) => size2 = size); |
| 747 |
733 size1 = size1 ? size1[0] * size1[1] : 0; | 748 size1 = size1 ? size1[0] * size1[1] : 0; |
734 | |
735 var size2 = getItemSize(item2); | |
736 size2 = size2 ? size2[0] * size2[1] : 0; | 749 size2 = size2 ? size2[0] * size2[1] : 0; |
737 return size1 - size2; | 750 return size1 - size2; |
738 } | 751 } |
739 | 752 |
740 function compareDocDomain(item1, item2) | 753 function compareDocDomain(item1, item2) |
741 { | 754 { |
742 if (item1.docDomain < item2.docDomain) | 755 if (item1.docDomain < item2.docDomain) |
743 return -1; | 756 return -1; |
744 else if (item1.docDomain > item2.docDomain) | 757 else if (item1.docDomain > item2.docDomain) |
745 return 1; | 758 return 1; |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
869 return ""; | 882 return ""; |
870 if (this.data && this.data.length) { | 883 if (this.data && this.data.length) { |
871 if (row >= this.data.length) | 884 if (row >= this.data.length) |
872 return ""; | 885 return ""; |
873 if (col == "type") | 886 if (col == "type") |
874 return localizedTypes.get(this.data[row].type); | 887 return localizedTypes.get(this.data[row].type); |
875 else if (col == "filter") | 888 else if (col == "filter") |
876 return (this.data[row].filter || ""); | 889 return (this.data[row].filter || ""); |
877 else if (col == "size") | 890 else if (col == "size") |
878 { | 891 { |
879 let size = getItemSize(this.data[row]); | 892 let result; |
880 return (size ? size.join(" x ") : ""); | 893 getItemSize(this.data[row], (size) => |
| 894 { |
| 895 if (typeof result == "undefined") |
| 896 result = size; |
| 897 else |
| 898 this.boxObject.invalidateRow(row) |
| 899 }); |
| 900 result = (result ? result.join(" x ") : ""); |
| 901 return result; |
881 } | 902 } |
882 else if (col == "docDomain") | 903 else if (col == "docDomain") |
883 return this.data[row].docDomain + " " + (this.data[row].thirdParty ? doc
DomainThirdParty : docDomainFirstParty); | 904 return this.data[row].docDomain + " " + (this.data[row].thirdParty ? doc
DomainThirdParty : docDomainFirstParty); |
884 else if (col == "filterSource") | 905 else if (col == "filterSource") |
885 { | 906 { |
886 let filter = getFilter(this.data[row]) | 907 let filter = getFilter(this.data[row]) |
887 if (!filter) | 908 if (!filter) |
888 return ""; | 909 return ""; |
889 | 910 |
890 return filter.subscriptions.filter(s => !s.disabled).map(s => s.title).j
oin(", "); | 911 return filter.subscriptions.filter(s => !s.disabled).map(s => s.title).j
oin(", "); |
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1278 return {tooltip: this.itemsDummyTooltip}; | 1299 return {tooltip: this.itemsDummyTooltip}; |
1279 }, | 1300 }, |
1280 | 1301 |
1281 invalidateItem: function(item) | 1302 invalidateItem: function(item) |
1282 { | 1303 { |
1283 let row = this.data.indexOf(item); | 1304 let row = this.data.indexOf(item); |
1284 if (row >= 0) | 1305 if (row >= 0) |
1285 this.boxObject.invalidateRow(row); | 1306 this.boxObject.invalidateRow(row); |
1286 } | 1307 } |
1287 } | 1308 } |
OLD | NEW |