| OLD | NEW |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 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.VBox} | 7 * @extends {WebInspector.VBox} |
| 8 * @implements {WebInspector.TargetManager.Observer} | 8 * @implements {WebInspector.TargetManager.Observer} |
| 9 */ | 9 */ |
| 10 WebInspector.AnimationTimeline = function() | 10 WebInspector.AnimationTimeline = function() |
| 11 { | 11 { |
| 12 WebInspector.VBox.call(this, true); | 12 WebInspector.VBox.call(this, true); |
| 13 this.registerRequiredCSS("animation/animationTimeline.css"); | 13 this.registerRequiredCSS("animation/animationTimeline.css"); |
| 14 this.element.classList.add("animations-timeline"); | 14 this.element.classList.add("animations-timeline"); |
| 15 | 15 |
| 16 this._grid = this.contentElement.createSVGChild("svg", "animation-timeline-g
rid"); | 16 this._grid = this.contentElement.createSVGChild("svg", "animation-timeline-g
rid"); |
| 17 | 17 |
| 18 this._underlyingPlaybackRate = 1; | 18 this._playbackRate = 1; |
| 19 this._allPaused = false; |
| 19 this._createHeader(); | 20 this._createHeader(); |
| 20 this._animationsContainer = this.contentElement.createChild("div", "animatio
n-timeline-rows"); | 21 this._animationsContainer = this.contentElement.createChild("div", "animatio
n-timeline-rows"); |
| 21 var timelineHint = this.contentElement.createChild("div", "animation-timelin
e-rows-hint"); | 22 var timelineHint = this.contentElement.createChild("div", "animation-timelin
e-rows-hint"); |
| 22 timelineHint.textContent = WebInspector.UIString("Select an effect above to
inspect and modify."); | 23 timelineHint.textContent = WebInspector.UIString("Select an effect above to
inspect and modify."); |
| 23 | 24 |
| 24 /** @const */ this._defaultDuration = 100; | 25 /** @const */ this._defaultDuration = 100; |
| 25 this._duration = this._defaultDuration; | 26 this._duration = this._defaultDuration; |
| 26 /** @const */ this._timelineControlsWidth = 150; | 27 /** @const */ this._timelineControlsWidth = 150; |
| 27 /** @type {!Map.<!DOMAgent.BackendNodeId, !WebInspector.AnimationTimeline.No
deUI>} */ | 28 /** @type {!Map.<!DOMAgent.BackendNodeId, !WebInspector.AnimationTimeline.No
deUI>} */ |
| 28 this._nodesMap = new Map(); | 29 this._nodesMap = new Map(); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 | 121 |
| 121 _createHeader: function() | 122 _createHeader: function() |
| 122 { | 123 { |
| 123 var toolbarContainer = this.contentElement.createChild("div", "animation
-timeline-toolbar-container"); | 124 var toolbarContainer = this.contentElement.createChild("div", "animation
-timeline-toolbar-container"); |
| 124 var topToolbar = new WebInspector.Toolbar("animation-timeline-toolbar",
toolbarContainer); | 125 var topToolbar = new WebInspector.Toolbar("animation-timeline-toolbar",
toolbarContainer); |
| 125 var clearButton = new WebInspector.ToolbarButton(WebInspector.UIString("
Clear all"), "clear-toolbar-item"); | 126 var clearButton = new WebInspector.ToolbarButton(WebInspector.UIString("
Clear all"), "clear-toolbar-item"); |
| 126 clearButton.addEventListener("click", this._reset.bind(this)); | 127 clearButton.addEventListener("click", this._reset.bind(this)); |
| 127 topToolbar.appendToolbarItem(clearButton); | 128 topToolbar.appendToolbarItem(clearButton); |
| 128 topToolbar.appendSeparator(); | 129 topToolbar.appendSeparator(); |
| 129 | 130 |
| 131 this._pauseButton = new WebInspector.ToolbarToggle(WebInspector.UIString
("Pause all"), "pause-toolbar-item"); |
| 132 this._pauseButton.addEventListener("click", this._togglePauseAll.bind(th
is)); |
| 133 topToolbar.appendToolbarItem(this._pauseButton); |
| 134 |
| 130 var playbackRateControl = toolbarContainer.createChild("div", "animation
-playback-rate-control"); | 135 var playbackRateControl = toolbarContainer.createChild("div", "animation
-playback-rate-control"); |
| 131 this._playbackRateButtons = []; | 136 this._playbackRateButtons = []; |
| 132 for (var playbackRate of WebInspector.AnimationTimeline.GlobalPlaybackRa
tes) { | 137 for (var playbackRate of WebInspector.AnimationTimeline.GlobalPlaybackRa
tes) { |
| 133 var button = playbackRateControl.createChild("div", "animation-playb
ack-rate-button"); | 138 var button = playbackRateControl.createChild("div", "animation-playb
ack-rate-button"); |
| 134 button.textContent = WebInspector.UIString(playbackRate * 100 + "%")
; | 139 button.textContent = playbackRate ? WebInspector.UIString(playbackRa
te * 100 + "%") : WebInspector.UIString("Pause"); |
| 135 button.playbackRate = playbackRate; | 140 button.playbackRate = playbackRate; |
| 136 button.addEventListener("click", this._setPlaybackRate.bind(this, pl
aybackRate)); | 141 button.addEventListener("click", this._setPlaybackRate.bind(this, pl
aybackRate)); |
| 137 button.title = WebInspector.UIString("Set speed to ") + button.textC
ontent; | 142 button.title = WebInspector.UIString("Set speed to ") + button.textC
ontent; |
| 138 this._playbackRateButtons.push(button); | 143 this._playbackRateButtons.push(button); |
| 139 } | 144 } |
| 140 this._updatePlaybackControls(); | 145 this._updatePlaybackControls(); |
| 141 | 146 |
| 142 this._previewContainer = this.contentElement.createChild("div", "animati
on-timeline-buffer"); | 147 this._previewContainer = this.contentElement.createChild("div", "animati
on-timeline-buffer"); |
| 143 this._popoverHelper = new WebInspector.PopoverHelper(this._previewContai
ner, this._getPopoverAnchor.bind(this), this._showPopover.bind(this), this._onHi
dePopover.bind(this), true); | 148 this._popoverHelper = new WebInspector.PopoverHelper(this._previewContai
ner, this._getPopoverAnchor.bind(this), this._showPopover.bind(this), this._onHi
dePopover.bind(this), true); |
| 144 this._popoverHelper.setTimeout(0); | 149 this._popoverHelper.setTimeout(0); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 return; | 196 return; |
| 192 var content = new WebInspector.AnimationScreenshotPopover(screenshots); | 197 var content = new WebInspector.AnimationScreenshotPopover(screenshots); |
| 193 popover.setNoMargins(true); | 198 popover.setNoMargins(true); |
| 194 popover.showView(content, anchor); | 199 popover.showView(content, anchor); |
| 195 }, | 200 }, |
| 196 | 201 |
| 197 _onHidePopover: function() | 202 _onHidePopover: function() |
| 198 { | 203 { |
| 199 }, | 204 }, |
| 200 | 205 |
| 206 _togglePauseAll: function() |
| 207 { |
| 208 this._allPaused = !this._allPaused; |
| 209 this._pauseButton.setToggled(this._allPaused); |
| 210 this._setPlaybackRate(this._playbackRate); |
| 211 this._pauseButton.setTitle(this._allPaused ? WebInspector.UIString("Resu
me all") : WebInspector.UIString("Pause all")); |
| 212 }, |
| 213 |
| 201 /** | 214 /** |
| 202 * @param {number} playbackRate | 215 * @param {number} playbackRate |
| 203 */ | 216 */ |
| 204 _setPlaybackRate: function(playbackRate) | 217 _setPlaybackRate: function(playbackRate) |
| 205 { | 218 { |
| 206 this._underlyingPlaybackRate = playbackRate; | 219 this._playbackRate = playbackRate; |
| 207 var target = WebInspector.targetManager.mainTarget(); | 220 var target = WebInspector.targetManager.mainTarget(); |
| 208 if (target) | 221 if (target) |
| 209 WebInspector.AnimationModel.fromTarget(target).setPlaybackRate(this.
_underlyingPlaybackRate); | 222 WebInspector.AnimationModel.fromTarget(target).setPlaybackRate(this.
_allPaused ? 0 : this._playbackRate); |
| 210 WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Action.Ani
mationsPlaybackRateChanged); | 223 WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Action.Ani
mationsPlaybackRateChanged); |
| 211 if (this._scrubberPlayer) | 224 if (this._scrubberPlayer) |
| 212 this._scrubberPlayer.playbackRate = this._effectivePlaybackRate(); | 225 this._scrubberPlayer.playbackRate = this._effectivePlaybackRate(); |
| 213 | 226 |
| 214 this._updatePlaybackControls(); | 227 this._updatePlaybackControls(); |
| 215 }, | 228 }, |
| 216 | 229 |
| 217 _updatePlaybackControls: function() | 230 _updatePlaybackControls: function() |
| 218 { | 231 { |
| 219 for (var button of this._playbackRateButtons) { | 232 for (var button of this._playbackRateButtons) { |
| 220 var selected = this._underlyingPlaybackRate === button.playbackRate; | 233 var selected = this._playbackRate === button.playbackRate; |
| 221 button.classList.toggle("selected", selected); | 234 button.classList.toggle("selected", selected); |
| 222 } | 235 } |
| 223 }, | 236 }, |
| 224 | 237 |
| 225 _controlButtonToggle: function() | 238 _controlButtonToggle: function() |
| 226 { | 239 { |
| 227 if (this._controlButton.state() === WebInspector.AnimationTimeline._Cont
rolState.Play) | 240 if (this._controlButton.state() === WebInspector.AnimationTimeline._Cont
rolState.Play) |
| 228 this._togglePause(false); | 241 this._togglePause(false); |
| 229 else if (this._controlButton.state() === WebInspector.AnimationTimeline.
_ControlState.Replay) | 242 else if (this._controlButton.state() === WebInspector.AnimationTimeline.
_ControlState.Replay) |
| 230 this._replay(); | 243 this._replay(); |
| 231 else | 244 else |
| 232 this._togglePause(true); | 245 this._togglePause(true); |
| 233 }, | 246 }, |
| 234 | 247 |
| 235 _updateControlButton: function() | 248 _updateControlButton: function() |
| 236 { | 249 { |
| 237 this._controlButton.setEnabled(!!this._selectedGroup); | 250 this._controlButton.setEnabled(!!this._selectedGroup); |
| 238 if (this._selectedGroup && this._selectedGroup.paused()) { | 251 if (this._selectedGroup && this._selectedGroup.paused()) { |
| 239 this._controlButton.setState(WebInspector.AnimationTimeline._Control
State.Play); | 252 this._controlButton.setState(WebInspector.AnimationTimeline._Control
State.Play); |
| 240 this._controlButton.setTitle(WebInspector.UIString("Play timeline"))
; | 253 this._controlButton.setTitle(WebInspector.UIString("Play timeline"))
; |
| 241 } else if (!this._scrubberPlayer || this._scrubberPlayer.currentTime >=
this.duration()) { | 254 } else if (!this._scrubberPlayer || this._scrubberPlayer.currentTime >=
this.duration()) { |
| 242 this._controlButton.setState(WebInspector.AnimationTimeline._Control
State.Replay); | 255 this._controlButton.setState(WebInspector.AnimationTimeline._Control
State.Replay); |
| 243 this._controlButton.setTitle(WebInspector.UIString("Replay timeline"
)); | 256 this._controlButton.setTitle(WebInspector.UIString("Replay timeline"
)); |
| 244 } else { | 257 } else { |
| 245 this._controlButton.setState(WebInspector.AnimationTimeline._Control
State.Pause); | 258 this._controlButton.setState(WebInspector.AnimationTimeline._Control
State.Pause); |
| 246 this._controlButton.setTitle(WebInspector.UIString("Pause timeline")
); | 259 this._controlButton.setTitle(WebInspector.UIString("Pause timeline")
); |
| 247 } | 260 } |
| 248 }, | 261 }, |
| 249 | 262 |
| 250 _updateAnimationsPlaybackRate: function() | |
| 251 { | |
| 252 /** | |
| 253 * @param {number} playbackRate | |
| 254 * @this {WebInspector.AnimationTimeline} | |
| 255 */ | |
| 256 function syncPlaybackRate(playbackRate) | |
| 257 { | |
| 258 this._underlyingPlaybackRate = playbackRate || 1; | |
| 259 this._updatePlaybackControls(); | |
| 260 } | |
| 261 | |
| 262 for (var target of WebInspector.targetManager.targets(WebInspector.Targe
t.Type.Page)) | |
| 263 WebInspector.AnimationModel.fromTarget(target).playbackRatePromise()
.then(syncPlaybackRate.bind(this)); | |
| 264 }, | |
| 265 | |
| 266 /** | 263 /** |
| 267 * @return {number} | 264 * @return {number} |
| 268 */ | 265 */ |
| 269 _effectivePlaybackRate: function() | 266 _effectivePlaybackRate: function() |
| 270 { | 267 { |
| 271 return this._selectedGroup && this._selectedGroup.paused() ? 0 : this._u
nderlyingPlaybackRate; | 268 return this._selectedGroup && this._selectedGroup.paused() ? 0 : this._p
laybackRate; |
| 272 }, | 269 }, |
| 273 | 270 |
| 274 /** | 271 /** |
| 275 * @param {boolean} pause | 272 * @param {boolean} pause |
| 276 */ | 273 */ |
| 277 _togglePause: function(pause) | 274 _togglePause: function(pause) |
| 278 { | 275 { |
| 279 this._selectedGroup.togglePause(pause); | 276 this._selectedGroup.togglePause(pause); |
| 280 if (this._scrubberPlayer) | 277 if (this._scrubberPlayer) |
| 281 this._scrubberPlayer.playbackRate = this._effectivePlaybackRate(); | 278 this._scrubberPlayer.playbackRate = this._effectivePlaybackRate(); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 if (this._scrubberPlayer) | 318 if (this._scrubberPlayer) |
| 322 this._scrubberPlayer.cancel(); | 319 this._scrubberPlayer.cancel(); |
| 323 delete this._scrubberPlayer; | 320 delete this._scrubberPlayer; |
| 324 this._currentTime.textContent = ""; | 321 this._currentTime.textContent = ""; |
| 325 this._updateControlButton(); | 322 this._updateControlButton(); |
| 326 }, | 323 }, |
| 327 | 324 |
| 328 _reset: function() | 325 _reset: function() |
| 329 { | 326 { |
| 330 this._clearTimeline(); | 327 this._clearTimeline(); |
| 331 this._updateAnimationsPlaybackRate(); | 328 if (this._allPaused) { |
| 329 this._playbackRate = 1; |
| 330 this._togglePauseAll(); |
| 331 } else { |
| 332 this._setPlaybackRate(1); |
| 333 } |
| 332 for (var group of this._groupBuffer) | 334 for (var group of this._groupBuffer) |
| 333 group.release(); | 335 group.release(); |
| 334 this._groupBuffer = []; | 336 this._groupBuffer = []; |
| 335 this._previewMap.clear(); | 337 this._previewMap.clear(); |
| 336 this._previewContainer.removeChildren(); | 338 this._previewContainer.removeChildren(); |
| 337 this._popoverHelper.hidePopover(); | 339 this._popoverHelper.hidePopover(); |
| 338 this._renderGrid(); | 340 this._renderGrid(); |
| 339 }, | 341 }, |
| 340 | 342 |
| 341 /** | 343 /** |
| (...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 775 | 777 |
| 776 /** | 778 /** |
| 777 * @override | 779 * @override |
| 778 * @return {!WebInspector.ToolbarItem} | 780 * @return {!WebInspector.ToolbarItem} |
| 779 */ | 781 */ |
| 780 item: function() | 782 item: function() |
| 781 { | 783 { |
| 782 return this._button; | 784 return this._button; |
| 783 } | 785 } |
| 784 } | 786 } |
| OLD | NEW |