diff --git a/common/content/commandline.js b/common/content/commandline.js index 6fed9f70..c916dd30 100644 --- a/common/content/commandline.js +++ b/common/content/commandline.js @@ -75,7 +75,7 @@ const CommandWidgets = Class("CommandWidgets", { onblur={_commandline + ".onMultilineInputEvent(event);"}/> - .* + .elements() }); this.elements = {}; diff --git a/common/content/events.js b/common/content/events.js index f217037c..4f4ee341 100644 --- a/common/content/events.js +++ b/common/content/events.js @@ -13,7 +13,7 @@ */ const Events = Module("events", { init: function () { - let _events = "if (window.dactyl ∧ dactyl.modules.loaded.events) return dactyl.modules.events" + let _events = "if (window.dactyl && dactyl.modules.loaded.events) return dactyl.modules.events" util.overlayWindow(window, { append: @@ -21,11 +21,11 @@ const Events = Module("events", { from: http://developer.mozilla.org/en/docs/XUL_Tutorial:Updating_Commands !--> + oncommandupdate={_events + ".onFocusChange(event);"}/> + oncommandupdate={_events + ".onSelectionChange(event);"}/> - .* + .elements() }); this._fullscreen = window.fullScreen; diff --git a/common/content/statusline.js b/common/content/statusline.js index 0d1a2f9d..44dc84b9 100644 --- a/common/content/statusline.js +++ b/common/content/statusline.js @@ -12,7 +12,7 @@ const StatusLine = Module("statusline", { init: function () { let _commandline = "if (window.dactyl) return dactyl.modules.commandline"; - let append = + let prepend = ; - for each (let attr in append..@key) + for each (let attr in prepend..@key) attr.parent().@id = "dactyl-statusline-field-" + attr; util.overlayWindow(window, { objects: this.widgets = { get status() this.container }, - append: append.* + prepend: prepend.elements() }); this._statusLine = document.getElementById("status-bar"); diff --git a/common/modules/styles.jsm b/common/modules/styles.jsm index aebf4401..c23a7c65 100644 --- a/common/modules/styles.jsm +++ b/common/modules/styles.jsm @@ -79,6 +79,11 @@ const Hive = Class("Hive", { this.names = {}; }, + cleanup: function cleanup() { + for (let sheet in values(this.sheets)) + sheet.enabled = false; + }, + __iterator__: function () Iterator(this.sheets), get sites() array(this.sheets).map(function (s) s.sites).flatten().uniq().array, @@ -214,6 +219,11 @@ const Styles = Module("Styles", { this.system = Hive(); }, + cleanup: function cleanup() { + for each (let hive in [this.user, this.system]) + hive.cleanup(); + }, + __iterator__: function () Iterator(this.user.sheets.concat(this.system.sheets)), _proxy: function (name, args) diff --git a/common/modules/util.jsm b/common/modules/util.jsm index 37d5954b..0d52730a 100644 --- a/common/modules/util.jsm +++ b/common/modules/util.jsm @@ -54,6 +54,13 @@ const Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]) this.overlays = {}; }, + cleanup: function cleanup() { + for (let win in iter(services.windowMediator.getEnumerator(null))) + for (let elem in values(win.document.dactylOverlayElements)) + if (elem.get() && elem.get().parentNode) + elem.get().parentNode.removeChild(elem.get()); + }, + // FIXME: Only works for Pentadactyl get activeWindow() services.windowMediator.getMostRecentWindow("navigator:browser"), dactyl: update(function dactyl(obj) { @@ -90,12 +97,13 @@ const Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]) let observers = obj.observe; function register(meth) { services.observer[meth](obj, "quit-application", true); + services.observer[meth](obj, "dactyl-unload", true); for (let target in keys(observers)) services.observer[meth](obj, target, true); } Class.replaceProperty(obj, "observe", function (subject, target, data) { - if (target == "quit-application") + if (target == "quit-application" || target == "dactyl-unload") register("removeObserver"); if (observers[target]) observers[target].call(obj, subject, data); @@ -908,6 +916,10 @@ const Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]) } }, _loadOverlay: function _loadOverlay(window, obj) { + let doc = window.document; + if (!doc.dactylOverlayElements) + doc.dactylOverlayElements = []; + function overlay(key, fn) { if (obj[key]) { let iterator = Iterator(obj[key]); @@ -915,9 +927,12 @@ const Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]) iterator = ([elem.@id, elem.*, elem.@*::*] for each (elem in obj[key])); for (let [elem, xml, attr] in iterator) { - if (elem = window.document.getElementById(elem)) { - fn(elem, util.xmlToDom(xml, window.document, obj.objects)); - for each (let attr in attr || []) + if (elem = doc.getElementById(elem)) { + let node = util.xmlToDom(xml, doc, obj.objects); + for (let n in array.iterValues(node.childNodes)) + doc.dactylOverlayElements.push(Cu.getWeakReference(n)); + fn(elem, node); + for each (let attr in attr || []) // FIXME: Cleanup... elem.setAttributeNS(attr.namespace(), attr.localName(), attr); } } @@ -929,22 +944,27 @@ const Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]) overlay("append", function (elem, dom) elem.appendChild(dom)); overlay("prepend", function (elem, dom) elem.insertBefore(dom, elem.firstChild)); if (obj.init) - obj.init(window, window.dactylDOMLoaded); + obj.init(window, window.document.dactylDOMLoaded); if (obj.load) - if (window.document.dactylLoaded) - obj.load(window, window.document.dactylLoaded); + if (doc.dactylLoaded) + obj.load(window, doc.dactylLoaded); else - window.document.addEventListener("load", wrapCallback(function load(event) { + doc.addEventListener("load", wrapCallback(function load(event) { if (event.originalTarget === event.target) { - window.document.removeEventListener("load", load.wrapper, true); - window.document.dactylLoaded = event; + doc.removeEventListener("load", load.wrapper, true); + doc.dactylLoaded = event; obj.load(window, event); } }), true); }, observe: { + "dactyl-cleanup": function () { + for (let module in values(defineModule.modules)) + if (module.cleanup) + module.cleanup(); + }, "toplevel-window-ready": function (window, data) { window.addEventListener("DOMContentLoaded", wrapCallback(function listener(event) { if (event.originalTarget === window.document) { @@ -965,8 +985,9 @@ const Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]) this.overlays[url] = []; this.overlays[url].push(fn); }, this); - for (let win in services.windowMediator.getEnumerator(null)) - if (win.dactylDOMLoaded) + + for (let win in iter(services.windowMediator.getEnumerator(null))) + if (win.document.dactylDOMLoaded) this._loadOverlays(win); } },