Toolbars.jsm 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. "use strict";
  5. const EXPORTED_SYMBOLS = ["S4EToolbars"];
  6. const CI = Components.interfaces;
  7. const CU = Components.utils;
  8. CU.import("resource://gre/modules/Services.jsm");
  9. function S4EToolbars(window, gBrowser, toolbox, service, getters)
  10. {
  11. this._window = window;
  12. this._toolbox = toolbox;
  13. this._service = service;
  14. this._getters = getters;
  15. this._handler = new ClassicS4EToolbars(this._window, this._toolbox);
  16. }
  17. S4EToolbars.prototype =
  18. {
  19. _window: null,
  20. _toolbox: null,
  21. _service: null,
  22. _getters: null,
  23. _handler: null,
  24. setup: function()
  25. {
  26. this.updateSplitters(false);
  27. this.updateWindowGripper(false);
  28. this._handler.setup(this._service.firstRun);
  29. },
  30. destroy: function()
  31. {
  32. this._handler.destroy();
  33. ["_window", "_toolbox", "_service", "_getters", "_handler"].forEach(function(prop)
  34. {
  35. delete this[prop];
  36. }, this);
  37. },
  38. updateSplitters: function(action)
  39. {
  40. let document = this._window.document;
  41. let splitter_before = document.getElementById("status4evar-status-splitter-before");
  42. if(splitter_before)
  43. {
  44. splitter_before.parentNode.removeChild(splitter_before);
  45. }
  46. let splitter_after = document.getElementById("status4evar-status-splitter-after");
  47. if(splitter_after)
  48. {
  49. splitter_after.parentNode.removeChild(splitter_after);
  50. }
  51. let status = this._getters.statusWidget;
  52. if(!action || !status)
  53. {
  54. return;
  55. }
  56. let urlbar = document.getElementById("urlbar-container");
  57. let stop = document.getElementById("stop-button");
  58. let fullscreenflex = document.getElementById("fullscreenflex");
  59. let nextSibling = status.nextSibling;
  60. let previousSibling = status.previousSibling;
  61. function getSplitter(splitter, suffix)
  62. {
  63. if(!splitter)
  64. {
  65. splitter = document.createElement("splitter");
  66. splitter.id = "status4evar-status-splitter-" + suffix;
  67. splitter.setAttribute("resizebefore", "flex");
  68. splitter.setAttribute("resizeafter", "flex");
  69. splitter.className = "chromeclass-toolbar-additional status4evar-status-splitter";
  70. }
  71. return splitter;
  72. }
  73. if((previousSibling && previousSibling.flex > 0)
  74. || (urlbar && stop && urlbar.getAttribute("combined") && stop == previousSibling))
  75. {
  76. status.parentNode.insertBefore(getSplitter(splitter_before, "before"), status);
  77. }
  78. if(nextSibling && nextSibling.flex > 0 && nextSibling != fullscreenflex)
  79. {
  80. status.parentNode.insertBefore(getSplitter(splitter_after, "after"), nextSibling);
  81. }
  82. },
  83. updateWindowGripper: function(action)
  84. {
  85. let document = this._window.document;
  86. let gripper = document.getElementById("status4evar-window-gripper");
  87. let toolbar = this._getters.statusBar || this._getters.addonbar;
  88. if(!action || !toolbar || !this._service.addonbarWindowGripper
  89. || this._window.windowState != CI.nsIDOMChromeWindow.STATE_NORMAL || toolbar.toolbox.customizing)
  90. {
  91. if(gripper)
  92. {
  93. gripper.parentNode.removeChild(gripper);
  94. }
  95. return;
  96. }
  97. gripper = this._handler.buildGripper(toolbar, gripper, "status4evar-window-gripper");
  98. toolbar.appendChild(gripper);
  99. }
  100. };
  101. function ClassicS4EToolbars(window, toolbox)
  102. {
  103. this._window = window;
  104. this._toolbox = toolbox;
  105. }
  106. ClassicS4EToolbars.prototype =
  107. {
  108. _window: null,
  109. _toolbox: null,
  110. setup: function(firstRun)
  111. {
  112. let document = this._window.document;
  113. let addon_bar = document.getElementById("addon-bar");
  114. if(addon_bar)
  115. {
  116. let baseSet = "addonbar-closebutton"
  117. + ",status4evar-status-widget"
  118. + ",status4evar-progress-widget";
  119. // Update the defaultSet
  120. let defaultSet = baseSet;
  121. let defaultSetIgnore = ["addonbar-closebutton", "spring", "status-bar"];
  122. addon_bar.getAttribute("defaultset").split(",").forEach(function(item)
  123. {
  124. if(defaultSetIgnore.indexOf(item) == -1)
  125. {
  126. defaultSet += "," + item;
  127. }
  128. });
  129. defaultSet += ",status-bar"
  130. addon_bar.setAttribute("defaultset", defaultSet);
  131. // Update the currentSet
  132. if(firstRun)
  133. {
  134. let isCustomizableToolbar = function(aElt)
  135. {
  136. return aElt.localName == "toolbar" && aElt.getAttribute("customizable") == "true";
  137. }
  138. let isCustomizedAlready = false;
  139. let toolbars = Array.filter(this._toolbox.childNodes, isCustomizableToolbar).concat(
  140. Array.filter(this._toolbox.externalToolbars, isCustomizableToolbar));
  141. toolbars.forEach(function(toolbar)
  142. {
  143. if(toolbar.currentSet.indexOf("status4evar") > -1)
  144. {
  145. isCustomizedAlready = true;
  146. }
  147. });
  148. if(!isCustomizedAlready)
  149. {
  150. let currentSet = baseSet;
  151. let currentSetIgnore = ["addonbar-closebutton", "spring"];
  152. addon_bar.currentSet.split(",").forEach(function(item)
  153. {
  154. if(currentSetIgnore.indexOf(item) == -1)
  155. {
  156. currentSet += "," + item;
  157. }
  158. });
  159. addon_bar.currentSet = currentSet;
  160. addon_bar.setAttribute("currentset", currentSet);
  161. document.persist(addon_bar.id, "currentset");
  162. this._window.setToolbarVisibility(addon_bar, true);
  163. }
  164. }
  165. }
  166. },
  167. destroy: function()
  168. {
  169. ["_window", "_toolbox"].forEach(function(prop)
  170. {
  171. delete this[prop];
  172. }, this);
  173. },
  174. buildGripper: function(toolbar, gripper, id)
  175. {
  176. if(!gripper)
  177. {
  178. let document = this._window.document;
  179. gripper = document.createElement("resizer");
  180. gripper.id = id;
  181. gripper.dir = "bottomend";
  182. }
  183. return gripper;
  184. }
  185. };