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

Side by Side Diff: lib/ui.js

Issue 5741004535627776: Fix toolbar icon customization in Australis (Closed)
Patch Set: Created Nov. 22, 2013, 5:06 p.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 | « lib/customizableUI.js ('k') | metadata.gecko » ('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 <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2013 Eyeo GmbH 3 * Copyright (C) 2006-2013 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 13 matching lines...) Expand all
24 let {FilterListener} = require("filterListener"); 24 let {FilterListener} = require("filterListener");
25 let {FilterStorage} = require("filterStorage"); 25 let {FilterStorage} = require("filterStorage");
26 let {FilterNotifier} = require("filterNotifier"); 26 let {FilterNotifier} = require("filterNotifier");
27 let {RequestNotifier} = require("requestNotifier"); 27 let {RequestNotifier} = require("requestNotifier");
28 let {Filter} = require("filterClasses"); 28 let {Filter} = require("filterClasses");
29 let {Subscription, SpecialSubscription, DownloadableSubscription} = require("sub scriptionClasses"); 29 let {Subscription, SpecialSubscription, DownloadableSubscription} = require("sub scriptionClasses");
30 let {Synchronizer} = require("synchronizer"); 30 let {Synchronizer} = require("synchronizer");
31 let {KeySelector} = require("keySelector"); 31 let {KeySelector} = require("keySelector");
32 let {Notification} = require("notification"); 32 let {Notification} = require("notification");
33 33
34 let CustomizableUI;
35 try
36 {
37 ({CustomizableUI}) = Cu.import("resource:///modules/CustomizableUI.jsm", null) ;
38 }
39 catch (e)
40 {
41 // No built-in CustomizableUI API, use our own implementation.
42 ({CustomizableUI}) = require("customizableUI");
43 }
44
34 /** 45 /**
35 * Filter corresponding with "disable on site" menu item (set in fillIconMent()) . 46 * Filter corresponding with "disable on site" menu item (set in fillIconMent()) .
36 * @type Filter 47 * @type Filter
37 */ 48 */
38 let siteWhitelist = null; 49 let siteWhitelist = null;
39 /** 50 /**
40 * Filter corresponding with "disable on site" menu item (set in fillIconMenu()) . 51 * Filter corresponding with "disable on site" menu item (set in fillIconMenu()) .
41 * @type Filter 52 * @type Filter
42 */ 53 */
43 let pageWhitelist = null; 54 let pageWhitelist = null;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 101
91 Utils.splitAllLabels(doc); 102 Utils.splitAllLabels(doc);
92 103
93 addCommandHandler("adblockplus-filters", UI.openFiltersDialog.bind(UI)); 104 addCommandHandler("adblockplus-filters", UI.openFiltersDialog.bind(UI));
94 105
95 let {Sync} = require("sync"); 106 let {Sync} = require("sync");
96 let syncEngine = Sync.getEngine(); 107 let syncEngine = Sync.getEngine();
97 hideElement("adblockplus-sync", !syncEngine); 108 hideElement("adblockplus-sync", !syncEngine);
98 109
99 let {defaultToolbarPosition, statusbarPosition} = require("appSupport"); 110 let {defaultToolbarPosition, statusbarPosition} = require("appSupport");
100 let hasToolbar = defaultToolbarPosition && !defaultToolbarPosition.isAddonBa r; 111 let hasToolbar = defaultToolbarPosition;
101 let hasAddonBar = defaultToolbarPosition && defaultToolbarPosition.isAddonBa r;
102 let hasStatusBar = statusbarPosition; 112 let hasStatusBar = statusbarPosition;
103 113
104 hideElement("adblockplus-showinaddonbar", !hasAddonBar);
105 hideElement("adblockplus-showintoolbar", !hasToolbar); 114 hideElement("adblockplus-showintoolbar", !hasToolbar);
106 hideElement("adblockplus-showinstatusbar", !hasStatusBar); 115 hideElement("adblockplus-showinstatusbar", !hasStatusBar);
107 116
108 let checkbox = doc.querySelector("setting[type=bool]"); 117 let checkbox = doc.querySelector("setting[type=bool]");
109 if (checkbox) 118 if (checkbox)
110 initCheckboxes(); 119 initCheckboxes();
111 120
112 function initCheckboxes() 121 function initCheckboxes()
113 { 122 {
114 if (!("value" in checkbox)) 123 if (!("value" in checkbox))
(...skipping 16 matching lines...) Expand all
131 { 140 {
132 this.value = UI.toggleAcceptableAds(); 141 this.value = UI.toggleAcceptableAds();
133 }); 142 });
134 143
135 setChecked("adblockplus-sync", syncEngine && syncEngine.enabled); 144 setChecked("adblockplus-sync", syncEngine && syncEngine.enabled);
136 addCommandHandler("adblockplus-sync", function() 145 addCommandHandler("adblockplus-sync", function()
137 { 146 {
138 this.value = UI.toggleSync(); 147 this.value = UI.toggleSync();
139 }); 148 });
140 149
141 let window = null; 150 setChecked("adblockplus-showintoolbar", UI.isToolbarIconVisible());
142 for (window in UI.applicationWindows) 151 addCommandHandler("adblockplus-showintoolbar", function()
143 break;
144
145 if (window)
146 { 152 {
147 setChecked("adblockplus-showinaddonbar", UI.isToolbarIconVisible(window) ); 153 UI.toggleToolbarIcon();
148 setChecked("adblockplus-showintoolbar", UI.isToolbarIconVisible(window)) ; 154 this.value = UI.isToolbarIconVisible();
149 155 });
150 let handler = function()
151 {
152 UI.toggleToolbarIcon();
153 this.value = UI.isToolbarIconVisible(window);
154 };
155 addCommandHandler("adblockplus-showinaddonbar", handler);
156 addCommandHandler("adblockplus-showintoolbar", handler);
157 }
158 156
159 let list = doc.getElementById("adblockplus-subscription-list"); 157 let list = doc.getElementById("adblockplus-subscription-list");
160 if (list) 158 if (list)
161 { 159 {
162 // Load subscriptions data 160 // Load subscriptions data
163 let request = new XMLHttpRequest(); 161 let request = new XMLHttpRequest();
164 request.mozBackgroundRequest = true; 162 request.mozBackgroundRequest = true;
165 request.open("GET", "chrome://adblockplus/content/ui/subscriptions.xml") ; 163 request.open("GET", "chrome://adblockplus/content/ui/subscriptions.xml") ;
166 request.addEventListener("load", function() 164 request.addEventListener("load", function()
167 { 165 {
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 filtersLoaded = true; 310 filtersLoaded = true;
313 if (overlayLoaded && filtersLoaded && sessionRestored) 311 if (overlayLoaded && filtersLoaded && sessionRestored)
314 this.initDone(); 312 this.initDone();
315 }.bind(this); 313 }.bind(this);
316 FilterNotifier.addListener(listener); 314 FilterNotifier.addListener(listener);
317 } 315 }
318 else 316 else
319 filtersLoaded = true; 317 filtersLoaded = true;
320 318
321 // Initialize UI after the session is restored 319 // Initialize UI after the session is restored
322 let window = null; 320 let window = this.currentWindow;
323 for (window in this.applicationWindows)
324 break;
325 if (!window && "nsISessionStore" in Ci) 321 if (!window && "nsISessionStore" in Ci)
326 { 322 {
327 // No application windows yet, the application must be starting up. Wait 323 // No application windows yet, the application must be starting up. Wait
328 // for session to be restored before initializing our UI. 324 // for session to be restored before initializing our UI.
329 new SessionRestoreObserver(function() 325 new SessionRestoreObserver(function()
330 { 326 {
331 sessionRestored = true; 327 sessionRestored = true;
332 if (overlayLoaded && filtersLoaded && sessionRestored) 328 if (overlayLoaded && filtersLoaded && sessionRestored)
333 this.initDone(); 329 this.initDone();
334 }.bind(this)); 330 }.bind(this));
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 400
405 /** 401 /**
406 * Gets called once the initialization is finished and Adblock Plus elements 402 * Gets called once the initialization is finished and Adblock Plus elements
407 * can be added to the UI. 403 * can be added to the UI.
408 */ 404 */
409 initDone: function() 405 initDone: function()
410 { 406 {
411 let {WindowObserver} = require("windowObserver"); 407 let {WindowObserver} = require("windowObserver");
412 new WindowObserver(this); 408 new WindowObserver(this);
413 409
410 // Add toolbar icon
411 let {defaultToolbarPosition} = require("appSupport");
412 if ("abp-toolbarbutton" in this.overlay && defaultToolbarPosition)
413 {
414 CustomizableUI.createWidget({
415 id: "abp-toolbarbutton",
416 positionAttribute: "abp-iconposition",
417 defaultArea: defaultToolbarPosition.parent,
418 defaultBefore: defaultToolbarPosition.before,
419 defaultAfter: defaultToolbarPosition.after,
420 removable: true,
421 onCreated: function(node)
422 {
423 for (let attribute of this.overlay["abp-toolbarbutton"].attributes)
424 node.setAttribute(attribute.name, attribute.value);
425 if (!node.firstChild)
426 for (let child of this.overlay["abp-toolbarbutton"].children)
427 node.appendChild(child.cloneNode(true));
428 if ("addClass" in defaultToolbarPosition)
429 icon.classList.add(defaultToolbarPosition.addClass);
430
431 this.updateIconState(node.ownerDocument.defaultView, node);
432 }.bind(this),
433 onClick: this.onIconClick,
434 onCommand: this.onIconCommand
435 });
436 onShutdown.add(CustomizableUI.destroyWidget.bind(CustomizableUI, "abp-tool barbutton"));
437 }
438
414 // Listen for pref and filters changes 439 // Listen for pref and filters changes
415 Prefs.addListener(function(name) 440 Prefs.addListener(function(name)
416 { 441 {
417 if (name == "enabled" || name == "defaulttoolbaraction" || name == "defaul tstatusbaraction") 442 if (name == "enabled" || name == "defaulttoolbaraction" || name == "defaul tstatusbaraction")
418 this.updateState(); 443 this.updateState();
419 else if (name == "showinstatusbar") 444 else if (name == "showinstatusbar")
420 { 445 {
421 for (let window in this.applicationWindows) 446 for (let window in this.applicationWindows)
422 this.updateStatusbarIcon(window); 447 this.updateStatusbarIcon(window);
423 } 448 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 if (!noDelay && delayInitialization) 487 if (!noDelay && delayInitialization)
463 { 488 {
464 Utils.runAsync(this.applyToWindow.bind(this, window, true)); 489 Utils.runAsync(this.applyToWindow.bind(this, window, true));
465 return; 490 return;
466 } 491 }
467 492
468 // Add general items to the document 493 // Add general items to the document
469 for (let i = 0; i < this.overlay.all.length; i++) 494 for (let i = 0; i < this.overlay.all.length; i++)
470 window.document.documentElement.appendChild(this.overlay.all[i].cloneNode( true)); 495 window.document.documentElement.appendChild(this.overlay.all[i].cloneNode( true));
471 496
472 // Add toolbar icon
473 if ("abp-toolbarbutton" in this.overlay)
474 {
475 let toolbox = this.getToolbox(window);
476 if (toolbox)
477 {
478 // Insert toolbar button asynchronously, otherwise it will show up
479 // before our stylesheet loads
480 Utils.runAsync(function()
481 {
482 toolbox.addEventListener("aftercustomization", this.onToolbarCustomiza tion, false);
483
484 let {defaultToolbarPosition} = require("appSupport");
485 let icon = this.overlay["abp-toolbarbutton"].cloneNode(true);
486 if ("addClass" in defaultToolbarPosition)
487 icon.classList.add(defaultToolbarPosition.addClass);
488 this.restoreToolbarIcon(toolbox, icon);
489 }.bind(this));
490 }
491 }
492
493 // Add status bar icon 497 // Add status bar icon
494 this.updateStatusbarIcon(window); 498 this.updateStatusbarIcon(window);
495 499
496 // Add tools menu item 500 // Add tools menu item
497 if ("abp-menuitem" in this.overlay) 501 if ("abp-menuitem" in this.overlay)
498 { 502 {
499 let {toolsMenu} = require("appSupport"); 503 let {toolsMenu} = require("appSupport");
500 let [parent, before] = this.resolveInsertionPoint(window, toolsMenu); 504 let [parent, before] = this.resolveInsertionPoint(window, toolsMenu);
501 if (parent) 505 if (parent)
502 parent.insertBefore(this.overlay["abp-menuitem"].cloneNode(true), before ); 506 parent.insertBefore(this.overlay["abp-menuitem"].cloneNode(true), before );
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 } 576 }
573 } 577 }
574 else 578 else
575 { 579 {
576 let clone = window.document.getElementById(id); 580 let clone = window.document.getElementById(id);
577 if (clone) 581 if (clone)
578 clone.parentNode.removeChild(clone); 582 clone.parentNode.removeChild(clone);
579 } 583 }
580 } 584 }
581 585
582 if ("abp-toolbarbutton" in this.overlay)
583 {
584 let toolbox = this.getToolbox(window);
585 if (toolbox)
586 {
587 toolbox.removeEventListener("aftercustomization", this.onToolbarCustomiz ation, false);
588
589 let paletteItem = this.getPaletteItem(toolbox);
590 if (paletteItem)
591 paletteItem.parentNode.removeChild(paletteItem);
592 }
593 }
594
595 window.removeEventListener("popupshowing", this.onPopupShowing, false); 586 window.removeEventListener("popupshowing", this.onPopupShowing, false);
596 window.removeEventListener("keypress", this.onKeyPress, false); 587 window.removeEventListener("keypress", this.onKeyPress, false);
597 removeBrowserLocationListeners(window); 588 removeBrowserLocationListeners(window);
598 removeBrowserClickListeners(window); 589 removeBrowserClickListeners(window);
599 }, 590 },
600 591
601 /** 592 /**
602 * The overlay information to be used when adding elements to the UI. 593 * The overlay information to be used when adding elements to the UI.
603 * @type Object 594 * @type Object
604 */ 595 */
(...skipping 15 matching lines...) Expand all
620 } 611 }
621 while (enumerator.hasMoreElements()) 612 while (enumerator.hasMoreElements())
622 { 613 {
623 let window = enumerator.getNext().QueryInterface(Ci.nsIDOMWindow); 614 let window = enumerator.getNext().QueryInterface(Ci.nsIDOMWindow);
624 if (isKnownWindow(window)) 615 if (isKnownWindow(window))
625 yield window; 616 yield window;
626 } 617 }
627 }, 618 },
628 619
629 /** 620 /**
621 * Returns the top-most application window or null if none exists.
622 * @type Window
623 */
624 get currentWindow()
625 {
626 for (let window of this.applicationWindows)
627 return window;
628 return null;
629 },
630
631 /**
630 * Opens a URL in the browser window. If browser window isn't passed as parame ter, 632 * Opens a URL in the browser window. If browser window isn't passed as parame ter,
631 * this function attempts to find a browser window. If an event is passed in 633 * this function attempts to find a browser window. If an event is passed in
632 * it should be passed in to the browser if possible (will e.g. open a tab in 634 * it should be passed in to the browser if possible (will e.g. open a tab in
633 * background depending on modifiers keys). 635 * background depending on modifiers keys).
634 */ 636 */
635 loadInBrowser: function(/**String*/ url, /**Window*/ currentWindow, /**Event*/ event) 637 loadInBrowser: function(/**String*/ url, /**Window*/ currentWindow, /**Event*/ event)
636 { 638 {
637 if (!currentWindow) 639 if (!currentWindow)
638 for (currentWindow in this.applicationWindows) 640 currentWindow = this.currentWindow;
639 break;
640 641
641 let {addTab} = require("appSupport"); 642 let {addTab} = require("appSupport");
642 if (currentWindow && addTab) 643 if (currentWindow && addTab)
643 addTab(currentWindow, url, event); 644 addTab(currentWindow, url, event);
644 else 645 else
645 { 646 {
646 let protocolService = Cc["@mozilla.org/uriloader/external-protocol-service ;1"].getService(Ci.nsIExternalProtocolService); 647 let protocolService = Cc["@mozilla.org/uriloader/external-protocol-service ;1"].getService(Ci.nsIExternalProtocolService);
647 protocolService.loadURI(Services.io.newURI(url, null, null), null); 648 protocolService.loadURI(Services.io.newURI(url, null, null), null);
648 } 649 }
649 }, 650 },
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
987 } 988 }
988 989
989 if (before && before.parentNode != parent) 990 if (before && before.parentNode != parent)
990 before = null; 991 before = null;
991 } 992 }
992 993
993 return [parent, before]; 994 return [parent, before];
994 }, 995 },
995 996
996 /** 997 /**
997 * Finds the toolbox element responsible for the toolbar where Adblock Plus
998 * icon should be placed.
999 */
1000 getToolbox: function(/**Window*/ window) /**Element*/
1001 {
1002 let {defaultToolbarPosition} = require("appSupport");
1003 if (!defaultToolbarPosition || !defaultToolbarPosition.parent)
1004 return null;
1005
1006 let toolbar = this.findElement(window, defaultToolbarPosition.parent);
1007 if (!toolbar)
1008 return null;
1009
1010 let toolbox = toolbar.toolbox;
1011 if (toolbox && ("palette" in toolbox) && toolbox.palette)
1012 return toolbox;
1013 else
1014 return null;
1015 },
1016
1017 /**
1018 * Restores the Adblock Plus icon at its original position.
1019 */
1020 restoreToolbarIcon: function(/**Element*/ toolbox, /**Element*/ icon)
1021 {
1022 // Insert into the palette first
1023 toolbox.palette.insertBefore(icon, toolbox.palette.firstChild);
1024
1025 // Now find where we should put the icon
1026 let position = toolbox.getAttribute("abp-iconposition");
1027 if (!/^\S*,\S*,\S*$/.test(position))
1028 position = null;
1029
1030 if (position == null)
1031 {
1032 // No explicitly saved position but maybe we can find it in a currentset
1033 // attribute somewhere.
1034 let toolbars = toolbox.externalToolbars.slice();
1035 for (let child = toolbox.firstElementChild; child; child = child.nextEleme ntSibling)
1036 if (child.localName == "toolbar")
1037 toolbars.push(child);
1038 for (let i = 0; i < toolbars.length; i++)
1039 {
1040 let toolbar = toolbars[i];
1041 let currentSet = toolbar.getAttribute("currentset");
1042 if (currentSet)
1043 {
1044 let items = currentSet.split(",");
1045 let index = items.indexOf("abp-toolbarbutton");
1046 if (index >= 0)
1047 {
1048 position = "visible," + toolbar.id + "," + (index + 1 < items.length ? items[index + 1] : "");
1049 toolbox.setAttribute("abp-iconposition", position);
1050 toolbox.ownerDocument.persist(toolbox.id, "abp-iconposition");
1051 break;
1052 }
1053 }
1054 }
1055 }
1056
1057 this.showToolbarIcon(toolbox, position);
1058 },
1059
1060 /**
1061 * Finds the toolbar button in the toolbar palette.
1062 */
1063 getPaletteItem: function(/**Element*/ toolbox) /**Element*/
1064 {
1065 for (var child = toolbox.palette.firstElementChild; child; child = child.nex tElementSibling)
1066 if (child.id == "abp-toolbarbutton")
1067 return child;
1068
1069 return null;
1070 },
1071
1072 /**
1073 * Called after toolbar customization, sets up our icon and remembers its
1074 * position.
1075 */
1076 onToolbarCustomization: function(/**Event*/ event)
1077 {
1078 let toolbox = event.currentTarget;
1079 let icon = toolbox.ownerDocument.getElementById("abp-toolbarbutton");
1080
1081 let position = toolbox.getAttribute("abp-iconposition") || "hidden,,";
1082 if (icon && icon.parentNode.localName == "toolbar")
1083 {
1084 this.updateIconState(icon.ownerDocument.defaultView, icon);
1085 icon.addEventListener("click", this.onIconClick, false);
1086 icon.addEventListener("command", this.onIconClick, false);
1087 position = "visible," + icon.parentNode.id + "," + (icon.nextSibling ? ico n.nextSibling.id : "");
1088 }
1089 else
1090 position = position.replace(/^visible,/, "hidden,")
1091
1092 toolbox.setAttribute("abp-iconposition", position);
1093 toolbox.ownerDocument.persist(toolbox.id, "abp-iconposition");
1094 },
1095
1096 /**
1097 * Shows or hides toolbar icon based on a remembered position.
1098 */
1099 showToolbarIcon: function(/**Element*/ toolbox, /**String*/ position)
1100 {
1101 let visible, parent, before;
1102 if (position)
1103 {
1104 [visible, parent, before] = position.split(",", 3);
1105 parent = toolbox.ownerDocument.getElementById(parent);
1106 if (before == "")
1107 before = null;
1108 else
1109 before = toolbox.ownerDocument.getElementById(before);
1110 if (before && before.parentNode != parent)
1111 before = null;
1112 }
1113 else
1114 {
1115 let {defaultToolbarPosition} = require("appSupport");
1116 visible = "visible";
1117 [parent, before] = this.resolveInsertionPoint(toolbox.ownerDocument.defaul tView, defaultToolbarPosition);
1118
1119 if (parent && parent.collapsed)
1120 {
1121 // First time we insert the toolbar icon, make sure it is actually visib le
1122 parent.setAttribute("collapsed", "false");
1123 toolbox.ownerDocument.persist(parent.id, "collapsed");
1124 }
1125 }
1126
1127 if (parent && parent.localName != "toolbar")
1128 parent = null;
1129
1130 if (visible != "visible")
1131 {
1132 // Hide icon if it is currently visible
1133 let icon = toolbox.ownerDocument.getElementById("abp-toolbarbutton");
1134 if (icon && icon.parentNode.localName == "toolbar")
1135 toolbox.palette.appendChild(icon);
1136 }
1137 else if (parent)
1138 {
1139 // Add the icon to the toolbar
1140 let items = parent.currentSet.split(",");
1141 let index = (before ? items.indexOf(before.id) : -1);
1142 if (index < 0)
1143 before = null;
1144 parent.insertItem("abp-toolbarbutton", before, null, false);
1145 }
1146
1147 this.onToolbarCustomization({currentTarget: toolbox});
1148 },
1149
1150 /**
1151 * Toggles visibility state of the toolbar icon. 998 * Toggles visibility state of the toolbar icon.
1152 */ 999 */
1153 toggleToolbarIcon: function() 1000 toggleToolbarIcon: function()
1154 { 1001 {
1155 for (let window in this.applicationWindows) 1002 if (this.isToolbarIconVisible())
1003 CustomizableUI.removeWidgetFromArea("abp-toolbarbutton");
1004 else
1156 { 1005 {
1157 let toolbox = this.getToolbox(window); 1006 let {defaultToolbarPosition} = require("appSupport");
1158 if (!toolbox) 1007 CustomizableUI.addWidgetToArea("abp-toolbarbutton", defaultToolbarPosition .parent);
1159 continue;
1160
1161 let position = toolbox.getAttribute("abp-iconposition");
1162 if (position)
1163 {
1164 let parts = position.split(",");
1165 parts[0] = (parts[0] == "visible" ? "hidden" : "visible");
1166 position = parts.join(",");
1167 }
1168 this.showToolbarIcon(toolbox, position);
1169 } 1008 }
1170 }, 1009 },
1171 1010
1172 /** 1011 /**
1173 * Updates Adblock Plus icon state for all windows. 1012 * Updates Adblock Plus icon state for all windows.
1174 */ 1013 */
1175 updateState: function() 1014 updateState: function()
1176 { 1015 {
1177 for (let window in this.applicationWindows) 1016 for (let window in this.applicationWindows)
1178 { 1017 {
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
1621 } 1460 }
1622 1461
1623 setDisabled("abp-command-sendReport", !location || !Policy.isBlockableScheme (location) || location.scheme == "mailto"); 1462 setDisabled("abp-command-sendReport", !location || !Policy.isBlockableScheme (location) || location.scheme == "mailto");
1624 1463
1625 setChecked(prefix + "disabled", !Prefs.enabled); 1464 setChecked(prefix + "disabled", !Prefs.enabled);
1626 setChecked(prefix + "frameobjects", Prefs.frameobjects); 1465 setChecked(prefix + "frameobjects", Prefs.frameobjects);
1627 setChecked(prefix + "slowcollapse", !Prefs.fastcollapse); 1466 setChecked(prefix + "slowcollapse", !Prefs.fastcollapse);
1628 setChecked(prefix + "savestats", Prefs.savestats); 1467 setChecked(prefix + "savestats", Prefs.savestats);
1629 1468
1630 let {defaultToolbarPosition, statusbarPosition} = require("appSupport"); 1469 let {defaultToolbarPosition, statusbarPosition} = require("appSupport");
1631 let hasToolbar = defaultToolbarPosition && !defaultToolbarPosition.isAddonBa r; 1470 let hasToolbar = defaultToolbarPosition;
1632 let hasAddonBar = defaultToolbarPosition && defaultToolbarPosition.isAddonBa r;
1633 let hasStatusBar = statusbarPosition; 1471 let hasStatusBar = statusbarPosition;
1634 hideElement(prefix + "showinaddonbar", !hasAddonBar || prefix == "abp-toolba r-");
1635 hideElement(prefix + "showintoolbar", !hasToolbar || prefix == "abp-toolbar- "); 1472 hideElement(prefix + "showintoolbar", !hasToolbar || prefix == "abp-toolbar- ");
1636 hideElement(prefix + "showinstatusbar", !hasStatusBar); 1473 hideElement(prefix + "showinstatusbar", !hasStatusBar);
1637 hideElement(prefix + "iconSettingsSeparator", (prefix == "abp-toolbar-" || ( !hasAddonBar && !hasToolbar)) && !hasStatusBar); 1474 hideElement(prefix + "iconSettingsSeparator", (prefix == "abp-toolbar-" || ! hasToolbar) && !hasStatusBar);
1638 1475
1639 setChecked(prefix + "showinaddonbar", this.isToolbarIconVisible(window)); 1476 setChecked(prefix + "showintoolbar", this.isToolbarIconVisible());
1640 setChecked(prefix + "showintoolbar", this.isToolbarIconVisible(window));
1641 setChecked(prefix + "showinstatusbar", Prefs.showinstatusbar); 1477 setChecked(prefix + "showinstatusbar", Prefs.showinstatusbar);
1642 1478
1643 let {Sync} = require("sync"); 1479 let {Sync} = require("sync");
1644 let syncEngine = Sync.getEngine(); 1480 let syncEngine = Sync.getEngine();
1645 hideElement(prefix + "sync", !syncEngine); 1481 hideElement(prefix + "sync", !syncEngine);
1646 setChecked(prefix + "sync", syncEngine && syncEngine.enabled); 1482 setChecked(prefix + "sync", syncEngine && syncEngine.enabled);
1647 1483
1648 let defAction = (!window.document.popupNode || window.document.popupNode.id == "abp-toolbarbutton" ? 1484 let defAction = (!window.document.popupNode || window.document.popupNode.id == "abp-toolbarbutton" ?
1649 Prefs.defaulttoolbaraction : 1485 Prefs.defaulttoolbaraction :
1650 Prefs.defaultstatusbaraction); 1486 Prefs.defaultstatusbaraction);
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
1828 let command = event.currentTarget.document.getElementById("abp-command-" + key); 1664 let command = event.currentTarget.document.getElementById("abp-command-" + key);
1829 if (command) 1665 if (command)
1830 command.doCommand(); 1666 command.doCommand();
1831 } 1667 }
1832 } 1668 }
1833 }, 1669 },
1834 1670
1835 /** 1671 /**
1836 * Checks whether the toolbar icon is currently displayed. 1672 * Checks whether the toolbar icon is currently displayed.
1837 */ 1673 */
1838 isToolbarIconVisible: function(/**Window*/ window) 1674 isToolbarIconVisible: function() /**Boolean*/
1839 { 1675 {
1840 let button = window.document.getElementById("abp-toolbarbutton"); 1676 let placement = CustomizableUI.getPlacementOfWidget("abp-toolbarbutton");
1841 return (button && button.parentNode && button.parentNode.localName == "toolb ar" && !button.parentNode.collapsed); 1677 return !!placement;
1842 }, 1678 },
1843 1679
1844 /** 1680 /**
1845 * Stores the selected hotkeys, initialized when the user presses a key. 1681 * Stores the selected hotkeys, initialized when the user presses a key.
1846 */ 1682 */
1847 hotkeys: null, 1683 hotkeys: null,
1848 1684
1849 /** 1685 /**
1850 * Chooses shortcut keys that are available in the window according to 1686 * Chooses shortcut keys that are available in the window according to
1851 * preferences. 1687 * preferences.
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1921 Prefs.hideContributeButton = true; 1757 Prefs.hideContributeButton = true;
1922 1758
1923 for each (let id in ["abp-status-contributebutton", "abp-toolbar-contributeb utton", "abp-menuitem-contributebutton"]) 1759 for each (let id in ["abp-status-contributebutton", "abp-toolbar-contributeb utton", "abp-menuitem-contributebutton"])
1924 { 1760 {
1925 let button = window.document.getElementById(id); 1761 let button = window.document.getElementById(id);
1926 if (button) 1762 if (button)
1927 button.hidden = true; 1763 button.hidden = true;
1928 } 1764 }
1929 }, 1765 },
1930 1766
1931 _showNextNotification: function(notification) 1767 _showNextNotification: function()
1932 { 1768 {
1933 let window = null; 1769 let window = this.currentWindow;
1934 for (window in this.applicationWindows)
1935 break;
1936
1937 if (!window) 1770 if (!window)
1938 return; 1771 return;
1939 1772
1940 let button = window.document.getElementById("abp-toolbarbutton") 1773 let button = window.document.getElementById("abp-toolbarbutton")
1941 || window.document.getElementById("abp-status"); 1774 || window.document.getElementById("abp-status");
1942 if (!button) 1775 if (!button)
1943 return; 1776 return;
1944 1777
1945 let notification = Notification.getNextToShow(); 1778 let notification = Notification.getNextToShow();
1946 if (!notification) 1779 if (!notification)
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1994 this.loadInBrowser(link.href, window); 1827 this.loadInBrowser(link.href, window);
1995 }.bind(this)); 1828 }.bind(this));
1996 1829
1997 let panel = window.document.getElementById("abp-notification"); 1830 let panel = window.document.getElementById("abp-notification");
1998 panel.openPopup(button, "bottomcenter topcenter", 0, 0, false, false, null); 1831 panel.openPopup(button, "bottomcenter topcenter", 0, 0, false, false, null);
1999 } 1832 }
2000 }; 1833 };
2001 UI.onPopupShowing = UI.onPopupShowing.bind(UI); 1834 UI.onPopupShowing = UI.onPopupShowing.bind(UI);
2002 UI.onKeyPress = UI.onKeyPress.bind(UI); 1835 UI.onKeyPress = UI.onKeyPress.bind(UI);
2003 UI.onIconClick = UI.onIconClick.bind(UI); 1836 UI.onIconClick = UI.onIconClick.bind(UI);
2004 UI.onToolbarCustomization = UI.onToolbarCustomization.bind(UI);
2005 UI.init(); 1837 UI.init();
2006 1838
2007 /** 1839 /**
2008 * List of event handers to be registered for each window. For each event 1840 * List of event handers to be registered for each window. For each event
2009 * handler the element ID, event and the actual event handler are listed. 1841 * handler the element ID, event and the actual event handler are listed.
2010 * @type Array 1842 * @type Array
2011 */ 1843 */
2012 let eventHandlers = [ 1844 let eventHandlers = [
2013 ["abp-command-sendReport", "command", UI.openReportDialog.bind(UI)], 1845 ["abp-command-sendReport", "command", UI.openReportDialog.bind(UI)],
2014 ["abp-command-filters", "command", UI.openFiltersDialog.bind(UI)], 1846 ["abp-command-filters", "command", UI.openFiltersDialog.bind(UI)],
(...skipping 10 matching lines...) Expand all
2025 ["abp-command-contribute", "command", UI.openContributePage.bind(UI)], 1857 ["abp-command-contribute", "command", UI.openContributePage.bind(UI)],
2026 ["abp-command-contribute-hide", "command", UI.hideContributeButton.bind(UI)] 1858 ["abp-command-contribute-hide", "command", UI.hideContributeButton.bind(UI)]
2027 ]; 1859 ];
2028 1860
2029 onShutdown.add(function() 1861 onShutdown.add(function()
2030 { 1862 {
2031 for (let window in UI.applicationWindows) 1863 for (let window in UI.applicationWindows)
2032 if (UI.isBottombarOpen(window)) 1864 if (UI.isBottombarOpen(window))
2033 UI.toggleBottombar(window); 1865 UI.toggleBottombar(window);
2034 }); 1866 });
OLDNEW
« no previous file with comments | « lib/customizableUI.js ('k') | metadata.gecko » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld