Esempio n. 1
0
/**
 * Eyedropper widget. Once opened, shows zoomed area above current pixel and
 * displays the color value of the center pixel. Clicking on the window will
 * close the widget and fire a 'select' event. If 'copyOnSelect' is true, the color
 * will also be copied to the clipboard.
 *
 * let eyedropper = new Eyedropper(window);
 * eyedropper.open();
 *
 * eyedropper.once("select", (ev, color) => {
 *   console.log(color);  // "rgb(20, 50, 230)"
 * })
 *
 * @param {DOMWindow} chromeWindow
 *        window to inspect
 * @param {object} opts
 *        optional options object, with 'copyOnSelect', 'context'
 */
function Eyedropper(chromeWindow, opts = { copyOnSelect: true, context: "other" }) {
  this.copyOnSelect = opts.copyOnSelect;

  this._onFirstMouseMove = this._onFirstMouseMove.bind(this);
  this._onMouseMove = this._onMouseMove.bind(this);
  this._onMouseDown = this._onMouseDown.bind(this);
  this._onKeyDown = this._onKeyDown.bind(this);
  this._onFrameLoaded = this._onFrameLoaded.bind(this);

  this._chromeWindow = chromeWindow;
  this._chromeDocument = chromeWindow.document;

  this._OS = XULRuntime.OS;

  this._dragging = true;
  this.loaded = false;

  this._mouseMoveCounter = 0;

  this.format = Services.prefs.getCharPref(FORMAT_PREF); // color value format
  this.zoom = Services.prefs.getIntPref(ZOOM_PREF);      // zoom level - integer

  this._zoomArea = {
    x: 0,          // the left coordinate of the center of the inspected region
    y: 0,          // the top coordinate of the center of the inspected region
    width: CANVAS_WIDTH,      // width of canvas to draw zoomed area onto
    height: CANVAS_WIDTH      // height of canvas
  };

  let mm = this._contentTab.linkedBrowser.messageManager;
  mm.loadFrameScript("resource:///modules/devtools/eyedropper/eyedropper-child.js", true);

  // record if this was opened via the picker or standalone
  var telemetry = new Telemetry();
  if (opts.context == "command") {
    telemetry.toolOpened("eyedropper");
  }
  else if (opts.context == "menu") {
    telemetry.toolOpened("menueyedropper");
  }
  else if (opts.context == "picker") {
    telemetry.toolOpened("pickereyedropper");
  }

  EventEmitter.decorate(this);
}
Esempio n. 2
0
 initialize: function() {
   telemetry.toolOpened("shadereditor");
   this._onHostChanged = this._onHostChanged.bind(this);
   this._onTabNavigated = this._onTabNavigated.bind(this);
   this._onProgramLinked = this._onProgramLinked.bind(this);
   this._onProgramsAdded = this._onProgramsAdded.bind(this);
   gToolbox.on("host-changed", this._onHostChanged);
   gTarget.on("will-navigate", this._onTabNavigated);
   gTarget.on("navigate", this._onTabNavigated);
   gFront.on("program-linked", this._onProgramLinked);
   this.reloadButton = $("#requests-menu-reload-notice-button");
   this.reloadButton.addEventListener("command", this._onReloadCommand);
 },
Esempio n. 3
0
 initialize: function() {
   telemetry.toolOpened("canvasdebugger");
   this._onTabNavigated = this._onTabNavigated.bind(this);
   gTarget.on("will-navigate", this._onTabNavigated);
   gTarget.on("navigate", this._onTabNavigated);
 },