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
Родитель 19227363e4
Коммит 0e06175e6e
6 изменённых файлов: 49 добавлений и 19 удалений

Просмотреть файл

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

Просмотреть файл

@ -213,7 +213,8 @@ function ResponsiveUI(aWindow, aTab)
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 = {
@ -305,7 +306,8 @@ ResponsiveUI.prototype = {
if (this.touchEventHandler)
this.touchEventHandler.stop();
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 });
},
/**

Просмотреть файл

@ -125,18 +125,42 @@ let CommandUtils = {
// Allow the command button to be toggleable
if (command.state) {
button.setAttribute("autocheck", false);
let onChange = (event, eventTab) => {
if (eventTab == target.tab) {
if (command.state.isChecked(target)) {
button.setAttribute("checked", true);
/**
* The onChange event should be called with an event object that
* 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")) {
button.removeAttribute("checked");
else {
updateChecked(reply);
}
}
};
command.state.onChange(target, onChange);
onChange(null, target.tab);
onChange("", { target: target });
document.defaultView.addEventListener("unload", () => {
command.state.offChange(target, onChange);
}, false);

Просмотреть файл

@ -144,7 +144,8 @@ Tilt.prototype = {
}
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);
},
@ -201,7 +202,8 @@ Tilt.prototype = {
this._isDestroying = false;
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);
},

Просмотреть файл

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

Просмотреть файл

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