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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
54 this.update(); | 54 this.update(); |
55 }, | 55 }, |
56 | 56 |
57 update: function() | 57 update: function() |
58 { | 58 { |
59 if (!this._model) | 59 if (!this._model) |
60 return; | 60 return; |
61 var frames = this._model.frames(); | 61 var frames = this._model.frames(); |
62 if (!frames.length) | 62 if (!frames.length) |
63 return; | 63 return; |
64 /** @type {!Map<!WebInspector.FilmStripModel.Frame, string>} */ | |
65 var imageDataForFrame = new Map(); | |
66 | |
67 var pendingImages = frames.length; | |
68 for (var frame of frames) | |
69 frame.requestImageData(onImageData.bind(this, frame)); | |
alph
2015/06/17 09:41:59
If you turn them into a promises, the code should
| |
70 | |
71 /** | |
72 * @this {WebInspector.FilmStripView} | |
73 * @param {!WebInspector.FilmStripModel.Frame} frame | |
74 * @param {?string} data | |
75 */ | |
76 function onImageData(frame, data) | |
77 { | |
78 --pendingImages; | |
79 if (!data) | |
80 return; | |
81 imageDataForFrame.set(frame, data); | |
82 if (!pendingImages) | |
83 this._updateWhenImagesLoaded(imageDataForFrame); | |
84 } | |
85 }, | |
86 | |
87 /** | |
88 * @param {!Map<!WebInspector.FilmStripModel.Frame, string>} imageDataForFra me | |
89 */ | |
90 _updateWhenImagesLoaded: function(imageDataForFrame) | |
91 { | |
64 this.contentElement.removeChildren(); | 92 this.contentElement.removeChildren(); |
65 this._label.remove(); | 93 this._label.remove(); |
66 var zeroTime = this._zeroTime; | 94 var zeroTime = this._zeroTime; |
95 var frames = this._model.frames(); | |
67 | 96 |
68 /** | 97 /** |
69 * @param {!WebInspector.FilmStripModel.Frame} frame | 98 * @param {!WebInspector.FilmStripModel.Frame} frame |
70 * @param {boolean=} skipTimeLabel | 99 * @param {boolean=} skipTimeLabel |
71 * @return {!Element} | 100 * @return {!Element} |
72 * @this {WebInspector.FilmStripView} | 101 * @this {WebInspector.FilmStripView} |
73 */ | 102 */ |
74 function createElementForFrame(frame, skipTimeLabel) | 103 function createElementForFrame(frame, skipTimeLabel) |
75 { | 104 { |
76 var time = frame.timestamp; | 105 var time = frame.timestamp; |
77 var element = createElementWithClass("div", "frame"); | 106 var element = createElementWithClass("div", "frame"); |
78 element.createChild("div", "thumbnail").createChild("img").src = "da ta:image/jpg;base64," + frame.imageData; | 107 element.createChild("div", "thumbnail").createChild("img").src = "da ta:image/jpg;base64," + imageDataForFrame.get(frame); |
79 if (!skipTimeLabel) | 108 if (!skipTimeLabel) |
80 element.createChild("div", "time").textContent = Number.millisTo String(time - zeroTime); | 109 element.createChild("div", "time").textContent = Number.millisTo String(time - zeroTime); |
81 element.addEventListener("mousedown", this._onMouseEvent.bind(this, WebInspector.FilmStripView.Events.FrameSelected, time), false); | 110 element.addEventListener("mousedown", this._onMouseEvent.bind(this, WebInspector.FilmStripView.Events.FrameSelected, time), false); |
82 element.addEventListener("mouseenter", this._onMouseEvent.bind(this, WebInspector.FilmStripView.Events.FrameEnter, time), false); | 111 element.addEventListener("mouseenter", this._onMouseEvent.bind(this, WebInspector.FilmStripView.Events.FrameEnter, time), false); |
83 element.addEventListener("mouseout", this._onMouseEvent.bind(this, W ebInspector.FilmStripView.Events.FrameExit, time), false); | 112 element.addEventListener("mouseout", this._onMouseEvent.bind(this, W ebInspector.FilmStripView.Events.FrameExit, time), false); |
84 element.addEventListener("dblclick", this._onDoubleClick.bind(this, frame), false); | 113 element.addEventListener("dblclick", this._onDoubleClick.bind(this, frame), false); |
85 this.contentElement.appendChild(element); | 114 this.contentElement.appendChild(element); |
86 return element; | 115 return element; |
87 } | 116 } |
88 | 117 |
(...skipping 22 matching lines...) Expand all Loading... | |
111 function comparator(time, frame) | 140 function comparator(time, frame) |
112 { | 141 { |
113 return time - frame.timestamp; | 142 return time - frame.timestamp; |
114 } | 143 } |
115 | 144 |
116 var width = this.contentElement.clientWidth; | 145 var width = this.contentElement.clientWidth; |
117 var scale = this._spanTime / width; | 146 var scale = this._spanTime / width; |
118 | 147 |
119 // Calculate frame width basing on the first frame. | 148 // Calculate frame width basing on the first frame. |
120 var tempElement = createElementWithClass("div", "frame"); | 149 var tempElement = createElementWithClass("div", "frame"); |
121 tempElement.createChild("div", "thumbnail").createChild("img").src = "da ta:image/jpg;base64," + frames[0].imageData; | 150 tempElement.createChild("div", "thumbnail").createChild("img").src = "da ta:image/jpg;base64," + imageDataForFrame.get(frames[0]); |
122 var frameWidth = Math.ceil(WebInspector.measurePreferredSize(tempElement , this.contentElement).width); | 151 var frameWidth = Math.ceil(WebInspector.measurePreferredSize(tempElement , this.contentElement).width); |
123 if (!frameWidth) | 152 if (!frameWidth) |
124 return; | 153 return; |
125 | 154 |
126 for (var pos = frameWidth; pos < width; pos += frameWidth) { | 155 for (var pos = frameWidth; pos < width; pos += frameWidth) { |
127 var time = pos * scale + zeroTime; | 156 var time = pos * scale + zeroTime; |
128 var index = frames.upperBound(time, comparator) - 1; | 157 var index = frames.upperBound(time, comparator) - 1; |
129 var element = index >= 0 ? createElementForFrame.call(this, frames[i ndex], true) : createEmptyElement.call(this); | 158 var element = index >= 0 ? createElementForFrame.call(this, frames[i ndex], true) : createEmptyElement.call(this); |
130 element.style.width = frameWidth + "px"; | 159 element.style.width = frameWidth + "px"; |
131 } | 160 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
174 | 203 |
175 setFetching: function() | 204 setFetching: function() |
176 { | 205 { |
177 this._label.textContent = WebInspector.UIString("Fetching frames..."); | 206 this._label.textContent = WebInspector.UIString("Fetching frames..."); |
178 }, | 207 }, |
179 | 208 |
180 __proto__: WebInspector.HBox.prototype | 209 __proto__: WebInspector.HBox.prototype |
181 } | 210 } |
182 | 211 |
183 /** | 212 /** |
213 * @param {!Image} image | |
214 * @param {!WebInspector.FilmStripModel.Frame} frame | |
215 */ | |
216 WebInspector.FilmStripView._loadImageForFrame = function(image, frame) | |
alph
2015/06/17 09:41:59
Can't find where is it used.
| |
217 { | |
218 frame.requestImageData(onGotImageData); | |
219 | |
220 /** | |
221 * @param {?string} data | |
222 */ | |
223 function onGotImageData(data) | |
224 { | |
225 if (data) | |
226 image.src = "data:image/jpg;base64," + data; | |
227 } | |
228 } | |
229 | |
230 /** | |
184 * @constructor | 231 * @constructor |
185 * @extends {WebInspector.DialogDelegate} | 232 * @extends {WebInspector.DialogDelegate} |
186 * @param {!WebInspector.FilmStripModel.Frame} filmStripFrame | 233 * @param {!WebInspector.FilmStripModel.Frame} filmStripFrame |
187 * @param {number=} zeroTime | 234 * @param {number=} zeroTime |
188 */ | 235 */ |
189 WebInspector.FilmStripView.DialogDelegate = function(filmStripFrame, zeroTime) | 236 WebInspector.FilmStripView.DialogDelegate = function(filmStripFrame, zeroTime) |
190 { | 237 { |
191 WebInspector.DialogDelegate.call(this); | 238 WebInspector.DialogDelegate.call(this); |
192 var shadowRoot = WebInspector.createShadowRootWithCoreStyles(this.element); | 239 var shadowRoot = WebInspector.createShadowRootWithCoreStyles(this.element); |
193 shadowRoot.appendChild(WebInspector.Widget.createStyleElement("components_la zy/filmStripDialog.css")); | 240 shadowRoot.appendChild(WebInspector.Widget.createStyleElement("components_la zy/filmStripDialog.css")); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
273 | 320 |
274 _onLastFrame: function() | 321 _onLastFrame: function() |
275 { | 322 { |
276 this._index = this._frames.length - 1; | 323 this._index = this._frames.length - 1; |
277 this._render(); | 324 this._render(); |
278 }, | 325 }, |
279 | 326 |
280 _render: function() | 327 _render: function() |
281 { | 328 { |
282 var frame = this._frames[this._index]; | 329 var frame = this._frames[this._index]; |
283 this._imageElement.src = "data:image/jpg;base64," + frame.imageData; | 330 frame.requestImageData(onGotImageData.bind(this)); |
331 /** | |
332 * @param {?string} data | |
333 * @this {WebInspector.DialogDelegate} | |
334 */ | |
335 function onGotImageData(data) | |
336 { | |
337 if (data) | |
338 this._imageElement.src = "data:image/jpg;base64," + data; | |
339 } | |
284 this._timeLabel.textContent = Number.millisToString(frame.timestamp - th is._zeroTime); | 340 this._timeLabel.textContent = Number.millisToString(frame.timestamp - th is._zeroTime); |
285 }, | 341 }, |
286 | 342 |
287 __proto__: WebInspector.DialogDelegate.prototype | 343 __proto__: WebInspector.DialogDelegate.prototype |
288 } | 344 } |
OLD | NEW |