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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: Source/devtools/front_end/components_lazy/FilmStripView.js
diff --git a/Source/devtools/front_end/components_lazy/FilmStripView.js b/Source/devtools/front_end/components_lazy/FilmStripView.js
index f465199a78133c6e3611504a7015d46a87d0775f..b52a81abf410e57aba32cf27cd9ab297f437542e 100644
--- a/Source/devtools/front_end/components_lazy/FilmStripView.js
+++ b/Source/devtools/front_end/components_lazy/FilmStripView.js
@@ -57,19 +57,25 @@ WebInspector.FilmStripView.prototype = {
/**
* @param {!WebInspector.FilmStripModel.Frame} frame
- * @return {!Element}
+ * @return {!Promise<!Element>}
*/
createFrameElement: function(frame)
{
var time = frame.timestamp;
var element = createElementWithClass("div", "frame");
- element.createChild("div", "thumbnail").createChild("img").src = "data:image/jpg;base64," + frame.imageData;
+ var imageElement = element.createChild("div", "thumbnail").createChild("img");
+ frame.imageDataPromise().then(WebInspector.FilmStripView._setImageData.bind(null, imageElement));
alph 2015/06/22 12:36:21 you can remove this line.
element.createChild("div", "time").textContent = Number.millisToString(time - this._zeroTime);
element.addEventListener("mousedown", this._onMouseEvent.bind(this, WebInspector.FilmStripView.Events.FrameSelected, time), false);
element.addEventListener("mouseenter", this._onMouseEvent.bind(this, WebInspector.FilmStripView.Events.FrameEnter, time), false);
element.addEventListener("mouseout", this._onMouseEvent.bind(this, WebInspector.FilmStripView.Events.FrameExit, time), false);
element.addEventListener("dblclick", this._onDoubleClick.bind(this, frame), false);
- return element;
+
+ return frame.imageDataPromise().then(WebInspector.FilmStripView._setImageData.bind(null, imageElement)).then(returnElement);
+ function returnElement()
alph 2015/06/22 12:36:21 nit: annotate? honestly, I'd just inline it into t
+ {
+ return element;
+ }
},
/**
@@ -101,26 +107,43 @@ WebInspector.FilmStripView.prototype = {
var frames = this._model.frames();
if (!frames.length)
return;
+
this.contentElement.removeChildren();
this._statusLabel.remove();
if (this._mode === WebInspector.FilmStripView.Modes.FrameBased) {
- frames.map(this.createFrameElement.bind(this)).forEach(this.contentElement.appendChild.bind(this.contentElement));
+ Promise.all(frames.map(this.createFrameElement.bind(this))).spread(this.contentElement.appendChildren.bind(this.contentElement));
return;
}
var width = this.contentElement.clientWidth;
var scale = this._spanTime / width;
- var element0 = this.createFrameElement(frames[0]); // Calculate frame width basing on the first frame.
- var frameWidth = Math.ceil(WebInspector.measurePreferredSize(element0, this.contentElement).width);
- if (!frameWidth)
- return;
+ this.createFrameElement(frames[0]).then(continueWhenFrameImageLoaded.bind(this)); // Calculate frame width basing on the first frame.
- for (var pos = frameWidth; pos < width; pos += frameWidth) {
- var time = pos * scale + this._zeroTime;
- var frame = this.frameByTime(time);
- var element = this.contentElement.appendChild(this.createFrameElement(frame));
- element.style.width = frameWidth + "px";
+ /**
+ * @this {WebInspector.FilmStripView}
+ * @param {!Element} element0
+ */
+ function continueWhenFrameImageLoaded(element0)
+ {
+ var frameWidth = Math.ceil(WebInspector.measurePreferredSize(element0, this.contentElement).width);
+ if (!frameWidth)
+ return;
+
+ var contentElement = this.contentElement;
+ for (var pos = frameWidth; pos < width; pos += frameWidth) {
+ var time = pos * scale + this._zeroTime;
+ this.createFrameElement(this.frameByTime(time)).then(appendElement);
+ }
+
+ /**
+ * @param {!Element} element
+ */
+ function appendElement(element)
alph 2015/06/22 12:36:21 Are these called in the proper order?
+ {
+ element.style.width = frameWidth + "px";
+ contentElement.appendChild(element);
+ }
}
},
@@ -174,6 +197,16 @@ WebInspector.FilmStripView.prototype = {
}
/**
+ * @param {!Element} imageElement
+ * @param {?string} data
+ */
+WebInspector.FilmStripView._setImageData = function(imageElement, data)
+{
+ if (data)
+ imageElement.src = "data:image/jpg;base64," + data;
+}
+
+/**
* @constructor
* @extends {WebInspector.DialogDelegate}
* @param {!WebInspector.FilmStripModel.Frame} filmStripFrame
@@ -273,7 +306,7 @@ WebInspector.FilmStripView.DialogDelegate.prototype = {
_render: function()
{
var frame = this._frames[this._index];
- this._imageElement.src = "data:image/jpg;base64," + frame.imageData;
+ frame.imageDataPromise().then(WebInspector.FilmStripView._setImageData.bind(null, this._imageElement));
this._timeLabel.textContent = Number.millisToString(frame.timestamp - this._zeroTime);
},
« 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