includes.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  3. * You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. "use strict";
  5. var { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components;
  6. const { loader, require } = Cu.import("resource://devtools/shared/Loader.jsm", {});
  7. const { XPCOMUtils } = require("resource://gre/modules/XPCOMUtils.jsm");
  8. const { EventTarget } = require("sdk/event/target");
  9. const { Task } = require("devtools/shared/task");
  10. const { Class } = require("sdk/core/heritage");
  11. const EventEmitter = require("devtools/shared/event-emitter");
  12. const DevToolsUtils = require("devtools/shared/DevToolsUtils");
  13. const Services = require("Services");
  14. const { gDevTools } = require("devtools/client/framework/devtools");
  15. const { LocalizationHelper } = require("devtools/shared/l10n");
  16. const { ViewHelpers } = require("devtools/client/shared/widgets/view-helpers");
  17. const STRINGS_URI = "devtools/client/locales/webaudioeditor.properties";
  18. const L10N = new LocalizationHelper(STRINGS_URI);
  19. loader.lazyRequireGetter(this, "LineGraphWidget",
  20. "devtools/client/shared/widgets/LineGraphWidget");
  21. // `AUDIO_NODE_DEFINITION` defined in the controller's initialization,
  22. // which describes all the properties of an AudioNode
  23. var AUDIO_NODE_DEFINITION;
  24. // Override DOM promises with Promise.jsm helpers
  25. const { defer, all } = require("promise");
  26. /* Events fired on `window` to indicate state or actions*/
  27. const EVENTS = {
  28. // Fired when the first AudioNode has been created, signifying
  29. // that the AudioContext is being used and should be tracked via the editor.
  30. START_CONTEXT: "WebAudioEditor:StartContext",
  31. // When the devtools theme changes.
  32. THEME_CHANGE: "WebAudioEditor:ThemeChange",
  33. // When the UI is reset from tab navigation.
  34. UI_RESET: "WebAudioEditor:UIReset",
  35. // When a param has been changed via the UI and successfully
  36. // pushed via the actor to the raw audio node.
  37. UI_SET_PARAM: "WebAudioEditor:UISetParam",
  38. // When a node is to be set in the InspectorView.
  39. UI_SELECT_NODE: "WebAudioEditor:UISelectNode",
  40. // When the inspector is finished setting a new node.
  41. UI_INSPECTOR_NODE_SET: "WebAudioEditor:UIInspectorNodeSet",
  42. // When the inspector is finished rendering in or out of view.
  43. UI_INSPECTOR_TOGGLED: "WebAudioEditor:UIInspectorToggled",
  44. // When an audio node is finished loading in the Properties tab.
  45. UI_PROPERTIES_TAB_RENDERED: "WebAudioEditor:UIPropertiesTabRendered",
  46. // When an audio node is finished loading in the Automation tab.
  47. UI_AUTOMATION_TAB_RENDERED: "WebAudioEditor:UIAutomationTabRendered",
  48. // When the Audio Context graph finishes rendering.
  49. // Is called with two arguments, first representing number of nodes
  50. // rendered, second being the number of edge connections rendering (not counting
  51. // param edges), followed by the count of the param edges rendered.
  52. UI_GRAPH_RENDERED: "WebAudioEditor:UIGraphRendered",
  53. // Called when the inspector splitter is moved and resized.
  54. UI_INSPECTOR_RESIZE: "WebAudioEditor:UIInspectorResize"
  55. };
  56. XPCOMUtils.defineConstant(this, "EVENTS", EVENTS);
  57. /**
  58. * The current target and the Web Audio Editor front, set by this tool's host.
  59. */
  60. var gToolbox, gTarget, gFront;
  61. /**
  62. * Convenient way of emitting events from the panel window.
  63. */
  64. EventEmitter.decorate(this);
  65. /**
  66. * DOM query helper.
  67. */
  68. function $(selector, target = document) { return target.querySelector(selector); }
  69. function $$(selector, target = document) { return target.querySelectorAll(selector); }
  70. /**
  71. * Takes an iterable collection, and a hash. Return the first
  72. * object in the collection that matches the values in the hash.
  73. * From Backbone.Collection#findWhere
  74. * http://backbonejs.org/#Collection-findWhere
  75. */
  76. function findWhere(collection, attrs) {
  77. let keys = Object.keys(attrs);
  78. for (let model of collection) {
  79. if (keys.every(key => model[key] === attrs[key])) {
  80. return model;
  81. }
  82. }
  83. return void 0;
  84. }
  85. function mixin(source, ...args) {
  86. args.forEach(obj => Object.keys(obj).forEach(prop => source[prop] = obj[prop]));
  87. return source;
  88. }