Skip to content

Commit

Permalink
Bug 984365 - Split out 'paintflashing' commands; r=mratcliffe
Browse files Browse the repository at this point in the history
Changes:
* Be consistent in using " rather than ' where possible
* Convert from JSM style to JS style, which means:
  * Adjust require paths to fit with SDK loader conventions
  * Use exports.items rather than EXPORTED_SYMBOLS
  • Loading branch information
joewalker committed Apr 3, 2014
1 parent 06f415f commit baa6b80
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 123 deletions.
123 changes: 0 additions & 123 deletions browser/devtools/commandline/BuiltinCommands.jsm
Expand Up @@ -1898,126 +1898,3 @@ this.items.push({
},
});


/* CmdPaintFlashing ------------------------------------------------------- */

(function(module) {
/**
* 'paintflashing' command
*/
this.items.push({
name: 'paintflashing',
description: gcli.lookup('paintflashingDesc')
});

this.items.push({
name: 'paintflashing on',
description: gcli.lookup('paintflashingOnDesc'),
manual: gcli.lookup('paintflashingManual'),
params: [{
group: "options",
params: [
{
type: "boolean",
name: "chrome",
get hidden() gcli.hiddenByChromePref(),
description: gcli.lookup("paintflashingChromeDesc"),
}
]
}],
exec: function(args, context) {
var window = args.chrome ?
context.environment.chromeWindow :
context.environment.window;

window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils)
.paintFlashing = true;
onPaintFlashingChanged(context);
}
});

this.items.push({
name: 'paintflashing off',
description: gcli.lookup('paintflashingOffDesc'),
manual: gcli.lookup('paintflashingManual'),
params: [{
group: "options",
params: [
{
type: "boolean",
name: "chrome",
get hidden() gcli.hiddenByChromePref(),
description: gcli.lookup("paintflashingChromeDesc"),
}
]
}],
exec: function(args, context) {
var window = args.chrome ?
context.environment.chromeWindow :
context.environment.window;

window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils)
.paintFlashing = false;
onPaintFlashingChanged(context);
}
});

this.items.push({
name: 'paintflashing toggle',
hidden: true,
buttonId: "command-button-paintflashing",
buttonClass: "command-button command-button-invertable",
state: {
isChecked: function(aTarget) {
if (aTarget.isLocalTab) {
let window = aTarget.tab.linkedBrowser.contentWindow;
let wUtils = window.QueryInterface(Ci.nsIInterfaceRequestor).
getInterface(Ci.nsIDOMWindowUtils);
return wUtils.paintFlashing;
} else {
throw new Error("Unsupported target");
}
},
onChange: function(aTarget, aChangeHandler) {
eventEmitter.on("changed", aChangeHandler);
},
offChange: function(aTarget, aChangeHandler) {
eventEmitter.off("changed", aChangeHandler);
},
},
tooltipText: gcli.lookup("paintflashingTooltip"),
description: gcli.lookup('paintflashingToggleDesc'),
manual: gcli.lookup('paintflashingManual'),
exec: function(args, context) {
var window = context.environment.window;
var wUtils = window.QueryInterface(Ci.nsIInterfaceRequestor).
getInterface(Ci.nsIDOMWindowUtils);
wUtils.paintFlashing = !wUtils.paintFlashing;
onPaintFlashingChanged(context);
}
});

let eventEmitter = new EventEmitter();
function onPaintFlashingChanged(context) {
var gBrowser = context.environment.chromeDocument.defaultView.gBrowser;
var tab = gBrowser.selectedTab;
eventEmitter.emit("changed", tab);
function fireChange() {
eventEmitter.emit("changed", tab);
}
var target = devtools.TargetFactory.forTab(tab);
target.off("navigate", fireChange);
target.once("navigate", fireChange);

var window = context.environment.window;
var wUtils = window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils);
if (wUtils.paintFlashing) {
telemetry.toolOpened("paintflashing");
} else {
telemetry.toolClosed("paintflashing");
}
}
}(this));
1 change: 1 addition & 0 deletions browser/devtools/commandline/commands-index.js
Expand Up @@ -11,6 +11,7 @@ const commandModules = [
"devtools/tilt/tilt-commands",
"gcli/commands/appcache",
"gcli/commands/media"
"gcli/commands/paintflashing",
];

gcli.addItemsByModule(commandModules, { delayedLoad: true });
Expand Down
129 changes: 129 additions & 0 deletions toolkit/devtools/gcli/commands/paintflashing.js
@@ -0,0 +1,129 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

"use strict";

const { Cc, Ci, Cu } = require("chrome");
const TargetFactory = require("resource://gre/modules/devtools/Loader.jsm").devtools.TargetFactory;

const Telemetry = require("devtools/shared/telemetry");
const telemetry = new Telemetry();

const EventEmitter = require("devtools/toolkit/event-emitter");
const eventEmitter = new EventEmitter();

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);
target.off("navigate", fireChange);
target.once("navigate", fireChange);

let window = context.environment.window;
let wUtils = window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils);
if (wUtils.paintFlashing) {
telemetry.toolOpened("paintflashing");
} else {
telemetry.toolClosed("paintflashing");
}
}

exports.items = [
{
name: "paintflashing",
description: gcli.lookup("paintflashingDesc")
},
{
name: "paintflashing on",
description: gcli.lookup("paintflashingOnDesc"),
manual: gcli.lookup("paintflashingManual"),
params: [{
group: "options",
params: [
{
type: "boolean",
name: "chrome",
get hidden() gcli.hiddenByChromePref(),
description: gcli.lookup("paintflashingChromeDesc"),
}
]
}],
exec: function(args, context) {
let window = args.chrome ?
context.environment.chromeWindow :
context.environment.window;

window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils)
.paintFlashing = true;
onPaintFlashingChanged(context);
}
},
{
name: "paintflashing off",
description: gcli.lookup("paintflashingOffDesc"),
manual: gcli.lookup("paintflashingManual"),
params: [{
group: "options",
params: [
{
type: "boolean",
name: "chrome",
get hidden() gcli.hiddenByChromePref(),
description: gcli.lookup("paintflashingChromeDesc"),
}
]
}],
exec: function(args, context) {
let window = args.chrome ?
context.environment.chromeWindow :
context.environment.window;

window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils)
.paintFlashing = false;
onPaintFlashingChanged(context);
}
},
{
name: "paintflashing toggle",
hidden: true,
buttonId: "command-button-paintflashing",
buttonClass: "command-button command-button-invertable",
state: {
isChecked: function(aTarget) {
if (aTarget.isLocalTab) {
let window = aTarget.tab.linkedBrowser.contentWindow;
let wUtils = window.QueryInterface(Ci.nsIInterfaceRequestor).
getInterface(Ci.nsIDOMWindowUtils);
return wUtils.paintFlashing;
} else {
throw new Error("Unsupported target");
}
},
onChange: function(aTarget, aChangeHandler) {
eventEmitter.on("changed", aChangeHandler);
},
offChange: function(aTarget, aChangeHandler) {
eventEmitter.off("changed", aChangeHandler);
},
},
tooltipText: gcli.lookup("paintflashingTooltip"),
description: gcli.lookup("paintflashingToggleDesc"),
manual: gcli.lookup("paintflashingManual"),
exec: function(args, context) {
let window = context.environment.window;
let wUtils = window.QueryInterface(Ci.nsIInterfaceRequestor).
getInterface(Ci.nsIDOMWindowUtils);
wUtils.paintFlashing = !wUtils.paintFlashing;
onPaintFlashingChanged(context);
}
}
];

0 comments on commit baa6b80

Please sign in to comment.