toolkit/devtools/gcli/commands/paintflashing.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/devtools/gcli/commands/paintflashing.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,129 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +"use strict";
     1.9 +
    1.10 +const { Cc, Ci, Cu } = require("chrome");
    1.11 +const TargetFactory = require("resource://gre/modules/devtools/Loader.jsm").devtools.TargetFactory;
    1.12 +
    1.13 +const Telemetry = require("devtools/shared/telemetry");
    1.14 +const telemetry = new Telemetry();
    1.15 +
    1.16 +const EventEmitter = require("devtools/toolkit/event-emitter");
    1.17 +const eventEmitter = new EventEmitter();
    1.18 +
    1.19 +const gcli = require("gcli/index");
    1.20 +
    1.21 +function onPaintFlashingChanged(context) {
    1.22 +  let tab = context.environment.chromeWindow.gBrowser.selectedTab;
    1.23 +  eventEmitter.emit("changed", tab);
    1.24 +  function fireChange() {
    1.25 +    eventEmitter.emit("changed", tab);
    1.26 +  }
    1.27 +  let target = TargetFactory.forTab(tab);
    1.28 +  target.off("navigate", fireChange);
    1.29 +  target.once("navigate", fireChange);
    1.30 +
    1.31 +  let window = context.environment.window;
    1.32 +  let wUtils = window.QueryInterface(Ci.nsIInterfaceRequestor)
    1.33 +                     .getInterface(Ci.nsIDOMWindowUtils);
    1.34 +  if (wUtils.paintFlashing) {
    1.35 +    telemetry.toolOpened("paintflashing");
    1.36 +  } else {
    1.37 +    telemetry.toolClosed("paintflashing");
    1.38 +  }
    1.39 +}
    1.40 +
    1.41 +exports.items = [
    1.42 +  {
    1.43 +    name: "paintflashing",
    1.44 +    description: gcli.lookup("paintflashingDesc")
    1.45 +  },
    1.46 +  {
    1.47 +    name: "paintflashing on",
    1.48 +    description: gcli.lookup("paintflashingOnDesc"),
    1.49 +    manual: gcli.lookup("paintflashingManual"),
    1.50 +    params: [{
    1.51 +      group: "options",
    1.52 +      params: [
    1.53 +        {
    1.54 +          type: "boolean",
    1.55 +          name: "chrome",
    1.56 +          get hidden() gcli.hiddenByChromePref(),
    1.57 +          description: gcli.lookup("paintflashingChromeDesc"),
    1.58 +        }
    1.59 +      ]
    1.60 +    }],
    1.61 +    exec: function(args, context) {
    1.62 +      let window = args.chrome ?
    1.63 +                  context.environment.chromeWindow :
    1.64 +                  context.environment.window;
    1.65 +
    1.66 +      window.QueryInterface(Ci.nsIInterfaceRequestor)
    1.67 +            .getInterface(Ci.nsIDOMWindowUtils)
    1.68 +            .paintFlashing = true;
    1.69 +      onPaintFlashingChanged(context);
    1.70 +    }
    1.71 +  },
    1.72 +  {
    1.73 +    name: "paintflashing off",
    1.74 +    description: gcli.lookup("paintflashingOffDesc"),
    1.75 +    manual: gcli.lookup("paintflashingManual"),
    1.76 +    params: [{
    1.77 +      group: "options",
    1.78 +      params: [
    1.79 +        {
    1.80 +          type: "boolean",
    1.81 +          name: "chrome",
    1.82 +          get hidden() gcli.hiddenByChromePref(),
    1.83 +          description: gcli.lookup("paintflashingChromeDesc"),
    1.84 +        }
    1.85 +      ]
    1.86 +    }],
    1.87 +    exec: function(args, context) {
    1.88 +      let window = args.chrome ?
    1.89 +                  context.environment.chromeWindow :
    1.90 +                  context.environment.window;
    1.91 +
    1.92 +      window.QueryInterface(Ci.nsIInterfaceRequestor)
    1.93 +            .getInterface(Ci.nsIDOMWindowUtils)
    1.94 +            .paintFlashing = false;
    1.95 +      onPaintFlashingChanged(context);
    1.96 +    }
    1.97 +  },
    1.98 +  {
    1.99 +    name: "paintflashing toggle",
   1.100 +    hidden: true,
   1.101 +    buttonId: "command-button-paintflashing",
   1.102 +    buttonClass: "command-button command-button-invertable",
   1.103 +    state: {
   1.104 +      isChecked: function(aTarget) {
   1.105 +        if (aTarget.isLocalTab) {
   1.106 +          let window = aTarget.tab.linkedBrowser.contentWindow;
   1.107 +          let wUtils = window.QueryInterface(Ci.nsIInterfaceRequestor).
   1.108 +                              getInterface(Ci.nsIDOMWindowUtils);
   1.109 +          return wUtils.paintFlashing;
   1.110 +        } else {
   1.111 +          throw new Error("Unsupported target");
   1.112 +        }
   1.113 +      },
   1.114 +      onChange: function(aTarget, aChangeHandler) {
   1.115 +        eventEmitter.on("changed", aChangeHandler);
   1.116 +      },
   1.117 +      offChange: function(aTarget, aChangeHandler) {
   1.118 +        eventEmitter.off("changed", aChangeHandler);
   1.119 +      },
   1.120 +    },
   1.121 +    tooltipText: gcli.lookup("paintflashingTooltip"),
   1.122 +    description: gcli.lookup("paintflashingToggleDesc"),
   1.123 +    manual: gcli.lookup("paintflashingManual"),
   1.124 +    exec: function(args, context) {
   1.125 +      let window = context.environment.window;
   1.126 +      let wUtils = window.QueryInterface(Ci.nsIInterfaceRequestor).
   1.127 +                   getInterface(Ci.nsIDOMWindowUtils);
   1.128 +      wUtils.paintFlashing = !wUtils.paintFlashing;
   1.129 +      onPaintFlashingChanged(context);
   1.130 +    }
   1.131 +  }
   1.132 +];

mercurial