diff --git a/common/content/events.js b/common/content/events.js index bdef70e8..aaa81b63 100644 --- a/common/content/events.js +++ b/common/content/events.js @@ -274,11 +274,20 @@ var EventHive = Class("EventHive", Group.Hive, { * phase, otherwise during the bubbling phase. */ listen: function (target, event, callback, capture) { - let args = Array.slice(arguments, 0); - args[2] = this.wrapListener(callback); - args[0].addEventListener.apply(args[0], args.slice(1)); - args[0] = Cu.getWeakReference(args[0]); - this.sessionListeners.push(args); + if (isObject(event)) + var [self, events] = [event, event[callback]]; + else + [self, events] = [null, array.toObject([[event, callback]])]; + + for (let [event, callback] in Iterator(events)) { + let args = [Cu.getWeakReference(target), + event, + this.wrapListener(callback, self), + capture]; + + target.addEventListener.apply(target, args.slice(1)); + this.sessionListeners.push(args); + } }, /** @@ -393,8 +402,7 @@ var Events = Module("events", { } this._activeMenubar = false; - for (let [event, callback] in Iterator(this.events)) - this.listen(window, event, callback, true); + this.listen(window, this, "events"); dactyl.registerObserver("modeChange", function () { delete self.processor; diff --git a/common/content/mow.js b/common/content/mow.js index 5cb6709e..06a93d94 100644 --- a/common/content/mow.js +++ b/common/content/mow.js @@ -9,7 +9,30 @@ var MOW = Module("mow", { init: function () { - this._resize = Timer(20, 400, function (force) { this.resize(force) }, this); + this._resize = Timer(20, 400, function () { + if (this.visible) { + this.resize(false); + this.updateMorePrompt(); + } + }, this); + + this._timer = Timer(20, 400, function () { + util.dump("RESIZE " + this.window.document.body.textContent); + this.resize(true); + + if (options["more"] && this.isScrollable(1)) { + // start the last executed command's output at the top of the screen + let elements = this.document.getElementsByClassName("ex-command-output"); + elements[elements.length - 1].scrollIntoView(true); + } + else + this.body.scrollTop = this.body.scrollHeight; + + dactyl.focus(this.window); + this.updateMorePrompt(); + }, this); + + events.listen(window, this, "windowEvents"); let fontSize = util.computedStyle(document.documentElement).fontSize; styles.system.add("font-size", "dactyl://content/buffer.xhtml", @@ -112,7 +135,7 @@ var MOW = Module("mow", { // FIXME: need to make sure an open MOW is closed when commands // that don't generate output are executed - if (this.widgets.mowContainer.collapsed) { + if (!this.visible) { this.body.scrollTop = 0; body.textContent = ""; } @@ -123,18 +146,9 @@ var MOW = Module("mow", { if (!silent) dactyl.triggerObserver("echoMultiline", data, highlightGroup, output); - this._resize.tell(true); - - if (options["more"] && this.isScrollable(1)) { - // start the last executed command's output at the top of the screen - let elements = this.document.getElementsByClassName("ex-command-output"); - elements[elements.length - 1].scrollIntoView(true); - } - else - this.body.scrollTop = this.body.scrollHeight; - - dactyl.focus(this.window); - this.updateMorePrompt(); + this._timer.tell(); + if (!this.visible) + this._timer.flush(); }, events: { @@ -172,6 +186,12 @@ var MOW = Module("mow", { } }, + windowEvents: { + resize: function onResize(event) { + this._resize.tell(); + } + }, + contextEvents: { popupshowing: function (event) { let menu = commandline.widgets.contextMenu; @@ -208,14 +228,14 @@ var MOW = Module("mow", { * already so. */ resize: function updateOutputHeight(open, extra) { - if (!open && this.widgets.mowContainer.collapsed) + if (!(open || this.visible)) return; let doc = this.widget.contentDocument; let availableHeight = config.outputHeight; - if (!this.widgets.mowContainer.collapsed) - availableHeight += parseFloat(this.widgets.mowContainer.height); + if (this.visible) + availableHeight += parseFloat(this.widgets.mowContainer.height || 0); availableHeight -= extra || 0; doc.body.style.minWidth = this.widgets.commandbar.commandline.scrollWidth + "px"; @@ -225,6 +245,7 @@ var MOW = Module("mow", { 0); doc.body.style.minWidth = ""; + this.visible = true; }, @@ -243,7 +264,7 @@ var MOW = Module("mow", { * and what they do. */ updateMorePrompt: function updateMorePrompt(force, showHelp) { - if (this.widgets.mowContainer.collapsed) + if (!this.visible) return this.widgets.message = null; let elem = this.widget.contentDocument.documentElement; @@ -256,6 +277,7 @@ var MOW = Module("mow", { }, visible: Modes.boundProperty({ + get: function get_mowVisible() !this.widgets.mowContainer.collapsed, set: function set_mowVisible(value) { this.widgets.mowContainer.collapsed = !value;