browser/devtools/tilt/tilt-commands.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/tilt/tilt-commands.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,175 @@
     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 gcli = require("gcli/index");
    1.11 +
    1.12 +// Fetch TiltManager using the current loader, but don't save a
    1.13 +// reference to it, because it might change with a tool reload.
    1.14 +// We can clean this up once the command line is loadered.
    1.15 +Object.defineProperty(this, "TiltManager", {
    1.16 +  get: function() {
    1.17 +    return require("devtools/tilt/tilt").TiltManager;
    1.18 +  },
    1.19 +  enumerable: true
    1.20 +});
    1.21 +
    1.22 +exports.items = [
    1.23 +{
    1.24 +  name: 'tilt',
    1.25 +  description: gcli.lookup("tiltDesc"),
    1.26 +  manual: gcli.lookup("tiltManual")
    1.27 +},
    1.28 +{
    1.29 +  name: 'tilt open',
    1.30 +  description: gcli.lookup("tiltOpenDesc"),
    1.31 +  manual: gcli.lookup("tiltOpenManual"),
    1.32 +  exec: function(args, context) {
    1.33 +    let chromeWindow = context.environment.chromeDocument.defaultView;
    1.34 +    let Tilt = TiltManager.getTiltForBrowser(chromeWindow);
    1.35 +    if (!Tilt.currentInstance) {
    1.36 +      Tilt.toggle();
    1.37 +    }
    1.38 +  }
    1.39 +},
    1.40 +{
    1.41 +  name: "tilt toggle",
    1.42 +  buttonId: "command-button-tilt",
    1.43 +  buttonClass: "command-button command-button-invertable",
    1.44 +  tooltipText: gcli.lookup("tiltToggleTooltip"),
    1.45 +  hidden: true,
    1.46 +  state: {
    1.47 +    isChecked: function(aTarget) {
    1.48 +      let browserWindow = aTarget.tab.ownerDocument.defaultView;
    1.49 +      return !!TiltManager.getTiltForBrowser(browserWindow).currentInstance;
    1.50 +    },
    1.51 +    onChange: function(aTarget, aChangeHandler) {
    1.52 +      let browserWindow = aTarget.tab.ownerDocument.defaultView;
    1.53 +      let tilt = TiltManager.getTiltForBrowser(browserWindow);
    1.54 +      tilt.on("change", aChangeHandler);
    1.55 +    },
    1.56 +    offChange: function(aTarget, aChangeHandler) {
    1.57 +      if (aTarget.tab) {
    1.58 +        let browserWindow = aTarget.tab.ownerDocument.defaultView;
    1.59 +        let tilt = TiltManager.getTiltForBrowser(browserWindow);
    1.60 +        tilt.off("change", aChangeHandler);
    1.61 +      }
    1.62 +    },
    1.63 +  },
    1.64 +  exec: function(args, context) {
    1.65 +    let chromeWindow = context.environment.chromeDocument.defaultView;
    1.66 +    let Tilt = TiltManager.getTiltForBrowser(chromeWindow);
    1.67 +    Tilt.toggle();
    1.68 +  }
    1.69 +},
    1.70 +{
    1.71 +  name: 'tilt translate',
    1.72 +  description: gcli.lookup("tiltTranslateDesc"),
    1.73 +  manual: gcli.lookup("tiltTranslateManual"),
    1.74 +  params: [
    1.75 +    {
    1.76 +      name: "x",
    1.77 +      type: "number",
    1.78 +      defaultValue: 0,
    1.79 +      description: gcli.lookup("tiltTranslateXDesc"),
    1.80 +      manual: gcli.lookup("tiltTranslateXManual")
    1.81 +    },
    1.82 +    {
    1.83 +      name: "y",
    1.84 +      type: "number",
    1.85 +      defaultValue: 0,
    1.86 +      description: gcli.lookup("tiltTranslateYDesc"),
    1.87 +      manual: gcli.lookup("tiltTranslateYManual")
    1.88 +    }
    1.89 +  ],
    1.90 +  exec: function(args, context) {
    1.91 +    let chromeWindow = context.environment.chromeDocument.defaultView;
    1.92 +    let Tilt = TiltManager.getTiltForBrowser(chromeWindow);
    1.93 +    if (Tilt.currentInstance) {
    1.94 +      Tilt.currentInstance.controller.arcball.translate([args.x, args.y]);
    1.95 +    }
    1.96 +  }
    1.97 +},
    1.98 +{
    1.99 +  name: 'tilt rotate',
   1.100 +  description: gcli.lookup("tiltRotateDesc"),
   1.101 +  manual: gcli.lookup("tiltRotateManual"),
   1.102 +  params: [
   1.103 +    {
   1.104 +      name: "x",
   1.105 +      type: { name: 'number', min: -360, max: 360, step: 10 },
   1.106 +      defaultValue: 0,
   1.107 +      description: gcli.lookup("tiltRotateXDesc"),
   1.108 +      manual: gcli.lookup("tiltRotateXManual")
   1.109 +    },
   1.110 +    {
   1.111 +      name: "y",
   1.112 +      type: { name: 'number', min: -360, max: 360, step: 10 },
   1.113 +      defaultValue: 0,
   1.114 +      description: gcli.lookup("tiltRotateYDesc"),
   1.115 +      manual: gcli.lookup("tiltRotateYManual")
   1.116 +    },
   1.117 +    {
   1.118 +      name: "z",
   1.119 +      type: { name: 'number', min: -360, max: 360, step: 10 },
   1.120 +      defaultValue: 0,
   1.121 +      description: gcli.lookup("tiltRotateZDesc"),
   1.122 +      manual: gcli.lookup("tiltRotateZManual")
   1.123 +    }
   1.124 +  ],
   1.125 +  exec: function(args, context) {
   1.126 +    let chromeWindow = context.environment.chromeDocument.defaultView;
   1.127 +    let Tilt = TiltManager.getTiltForBrowser(chromeWindow);
   1.128 +    if (Tilt.currentInstance) {
   1.129 +      Tilt.currentInstance.controller.arcball.rotate([args.x, args.y, args.z]);
   1.130 +    }
   1.131 +  }
   1.132 +},
   1.133 +{
   1.134 +  name: 'tilt zoom',
   1.135 +  description: gcli.lookup("tiltZoomDesc"),
   1.136 +  manual: gcli.lookup("tiltZoomManual"),
   1.137 +  params: [
   1.138 +    {
   1.139 +      name: "zoom",
   1.140 +      type: { name: 'number' },
   1.141 +      description: gcli.lookup("tiltZoomAmountDesc"),
   1.142 +      manual: gcli.lookup("tiltZoomAmountManual")
   1.143 +    }
   1.144 +  ],
   1.145 +  exec: function(args, context) {
   1.146 +    let chromeWindow = context.environment.chromeDocument.defaultView;
   1.147 +    let Tilt = TiltManager.getTiltForBrowser(chromeWindow);
   1.148 +
   1.149 +    if (Tilt.currentInstance) {
   1.150 +      Tilt.currentInstance.controller.arcball.zoom(-args.zoom);
   1.151 +    }
   1.152 +  }
   1.153 +},
   1.154 +{
   1.155 +  name: 'tilt reset',
   1.156 +  description: gcli.lookup("tiltResetDesc"),
   1.157 +  manual: gcli.lookup("tiltResetManual"),
   1.158 +  exec: function(args, context) {
   1.159 +    let chromeWindow = context.environment.chromeDocument.defaultView;
   1.160 +    let Tilt = TiltManager.getTiltForBrowser(chromeWindow);
   1.161 +
   1.162 +    if (Tilt.currentInstance) {
   1.163 +      Tilt.currentInstance.controller.arcball.reset();
   1.164 +    }
   1.165 +  }
   1.166 +},
   1.167 +{
   1.168 +  name: 'tilt close',
   1.169 +  description: gcli.lookup("tiltCloseDesc"),
   1.170 +  manual: gcli.lookup("tiltCloseManual"),
   1.171 +  exec: function(args, context) {
   1.172 +    let chromeWindow = context.environment.chromeDocument.defaultView;
   1.173 +    let Tilt = TiltManager.getTiltForBrowser(chromeWindow);
   1.174 +
   1.175 +    Tilt.destroy(Tilt.currentWindowId);
   1.176 +  }
   1.177 +}
   1.178 +];

mercurial