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 * @extends {WebInspector.SidebarPane} | |
| 8 */ | |
| 9 WebInspector.AnimationsSidebarPane = function(stylesPane) | |
| 10 { | |
| 11 WebInspector.SidebarPane.call(this, WebInspector.UIString("Animations")); | |
| 12 this._stylesPane = stylesPane; | |
| 13 | |
| 14 this._emptyElement = document.createElement("div"); | |
| 15 this._emptyElement.className = "info"; | |
| 16 this._emptyElement.textContent = WebInspector.UIString("No Animations"); | |
| 17 | |
| 18 this.bodyElement.appendChild(this._emptyElement); | |
| 19 } | |
| 20 | |
| 21 WebInspector.AnimationsSidebarPane.prototype = { | |
| 22 /** | |
| 23 * @param {?WebInspector.DOMNode} node | |
| 24 */ | |
| 25 update: function(node) | |
| 26 { | |
| 27 /** | |
| 28 * @param {?Array.<!WebInspector.DOMModel.AnimationPlayer>} animationPla yers | |
| 29 * @this {WebInspector.AnimationsSidebarPane} | |
| 30 */ | |
| 31 function animationPlayersCallback(animationPlayers) | |
| 32 { | |
| 33 this.bodyElement.removeChildren(); | |
| 34 this._animationSections = []; | |
| 35 if (!animationPlayers || !animationPlayers.length) { | |
| 36 this.bodyElement.appendChild(this._emptyElement); | |
| 37 return; | |
| 38 } | |
| 39 | |
| 40 for (var i = 0; i < animationPlayers.length; ++i) { | |
| 41 var player = animationPlayers[i]; | |
| 42 this._animationSections[i] = new WebInspector.AnimationSection(t his, player); | |
| 43 var separatorElement = this.bodyElement.createChild("div", "side bar-separator"); | |
| 44 var id = player.animation().name() ? player.animation().name() : player.id(); | |
| 45 separatorElement.createTextChild(WebInspector.UIString("Animatio n") + " " + id); | |
| 46 this.bodyElement.appendChild(this._animationSections[i].element) ; | |
| 47 } | |
| 48 } | |
| 49 | |
| 50 if (this._selectedNode == node) { | |
|
vsevik
2014/10/14 09:08:08
We use ===
samli
2014/10/15 08:46:44
Done.
| |
| 51 for (var i = 0; i < this._animationSections.length; ++i) { | |
|
vsevik
2014/10/14 09:08:09
no need to use {} for one line loops / ifs
samli
2014/10/15 08:46:44
Done.
| |
| 52 this._animationSections[i].updateCurrentTime(); | |
| 53 } | |
| 54 return; | |
| 55 } | |
| 56 this._selectedNode = node; | |
| 57 node.animationPlayers(animationPlayersCallback.bind(this)); | |
| 58 }, | |
| 59 __proto__: WebInspector.SidebarPane.prototype | |
| 60 } | |
| 61 | |
| 62 /** | |
| 63 * @constructor | |
| 64 * @param {!WebInspector.AnimationsSidebarPane} parentPane | |
| 65 * @param {?WebInspector.DOMModel.AnimationPlayer} animationPlayer | |
| 66 */ | |
| 67 WebInspector.AnimationSection = function(parentPane, animationPlayer) | |
| 68 { | |
| 69 this._parentPane = parentPane; | |
| 70 this.propertiesSection = document.createElement("div"); | |
| 71 this._setAnimationPlayer(animationPlayer); | |
| 72 | |
| 73 this.element = document.createElement("div"); | |
| 74 this.element.className = "styles-section"; | |
| 75 | |
| 76 this._updateThrottler = new WebInspector.Throttler(WebInspector.AnimationSec tion.updateTimeout); | |
| 77 this.element.appendChild(this._createAnimationControls()); | |
| 78 this.element.appendChild(this.propertiesSection); | |
| 79 } | |
| 80 | |
| 81 WebInspector.AnimationSection.updateTimeout = 100; | |
| 82 | |
| 83 WebInspector.AnimationSection.prototype = { | |
| 84 updateCurrentTime: function() | |
| 85 { | |
| 86 this._updateThrottler.schedule(this._updateCurrentTime.bind(this), false ); | |
| 87 }, | |
| 88 | |
| 89 /** | |
| 90 * @param {!WebInspector.Throttler.FinishCallback} finishCallback | |
| 91 * @private | |
|
vsevik
2014/10/14 09:08:08
we do not use @private annotations.
samli
2014/10/15 08:46:44
Done.
| |
| 92 */ | |
| 93 _updateCurrentTime: function(finishCallback) | |
| 94 { | |
| 95 /** | |
| 96 * @param {number} currentTime | |
| 97 * @param {boolean} isRunning | |
| 98 * @this {WebInspector.AnimationSection} | |
| 99 */ | |
| 100 function updateSliderCallback(currentTime, isRunning) | |
| 101 { | |
| 102 this.currentTimeSlider.value = this.player.animation().iterationCoun t() == null ? currentTime % this.player.animation().duration() : currentTime; | |
| 103 finishCallback(); | |
| 104 if (isRunning && this._parentPane.isShowing()) | |
| 105 this.updateCurrentTime(); | |
| 106 } | |
| 107 this.player.getCurrentState(updateSliderCallback.bind(this)); | |
| 108 }, | |
| 109 | |
| 110 /** | |
| 111 * @return {!Element} | |
| 112 * @private | |
| 113 */ | |
| 114 _createCurrentTimeSlider: function() | |
| 115 { | |
| 116 /** | |
| 117 * @param {!Event} e | |
| 118 * @this {WebInspector.AnimationSection} | |
| 119 */ | |
| 120 function sliderInputHandler(e) | |
| 121 { | |
| 122 this.player.setCurrentTime(parseFloat(e.target.value), this._setAnim ationPlayer.bind(this)); | |
| 123 } | |
|
vsevik
2014/10/14 09:08:08
Please add a blank line after a funciton
samli
2014/10/15 08:46:44
Done.
| |
| 124 var iterationDuration = this.player.animation().duration(); | |
| 125 var iterationCount = this.player.animation().iterationCount(); | |
| 126 var slider = document.createElement("input"); | |
| 127 slider.type = "range"; | |
| 128 slider.min = 0; | |
| 129 slider.step = 0.01; | |
| 130 | |
| 131 if (!iterationCount) { | |
| 132 // Infinite iterations | |
| 133 slider.max = iterationDuration; | |
| 134 slider.value = this.player.currentTime() % iterationDuration; | |
| 135 } else { | |
| 136 slider.max = iterationCount * iterationDuration; | |
| 137 slider.value = this.player.currentTime(); | |
| 138 } | |
| 139 | |
| 140 slider.addEventListener("input", sliderInputHandler.bind(this)); | |
| 141 this.updateCurrentTime(); | |
| 142 return slider; | |
| 143 }, | |
| 144 | |
| 145 /** | |
| 146 * @return {!Element} | |
| 147 * @private | |
| 148 */ | |
| 149 _createAnimationControls: function() | |
| 150 { | |
| 151 /** | |
| 152 * @this {WebInspector.AnimationSection} | |
| 153 */ | |
| 154 function pauseButtonHandler() | |
| 155 { | |
| 156 if (this.player.paused()) { | |
| 157 this.player.play(this._setAnimationPlayer.bind(this)); | |
| 158 updatePauseButton.call(this, false); | |
| 159 this.updateCurrentTime(); | |
| 160 } else { | |
| 161 this.player.pause(this._setAnimationPlayer.bind(this)); | |
| 162 updatePauseButton.call(this, true); | |
| 163 } | |
| 164 } | |
| 165 | |
| 166 /** | |
| 167 * @param {boolean} paused | |
| 168 * @this {WebInspector.AnimationSection} | |
| 169 */ | |
| 170 function updatePauseButton(paused) | |
| 171 { | |
| 172 this._pauseButton.state = paused; | |
| 173 if (paused) | |
| 174 this._pauseButton.title = WebInspector.UIString("Play animation" ); | |
|
vsevik
2014/10/14 09:08:09
this._pauseButton.title = paused ? WebInspector.UI
samli
2014/10/15 08:46:44
Done.
| |
| 175 else | |
| 176 this._pauseButton.title = WebInspector.UIString("Pause animation "); | |
| 177 } | |
| 178 | |
| 179 this._pauseButton = new WebInspector.StatusBarButton("", "animation-paus e"); | |
| 180 updatePauseButton.call(this, this.player.paused()); | |
| 181 this._pauseButton.addEventListener("click", pauseButtonHandler, this); | |
| 182 | |
| 183 this.currentTimeSlider = this._createCurrentTimeSlider(); | |
| 184 | |
| 185 var controls = document.createElement("div"); | |
| 186 controls.appendChild(this._pauseButton.element); | |
| 187 controls.appendChild(this.currentTimeSlider); | |
| 188 | |
| 189 return controls; | |
| 190 }, | |
| 191 | |
| 192 /** | |
| 193 * @param {?WebInspector.DOMModel.AnimationPlayer} p | |
| 194 * @private | |
| 195 */ | |
| 196 _setAnimationPlayer: function(p) | |
| 197 { | |
| 198 if (!p || p === this.player) | |
| 199 return; | |
| 200 this.player = p; | |
| 201 this.propertiesSection.removeChildren(); | |
| 202 var animationObject = { | |
| 203 "paused": p.paused(), | |
| 204 "finished": p.finished(), | |
| 205 "start-time": p.startTime(), | |
| 206 "player-playback-rate": p.playbackRate(), | |
| 207 "id": p.id(), | |
| 208 "start-delay": p.animation().startDelay(), | |
| 209 "playback-rate": p.animation().playbackRate(), | |
| 210 "iteration-start": p.animation().iterationStart(), | |
| 211 "iteration-count": p.animation().iterationCount(), | |
| 212 "duration": p.animation().duration(), | |
| 213 "direction": p.animation().direction(), | |
| 214 "fill-mode": p.animation().fillMode(), | |
| 215 "time-fraction": p.animation().timeFraction() | |
| 216 }; | |
| 217 var obj = WebInspector.RemoteObject.fromLocalObject(animationObject); | |
| 218 var section = new WebInspector.ObjectPropertiesSection(obj, WebInspector .UIString("Animation Properties")); | |
| 219 this.propertiesSection.appendChild(section.element); | |
| 220 } | |
| 221 } | |
| OLD | NEW |