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 */ | 8 */ |
9 WebInspector.FilmStripView = function() | 9 WebInspector.FilmStripView = function() |
10 { | 10 { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
56 }, | 56 }, |
57 | 57 |
58 /** | 58 /** |
59 * @param {!WebInspector.FilmStripModel.Frame} frame | 59 * @param {!WebInspector.FilmStripModel.Frame} frame |
60 * @return {!Element} | 60 * @return {!Element} |
61 */ | 61 */ |
62 createFrameElement: function(frame) | 62 createFrameElement: function(frame) |
63 { | 63 { |
64 var time = frame.timestamp; | 64 var time = frame.timestamp; |
65 var element = createElementWithClass("div", "frame"); | 65 var element = createElementWithClass("div", "frame"); |
66 element.createChild("div", "thumbnail").createChild("img").src = "data:i mage/jpg;base64," + frame.imageData; | 66 element.createChild("div", "thumbnail").createChild("img").src = "data:i mage/jpg;base64," + this._imageDataForFrame.get(frame); |
67 element.createChild("div", "time").textContent = Number.millisToString(t ime - this._zeroTime); | 67 element.createChild("div", "time").textContent = Number.millisToString(t ime - this._zeroTime); |
68 element.addEventListener("mousedown", this._onMouseEvent.bind(this, WebI nspector.FilmStripView.Events.FrameSelected, time), false); | 68 element.addEventListener("mousedown", this._onMouseEvent.bind(this, WebI nspector.FilmStripView.Events.FrameSelected, time), false); |
69 element.addEventListener("mouseenter", this._onMouseEvent.bind(this, Web Inspector.FilmStripView.Events.FrameEnter, time), false); | 69 element.addEventListener("mouseenter", this._onMouseEvent.bind(this, Web Inspector.FilmStripView.Events.FrameEnter, time), false); |
70 element.addEventListener("mouseout", this._onMouseEvent.bind(this, WebIn spector.FilmStripView.Events.FrameExit, time), false); | 70 element.addEventListener("mouseout", this._onMouseEvent.bind(this, WebIn spector.FilmStripView.Events.FrameExit, time), false); |
71 element.addEventListener("dblclick", this._onDoubleClick.bind(this, fram e), false); | 71 element.addEventListener("dblclick", this._onDoubleClick.bind(this, fram e), false); |
72 return element; | 72 return element; |
73 }, | 73 }, |
74 | 74 |
75 /** | 75 /** |
76 * @param {number} time | 76 * @param {number} time |
(...skipping 17 matching lines...) Expand all Loading... | |
94 return frames[index]; | 94 return frames[index]; |
95 }, | 95 }, |
96 | 96 |
97 update: function() | 97 update: function() |
98 { | 98 { |
99 if (!this._model) | 99 if (!this._model) |
100 return; | 100 return; |
101 var frames = this._model.frames(); | 101 var frames = this._model.frames(); |
102 if (!frames.length) | 102 if (!frames.length) |
103 return; | 103 return; |
104 /** @type {!Map<!WebInspector.FilmStripModel.Frame, string>} */ | |
105 this._imageDataForFrame = new Map(); | |
alph
2015/06/18 13:10:34
What if another update is fired while promises are
| |
106 | |
107 var promises = []; | |
108 for (var frame of frames) | |
109 promises.push(frame.imageDataPromise().then(setImageData.bind(this, frame))); | |
110 | |
111 Promise.all(promises).then(this._updateWhenImagesLoaded.bind(this)); | |
112 /** | |
113 * @this {WebInspector.FilmStripView} | |
114 * @param {!WebInspector.FilmStripModel.Frame} frame | |
115 * @param {?string} data | |
116 */ | |
117 function setImageData(frame, data) | |
118 { | |
119 if (data) | |
120 this._imageDataForFrame.set(frame, data); | |
121 } | |
122 }, | |
123 | |
124 _updateWhenImagesLoaded: function() | |
125 { | |
104 this.contentElement.removeChildren(); | 126 this.contentElement.removeChildren(); |
105 this._statusLabel.remove(); | 127 this._statusLabel.remove(); |
106 | 128 |
129 var frames = this._model.frames(); | |
130 | |
107 if (this._mode === WebInspector.FilmStripView.Modes.FrameBased) { | 131 if (this._mode === WebInspector.FilmStripView.Modes.FrameBased) { |
108 frames.map(this.createFrameElement.bind(this)).forEach(this.contentE lement.appendChild.bind(this.contentElement)); | 132 frames.map(this.createFrameElement.bind(this)).forEach(this.contentE lement.appendChild.bind(this.contentElement)); |
109 return; | 133 return; |
110 } | 134 } |
111 | 135 |
112 var width = this.contentElement.clientWidth; | 136 var width = this.contentElement.clientWidth; |
113 var scale = this._spanTime / width; | 137 var scale = this._spanTime / width; |
114 var element0 = this.createFrameElement(frames[0]); // Calculate frame w idth basing on the first frame. | 138 var element0 = this.createFrameElement(frames[0]); // Calculate frame w idth basing on the first frame. |
115 var frameWidth = Math.ceil(WebInspector.measurePreferredSize(element0, t his.contentElement).width); | 139 var frameWidth = Math.ceil(WebInspector.measurePreferredSize(element0, t his.contentElement).width); |
116 if (!frameWidth) | 140 if (!frameWidth) |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
266 | 290 |
267 _onLastFrame: function() | 291 _onLastFrame: function() |
268 { | 292 { |
269 this._index = this._frames.length - 1; | 293 this._index = this._frames.length - 1; |
270 this._render(); | 294 this._render(); |
271 }, | 295 }, |
272 | 296 |
273 _render: function() | 297 _render: function() |
274 { | 298 { |
275 var frame = this._frames[this._index]; | 299 var frame = this._frames[this._index]; |
276 this._imageElement.src = "data:image/jpg;base64," + frame.imageData; | 300 frame.imageDataPromise().then(onGotImageData.bind(this)); |
301 /** | |
302 * @param {?string} data | |
303 * @this {WebInspector.DialogDelegate} | |
304 */ | |
305 function onGotImageData(data) | |
306 { | |
307 if (data) | |
308 this._imageElement.src = "data:image/jpg;base64," + data; | |
309 } | |
277 this._timeLabel.textContent = Number.millisToString(frame.timestamp - th is._zeroTime); | 310 this._timeLabel.textContent = Number.millisToString(frame.timestamp - th is._zeroTime); |
278 }, | 311 }, |
279 | 312 |
280 __proto__: WebInspector.DialogDelegate.prototype | 313 __proto__: WebInspector.DialogDelegate.prototype |
281 } | 314 } |
OLD | NEW |