Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: chrome/content/ui/sidebar.js

Issue 29329786: Issue 3258 - Blockable items: fix Size column (Closed)
Patch Set: Cleaner approach: split up getItemSize into sync and async parts Created Nov. 26, 2015, 11:06 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | lib/child/requestNotifier.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 // Returns item's size if already known, otherwise undefined
668 function getItemSize(item) 676 function getCachedItemSize(item)
669 { 677 {
678 if ("size" in item)
679 return 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 null;
673 684
674 for (let node of item.nodes) 685 return undefined;
686 }
687
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)
675 { 693 {
676 if (node instanceof HTMLImageElement && (node.naturalWidth || node.naturalHe ight)) 694 callback(size);
677 return [node.naturalWidth, node.naturalHeight]; 695 return;
678 else if (node instanceof HTMLElement && (node.offsetWidth || node.offsetHeig ht))
679 return [node.offsetWidth, node.offsetHeight];
680 } 696 }
681 return null; 697
698 requestNotifier.retrieveNodeSize(item.ids, function(size)
699 {
700 if (size)
701 item.size = size;
702 callback(size);
703 });
682 } 704 }
683 705
684 // Sort functions for the item list 706 // Sort functions for the item list
685 function sortByAddress(item1, item2) { 707 function sortByAddress(item1, item2) {
686 if (item1.location < item2.location) 708 if (item1.location < item2.location)
687 return -1; 709 return -1;
688 else if (item1.location > item2.location) 710 else if (item1.location > item2.location)
689 return 1; 711 return 1;
690 else 712 else
691 return 0; 713 return 0;
(...skipping 29 matching lines...) Expand all
721 743
722 function compareState(item1, item2) 744 function compareState(item1, item2)
723 { 745 {
724 let filter1 = getFilter(item1); 746 let filter1 = getFilter(item1);
725 let filter2 = getFilter(item2); 747 let filter2 = getFilter(item2);
726 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)));
727 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)));
728 return state1 - state2; 750 return state1 - state2;
729 } 751 }
730 752
731 function compareSize(item1, item2) { 753 function compareSize(item1, item2)
732 var size1 = getItemSize(item1); 754 {
755 let size1 = getCachedItemSize(item1);
756 let size2 = getCachedItemSize(item2);
757
733 size1 = size1 ? size1[0] * size1[1] : 0; 758 size1 = size1 ? size1[0] * size1[1] : 0;
734
735 var size2 = getItemSize(item2);
736 size2 = size2 ? size2[0] * size2[1] : 0; 759 size2 = size2 ? size2[0] * size2[1] : 0;
737 return size1 - size2; 760 return size1 - size2;
738 } 761 }
739 762
740 function compareDocDomain(item1, item2) 763 function compareDocDomain(item1, item2)
741 { 764 {
742 if (item1.docDomain < item2.docDomain) 765 if (item1.docDomain < item2.docDomain)
743 return -1; 766 return -1;
744 else if (item1.docDomain > item2.docDomain) 767 else if (item1.docDomain > item2.docDomain)
745 return 1; 768 return 1;
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
869 return ""; 892 return "";
870 if (this.data && this.data.length) { 893 if (this.data && this.data.length) {
871 if (row >= this.data.length) 894 if (row >= this.data.length)
872 return ""; 895 return "";
873 if (col == "type") 896 if (col == "type")
874 return localizedTypes.get(this.data[row].type); 897 return localizedTypes.get(this.data[row].type);
875 else if (col == "filter") 898 else if (col == "filter")
876 return (this.data[row].filter || ""); 899 return (this.data[row].filter || "");
877 else if (col == "size") 900 else if (col == "size")
878 { 901 {
879 let size = getItemSize(this.data[row]); 902 let size = getCachedItemSize(this.data[row]);
903 if (typeof size == "undefined")
904 {
905 getItemSize(this.data[row], (size) =>
906 {
907 if (size)
908 this.boxObject.invalidateRow(row)
909 });
910 }
880 return (size ? size.join(" x ") : ""); 911 return (size ? size.join(" x ") : "");
881 } 912 }
882 else if (col == "docDomain") 913 else if (col == "docDomain")
883 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);
884 else if (col == "filterSource") 915 else if (col == "filterSource")
885 { 916 {
886 let filter = getFilter(this.data[row]) 917 let filter = getFilter(this.data[row])
887 if (!filter) 918 if (!filter)
888 return ""; 919 return "";
889 920
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
1278 return {tooltip: this.itemsDummyTooltip}; 1309 return {tooltip: this.itemsDummyTooltip};
1279 }, 1310 },
1280 1311
1281 invalidateItem: function(item) 1312 invalidateItem: function(item)
1282 { 1313 {
1283 let row = this.data.indexOf(item); 1314 let row = this.data.indexOf(item);
1284 if (row >= 0) 1315 if (row >= 0)
1285 this.boxObject.invalidateRow(row); 1316 this.boxObject.invalidateRow(row);
1286 } 1317 }
1287 } 1318 }
OLDNEW
« no previous file with comments | « no previous file | lib/child/requestNotifier.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld