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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
50 var frames = filmStripModel.frames(); | 50 var frames = filmStripModel.frames(); |
51 if (!frames.length) { | 51 if (!frames.length) { |
52 this.reset(); | 52 this.reset(); |
53 return; | 53 return; |
54 } | 54 } |
55 this.update(); | 55 this.update(); |
56 }, | 56 }, |
57 | 57 |
58 /** | 58 /** |
59 * @param {!WebInspector.FilmStripModel.Frame} frame | 59 * @param {!WebInspector.FilmStripModel.Frame} frame |
60 * @param {function()=} imageLoadedCallback | |
60 * @return {!Element} | 61 * @return {!Element} |
61 */ | 62 */ |
62 createFrameElement: function(frame) | 63 createFrameElement: function(frame, imageLoadedCallback) |
63 { | 64 { |
64 var time = frame.timestamp; | 65 var time = frame.timestamp; |
65 var element = createElementWithClass("div", "frame"); | 66 var element = createElementWithClass("div", "frame"); |
66 element.createChild("div", "thumbnail").createChild("img").src = "data:i mage/jpg;base64," + frame.imageData; | 67 var imageElement = element.createChild("div", "thumbnail").createChild(" img"); |
68 if (imageLoadedCallback) | |
69 imageElement.addEventListener("load", imageLoadedCallback); | |
70 frame.imageDataPromise().then(WebInspector.FilmStripView._setImageData.b ind(null, imageElement)); | |
67 element.createChild("div", "time").textContent = Number.millisToString(t ime - this._zeroTime); | 71 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); | 72 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); | 73 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); | 74 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); | 75 element.addEventListener("dblclick", this._onDoubleClick.bind(this, fram e), false); |
76 | |
72 return element; | 77 return element; |
73 }, | 78 }, |
74 | 79 |
75 /** | 80 /** |
76 * @param {number} time | 81 * @param {number} time |
77 * @return {!WebInspector.FilmStripModel.Frame} | 82 * @return {!WebInspector.FilmStripModel.Frame} |
78 */ | 83 */ |
79 frameByTime: function(time) | 84 frameByTime: function(time) |
80 { | 85 { |
81 /** | 86 /** |
(...skipping 12 matching lines...) Expand all Loading... | |
94 return frames[index]; | 99 return frames[index]; |
95 }, | 100 }, |
96 | 101 |
97 update: function() | 102 update: function() |
98 { | 103 { |
99 if (!this._model) | 104 if (!this._model) |
100 return; | 105 return; |
101 var frames = this._model.frames(); | 106 var frames = this._model.frames(); |
102 if (!frames.length) | 107 if (!frames.length) |
103 return; | 108 return; |
109 | |
104 this.contentElement.removeChildren(); | 110 this.contentElement.removeChildren(); |
105 this._statusLabel.remove(); | 111 this._statusLabel.remove(); |
106 | 112 |
107 if (this._mode === WebInspector.FilmStripView.Modes.FrameBased) { | 113 if (this._mode === WebInspector.FilmStripView.Modes.FrameBased) { |
108 frames.map(this.createFrameElement.bind(this)).forEach(this.contentE lement.appendChild.bind(this.contentElement)); | 114 frames.map(this.createFrameElement.bind(this)).forEach(this.contentE lement.appendChild.bind(this.contentElement)); |
alph
2015/06/19 14:22:37
Hmm, how does it work?
Array.map passes index as t
| |
109 return; | 115 return; |
110 } | 116 } |
111 | 117 |
112 var width = this.contentElement.clientWidth; | 118 var width = this.contentElement.clientWidth; |
113 var scale = this._spanTime / width; | 119 var scale = this._spanTime / width; |
114 var element0 = this.createFrameElement(frames[0]); // Calculate frame w idth basing on the first frame. | 120 var element0 = this.createFrameElement(frames[0], continueWhenFrameImage Loaded.bind(this)); // Calculate frame width basing on the first frame. |
alph
2015/06/19 14:22:37
Why don't stay with your previous schema, but use
| |
115 var frameWidth = Math.ceil(WebInspector.measurePreferredSize(element0, t his.contentElement).width); | |
116 if (!frameWidth) | |
117 return; | |
118 | 121 |
119 for (var pos = frameWidth; pos < width; pos += frameWidth) { | 122 /** |
120 var time = pos * scale + this._zeroTime; | 123 * @this {WebInspector.FilmStripView} |
121 var frame = this.frameByTime(time); | 124 */ |
122 var element = this.contentElement.appendChild(this.createFrameElemen t(frame)); | 125 function continueWhenFrameImageLoaded() |
123 element.style.width = frameWidth + "px"; | 126 { |
127 var frameWidth = Math.ceil(WebInspector.measurePreferredSize(element 0, this.contentElement).width); | |
128 if (!frameWidth) | |
129 return; | |
130 | |
131 for (var pos = frameWidth; pos < width; pos += frameWidth) { | |
132 var time = pos * scale + this._zeroTime; | |
133 var frame = this.frameByTime(time); | |
134 var element = this.contentElement.appendChild(this.createFrameEl ement(frame)); | |
135 element.style.width = frameWidth + "px"; | |
136 } | |
124 } | 137 } |
125 }, | 138 }, |
126 | 139 |
127 /** | 140 /** |
128 * @override | 141 * @override |
129 */ | 142 */ |
130 onResize: function() | 143 onResize: function() |
131 { | 144 { |
132 if (this._mode === WebInspector.FilmStripView.Modes.FrameBased) | 145 if (this._mode === WebInspector.FilmStripView.Modes.FrameBased) |
133 return; | 146 return; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
167 | 180 |
168 setFetching: function() | 181 setFetching: function() |
169 { | 182 { |
170 this._statusLabel.textContent = WebInspector.UIString("Fetching frames.. ."); | 183 this._statusLabel.textContent = WebInspector.UIString("Fetching frames.. ."); |
171 }, | 184 }, |
172 | 185 |
173 __proto__: WebInspector.HBox.prototype | 186 __proto__: WebInspector.HBox.prototype |
174 } | 187 } |
175 | 188 |
176 /** | 189 /** |
190 * @param {!Element} imageElement | |
191 * @param {?string} data | |
192 */ | |
193 WebInspector.FilmStripView._setImageData = function(imageElement, data) | |
194 { | |
195 if (data) | |
196 imageElement.src = "data:image/jpg;base64," + data; | |
197 } | |
198 | |
199 /** | |
177 * @constructor | 200 * @constructor |
178 * @extends {WebInspector.DialogDelegate} | 201 * @extends {WebInspector.DialogDelegate} |
179 * @param {!WebInspector.FilmStripModel.Frame} filmStripFrame | 202 * @param {!WebInspector.FilmStripModel.Frame} filmStripFrame |
180 * @param {number=} zeroTime | 203 * @param {number=} zeroTime |
181 */ | 204 */ |
182 WebInspector.FilmStripView.DialogDelegate = function(filmStripFrame, zeroTime) | 205 WebInspector.FilmStripView.DialogDelegate = function(filmStripFrame, zeroTime) |
183 { | 206 { |
184 WebInspector.DialogDelegate.call(this); | 207 WebInspector.DialogDelegate.call(this); |
185 var shadowRoot = WebInspector.createShadowRootWithCoreStyles(this.element); | 208 var shadowRoot = WebInspector.createShadowRootWithCoreStyles(this.element); |
186 shadowRoot.appendChild(WebInspector.Widget.createStyleElement("components_la zy/filmStripDialog.css")); | 209 shadowRoot.appendChild(WebInspector.Widget.createStyleElement("components_la zy/filmStripDialog.css")); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
266 | 289 |
267 _onLastFrame: function() | 290 _onLastFrame: function() |
268 { | 291 { |
269 this._index = this._frames.length - 1; | 292 this._index = this._frames.length - 1; |
270 this._render(); | 293 this._render(); |
271 }, | 294 }, |
272 | 295 |
273 _render: function() | 296 _render: function() |
274 { | 297 { |
275 var frame = this._frames[this._index]; | 298 var frame = this._frames[this._index]; |
276 this._imageElement.src = "data:image/jpg;base64," + frame.imageData; | 299 frame.imageDataPromise().then(WebInspector.FilmStripView._setImageData.b ind(null, this._imageElement)); |
277 this._timeLabel.textContent = Number.millisToString(frame.timestamp - th is._zeroTime); | 300 this._timeLabel.textContent = Number.millisToString(frame.timestamp - th is._zeroTime); |
278 }, | 301 }, |
279 | 302 |
280 __proto__: WebInspector.DialogDelegate.prototype | 303 __proto__: WebInspector.DialogDelegate.prototype |
281 } | 304 } |
OLD | NEW |