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 promises = []; |
| 68 for (var frame of frames) |
| 69 promises.push(frame.imageDataPromise().then(setImageData.bind(null,
frame))); |
| 70 |
| 71 Promise.all(promises).then(this._updateWhenImagesLoaded.bind(this, image
DataForFrame)); |
| 72 /** |
| 73 * @param {!WebInspector.FilmStripModel.Frame} frame |
| 74 * @param {?string} data |
| 75 */ |
| 76 function setImageData(frame, data) |
| 77 { |
| 78 if (data) |
| 79 imageDataForFrame.set(frame, data); |
| 80 } |
| 81 }, |
| 82 |
| 83 /** |
| 84 * @param {!Map<!WebInspector.FilmStripModel.Frame, string>} imageDataForFra
me |
| 85 */ |
| 86 _updateWhenImagesLoaded: function(imageDataForFrame) |
| 87 { |
64 this.contentElement.removeChildren(); | 88 this.contentElement.removeChildren(); |
65 this._label.remove(); | 89 this._label.remove(); |
66 var zeroTime = this._zeroTime; | 90 var zeroTime = this._zeroTime; |
| 91 var frames = this._model.frames(); |
67 | 92 |
68 /** | 93 /** |
69 * @param {!WebInspector.FilmStripModel.Frame} frame | 94 * @param {!WebInspector.FilmStripModel.Frame} frame |
70 * @param {boolean=} skipTimeLabel | 95 * @param {boolean=} skipTimeLabel |
71 * @return {!Element} | 96 * @return {!Element} |
72 * @this {WebInspector.FilmStripView} | 97 * @this {WebInspector.FilmStripView} |
73 */ | 98 */ |
74 function createElementForFrame(frame, skipTimeLabel) | 99 function createElementForFrame(frame, skipTimeLabel) |
75 { | 100 { |
76 var time = frame.timestamp; | 101 var time = frame.timestamp; |
77 var element = createElementWithClass("div", "frame"); | 102 var element = createElementWithClass("div", "frame"); |
78 element.createChild("div", "thumbnail").createChild("img").src = "da
ta:image/jpg;base64," + frame.imageData; | 103 element.createChild("div", "thumbnail").createChild("img").src = "da
ta:image/jpg;base64," + imageDataForFrame.get(frame); |
79 if (!skipTimeLabel) | 104 if (!skipTimeLabel) |
80 element.createChild("div", "time").textContent = Number.millisTo
String(time - zeroTime); | 105 element.createChild("div", "time").textContent = Number.millisTo
String(time - zeroTime); |
81 element.addEventListener("mousedown", this._onMouseEvent.bind(this,
WebInspector.FilmStripView.Events.FrameSelected, time), false); | 106 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); | 107 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); | 108 element.addEventListener("mouseout", this._onMouseEvent.bind(this, W
ebInspector.FilmStripView.Events.FrameExit, time), false); |
84 element.addEventListener("dblclick", this._onDoubleClick.bind(this,
frame), false); | 109 element.addEventListener("dblclick", this._onDoubleClick.bind(this,
frame), false); |
85 this.contentElement.appendChild(element); | 110 this.contentElement.appendChild(element); |
86 return element; | 111 return element; |
87 } | 112 } |
88 | 113 |
(...skipping 22 matching lines...) Expand all Loading... |
111 function comparator(time, frame) | 136 function comparator(time, frame) |
112 { | 137 { |
113 return time - frame.timestamp; | 138 return time - frame.timestamp; |
114 } | 139 } |
115 | 140 |
116 var width = this.contentElement.clientWidth; | 141 var width = this.contentElement.clientWidth; |
117 var scale = this._spanTime / width; | 142 var scale = this._spanTime / width; |
118 | 143 |
119 // Calculate frame width basing on the first frame. | 144 // Calculate frame width basing on the first frame. |
120 var tempElement = createElementWithClass("div", "frame"); | 145 var tempElement = createElementWithClass("div", "frame"); |
121 tempElement.createChild("div", "thumbnail").createChild("img").src = "da
ta:image/jpg;base64," + frames[0].imageData; | 146 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); | 147 var frameWidth = Math.ceil(WebInspector.measurePreferredSize(tempElement
, this.contentElement).width); |
123 if (!frameWidth) | 148 if (!frameWidth) |
124 return; | 149 return; |
125 | 150 |
126 for (var pos = frameWidth; pos < width; pos += frameWidth) { | 151 for (var pos = frameWidth; pos < width; pos += frameWidth) { |
127 var time = pos * scale + zeroTime; | 152 var time = pos * scale + zeroTime; |
128 var index = frames.upperBound(time, comparator) - 1; | 153 var index = frames.upperBound(time, comparator) - 1; |
129 var element = index >= 0 ? createElementForFrame.call(this, frames[i
ndex], true) : createEmptyElement.call(this); | 154 var element = index >= 0 ? createElementForFrame.call(this, frames[i
ndex], true) : createEmptyElement.call(this); |
130 element.style.width = frameWidth + "px"; | 155 element.style.width = frameWidth + "px"; |
131 } | 156 } |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 | 298 |
274 _onLastFrame: function() | 299 _onLastFrame: function() |
275 { | 300 { |
276 this._index = this._frames.length - 1; | 301 this._index = this._frames.length - 1; |
277 this._render(); | 302 this._render(); |
278 }, | 303 }, |
279 | 304 |
280 _render: function() | 305 _render: function() |
281 { | 306 { |
282 var frame = this._frames[this._index]; | 307 var frame = this._frames[this._index]; |
283 this._imageElement.src = "data:image/jpg;base64," + frame.imageData; | 308 frame.imageDataPromise().then(onGotImageData.bind(this)); |
| 309 /** |
| 310 * @param {?string} data |
| 311 * @this {WebInspector.DialogDelegate} |
| 312 */ |
| 313 function onGotImageData(data) |
| 314 { |
| 315 if (data) |
| 316 this._imageElement.src = "data:image/jpg;base64," + data; |
| 317 } |
284 this._timeLabel.textContent = Number.millisToString(frame.timestamp - th
is._zeroTime); | 318 this._timeLabel.textContent = Number.millisToString(frame.timestamp - th
is._zeroTime); |
285 }, | 319 }, |
286 | 320 |
287 __proto__: WebInspector.DialogDelegate.prototype | 321 __proto__: WebInspector.DialogDelegate.prototype |
288 } | 322 } |
OLD | NEW |