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

Unified Diff: Source/devtools/front_end/ui/UIUtils.js

Issue 450973002: DevTools: animate changes to flame chart window. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 4 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/ui/UIUtils.js
diff --git a/Source/devtools/front_end/ui/UIUtils.js b/Source/devtools/front_end/ui/UIUtils.js
index 972051dcc68fa511edb4d7b292f4de2db86d1ddb..b963877b595f496d2df0fdfd5edbdc6538c12d67 100644
--- a/Source/devtools/front_end/ui/UIUtils.js
+++ b/Source/devtools/front_end/ui/UIUtils.js
@@ -916,6 +916,51 @@ WebInspector.invokeOnceAfterBatchUpdate = function(object, method)
WebInspector._postUpdateHandlers.add(object, method);
}
+/**
+ * @param {!Function} func
+ * @param {!Array.<{from:number, to:number}>} params
+ * @param {number} frames
+ * @param {function()=} animationComplete
+ * @return {function()}
+ */
+WebInspector.animateFunction = function(func, params, frames, animationComplete)
+{
+ var values = new Array(params.length);
+ var deltas = new Array(params.length);
+ for (var i = 0; i < params.length; ++i) {
+ values[i] = params[i].from;
+ deltas[i] = (params[i].to - params[i].from) / frames;
+ }
+
+ var raf = requestAnimationFrame(animationStep);
+
+ var framesLeft = frames;
+
+ function animationStep()
+ {
+ if (--framesLeft < 0) {
+ if (animationComplete)
+ animationComplete();
+ return;
+ }
+ for (var i = 0; i < params.length; ++i) {
+ if (params[i].to > params[i].from)
+ values[i] = Number.constrain(values[i] + deltas[i], params[i].from, params[i].to);
+ else
+ values[i] = Number.constrain(values[i] + deltas[i], params[i].to, params[i].from);
+ }
+ func.apply(null, values);
+ raf = window.requestAnimationFrame(animationStep);
+ }
+
+ function cancelAnimation()
+ {
+ window.cancelAnimationFrame(raf);
+ }
+
+ return cancelAnimation;
+}
+
;(function() {
function windowLoaded()

Powered by Google App Engine
This is Rietveld 408576698