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.AnimationModel.AnimationPlayer>} animat
ionPlayers |
| 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.source().name() ? player.source().name() : playe
r.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) { |
| 51 for (var i = 0; i < this._animationSections.length; ++i) |
| 52 this._animationSections[i].updateCurrentTime(); |
| 53 return; |
| 54 } |
| 55 this._selectedNode = node; |
| 56 node.target().animationModel.animationPlayers(node.id, animationPlayersC
allback.bind(this)); |
| 57 }, |
| 58 __proto__: WebInspector.SidebarPane.prototype |
| 59 } |
| 60 |
| 61 /** |
| 62 * @constructor |
| 63 * @param {!WebInspector.AnimationsSidebarPane} parentPane |
| 64 * @param {?WebInspector.AnimationModel.AnimationPlayer} animationPlayer |
| 65 */ |
| 66 WebInspector.AnimationSection = function(parentPane, animationPlayer) |
| 67 { |
| 68 this._parentPane = parentPane; |
| 69 this.propertiesSection = document.createElement("div"); |
| 70 this._setAnimationPlayer(animationPlayer); |
| 71 |
| 72 this.element = document.createElement("div"); |
| 73 this.element.className = "styles-section"; |
| 74 |
| 75 this._updateThrottler = new WebInspector.Throttler(WebInspector.AnimationSec
tion.updateTimeout); |
| 76 this.element.appendChild(this._createAnimationControls()); |
| 77 this.element.appendChild(this.propertiesSection); |
| 78 } |
| 79 |
| 80 WebInspector.AnimationSection.updateTimeout = 100; |
| 81 |
| 82 WebInspector.AnimationSection.prototype = { |
| 83 updateCurrentTime: function() |
| 84 { |
| 85 this._updateThrottler.schedule(this._updateCurrentTime.bind(this), false
); |
| 86 }, |
| 87 |
| 88 /** |
| 89 * @param {!WebInspector.Throttler.FinishCallback} finishCallback |
| 90 */ |
| 91 _updateCurrentTime: function(finishCallback) |
| 92 { |
| 93 /** |
| 94 * @param {number} currentTime |
| 95 * @param {boolean} isRunning |
| 96 * @this {WebInspector.AnimationSection} |
| 97 */ |
| 98 function updateSliderCallback(currentTime, isRunning) |
| 99 { |
| 100 this.currentTimeSlider.value = this.player.source().iterationCount()
== null ? currentTime % this.player.source().duration() : currentTime; |
| 101 finishCallback(); |
| 102 if (isRunning && this._parentPane.isShowing()) |
| 103 this.updateCurrentTime(); |
| 104 } |
| 105 this.player.getCurrentState(updateSliderCallback.bind(this)); |
| 106 }, |
| 107 |
| 108 /** |
| 109 * @return {!Element} |
| 110 */ |
| 111 _createCurrentTimeSlider: function() |
| 112 { |
| 113 /** |
| 114 * @param {!Event} e |
| 115 * @this {WebInspector.AnimationSection} |
| 116 */ |
| 117 function sliderInputHandler(e) |
| 118 { |
| 119 this.player.setCurrentTime(parseFloat(e.target.value), this._setAnim
ationPlayer.bind(this)); |
| 120 } |
| 121 |
| 122 var iterationDuration = this.player.source().duration(); |
| 123 var iterationCount = this.player.source().iterationCount(); |
| 124 var slider = document.createElement("input"); |
| 125 slider.type = "range"; |
| 126 slider.min = 0; |
| 127 slider.step = 0.01; |
| 128 |
| 129 if (!iterationCount) { |
| 130 // Infinite iterations |
| 131 slider.max = iterationDuration; |
| 132 slider.value = this.player.currentTime() % iterationDuration; |
| 133 } else { |
| 134 slider.max = iterationCount * iterationDuration; |
| 135 slider.value = this.player.currentTime(); |
| 136 } |
| 137 |
| 138 slider.addEventListener("input", sliderInputHandler.bind(this)); |
| 139 this.updateCurrentTime(); |
| 140 return slider; |
| 141 }, |
| 142 |
| 143 /** |
| 144 * @return {!Element} |
| 145 */ |
| 146 _createAnimationControls: function() |
| 147 { |
| 148 /** |
| 149 * @this {WebInspector.AnimationSection} |
| 150 */ |
| 151 function pauseButtonHandler() |
| 152 { |
| 153 if (this.player.paused()) { |
| 154 this.player.play(this._setAnimationPlayer.bind(this)); |
| 155 updatePauseButton.call(this, false); |
| 156 this.updateCurrentTime(); |
| 157 } else { |
| 158 this.player.pause(this._setAnimationPlayer.bind(this)); |
| 159 updatePauseButton.call(this, true); |
| 160 } |
| 161 } |
| 162 |
| 163 /** |
| 164 * @param {boolean} paused |
| 165 * @this {WebInspector.AnimationSection} |
| 166 */ |
| 167 function updatePauseButton(paused) |
| 168 { |
| 169 this._pauseButton.state = paused; |
| 170 this._pauseButton.title = paused ? WebInspector.UIString("Play anima
tion") : WebInspector.UIString("Pause animation"); |
| 171 } |
| 172 |
| 173 this._pauseButton = new WebInspector.StatusBarButton("", "animation-paus
e"); |
| 174 updatePauseButton.call(this, this.player.paused()); |
| 175 this._pauseButton.addEventListener("click", pauseButtonHandler, this); |
| 176 |
| 177 this.currentTimeSlider = this._createCurrentTimeSlider(); |
| 178 |
| 179 var controls = document.createElement("div"); |
| 180 controls.appendChild(this._pauseButton.element); |
| 181 controls.appendChild(this.currentTimeSlider); |
| 182 |
| 183 return controls; |
| 184 }, |
| 185 |
| 186 /** |
| 187 * @param {?WebInspector.AnimationModel.AnimationPlayer} p |
| 188 */ |
| 189 _setAnimationPlayer: function(p) |
| 190 { |
| 191 if (!p || p === this.player) |
| 192 return; |
| 193 this.player = p; |
| 194 this.propertiesSection.removeChildren(); |
| 195 var animationObject = { |
| 196 "playState": p.playState(), |
| 197 "start-time": p.startTime(), |
| 198 "player-playback-rate": p.playbackRate(), |
| 199 "id": p.id(), |
| 200 "start-delay": p.source().startDelay(), |
| 201 "playback-rate": p.source().playbackRate(), |
| 202 "iteration-start": p.source().iterationStart(), |
| 203 "iteration-count": p.source().iterationCount(), |
| 204 "duration": p.source().duration(), |
| 205 "direction": p.source().direction(), |
| 206 "fill-mode": p.source().fillMode(), |
| 207 "time-fraction": p.source().timeFraction() |
| 208 }; |
| 209 var obj = WebInspector.RemoteObject.fromLocalObject(animationObject); |
| 210 var section = new WebInspector.ObjectPropertiesSection(obj, WebInspector
.UIString("Animation Properties")); |
| 211 this.propertiesSection.appendChild(section.element); |
| 212 } |
| 213 } |
OLD | NEW |