| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 /** | |
| 6 * @constructor | |
| 7 * @extends {WebInspector.StylesSidebarPane.BaseToolbarPaneWidget} | |
| 8 */ | |
| 9 WebInspector.AnimationControlPane = function(toolbarItem) | |
| 10 { | |
| 11 WebInspector.StylesSidebarPane.BaseToolbarPaneWidget.call(this, toolbarItem)
; | |
| 12 this._animationsPaused = false; | |
| 13 this._animationsPlaybackRate = 1; | |
| 14 | |
| 15 this.element.className = "styles-animations-controls-pane"; | |
| 16 this.element.createChild("div").createTextChild("Animations"); | |
| 17 var container = this.element.createChild("div", "animations-controls"); | |
| 18 | |
| 19 var toolbar = new WebInspector.Toolbar(); | |
| 20 this._animationsPauseButton = new WebInspector.ToolbarButton("", "pause-tool
bar-item"); | |
| 21 toolbar.appendToolbarItem(this._animationsPauseButton); | |
| 22 this._animationsPauseButton.addEventListener("click", this._pauseButtonHandl
er.bind(this)); | |
| 23 container.appendChild(toolbar.element); | |
| 24 | |
| 25 this._animationsPlaybackSlider = container.createChild("input"); | |
| 26 this._animationsPlaybackSlider.type = "range"; | |
| 27 this._animationsPlaybackSlider.min = 0; | |
| 28 this._animationsPlaybackSlider.max = WebInspector.AnimationTimeline.GlobalPl
aybackRates.length - 1; | |
| 29 this._animationsPlaybackSlider.value = this._animationsPlaybackSlider.max; | |
| 30 this._animationsPlaybackSlider.addEventListener("input", this._playbackSlide
rInputHandler.bind(this)); | |
| 31 | |
| 32 this._animationsPlaybackLabel = container.createChild("div", "playback-label
"); | |
| 33 this._animationsPlaybackLabel.createTextChild("1x"); | |
| 34 } | |
| 35 | |
| 36 WebInspector.AnimationControlPane.prototype = { | |
| 37 | |
| 38 /** | |
| 39 * @param {!Event} event | |
| 40 */ | |
| 41 _playbackSliderInputHandler: function (event) | |
| 42 { | |
| 43 this._animationsPlaybackRate = WebInspector.AnimationTimeline.GlobalPlay
backRates[event.target.value]; | |
| 44 this._target.animationModel.setPlaybackRate(this._animationsPaused ? 0 :
this._animationsPlaybackRate); | |
| 45 this._animationsPlaybackLabel.textContent = this._animationsPlaybackRate
+ "x"; | |
| 46 WebInspector.userMetrics.AnimationsPlaybackRateChanged.record(); | |
| 47 }, | |
| 48 | |
| 49 _pauseButtonHandler: function () | |
| 50 { | |
| 51 this._animationsPaused = !this._animationsPaused; | |
| 52 this._target.animationModel.setPlaybackRate(this._animationsPaused ? 0 :
this._animationsPlaybackRate); | |
| 53 WebInspector.userMetrics.AnimationsPlaybackRateChanged.record(); | |
| 54 this._animationsPauseButton.element.classList.toggle("pause-toolbar-item
"); | |
| 55 this._animationsPauseButton.element.classList.toggle("play-toolbar-item"
); | |
| 56 }, | |
| 57 | |
| 58 /** | |
| 59 * @param {!WebInspector.Event=} event | |
| 60 */ | |
| 61 _updateAnimationsPlaybackRate: function(event) | |
| 62 { | |
| 63 /** | |
| 64 * @param {?Protocol.Error} error | |
| 65 * @param {number} playbackRate | |
| 66 * @this {WebInspector.AnimationControlPane} | |
| 67 */ | |
| 68 function setPlaybackRate(error, playbackRate) | |
| 69 { | |
| 70 this._animationsPlaybackSlider.value = WebInspector.AnimationTimelin
e.GlobalPlaybackRates.indexOf(playbackRate); | |
| 71 this._animationsPlaybackLabel.textContent = playbackRate + "x"; | |
| 72 } | |
| 73 | |
| 74 if (this._target) | |
| 75 this._target.animationAgent().getPlaybackRate(setPlaybackRate.bind(t
his)); | |
| 76 }, | |
| 77 | |
| 78 /** | |
| 79 * @override | |
| 80 * @param {?WebInspector.DOMNode} node | |
| 81 */ | |
| 82 onNodeChanged: function(node) | |
| 83 { | |
| 84 if (!node) { | |
| 85 this.detach(); | |
| 86 return; | |
| 87 } | |
| 88 | |
| 89 if (this._target) | |
| 90 this._target.resourceTreeModel.removeEventListener(WebInspector.Reso
urceTreeModel.EventTypes.MainFrameNavigated, this._updateAnimationsPlaybackRate,
this); | |
| 91 | |
| 92 this._target = node.target(); | |
| 93 this._target.resourceTreeModel.addEventListener(WebInspector.ResourceTre
eModel.EventTypes.MainFrameNavigated, this._updateAnimationsPlaybackRate, this); | |
| 94 this._updateAnimationsPlaybackRate(); | |
| 95 }, | |
| 96 | |
| 97 __proto__: WebInspector.StylesSidebarPane.BaseToolbarPaneWidget.prototype | |
| 98 } | |
| 99 | |
| 100 /** | |
| 101 * @constructor | |
| 102 * @implements {WebInspector.ToolbarItem.Provider} | |
| 103 */ | |
| 104 WebInspector.AnimationControlPane.ButtonProvider = function() | |
| 105 { | |
| 106 this._button = new WebInspector.ToolbarButton(WebInspector.UIString("Animati
ons Controls"), "animation-toolbar-item"); | |
| 107 this._button.addEventListener("click", this._clicked, this); | |
| 108 WebInspector.context.addFlavorChangeListener(WebInspector.DOMNode, this._nod
eChanged, this); | |
| 109 this._nodeChanged(); | |
| 110 } | |
| 111 | |
| 112 WebInspector.AnimationControlPane.ButtonProvider.prototype = { | |
| 113 _animationTimelineModeClick: function() | |
| 114 { | |
| 115 if (!this._animationTimeline) | |
| 116 this._animationTimeline = new WebInspector.AnimationTimeline(); | |
| 117 this._button.setToggled(!this._animationTimeline.isShowing()); | |
| 118 var elementsPanel = WebInspector.ElementsPanel.instance(); | |
| 119 elementsPanel.setWidgetBelowDOM(!this._animationTimeline.isShowing() ? t
his._animationTimeline : null); | |
| 120 }, | |
| 121 | |
| 122 _animationControlPaneModeClick: function() | |
| 123 { | |
| 124 if (!this._animationsControlPane) | |
| 125 this._animationsControlPane = new WebInspector.AnimationControlPane(
this.item()); | |
| 126 var stylesSidebarPane = WebInspector.ElementsPanel.instance().sidebarPan
es.styles; | |
| 127 stylesSidebarPane.showToolbarPane(!this._animationsControlPane.isShowing
() ? this._animationsControlPane : null); | |
| 128 }, | |
| 129 | |
| 130 _clicked: function() | |
| 131 { | |
| 132 if (Runtime.experiments.isEnabled("animationInspection")) | |
| 133 this._animationTimelineModeClick(); | |
| 134 else | |
| 135 this._animationControlPaneModeClick(); | |
| 136 }, | |
| 137 | |
| 138 _nodeChanged: function() | |
| 139 { | |
| 140 this._button.setEnabled(!!WebInspector.context.flavor(WebInspector.DOMNo
de)); | |
| 141 }, | |
| 142 | |
| 143 /** | |
| 144 * @override | |
| 145 * @return {!WebInspector.ToolbarItem} | |
| 146 */ | |
| 147 item: function() | |
| 148 { | |
| 149 return this._button; | |
| 150 } | |
| 151 } | |
| OLD | NEW |