Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 * @constructor | |
| 7 * @param {?WebInspector.DOMModel.AnimationPlayer} animationPlayer | |
| 8 */ | |
| 9 WebInspector.AnimationSection = function(animationPlayer) | |
| 10 { | |
| 11 this.propertiesSection = document.createElement("div"); | |
| 12 this.setAnimationPlayer(animationPlayer); | |
| 13 | |
| 14 this.element = document.createElement("div"); | |
| 15 this.element.className = "styles-section"; | |
| 16 | |
| 17 this.element.appendChild(this._createAnimationControls()); | |
| 18 this.element.appendChild(this.propertiesSection); | |
| 19 } | |
| 20 | |
| 21 WebInspector.AnimationSection.prototype = { | |
| 22 /** | |
| 23 * @private | |
| 24 */ | |
| 25 _updateCurrentTime: function() | |
| 26 { | |
| 27 /** | |
| 28 * @param {number} currentTime | |
| 29 * @param {boolean} isRunning | |
| 30 * @this {WebInspector.AnimationSection} | |
| 31 */ | |
| 32 function updateSliderCallback(currentTime, isRunning) | |
| 33 { | |
| 34 this.currentTimeSlider.value = this.player.animation().iterationCoun t() == null ? currentTime % this.player.animation().duration() : currentTime; | |
| 35 if (isRunning) | |
| 36 requestAnimationFrame(this._updateCurrentTime.bind(this)); | |
|
vsevik
2014/10/06 16:00:54
I think polling this on each animation frame creat
samli
2014/10/07 05:25:43
Done.
| |
| 37 } | |
| 38 this.player.getCurrentState(updateSliderCallback.bind(this)); | |
| 39 }, | |
| 40 | |
| 41 /** | |
| 42 * @return {!Element} | |
| 43 * @private | |
| 44 */ | |
| 45 _createCurrentTimeSlider: function() | |
| 46 { | |
| 47 /** | |
| 48 * @param {!Event} e | |
| 49 * @this {WebInspector.AnimationSection} | |
| 50 */ | |
| 51 function sliderInputHandler(e) | |
| 52 { | |
| 53 this.player.setCurrentTime(parseFloat(e.target.value), this.setAnima tionPlayer.bind(this)); | |
| 54 } | |
| 55 var iterationDuration = this.player.animation().duration(); | |
| 56 var iterationCount = this.player.animation().iterationCount(); | |
| 57 var slider = document.createElement("input"); | |
| 58 slider.type = "range"; | |
| 59 slider.min = 0; | |
| 60 slider.step = 0.01; | |
| 61 | |
| 62 if (!iterationCount) { | |
| 63 // Infinite iterations | |
| 64 slider.max = iterationDuration; | |
| 65 slider.value = this.player.currentTime() % iterationDuration; | |
| 66 } else { | |
| 67 slider.max = iterationCount * iterationDuration; | |
| 68 slider.value = this.player.currentTime(); | |
| 69 } | |
| 70 | |
| 71 slider.addEventListener("input", sliderInputHandler.bind(this)); | |
| 72 requestAnimationFrame(this._updateCurrentTime.bind(this)); | |
| 73 return slider; | |
| 74 }, | |
| 75 | |
| 76 /** | |
| 77 * @return {!Element} | |
| 78 * @private | |
| 79 */ | |
| 80 _createAnimationControls: function() | |
| 81 { | |
| 82 /** | |
| 83 * @this {WebInspector.AnimationSection} | |
| 84 */ | |
| 85 function pauseButtonHandler() | |
| 86 { | |
| 87 if (this.player.paused()) { | |
| 88 this.player.play(this.setAnimationPlayer.bind(this)); | |
| 89 updatePauseButton.call(this, false); | |
| 90 } else { | |
| 91 this.player.pause(this.setAnimationPlayer.bind(this)); | |
| 92 updatePauseButton.call(this, true); | |
| 93 } | |
| 94 } | |
| 95 | |
| 96 /** | |
| 97 * @param {boolean} paused | |
| 98 * @this {WebInspector.AnimationSection} | |
| 99 */ | |
| 100 function updatePauseButton(paused) | |
| 101 { | |
| 102 this._pauseButton.state = paused; | |
| 103 if (paused) | |
| 104 this._pauseButton.title = WebInspector.UIString("Play animation" ); | |
| 105 else | |
| 106 this._pauseButton.title = WebInspector.UIString("Pause animation "); | |
| 107 } | |
| 108 | |
| 109 this._pauseButton = new WebInspector.StatusBarButton("", "animation-paus e"); | |
| 110 updatePauseButton.call(this, this.player.paused()); | |
| 111 this._pauseButton.addEventListener("click", pauseButtonHandler, this); | |
| 112 | |
| 113 this.currentTimeSlider = this._createCurrentTimeSlider(); | |
| 114 | |
| 115 var controls = document.createElement("div"); | |
| 116 controls.appendChild(this._pauseButton.element); | |
| 117 controls.appendChild(this.currentTimeSlider); | |
| 118 | |
| 119 return controls; | |
| 120 }, | |
| 121 | |
| 122 /** | |
| 123 * @param {?WebInspector.DOMModel.AnimationPlayer} p | |
| 124 */ | |
| 125 setAnimationPlayer: function(p) | |
|
vsevik
2014/10/06 16:00:55
This should be private (name should start with und
samli
2014/10/07 05:25:43
Done.
| |
| 126 { | |
| 127 if (!p || p === this.player) | |
| 128 return; | |
| 129 | |
| 130 this.player = p; | |
| 131 | |
| 132 if (p instanceof WebInspector.DOMModel.AnimationPlayer) { | |
|
vsevik
2014/10/06 16:00:54
Why do you need this check? It seems redundant
samli
2014/10/07 05:25:43
Done.
| |
| 133 this.propertiesSection.removeChildren(); | |
| 134 var animationObject = { | |
| 135 "paused": p.paused(), | |
| 136 "finished": p.finished(), | |
| 137 "start-time": p.startTime(), | |
| 138 "player-playback-rate": p.playbackRate(), | |
| 139 "id": p.id(), | |
| 140 "start-delay": p.animation().startDelay(), | |
| 141 "playback-rate": p.animation().playbackRate(), | |
| 142 "iteration-start": p.animation().iterationStart(), | |
| 143 "iteration-count": p.animation().iterationCount(), | |
| 144 "duration": p.animation().duration(), | |
| 145 "direction": p.animation().direction(), | |
| 146 "fill-mode": p.animation().fillMode(), | |
| 147 "time-fraction": p.animation().timeFraction() | |
| 148 }; | |
| 149 var obj = WebInspector.RemoteObject.fromLocalObject(animationObject) ; | |
| 150 var section = new WebInspector.ObjectPropertiesSection(obj, WebInspe ctor.UIString("Animation Properties")); | |
| 151 this.propertiesSection.appendChild(section.element); | |
| 152 | |
| 153 requestAnimationFrame(this._updateCurrentTime.bind(this)); | |
| 154 } | |
| 155 } | |
| 156 } | |
| OLD | NEW |