-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path1013544-highlight-active-node-wae.patch
270 lines (251 loc) · 9.42 KB
/
1013544-highlight-active-node-wae.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
From 20efaa6b581e666bf123d2788dfe4aaedca42d00 Mon Sep 17 00:00:00 2001
From: Jordan Santell <[email protected]>
Date: Thu, 22 May 2014 12:44:41 -0700
Subject: Bug 1013544 - Highlight active node in web audio editor. r=vp
---
browser/devtools/webaudioeditor/test/browser.ini | 1 +
.../webaudioeditor/test/browser_wa_graph-click.js | 18 --------
.../test/browser_wa_graph-selected.js | 52 ++++++++++++++++++++++
browser/devtools/webaudioeditor/test/head.js | 23 ++++++++++
.../devtools/webaudioeditor/webaudioeditor-view.js | 25 ++++++-----
5 files changed, 91 insertions(+), 28 deletions(-)
create mode 100644 browser/devtools/webaudioeditor/test/browser_wa_graph-selected.js
diff --git a/browser/devtools/webaudioeditor/test/browser.ini b/browser/devtools/webaudioeditor/test/browser.ini
index 84c5479..7d1a5f7 100644
--- a/browser/devtools/webaudioeditor/test/browser.ini
+++ b/browser/devtools/webaudioeditor/test/browser.ini
@@ -15,14 +15,15 @@ support-files =
[browser_webaudio-actor-simple.js]
[browser_wa_first-run.js]
[browser_wa_graph-click.js]
[browser_wa_graph-render-01.js]
[browser_wa_graph-render-02.js]
[browser_wa_graph-markers.js]
+[browser_wa_graph-selected.js]
[browser_wa_properties-view.js]
[browser_wa_properties-view-edit.js]
[browser_wa_inspector.js]
[browser_wa_inspector-toggle.js]
diff --git a/browser/devtools/webaudioeditor/test/browser_wa_graph-click.js b/browser/devtools/webaudioeditor/test/browser_wa_graph-click.js
index 40c0147..9ce825d 100644
--- a/browser/devtools/webaudioeditor/test/browser_wa_graph-click.js
+++ b/browser/devtools/webaudioeditor/test/browser_wa_graph-click.js
@@ -47,26 +47,8 @@ function spawnTest() {
is(WebAudioInspectorView.getCurrentNode().id, nodeIds[4], "Clicking on a <tspan> works as expected.");
ok(WebAudioInspectorView.isVisible(),
"InspectorView still visible after several nodes have been clicked.");
yield teardown(panel);
finish();
}
-
-function clickGraphNode (panelWin, el, waitForToggle = false) {
- let { promise, resolve } = Promise.defer();
- let promises = [
- once(panelWin, EVENTS.UI_INSPECTOR_NODE_SET)
- ];
-
- if (waitForToggle) {
- promises.push(once(panelWin, EVENTS.UI_INSPECTOR_TOGGLED));
- }
-
- // Use `el` as the element if it is one, otherwise
- // assume it's an ID and find the related graph node
- let element = el.tagName ? el : findGraphNode(panelWin, el);
- click(panelWin, element);
-
- return Promise.all(promises);
-}
diff --git a/browser/devtools/webaudioeditor/test/browser_wa_graph-selected.js b/browser/devtools/webaudioeditor/test/browser_wa_graph-selected.js
new file mode 100644
index 0000000..bd667d7
--- /dev/null
+++ b/browser/devtools/webaudioeditor/test/browser_wa_graph-selected.js
@@ -0,0 +1,52 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/**
+ * Tests that SVG nodes and edges were created for the Graph View.
+ */
+
+function spawnTest() {
+ let [target, debuggee, panel] = yield initWebAudioEditor(SIMPLE_CONTEXT_URL);
+ let { panelWin } = panel;
+ let { gFront, $, $$, EVENTS } = panelWin;
+
+ let started = once(gFront, "start-context");
+
+ reload(target);
+
+ let [actors] = yield Promise.all([
+ get3(gFront, "create-node"),
+ waitForGraphRendered(panelWin, 3, 2)
+ ]);
+
+ let [destId, oscId, gainId] = actors.map(actor => actor.actorID);
+
+ ok(!findGraphNode(panelWin, destId).classList.contains("selected"),
+ "No nodes selected on start. (destination)");
+ ok(!findGraphNode(panelWin, oscId).classList.contains("selected"),
+ "No nodes selected on start. (oscillator)");
+ ok(!findGraphNode(panelWin, gainId).classList.contains("selected"),
+ "No nodes selected on start. (gain)");
+
+ yield clickGraphNode(panelWin, oscId);
+
+ ok(findGraphNode(panelWin, oscId).classList.contains("selected"),
+ "Selected node has class 'selected'.");
+ ok(!findGraphNode(panelWin, destId).classList.contains("selected"),
+ "Non-selected nodes do not have class 'selected'.");
+ ok(!findGraphNode(panelWin, gainId).classList.contains("selected"),
+ "Non-selected nodes do not have class 'selected'.");
+
+ yield clickGraphNode(panelWin, gainId);
+
+ ok(!findGraphNode(panelWin, oscId).classList.contains("selected"),
+ "Previously selected node no longer has class 'selected'.");
+ ok(!findGraphNode(panelWin, destId).classList.contains("selected"),
+ "Non-selected nodes do not have class 'selected'.");
+ ok(findGraphNode(panelWin, gainId).classList.contains("selected"),
+ "Newly selected node now has class 'selected'.");
+
+ yield teardown(panel);
+ finish();
+}
+
diff --git a/browser/devtools/webaudioeditor/test/head.js b/browser/devtools/webaudioeditor/test/head.js
index d9d6f6b..b3e80f0 100644
--- a/browser/devtools/webaudioeditor/test/head.js
+++ b/browser/devtools/webaudioeditor/test/head.js
@@ -288,16 +288,39 @@ function isVisible (element) {
function wait (n) {
let { promise, resolve } = Promise.defer();
setTimeout(resolve, n);
info("Waiting " + n/1000 + " seconds.");
return promise;
}
/**
+ * Clicks a graph node based on actorID or passing in an element.
+ * Returns a promise that resolves once
+ * UI_INSPECTOR_NODE_SET is fired.
+ */
+function clickGraphNode (panelWin, el, waitForToggle = false) {
+ let { promise, resolve } = Promise.defer();
+ let promises = [
+ once(panelWin, panelWin.EVENTS.UI_INSPECTOR_NODE_SET)
+ ];
+
+ if (waitForToggle) {
+ promises.push(once(panelWin, panelWin.EVENTS.UI_INSPECTOR_TOGGLED));
+ }
+
+ // Use `el` as the element if it is one, otherwise
+ // assume it's an ID and find the related graph node
+ let element = el.tagName ? el : findGraphNode(panelWin, el);
+ click(panelWin, element);
+
+ return Promise.all(promises);
+}
+
+/**
* List of audio node properties to test against expectations of the AudioNode actor
*/
const NODE_PROPERTIES = {
"OscillatorNode": ["type", "frequency", "detune"],
"GainNode": ["gain"],
"DelayNode": ["delayTime"],
"AudioBufferSourceNode": ["buffer", "playbackRate", "loop", "loopStart", "loopEnd"],
diff --git a/browser/devtools/webaudioeditor/webaudioeditor-view.js b/browser/devtools/webaudioeditor/webaudioeditor-view.js
index e23d7e9..e89c921 100644
--- a/browser/devtools/webaudioeditor/webaudioeditor-view.js
+++ b/browser/devtools/webaudioeditor/webaudioeditor-view.js
@@ -47,32 +47,35 @@ const GENERIC_VARIABLES_VIEW_SETTINGS = {
*/
let WebAudioGraphView = {
/**
* Initialization function, called when the tool is started.
*/
initialize: function() {
this._onGraphNodeClick = this._onGraphNodeClick.bind(this);
this._onThemeChange = this._onThemeChange.bind(this);
+ this._onNodeSelect = this._onNodeSelect.bind(this);
this.draw = debounce(this.draw.bind(this), GRAPH_DEBOUNCE_TIMER);
$('#graph-target').addEventListener('click', this._onGraphNodeClick, false);
window.on(EVENTS.THEME_CHANGE, this._onThemeChange);
+ window.on(EVENTS.UI_INSPECTOR_NODE_SET, this._onNodeSelect);
},
/**
* Destruction function, called when the tool is closed.
*/
destroy: function() {
if (this._zoomBinding) {
this._zoomBinding.on("zoom", null);
}
$('#graph-target').removeEventListener('click', this._onGraphNodeClick, false);
window.off(EVENTS.THEME_CHANGE, this._onThemeChange);
+ window.off(EVENTS.UI_INSPECTOR_NODE_SET, this._onNodeSelect);
},
/**
* Called when a page is reloaded and waiting for a "start-context" event
* and clears out old content
*/
resetUI: function () {
$("#reload-notice").hidden = true;
@@ -96,30 +99,28 @@ let WebAudioGraphView = {
* Clears out the rendered graph, called when resetting the SVG elements to draw again,
* or when resetting the entire UI tool
*/
resetGraph: function () {
$("#graph-target").innerHTML = "";
},
/**
- * Makes the corresponding graph node appear "focused", called from WebAudioParamView
+ * Makes the corresponding graph node appear "focused", removing
+ * focused styles from all other nodes. If no `actorID` specified,
+ * make all nodes appear unselected.
+ * Called from UI_INSPECTOR_NODE_SELECT.
*/
focusNode: function (actorID) {
// Remove class "selected" from all nodes
- Array.prototype.forEach.call($$(".nodes > g"), $node => $node.classList.remove("selected"));
+ Array.forEach($$(".nodes > g"), $node => $node.classList.remove("selected"));
// Add to "selected"
- this._getNodeByID(actorID).classList.add("selected");
- },
-
- /**
- * Unfocuses the corresponding graph node, called from WebAudioParamView
- */
- blurNode: function (actorID) {
- this._getNodeByID(actorID).classList.remove("selected");
+ if (actorID) {
+ this._getNodeByID(actorID).classList.add("selected");
+ }
},
/**
* Takes an actorID and returns the corresponding DOM SVG element in the graph
*/
_getNodeByID: function (actorID) {
return $(".nodes > g[data-id='" + actorID + "']");
},
@@ -229,16 +230,20 @@ let WebAudioGraphView = {
d3.select("svg").call(this._zoomBinding);
}
},
/**
* Event handlers
*/
+ _onNodeSelect: function (eventName, id) {
+ this.focusNode(id);
+ },
+
/**
* Fired when the devtools theme changes.
*/
_onThemeChange: function (eventName, theme) {
let markerColor = MARKER_STYLING[theme];
let marker = $("#arrowhead");
if (marker) {
marker.setAttribute("style", "fill: " + markerColor);
--
1.8.4.2