Bug 1028234 - Allow command buttons to use target; r=bgrins

This commit is contained in:
Joe Walker 2014-06-25 11:21:07 +01:00
parent 00e21c30de
commit 23e8b27ae9
6 changed files with 49 additions and 19 deletions

View File

@ -41,10 +41,10 @@ exports.items = [{
let dropper = EyedropperManager.createInstance(chromeWindow); let dropper = EyedropperManager.createInstance(chromeWindow);
dropper.open(); dropper.open();
eventEmitter.emit("changed", target.tab); eventEmitter.emit("changed", { target: target });
dropper.once("destroy", () => { dropper.once("destroy", () => {
eventEmitter.emit("changed", target.tab); eventEmitter.emit("changed", { target: target });
}); });
} }
}]; }];

View File

@ -213,7 +213,8 @@ function ResponsiveUI(aWindow, aTab)
this.onPageLoad(); this.onPageLoad();
} }
ResponsiveUIManager.emit("on", this.tab, this); // E10S: We should be using target here. See bug 1028234
ResponsiveUIManager.emit("on", { tab: this.tab });
} }
ResponsiveUI.prototype = { ResponsiveUI.prototype = {
@ -305,7 +306,8 @@ ResponsiveUI.prototype = {
if (this.touchEventHandler) if (this.touchEventHandler)
this.touchEventHandler.stop(); this.touchEventHandler.stop();
this._telemetry.toolClosed("responsive"); this._telemetry.toolClosed("responsive");
ResponsiveUIManager.emit("off", this.tab, this); // E10S: We should be using target here. See bug 1028234
ResponsiveUIManager.emit("off", { tab: this.tab });
}, },
/** /**

View File

@ -125,18 +125,42 @@ let CommandUtils = {
// Allow the command button to be toggleable // Allow the command button to be toggleable
if (command.state) { if (command.state) {
button.setAttribute("autocheck", false); button.setAttribute("autocheck", false);
let onChange = (event, eventTab) => {
if (eventTab == target.tab) { /**
if (command.state.isChecked(target)) { * The onChange event should be called with an event object that
button.setAttribute("checked", true); * contains a target property which specifies which target the event
* applies to. For legacy reasons the event object can also contain
* a tab property.
*/
let onChange = (eventName, ev) => {
if (ev.target == target || ev.tab == target.tab) {
let updateChecked = (checked) => {
if (checked) {
button.setAttribute("checked", true);
}
else if (button.hasAttribute("checked")) {
button.removeAttribute("checked");
}
};
// isChecked would normally be synchronous. An annoying quirk
// of the 'csscoverage toggle' command forces us to accept a
// promise here, but doing Promise.resolve(reply).then(...) here
// makes this async for everyone, which breaks some tests so we
// treat non-promise replies separately to keep then synchronous.
let reply = command.state.isChecked(target);
if (typeof reply.then == "function") {
reply.then(updateChecked, console.error);
} }
else if (button.hasAttribute("checked")) { else {
button.removeAttribute("checked"); updateChecked(reply);
} }
} }
}; };
command.state.onChange(target, onChange); command.state.onChange(target, onChange);
onChange(null, target.tab); onChange("", { target: target });
document.defaultView.addEventListener("unload", () => { document.defaultView.addEventListener("unload", () => {
command.state.offChange(target, onChange); command.state.offChange(target, onChange);
}, false); }, false);

View File

@ -144,7 +144,8 @@ Tilt.prototype = {
} }
this.lastInstanceId = id; this.lastInstanceId = id;
this.emit("change", this.chromeWindow.gBrowser.selectedTab); // E10S: We should be using target here. See bug 1028234
this.emit("change", { tab: this.chromeWindow.gBrowser.selectedTab });
Services.obs.notifyObservers(contentWindow, TILT_NOTIFICATIONS.INITIALIZING, null); Services.obs.notifyObservers(contentWindow, TILT_NOTIFICATIONS.INITIALIZING, null);
}, },
@ -201,7 +202,8 @@ Tilt.prototype = {
this._isDestroying = false; this._isDestroying = false;
this.chromeWindow.gBrowser.selectedBrowser.focus(); this.chromeWindow.gBrowser.selectedBrowser.focus();
this.emit("change", this.chromeWindow.gBrowser.selectedTab); // E10S: We should be using target here. See bug 1028234
this.emit("change", { tab: this.chromeWindow.gBrowser.selectedTab });
Services.obs.notifyObservers(contentWindow, TILT_NOTIFICATIONS.DESTROYED, null); Services.obs.notifyObservers(contentWindow, TILT_NOTIFICATIONS.DESTROYED, null);
}, },

View File

@ -16,7 +16,7 @@ gDevTools.on("toolbox-ready", (e, toolbox) => {
} }
let fireChangeForTab = () => { let fireChangeForTab = () => {
eventEmitter.emit("changed", toolbox.target.tab); eventEmitter.emit("changed", { target: toolbox.target });
}; };
toolbox.on("split-console", fireChangeForTab); toolbox.on("split-console", fireChangeForTab);
@ -38,7 +38,7 @@ exports.items = [
state: { state: {
isChecked: function(target) { isChecked: function(target) {
let toolbox = gDevTools.getToolbox(target); let toolbox = gDevTools.getToolbox(target);
return toolbox && toolbox.splitConsole; return !!(toolbox && toolbox.splitConsole);
}, },
onChange: function(target, changeHandler) { onChange: function(target, changeHandler) {
eventEmitter.on("changed", changeHandler); eventEmitter.on("changed", changeHandler);

View File

@ -17,11 +17,13 @@ const gcli = require("gcli/index");
function onPaintFlashingChanged(context) { function onPaintFlashingChanged(context) {
let tab = context.environment.chromeWindow.gBrowser.selectedTab; let tab = context.environment.chromeWindow.gBrowser.selectedTab;
eventEmitter.emit("changed", tab);
function fireChange() {
eventEmitter.emit("changed", tab);
}
let target = TargetFactory.forTab(tab); let target = TargetFactory.forTab(tab);
eventEmitter.emit("changed", { target: target });
function fireChange() {
eventEmitter.emit("changed", { target: target });
}
target.off("navigate", fireChange); target.off("navigate", fireChange);
target.once("navigate", fireChange); target.once("navigate", fireChange);