OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @constructor | 6 * @constructor |
7 * @extends {WebInspector.HBox} | 7 * @extends {WebInspector.HBox} |
8 * @implements {WebInspector.TracingManagerClient} | 8 * @implements {WebInspector.TracingManagerClient} |
9 * @param {!WebInspector.NetworkTimeCalculator} calculator | 9 * @param {!WebInspector.NetworkTimeCalculator} calculator |
10 */ | 10 */ |
11 WebInspector.NetworkFilmStripView = function(calculator) | 11 WebInspector.NetworkFilmStripView = function(calculator) |
12 { | 12 { |
13 WebInspector.HBox.call(this, true); | 13 WebInspector.HBox.call(this, true); |
14 this.registerRequiredCSS("network/networkFilmStripView.css"); | 14 this.registerRequiredCSS("network/networkFilmStripView.css"); |
15 this.element.classList.add("network-film-strip-view"); | 15 this.element.classList.add("network-film-strip-view"); |
16 this.contentElement.classList.add("shadow-network-film-strip-view"); | 16 this.contentElement.classList.add("shadow-network-film-strip-view"); |
17 | |
18 /** @type {!WebInspector.NetworkTimeCalculator} */ | 17 /** @type {!WebInspector.NetworkTimeCalculator} */ |
19 this._calculator = calculator; | 18 this._calculator = calculator; |
20 | 19 |
21 this.reset(); | 20 this.reset(); |
22 } | 21 } |
23 | 22 |
24 WebInspector.NetworkFilmStripView._maximumFrameCount = 60; | 23 WebInspector.NetworkFilmStripView._maximumFrameCount = 60; |
25 | 24 |
26 WebInspector.NetworkFilmStripView.Events = { | 25 WebInspector.NetworkFilmStripView.Events = { |
27 FrameSelected: "FrameSelected", | 26 FrameSelected: "FrameSelected", |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 } | 69 } |
71 } | 70 } |
72 } | 71 } |
73 | 72 |
74 if (!frames.length) { | 73 if (!frames.length) { |
75 this.reset(); | 74 this.reset(); |
76 return; | 75 return; |
77 } | 76 } |
78 this._label.remove(); | 77 this._label.remove(); |
79 | 78 |
80 for (var i = 0; i < frames.length; ++i) | 79 for (var i = 0; i < frames.length; ++i) { |
| 80 frames[i]._index = i; |
81 frames[i].show(this.contentElement); | 81 frames[i].show(this.contentElement); |
| 82 |
| 83 } |
82 this._frames = frames; | 84 this._frames = frames; |
83 this._updateTimeOffset(true); | 85 this._updateTimeOffset(true); |
84 }, | 86 }, |
85 | 87 |
86 reset: function() | 88 reset: function() |
87 { | 89 { |
88 this.contentElement.removeChildren(); | 90 this.contentElement.removeChildren(); |
89 /** @type {?number} */ | 91 /** @type {?number} */ |
90 this._timeOffset = null; | 92 this._timeOffset = null; |
91 /** @type {!Array.<!WebInspector.NetworkFilmStripFrame>} */ | 93 /** @type {!Array.<!WebInspector.NetworkFilmStripFrame>} */ |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 if (this._target) | 160 if (this._target) |
159 return; | 161 return; |
160 | 162 |
161 this.reset(); | 163 this.reset(); |
162 this._target = WebInspector.targetManager.mainTarget(); | 164 this._target = WebInspector.targetManager.mainTarget(); |
163 this._tracingModel = new WebInspector.TracingModel(new WebInspector.Temp
FileBackingStorage("tracing")); | 165 this._tracingModel = new WebInspector.TracingModel(new WebInspector.Temp
FileBackingStorage("tracing")); |
164 this._target.tracingManager.start(this, "-*,disabled-by-default-devtools
.screenshot", ""); | 166 this._target.tracingManager.start(this, "-*,disabled-by-default-devtools
.screenshot", ""); |
165 this._label.textContent = WebInspector.UIString("Recording frames..."); | 167 this._label.textContent = WebInspector.UIString("Recording frames..."); |
166 }, | 168 }, |
167 | 169 |
| 170 /** |
| 171 * @return {boolean} |
| 172 */ |
| 173 isRecording: function() |
| 174 { |
| 175 return !!this._target; |
| 176 }, |
| 177 |
168 stopRecording: function() | 178 stopRecording: function() |
169 { | 179 { |
170 if (!this._target) | 180 if (!this._target) |
171 return; | 181 return; |
172 | 182 |
173 this._target.tracingManager.stop(); | 183 this._target.tracingManager.stop(); |
174 this._target = null; | 184 this._target = null; |
175 }, | 185 }, |
176 | 186 |
177 /** | 187 /** |
(...skipping 12 matching lines...) Expand all Loading... |
190 * @param {!WebInspector.NetworkFilmStripView} parent | 200 * @param {!WebInspector.NetworkFilmStripView} parent |
191 * @param {?string} imageData | 201 * @param {?string} imageData |
192 * @param {number} timestamp | 202 * @param {number} timestamp |
193 */ | 203 */ |
194 WebInspector.NetworkFilmStripFrame = function(parent, imageData, timestamp) | 204 WebInspector.NetworkFilmStripFrame = function(parent, imageData, timestamp) |
195 { | 205 { |
196 this._parent = parent; | 206 this._parent = parent; |
197 this._timestamp = timestamp; | 207 this._timestamp = timestamp; |
198 this._element = createElementWithClass("div", "frame"); | 208 this._element = createElementWithClass("div", "frame"); |
199 this._element.createChild("div", "thumbnail").createChild("img").src = "data
:image/jpg;base64," + imageData; | 209 this._element.createChild("div", "thumbnail").createChild("img").src = "data
:image/jpg;base64," + imageData; |
| 210 this._imageData = imageData; |
200 this._timeLabel = this._element.createChild("div", "time"); | 211 this._timeLabel = this._element.createChild("div", "time"); |
201 this._element.addEventListener("mousedown", this._onMouseDown.bind(this), fa
lse); | 212 this._element.addEventListener("mousedown", this._onMouseDown.bind(this), fa
lse); |
| 213 this._element.addEventListener("dblclick", this._onDoubleClick.bind(this), f
alse); |
202 } | 214 } |
203 | 215 |
204 WebInspector.NetworkFilmStripFrame.prototype = { | 216 WebInspector.NetworkFilmStripFrame.prototype = { |
205 /** | 217 /** |
206 * @param {!Element} parent | 218 * @param {!Element} parent |
207 */ | 219 */ |
208 show: function(parent) | 220 show: function(parent) |
209 { | 221 { |
210 parent.appendChild(this._element); | 222 parent.appendChild(this._element); |
211 }, | 223 }, |
212 | 224 |
213 /** | 225 _onMouseDown: function() |
214 * @param {!Event} event | |
215 */ | |
216 _onMouseDown: function(event) | |
217 { | 226 { |
218 this._parent._selectFrame(this); | 227 this._parent._selectFrame(this); |
219 }, | 228 }, |
220 | 229 |
| 230 _onDoubleClick: function() |
| 231 { |
| 232 WebInspector.Dialog.show(WebInspector.Dialog.modalHostView().element, ne
w WebInspector.NetworkFilmStripFrame.DialogDelegate(this._parent._frames, this._
index)); |
| 233 }, |
| 234 |
221 /** | 235 /** |
222 * @return {number} | 236 * @return {number} |
223 */ | 237 */ |
224 timestamp: function() | 238 timestamp: function() |
225 { | 239 { |
226 return this._timestamp; | 240 return this._timestamp; |
227 }, | 241 }, |
228 | 242 |
229 /** | 243 /** |
230 * @param {number} offset | 244 * @param {number} offset |
231 */ | 245 */ |
232 _setTimeOffset: function(offset) | 246 _setTimeOffset: function(offset) |
233 { | 247 { |
234 this._timeLabel.textContent = Number.secondsToString(this._timestamp - o
ffset); | 248 this._timeLabel.textContent = Number.secondsToString(this._timestamp - o
ffset); |
235 } | 249 } |
236 } | 250 } |
| 251 |
| 252 |
| 253 /** |
| 254 * @constructor |
| 255 * @extends {WebInspector.DialogDelegate} |
| 256 * @param {!Array<!WebInspector.NetworkFilmStripFrame>} frames |
| 257 * @param {number} index |
| 258 */ |
| 259 WebInspector.NetworkFilmStripFrame.DialogDelegate = function(frames, index) |
| 260 { |
| 261 WebInspector.DialogDelegate.call(this); |
| 262 this.element.classList.add("network-filmstrip-preview"); |
| 263 this.element.tabIndex = 0; |
| 264 |
| 265 this._frames = frames; |
| 266 this._index = index; |
| 267 |
| 268 this._imageElement = this.element.createChild("img"); |
| 269 var footerElement = this.element.createChild("div", "network-filmstrip-previ
ew-footer"); |
| 270 footerElement.createChild("div", "flex-auto"); |
| 271 var prevButton = createTextButton("\u25C0", this._onPrevFrame.bind(this), un
defined, WebInspector.UIString("Previous frame")); |
| 272 footerElement.appendChild(prevButton); |
| 273 this._timeLabel = footerElement.createChild("div", "network-filmstrip-previe
w-label"); |
| 274 var nextButton = createTextButton("\u25B6", this._onNextFrame.bind(this), un
defined, WebInspector.UIString("Next frame")); |
| 275 footerElement.appendChild(nextButton); |
| 276 footerElement.createChild("div", "flex-auto"); |
| 277 |
| 278 this._render(); |
| 279 this.element.addEventListener("keydown", this._keyDown.bind(this), false); |
| 280 } |
| 281 |
| 282 WebInspector.NetworkFilmStripFrame.DialogDelegate.prototype = { |
| 283 /** |
| 284 * @override |
| 285 */ |
| 286 focus: function() |
| 287 { |
| 288 this.element.focus(); |
| 289 }, |
| 290 |
| 291 /** |
| 292 * @param {!Event} event |
| 293 */ |
| 294 _keyDown: function(event) |
| 295 { |
| 296 if (event.keyIdentifier === "Left") { |
| 297 if (WebInspector.isMac() && event.metaKey) { |
| 298 this._onFirstFrame(); |
| 299 return; |
| 300 } |
| 301 |
| 302 this._onPrevFrame(); |
| 303 return; |
| 304 } |
| 305 |
| 306 if (event.keyIdentifier === "Right") { |
| 307 if (WebInspector.isMac() && event.metaKey) { |
| 308 this._onLastFrame(); |
| 309 return; |
| 310 } |
| 311 |
| 312 this._onNextFrame(); |
| 313 } |
| 314 |
| 315 if (event.keyIdentifier === "Home") { |
| 316 this._onFirstFrame(); |
| 317 return; |
| 318 } |
| 319 |
| 320 if (event.keyIdentifier === "End") { |
| 321 this._onLastFrame(); |
| 322 return; |
| 323 } |
| 324 }, |
| 325 |
| 326 _onPrevFrame: function() |
| 327 { |
| 328 if (this._index > 0) |
| 329 --this._index; |
| 330 this._render(); |
| 331 }, |
| 332 |
| 333 _onNextFrame: function() |
| 334 { |
| 335 if (this._index < this._frames.length - 1) |
| 336 ++this._index; |
| 337 this._render(); |
| 338 }, |
| 339 |
| 340 _onFirstFrame: function() |
| 341 { |
| 342 this._index = 0; |
| 343 this._render(); |
| 344 }, |
| 345 |
| 346 _onLastFrame: function() |
| 347 { |
| 348 this._index = this._frames.length - 1; |
| 349 this._render(); |
| 350 }, |
| 351 |
| 352 _render: function() |
| 353 { |
| 354 var frame = this._frames[this._index]; |
| 355 this._imageElement.src = "data:image/jpg;base64," + frame._imageData; |
| 356 this._timeLabel.textContent = frame._timeLabel.textContent; |
| 357 }, |
| 358 |
| 359 __proto__: WebInspector.DialogDelegate.prototype |
| 360 } |
OLD | NEW |