From baa6b8050d3171e5be639929dcaa4c3b0b90e892 Mon Sep 17 00:00:00 2001 From: Joe Walker Date: Tue, 25 Mar 2014 07:54:22 +0000 Subject: [PATCH] Bug 984365 - Split out 'paintflashing' commands; r=mratcliffe 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 --- .../devtools/commandline/BuiltinCommands.jsm | 123 ----------------- .../devtools/commandline/commands-index.js | 1 + .../devtools/gcli/commands/paintflashing.js | 129 ++++++++++++++++++ 3 files changed, 130 insertions(+), 123 deletions(-) create mode 100644 toolkit/devtools/gcli/commands/paintflashing.js diff --git a/browser/devtools/commandline/BuiltinCommands.jsm b/browser/devtools/commandline/BuiltinCommands.jsm index 2a8fd44753702..70eef221b2574 100644 --- a/browser/devtools/commandline/BuiltinCommands.jsm +++ b/browser/devtools/commandline/BuiltinCommands.jsm @@ -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)); diff --git a/browser/devtools/commandline/commands-index.js b/browser/devtools/commandline/commands-index.js index 96d51c4a2a7ee..fa84c419e5b50 100644 --- a/browser/devtools/commandline/commands-index.js +++ b/browser/devtools/commandline/commands-index.js @@ -11,6 +11,7 @@ const commandModules = [ "devtools/tilt/tilt-commands", "gcli/commands/appcache", "gcli/commands/media" + "gcli/commands/paintflashing", ]; gcli.addItemsByModule(commandModules, { delayedLoad: true }); diff --git a/toolkit/devtools/gcli/commands/paintflashing.js b/toolkit/devtools/gcli/commands/paintflashing.js new file mode 100644 index 0000000000000..d1722fdb33b8a --- /dev/null +++ b/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); + } + } +];