Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(189)

Side by Side Diff: Source/devtools/front_end/components_lazy/FilmStripView.js

Issue 1184383002: DevTools: adopt FilmStripModel to new screenshot recorder trace format (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: get rid of callback in createFrameElement() Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 * @return {!Element} 60 * @return {!Promise<!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 var imageElement = element.createChild("div", "thumbnail").createChild(" img");
67 frame.imageDataPromise().then(WebInspector.FilmStripView._setImageData.b ind(null, imageElement));
alph 2015/06/22 12:36:21 you can remove this line.
67 element.createChild("div", "time").textContent = Number.millisToString(t ime - this._zeroTime); 68 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); 69 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); 70 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); 71 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); 72 element.addEventListener("dblclick", this._onDoubleClick.bind(this, fram e), false);
72 return element; 73
74 return frame.imageDataPromise().then(WebInspector.FilmStripView._setImag eData.bind(null, imageElement)).then(returnElement);
75 function returnElement()
alph 2015/06/22 12:36:21 nit: annotate? honestly, I'd just inline it into t
76 {
77 return element;
78 }
73 }, 79 },
74 80
75 /** 81 /**
76 * @param {number} time 82 * @param {number} time
77 * @return {!WebInspector.FilmStripModel.Frame} 83 * @return {!WebInspector.FilmStripModel.Frame}
78 */ 84 */
79 frameByTime: function(time) 85 frameByTime: function(time)
80 { 86 {
81 /** 87 /**
82 * @param {number} time 88 * @param {number} time
(...skipping 11 matching lines...) Expand all
94 return frames[index]; 100 return frames[index];
95 }, 101 },
96 102
97 update: function() 103 update: function()
98 { 104 {
99 if (!this._model) 105 if (!this._model)
100 return; 106 return;
101 var frames = this._model.frames(); 107 var frames = this._model.frames();
102 if (!frames.length) 108 if (!frames.length)
103 return; 109 return;
110
104 this.contentElement.removeChildren(); 111 this.contentElement.removeChildren();
105 this._statusLabel.remove(); 112 this._statusLabel.remove();
106 113
107 if (this._mode === WebInspector.FilmStripView.Modes.FrameBased) { 114 if (this._mode === WebInspector.FilmStripView.Modes.FrameBased) {
108 frames.map(this.createFrameElement.bind(this)).forEach(this.contentE lement.appendChild.bind(this.contentElement)); 115 Promise.all(frames.map(this.createFrameElement.bind(this))).spread(t his.contentElement.appendChildren.bind(this.contentElement));
109 return; 116 return;
110 } 117 }
111 118
112 var width = this.contentElement.clientWidth; 119 var width = this.contentElement.clientWidth;
113 var scale = this._spanTime / width; 120 var scale = this._spanTime / width;
114 var element0 = this.createFrameElement(frames[0]); // Calculate frame w idth basing on the first frame. 121 this.createFrameElement(frames[0]).then(continueWhenFrameImageLoaded.bin d(this)); // Calculate frame width basing on the first frame.
115 var frameWidth = Math.ceil(WebInspector.measurePreferredSize(element0, t his.contentElement).width);
116 if (!frameWidth)
117 return;
118 122
119 for (var pos = frameWidth; pos < width; pos += frameWidth) { 123 /**
120 var time = pos * scale + this._zeroTime; 124 * @this {WebInspector.FilmStripView}
121 var frame = this.frameByTime(time); 125 * @param {!Element} element0
122 var element = this.contentElement.appendChild(this.createFrameElemen t(frame)); 126 */
123 element.style.width = frameWidth + "px"; 127 function continueWhenFrameImageLoaded(element0)
128 {
129 var frameWidth = Math.ceil(WebInspector.measurePreferredSize(element 0, this.contentElement).width);
130 if (!frameWidth)
131 return;
132
133 var contentElement = this.contentElement;
134 for (var pos = frameWidth; pos < width; pos += frameWidth) {
135 var time = pos * scale + this._zeroTime;
136 this.createFrameElement(this.frameByTime(time)).then(appendEleme nt);
137 }
138
139 /**
140 * @param {!Element} element
141 */
142 function appendElement(element)
alph 2015/06/22 12:36:21 Are these called in the proper order?
143 {
144 element.style.width = frameWidth + "px";
145 contentElement.appendChild(element);
146 }
124 } 147 }
125 }, 148 },
126 149
127 /** 150 /**
128 * @override 151 * @override
129 */ 152 */
130 onResize: function() 153 onResize: function()
131 { 154 {
132 if (this._mode === WebInspector.FilmStripView.Modes.FrameBased) 155 if (this._mode === WebInspector.FilmStripView.Modes.FrameBased)
133 return; 156 return;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 190
168 setFetching: function() 191 setFetching: function()
169 { 192 {
170 this._statusLabel.textContent = WebInspector.UIString("Fetching frames.. ."); 193 this._statusLabel.textContent = WebInspector.UIString("Fetching frames.. .");
171 }, 194 },
172 195
173 __proto__: WebInspector.HBox.prototype 196 __proto__: WebInspector.HBox.prototype
174 } 197 }
175 198
176 /** 199 /**
200 * @param {!Element} imageElement
201 * @param {?string} data
202 */
203 WebInspector.FilmStripView._setImageData = function(imageElement, data)
204 {
205 if (data)
206 imageElement.src = "data:image/jpg;base64," + data;
207 }
208
209 /**
177 * @constructor 210 * @constructor
178 * @extends {WebInspector.DialogDelegate} 211 * @extends {WebInspector.DialogDelegate}
179 * @param {!WebInspector.FilmStripModel.Frame} filmStripFrame 212 * @param {!WebInspector.FilmStripModel.Frame} filmStripFrame
180 * @param {number=} zeroTime 213 * @param {number=} zeroTime
181 */ 214 */
182 WebInspector.FilmStripView.DialogDelegate = function(filmStripFrame, zeroTime) 215 WebInspector.FilmStripView.DialogDelegate = function(filmStripFrame, zeroTime)
183 { 216 {
184 WebInspector.DialogDelegate.call(this); 217 WebInspector.DialogDelegate.call(this);
185 var shadowRoot = WebInspector.createShadowRootWithCoreStyles(this.element); 218 var shadowRoot = WebInspector.createShadowRootWithCoreStyles(this.element);
186 shadowRoot.appendChild(WebInspector.Widget.createStyleElement("components_la zy/filmStripDialog.css")); 219 shadowRoot.appendChild(WebInspector.Widget.createStyleElement("components_la zy/filmStripDialog.css"));
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 299
267 _onLastFrame: function() 300 _onLastFrame: function()
268 { 301 {
269 this._index = this._frames.length - 1; 302 this._index = this._frames.length - 1;
270 this._render(); 303 this._render();
271 }, 304 },
272 305
273 _render: function() 306 _render: function()
274 { 307 {
275 var frame = this._frames[this._index]; 308 var frame = this._frames[this._index];
276 this._imageElement.src = "data:image/jpg;base64," + frame.imageData; 309 frame.imageDataPromise().then(WebInspector.FilmStripView._setImageData.b ind(null, this._imageElement));
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 }
OLDNEW
« no previous file with comments | « Source/devtools/front_end/components_lazy/FilmStripModel.js ('k') | Source/devtools/front_end/sdk/TracingModel.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698