| OLD | NEW |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * @constructor | 6 * @constructor |
| 7 * @extends {WebInspector.ElementsSidebarPane} | 7 * @extends {WebInspector.ElementsSidebarPane} |
| 8 */ | 8 */ |
| 9 WebInspector.AnimationsSidebarPane = function(stylesPane) | 9 WebInspector.AnimationsSidebarPane = function(stylesPane) |
| 10 { | 10 { |
| 11 WebInspector.ElementsSidebarPane.call(this, WebInspector.UIString("Animation
s")); | 11 WebInspector.ElementsSidebarPane.call(this, WebInspector.UIString("Animation
s")); |
| 12 this._stylesPane = stylesPane; | 12 this._stylesPane = stylesPane; |
| 13 | 13 |
| 14 this.headerElement = createElementWithClass("div", "animationsSettings"); |
| 15 this._showSubtreeSetting = WebInspector.settings.createSetting("showSubtreeA
nimations", true); |
| 16 this.headerElement.appendChild(WebInspector.AnimationsSidebarPane._showSubtr
eeAnimationsCheckbox(this._showSubtreeSetting)); |
| 17 this._showSubtreeSetting.addChangeListener(this._showSubtreeSettingChanged.b
ind(this)); |
| 14 this._emptyElement = createElement("div"); | 18 this._emptyElement = createElement("div"); |
| 15 this._emptyElement.className = "info"; | 19 this._emptyElement.className = "info"; |
| 16 this._emptyElement.textContent = WebInspector.UIString("No Animations"); | 20 this._emptyElement.textContent = WebInspector.UIString("No Animations"); |
| 21 this.animationsElement = createElement("div"); |
| 22 this.animationsElement.appendChild(this._emptyElement); |
| 17 | 23 |
| 18 this._animationSections = []; | 24 this._animationSections = []; |
| 19 | 25 |
| 20 this.bodyElement.appendChild(this._emptyElement); | 26 this.bodyElement.appendChild(this.headerElement); |
| 27 this.bodyElement.appendChild(this.animationsElement); |
| 28 } |
| 29 |
| 30 /** |
| 31 * @param {!WebInspector.Setting} setting |
| 32 * @return {!Element} |
| 33 */ |
| 34 WebInspector.AnimationsSidebarPane._showSubtreeAnimationsCheckbox = function(set
ting) |
| 35 { |
| 36 if (!WebInspector.AnimationsSidebarPane._showSubtreeAnimationsCheckboxElemen
t) { |
| 37 WebInspector.AnimationsSidebarPane._showSubtreeAnimationsCheckboxElement
= WebInspector.SettingsUI.createSettingCheckbox(WebInspector.UIString("Show sub
tree animations"), setting, true); |
| 38 WebInspector.AnimationsSidebarPane._showSubtreeAnimationsCheckboxElement
.classList.add("checkbox-with-label"); |
| 39 } |
| 40 return WebInspector.AnimationsSidebarPane._showSubtreeAnimationsCheckboxElem
ent; |
| 21 } | 41 } |
| 22 | 42 |
| 23 WebInspector.AnimationsSidebarPane.prototype = { | 43 WebInspector.AnimationsSidebarPane.prototype = { |
| 44 _showSubtreeSettingChanged: function() |
| 45 { |
| 46 this._forceUpdate = true; |
| 47 this.update(); |
| 48 }, |
| 49 |
| 24 /** | 50 /** |
| 25 * @param {!WebInspector.Throttler.FinishCallback} finishCallback | 51 * @param {!WebInspector.Throttler.FinishCallback} finishCallback |
| 26 * @protected | 52 * @protected |
| 27 */ | 53 */ |
| 28 doUpdate: function(finishCallback) | 54 doUpdate: function(finishCallback) |
| 29 { | 55 { |
| 30 /** | 56 /** |
| 31 * @param {?Array.<!WebInspector.AnimationModel.AnimationPlayer>} animat
ionPlayers | 57 * @param {?Array.<!WebInspector.AnimationModel.AnimationPlayer>} animat
ionPlayers |
| 32 * @this {WebInspector.AnimationsSidebarPane} | 58 * @this {WebInspector.AnimationsSidebarPane} |
| 33 */ | 59 */ |
| 34 function animationPlayersCallback(animationPlayers) | 60 function animationPlayersCallback(animationPlayers) |
| 35 { | 61 { |
| 36 this.bodyElement.removeChildren(); | 62 this.animationsElement.removeChildren(); |
| 37 this._animationSections = []; | 63 this._animationSections = []; |
| 38 if (!animationPlayers || !animationPlayers.length) { | 64 if (!animationPlayers || !animationPlayers.length) { |
| 39 this.bodyElement.appendChild(this._emptyElement); | 65 this.animationsElement.appendChild(this._emptyElement); |
| 40 finishCallback(); | 66 finishCallback(); |
| 41 return; | 67 return; |
| 42 } | 68 } |
| 43 | |
| 44 for (var i = 0; i < animationPlayers.length; ++i) { | 69 for (var i = 0; i < animationPlayers.length; ++i) { |
| 45 var player = animationPlayers[i]; | 70 var player = animationPlayers[i]; |
| 46 this._animationSections[i] = new WebInspector.AnimationSection(t
his, player); | 71 this._animationSections[i] = new WebInspector.AnimationSection(t
his, this._stylesPane, player); |
| 47 var separatorElement = this.bodyElement.createChild("div", "side
bar-separator"); | 72 if (animationPlayers.length < 5) |
| 48 separatorElement.createTextChild(WebInspector.UIString("Animatio
n") + " " + player.name()); | 73 this._animationSections[i].expand(true); |
| 49 this.bodyElement.appendChild(this._animationSections[i].element)
; | 74 this.animationsElement.appendChild(this._animationSections[i].el
ement); |
| 50 | |
| 51 if (player.source().keyframesRule()) { | |
| 52 var keyframes = player.source().keyframesRule().keyframes(); | |
| 53 for (var j = 0; j < keyframes.length; j++) { | |
| 54 var style = { selectorText: keyframes[j].offset(), style
: keyframes[j].style(), isAttribute: true }; | |
| 55 var section = new WebInspector.StylePropertiesSection(th
is._stylesPane, style, true, false); | |
| 56 section.expanded = true; | |
| 57 this.bodyElement.appendChild(section.element); | |
| 58 } | |
| 59 } | |
| 60 } | 75 } |
| 61 finishCallback(); | 76 finishCallback(); |
| 62 } | 77 } |
| 63 | 78 |
| 64 if (!this.node()) | 79 if (!this.node()) { |
| 80 finishCallback(); |
| 65 return; | 81 return; |
| 66 this.node().target().animationModel.getAnimationPlayers(this.node().id,
animationPlayersCallback.bind(this)); | 82 } |
| 83 |
| 84 if (!this._forceUpdate && this._selectedNode === this.node()) { |
| 85 for (var i = 0; i < this._animationSections.length; ++i) |
| 86 this._animationSections[i].updateCurrentTime(); |
| 87 finishCallback(); |
| 88 return; |
| 89 } |
| 90 |
| 91 this._forceUpdate = false; |
| 92 this._selectedNode = this.node(); |
| 93 this.node().target().animationModel.getAnimationPlayers(this.node().id,
this._showSubtreeSetting.get(), animationPlayersCallback.bind(this)); |
| 67 }, | 94 }, |
| 68 | 95 |
| 69 __proto__: WebInspector.ElementsSidebarPane.prototype | 96 __proto__: WebInspector.ElementsSidebarPane.prototype |
| 70 } | 97 } |
| 71 | 98 |
| 72 /** | 99 /** |
| 73 * @constructor | 100 * @constructor |
| 74 * @param {!WebInspector.AnimationsSidebarPane} parentPane | 101 * @param {!WebInspector.AnimationsSidebarPane} parentPane |
| 102 * @param {!WebInspector.StylesSidebarPane} stylesPane |
| 75 * @param {?WebInspector.AnimationModel.AnimationPlayer} animationPlayer | 103 * @param {?WebInspector.AnimationModel.AnimationPlayer} animationPlayer |
| 76 */ | 104 */ |
| 77 WebInspector.AnimationSection = function(parentPane, animationPlayer) | 105 WebInspector.AnimationSection = function(parentPane, stylesPane, animationPlayer
) |
| 78 { | 106 { |
| 79 this._parentPane = parentPane; | 107 this._parentPane = parentPane; |
| 80 this.propertiesSection = createElement("div"); | 108 this._stylesPane = stylesPane; |
| 109 this._propertiesElement = createElement("div"); |
| 110 this._keyframesElement = createElement("div"); |
| 81 this._setAnimationPlayer(animationPlayer); | 111 this._setAnimationPlayer(animationPlayer); |
| 82 | 112 |
| 113 this._updateThrottler = new WebInspector.Throttler(WebInspector.AnimationSec
tion.updateTimeout); |
| 114 |
| 83 this.element = createElement("div"); | 115 this.element = createElement("div"); |
| 84 this.element.className = "styles-section"; | 116 this.element.appendChild(this._createHeader()); |
| 85 | 117 this.bodyElement = this.element.createChild("div", "animationSectionBody"); |
| 86 this._updateThrottler = new WebInspector.Throttler(WebInspector.AnimationSec
tion.updateTimeout); | 118 this.bodyElement.appendChild(this._createAnimationControls()); |
| 87 this.element.appendChild(this._createAnimationControls()); | 119 this.bodyElement.appendChild(this._propertiesElement); |
| 88 this.element.appendChild(this.propertiesSection); | 120 this.bodyElement.appendChild(this._keyframesElement); |
| 89 } | 121 } |
| 90 | 122 |
| 91 WebInspector.AnimationSection.updateTimeout = 100; | 123 WebInspector.AnimationSection.updateTimeout = 100; |
| 92 | 124 |
| 93 WebInspector.AnimationSection.prototype = { | 125 WebInspector.AnimationSection.prototype = { |
| 94 updateCurrentTime: function() | 126 /** |
| 127 * @return {boolean} |
| 128 */ |
| 129 _expanded: function() |
| 95 { | 130 { |
| 96 this._updateThrottler.schedule(this._updateCurrentTime.bind(this), false
); | 131 return this.bodyElement.classList.contains("expanded"); |
| 132 }, |
| 133 |
| 134 _toggle: function() |
| 135 { |
| 136 this.bodyElement.classList.toggle("expanded"); |
| 137 this.updateCurrentTime(); |
| 97 }, | 138 }, |
| 98 | 139 |
| 99 /** | 140 /** |
| 141 * @param {boolean} expanded |
| 142 */ |
| 143 expand: function(expanded) |
| 144 { |
| 145 this.bodyElement.classList.toggle("expanded", expanded); |
| 146 this.updateCurrentTime(); |
| 147 }, |
| 148 |
| 149 updateCurrentTime: function() |
| 150 { |
| 151 if (this._expanded()) |
| 152 this._updateThrottler.schedule(this._updateCurrentTime.bind(this), f
alse); |
| 153 }, |
| 154 |
| 155 /** |
| 100 * @param {!WebInspector.Throttler.FinishCallback} finishCallback | 156 * @param {!WebInspector.Throttler.FinishCallback} finishCallback |
| 101 */ | 157 */ |
| 102 _updateCurrentTime: function(finishCallback) | 158 _updateCurrentTime: function(finishCallback) |
| 103 { | 159 { |
| 104 /** | 160 /** |
| 105 * @param {number} currentTime | 161 * @param {number} currentTime |
| 106 * @param {boolean} isRunning | 162 * @param {boolean} isRunning |
| 107 * @this {WebInspector.AnimationSection} | 163 * @this {WebInspector.AnimationSection} |
| 108 */ | 164 */ |
| 109 function updateSliderCallback(currentTime, isRunning) | 165 function updateSliderCallback(currentTime, isRunning) |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 } | 203 } |
| 148 | 204 |
| 149 slider.addEventListener("input", sliderInputHandler.bind(this)); | 205 slider.addEventListener("input", sliderInputHandler.bind(this)); |
| 150 this.updateCurrentTime(); | 206 this.updateCurrentTime(); |
| 151 return slider; | 207 return slider; |
| 152 }, | 208 }, |
| 153 | 209 |
| 154 /** | 210 /** |
| 155 * @return {!Element} | 211 * @return {!Element} |
| 156 */ | 212 */ |
| 213 _createHeader: function() |
| 214 { |
| 215 /** |
| 216 * @param {?WebInspector.DOMNode} node |
| 217 */ |
| 218 function nodeResolved(node) |
| 219 { |
| 220 headerElement.addEventListener("mouseover", node.highlight.bind(node
, undefined, undefined), false); |
| 221 headerElement.addEventListener("mouseleave", node.domModel().hideDOM
NodeHighlight.bind(node.domModel()), false); |
| 222 } |
| 223 |
| 224 var headerElement = createElementWithClass("div", "sidebar-separator"); |
| 225 var id = this.player.source().name() ? this.player.source().name() : thi
s.player.id(); |
| 226 headerElement.createTextChild(WebInspector.UIString("Animation") + " " +
id); |
| 227 headerElement.addEventListener("click", this._toggle.bind(this), false); |
| 228 this.player.source().getNode(nodeResolved); |
| 229 return headerElement; |
| 230 }, |
| 231 |
| 232 /** |
| 233 * @return {!Element} |
| 234 */ |
| 157 _createAnimationControls: function() | 235 _createAnimationControls: function() |
| 158 { | 236 { |
| 159 /** | 237 /** |
| 160 * @this {WebInspector.AnimationSection} | 238 * @this {WebInspector.AnimationSection} |
| 161 */ | 239 */ |
| 162 function pauseButtonHandler() | 240 function pauseButtonHandler() |
| 163 { | 241 { |
| 164 if (this.player.paused()) { | 242 if (this.player.paused()) { |
| 165 this.player.play(this._setAnimationPlayer.bind(this)); | 243 this.player.play(this._setAnimationPlayer.bind(this)); |
| 166 updatePauseButton.call(this, false); | 244 updatePauseButton.call(this, false); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 195 }, | 273 }, |
| 196 | 274 |
| 197 /** | 275 /** |
| 198 * @param {?WebInspector.AnimationModel.AnimationPlayer} p | 276 * @param {?WebInspector.AnimationModel.AnimationPlayer} p |
| 199 */ | 277 */ |
| 200 _setAnimationPlayer: function(p) | 278 _setAnimationPlayer: function(p) |
| 201 { | 279 { |
| 202 if (!p || p === this.player) | 280 if (!p || p === this.player) |
| 203 return; | 281 return; |
| 204 this.player = p; | 282 this.player = p; |
| 205 this.propertiesSection.removeChildren(); | 283 this._propertiesElement.removeChildren(); |
| 206 var animationObject = { | 284 var animationObject = { |
| 207 "playState": p.playState(), | 285 "playState": p.playState(), |
| 208 "start-time": p.startTime(), | 286 "start-time": p.startTime(), |
| 209 "player-playback-rate": p.playbackRate(), | 287 "player-playback-rate": p.playbackRate(), |
| 210 "id": p.id(), | 288 "id": p.id(), |
| 211 "start-delay": p.source().startDelay(), | 289 "start-delay": p.source().startDelay(), |
| 212 "playback-rate": p.source().playbackRate(), | 290 "playback-rate": p.source().playbackRate(), |
| 213 "iteration-start": p.source().iterationStart(), | 291 "iteration-start": p.source().iterationStart(), |
| 214 "iteration-count": p.source().iterationCount(), | 292 "iteration-count": p.source().iterationCount(), |
| 215 "duration": p.source().duration(), | 293 "duration": p.source().duration(), |
| 216 "direction": p.source().direction(), | 294 "direction": p.source().direction(), |
| 217 "fill-mode": p.source().fillMode(), | 295 "fill-mode": p.source().fillMode(), |
| 218 "time-fraction": p.source().timeFraction() | 296 "time-fraction": p.source().timeFraction() |
| 219 }; | 297 }; |
| 220 var obj = WebInspector.RemoteObject.fromLocalObject(animationObject); | 298 var obj = WebInspector.RemoteObject.fromLocalObject(animationObject); |
| 221 var section = new WebInspector.ObjectPropertiesSection(obj, WebInspector
.UIString("Animation Properties")); | 299 var objSection = new WebInspector.ObjectPropertiesSection(obj, WebInspec
tor.UIString("Animation Properties")); |
| 222 this.propertiesSection.appendChild(section.element); | 300 this._propertiesElement.appendChild(objSection.element); |
| 301 |
| 302 if (this.player.source().keyframesRule()) { |
| 303 var keyframes = this.player.source().keyframesRule().keyframes(); |
| 304 for (var j = 0; j < keyframes.length; j++) { |
| 305 var inlineStyle = { selectorText: keyframes[j].offset(), style:
keyframes[j].style(), isAttribute: true }; |
| 306 var styleSection = new WebInspector.StylePropertiesSection(this.
_stylesPane, inlineStyle, true, false); |
| 307 styleSection.expanded = true; |
| 308 this._keyframesElement.appendChild(styleSection.element); |
| 309 } |
| 310 } |
| 223 } | 311 } |
| 224 } | 312 } |
| OLD | NEW |