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

Side by Side Diff: Source/devtools/front_end/elements/AnimationSection.js

Issue 620783002: Devtools Animations: Basic animation inspection & control in Styles pane (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Review changes for AnimationSection Created 6 years, 2 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
OLDNEW
(Empty)
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5
6 /**
7 * @constructor
8 * @param {?WebInspector.DOMModel.AnimationPlayer} animationPlayer
9 */
10 WebInspector.AnimationSection = function(animationPlayer)
11 {
12 this.propertiesSection = document.createElement("div");
13 this.setAnimationPlayer(animationPlayer);
14
15 this.element = document.createElement("div");
16 this.element.className = "styles-section";
17
18 this.element.appendChild(this._createAnimationControls());
19 this.element.appendChild(this.propertiesSection);
20 }
21
22 WebInspector.AnimationSection.prototype = {
23 /**
24 * @private
25 */
26 _updateCurrentTime: function()
27 {
28 /**
29 * @param {number} currentTime
30 * @param {boolean} isRunning
31 * @this {WebInspector.AnimationSection}
32 */
33 function updateSliderCallback(currentTime, isRunning)
34 {
35 this.currentTimeSlider.value = this.player.animation().iterationCoun t() == null ? currentTime % this.player.animation().duration() : currentTime;
36 if (isRunning)
37 requestAnimationFrame(this._updateCurrentTime.bind(this));
38 }
39 this.player.getCurrentState(updateSliderCallback.bind(this));
40 },
41
42 /**
43 * @return {!Element}
44 * @private
45 */
46 _createCurrentTimeSlider: function()
47 {
48 /**
49 * @param {!Event} e
50 * @this {WebInspector.AnimationSection}
51 */
52 function sliderInputHandler(e)
53 {
54 this.player.setCurrentTime(parseFloat(e.target.value), this.setAnima tionPlayer.bind(this));
55 }
56 var iterationDuration = this.player.animation().duration();
57 var iterationCount = this.player.animation().iterationCount();
58 var slider = document.createElement("input");
59 slider.type = "range";
60 slider.min = 0;
61 slider.step = 0.01;
62
63 if (!iterationCount) {
64 // Infinite iterations
65 slider.max = iterationDuration;
66 slider.value = this.player.currentTime() % iterationDuration;
67 } else {
68 slider.max = iterationCount * iterationDuration;
69 slider.value = this.player.currentTime();
70 }
71
72 slider.addEventListener("input", sliderInputHandler.bind(this));
73 requestAnimationFrame(this._updateCurrentTime.bind(this));
74 return slider;
75 },
76
77 /**
78 * @return {!Element}
79 * @private
80 */
81 _createAnimationControls: function()
82 {
83 /**
84 * @this {WebInspector.AnimationSection}
85 */
86 function pausePlayHandler ()
87 {
88 if (this.player.paused()) {
89 this.player.play(this.setAnimationPlayer.bind(this));
90 pausePlayButton.textContent = WebInspector.UIString("Pause");
91 } else {
92 this.player.pause(this.setAnimationPlayer.bind(this));
93 pausePlayButton.textContent = WebInspector.UIString("Play");
94 }
95 }
96 var controls = document.createElement("div");
97
98 // Pause/play button
99 var pausePlayButton = document.createElement("button");
100 if (this.player.paused())
101 pausePlayButton.textContent = WebInspector.UIString("Play");
102 else
103 pausePlayButton.textContent = WebInspector.UIString("Pause");
104 pausePlayButton.addEventListener("click", pausePlayHandler.bind(this));
105 controls.appendChild(pausePlayButton);
106
107 // Current time slider
108 this.currentTimeSlider = this._createCurrentTimeSlider();
109 controls.appendChild(this.currentTimeSlider);
110
111 return controls;
112 },
113
114 /**
115 * @param {?WebInspector.DOMModel.AnimationPlayer} p
116 */
117 setAnimationPlayer: function(p)
118 {
119 if (!p || p === this.player)
120 return;
121
122 this.player = p;
123
124 if (p instanceof WebInspector.DOMModel.AnimationPlayer) {
125 this.propertiesSection.removeChildren();
126 var animationObject = {
127 "paused": p.paused(),
128 "finished": p.finished(),
129 "start-time": p.startTime(),
130 "player-playback-rate": p.playbackRate(),
131 "id": p.sequenceNumber(),
132 "start-delay": p.animation().startDelay(),
133 "playback-rate": p.animation().playbackRate(),
134 "iteration-start": p.animation().iterationStart(),
135 "iteration-count": p.animation().iterationCount(),
136 "duration": p.animation().duration(),
137 "direction": p.animation().direction(),
138 "fill-mode": p.animation().fillMode(),
139 "time-fraction": p.animation().timeFraction()
140 };
141 var obj = WebInspector.RemoteObject.fromLocalObject(animationObject) ;
142 var section = new WebInspector.ObjectPropertiesSection(obj, WebInspe ctor.UIString("Animation Properties"));
143 this.propertiesSection.appendChild(section.element);
144
145 requestAnimationFrame(this._updateCurrentTime.bind(this));
146 }
147 }
148 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698