Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(41)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/animation/AnimationTimeline.js

Issue 2493373002: DevTools: rename WebInspector into modules. (Closed)
Patch Set: for bots Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 * @implements {WebInspector.TargetManager.Observer} 5 * @implements {SDK.TargetManager.Observer}
6 * @unrestricted 6 * @unrestricted
7 */ 7 */
8 WebInspector.AnimationTimeline = class extends WebInspector.VBox { 8 Animation.AnimationTimeline = class extends UI.VBox {
9 constructor() { 9 constructor() {
10 super(true); 10 super(true);
11 this.registerRequiredCSS('animation/animationTimeline.css'); 11 this.registerRequiredCSS('animation/animationTimeline.css');
12 this.element.classList.add('animations-timeline'); 12 this.element.classList.add('animations-timeline');
13 13
14 this._grid = this.contentElement.createSVGChild('svg', 'animation-timeline-g rid'); 14 this._grid = this.contentElement.createSVGChild('svg', 'animation-timeline-g rid');
15 15
16 this._playbackRate = 1; 16 this._playbackRate = 1;
17 this._allPaused = false; 17 this._allPaused = false;
18 this._createHeader(); 18 this._createHeader();
19 this._animationsContainer = this.contentElement.createChild('div', 'animatio n-timeline-rows'); 19 this._animationsContainer = this.contentElement.createChild('div', 'animatio n-timeline-rows');
20 var timelineHint = this.contentElement.createChild('div', 'animation-timelin e-rows-hint'); 20 var timelineHint = this.contentElement.createChild('div', 'animation-timelin e-rows-hint');
21 timelineHint.textContent = WebInspector.UIString('Select an effect above to inspect and modify.'); 21 timelineHint.textContent = Common.UIString('Select an effect above to inspec t and modify.');
22 22
23 /** @const */ this._defaultDuration = 100; 23 /** @const */ this._defaultDuration = 100;
24 this._duration = this._defaultDuration; 24 this._duration = this._defaultDuration;
25 /** @const */ this._timelineControlsWidth = 150; 25 /** @const */ this._timelineControlsWidth = 150;
26 /** @type {!Map.<!Protocol.DOM.BackendNodeId, !WebInspector.AnimationTimelin e.NodeUI>} */ 26 /** @type {!Map.<!Protocol.DOM.BackendNodeId, !Animation.AnimationTimeline.N odeUI>} */
27 this._nodesMap = new Map(); 27 this._nodesMap = new Map();
28 this._uiAnimations = []; 28 this._uiAnimations = [];
29 this._groupBuffer = []; 29 this._groupBuffer = [];
30 /** @type {!Map.<!WebInspector.AnimationModel.AnimationGroup, !WebInspector. AnimationGroupPreviewUI>} */ 30 /** @type {!Map.<!Animation.AnimationModel.AnimationGroup, !Animation.Animat ionGroupPreviewUI>} */
31 this._previewMap = new Map(); 31 this._previewMap = new Map();
32 this._symbol = Symbol('animationTimeline'); 32 this._symbol = Symbol('animationTimeline');
33 /** @type {!Map.<string, !WebInspector.AnimationModel.Animation>} */ 33 /** @type {!Map.<string, !Animation.AnimationModel.Animation>} */
34 this._animationsMap = new Map(); 34 this._animationsMap = new Map();
35 WebInspector.targetManager.addModelListener( 35 SDK.targetManager.addModelListener(
36 WebInspector.DOMModel, WebInspector.DOMModel.Events.NodeRemoved, this._n odeRemoved, this); 36 SDK.DOMModel, SDK.DOMModel.Events.NodeRemoved, this._nodeRemoved, this);
37 WebInspector.targetManager.observeTargets(this, WebInspector.Target.Capabili ty.DOM); 37 SDK.targetManager.observeTargets(this, SDK.Target.Capability.DOM);
38 WebInspector.context.addFlavorChangeListener(WebInspector.DOMNode, this._nod eChanged, this); 38 UI.context.addFlavorChangeListener(SDK.DOMNode, this._nodeChanged, this);
39 } 39 }
40 40
41 /** 41 /**
42 * @override 42 * @override
43 */ 43 */
44 wasShown() { 44 wasShown() {
45 for (var target of WebInspector.targetManager.targets(WebInspector.Target.Ca pability.DOM)) 45 for (var target of SDK.targetManager.targets(SDK.Target.Capability.DOM))
46 this._addEventListeners(target); 46 this._addEventListeners(target);
47 } 47 }
48 48
49 /** 49 /**
50 * @override 50 * @override
51 */ 51 */
52 willHide() { 52 willHide() {
53 for (var target of WebInspector.targetManager.targets(WebInspector.Target.Ca pability.DOM)) 53 for (var target of SDK.targetManager.targets(SDK.Target.Capability.DOM))
54 this._removeEventListeners(target); 54 this._removeEventListeners(target);
55 this._popoverHelper.hidePopover(); 55 this._popoverHelper.hidePopover();
56 } 56 }
57 57
58 /** 58 /**
59 * @override 59 * @override
60 * @param {!WebInspector.Target} target 60 * @param {!SDK.Target} target
61 */ 61 */
62 targetAdded(target) { 62 targetAdded(target) {
63 if (this.isShowing()) 63 if (this.isShowing())
64 this._addEventListeners(target); 64 this._addEventListeners(target);
65 } 65 }
66 66
67 /** 67 /**
68 * @override 68 * @override
69 * @param {!WebInspector.Target} target 69 * @param {!SDK.Target} target
70 */ 70 */
71 targetRemoved(target) { 71 targetRemoved(target) {
72 this._removeEventListeners(target); 72 this._removeEventListeners(target);
73 } 73 }
74 74
75 /** 75 /**
76 * @param {!WebInspector.Target} target 76 * @param {!SDK.Target} target
77 */ 77 */
78 _addEventListeners(target) { 78 _addEventListeners(target) {
79 var animationModel = WebInspector.AnimationModel.fromTarget(target); 79 var animationModel = Animation.AnimationModel.fromTarget(target);
80 animationModel.ensureEnabled(); 80 animationModel.ensureEnabled();
81 animationModel.addEventListener( 81 animationModel.addEventListener(
82 WebInspector.AnimationModel.Events.AnimationGroupStarted, this._animatio nGroupStarted, this); 82 Animation.AnimationModel.Events.AnimationGroupStarted, this._animationGr oupStarted, this);
83 animationModel.addEventListener(WebInspector.AnimationModel.Events.ModelRese t, this._reset, this); 83 animationModel.addEventListener(Animation.AnimationModel.Events.ModelReset, this._reset, this);
84 } 84 }
85 85
86 /** 86 /**
87 * @param {!WebInspector.Target} target 87 * @param {!SDK.Target} target
88 */ 88 */
89 _removeEventListeners(target) { 89 _removeEventListeners(target) {
90 var animationModel = WebInspector.AnimationModel.fromTarget(target); 90 var animationModel = Animation.AnimationModel.fromTarget(target);
91 animationModel.removeEventListener( 91 animationModel.removeEventListener(
92 WebInspector.AnimationModel.Events.AnimationGroupStarted, this._animatio nGroupStarted, this); 92 Animation.AnimationModel.Events.AnimationGroupStarted, this._animationGr oupStarted, this);
93 animationModel.removeEventListener(WebInspector.AnimationModel.Events.ModelR eset, this._reset, this); 93 animationModel.removeEventListener(Animation.AnimationModel.Events.ModelRese t, this._reset, this);
94 } 94 }
95 95
96 _nodeChanged() { 96 _nodeChanged() {
97 for (var nodeUI of this._nodesMap.values()) 97 for (var nodeUI of this._nodesMap.values())
98 nodeUI._nodeChanged(); 98 nodeUI._nodeChanged();
99 } 99 }
100 100
101 /** 101 /**
102 * @return {!Element} element 102 * @return {!Element} element
103 */ 103 */
104 _createScrubber() { 104 _createScrubber() {
105 this._timelineScrubber = createElementWithClass('div', 'animation-scrubber h idden'); 105 this._timelineScrubber = createElementWithClass('div', 'animation-scrubber h idden');
106 this._timelineScrubberLine = this._timelineScrubber.createChild('div', 'anim ation-scrubber-line'); 106 this._timelineScrubberLine = this._timelineScrubber.createChild('div', 'anim ation-scrubber-line');
107 this._timelineScrubberLine.createChild('div', 'animation-scrubber-head'); 107 this._timelineScrubberLine.createChild('div', 'animation-scrubber-head');
108 this._timelineScrubber.createChild('div', 'animation-time-overlay'); 108 this._timelineScrubber.createChild('div', 'animation-time-overlay');
109 return this._timelineScrubber; 109 return this._timelineScrubber;
110 } 110 }
111 111
112 _createHeader() { 112 _createHeader() {
113 var toolbarContainer = this.contentElement.createChild('div', 'animation-tim eline-toolbar-container'); 113 var toolbarContainer = this.contentElement.createChild('div', 'animation-tim eline-toolbar-container');
114 var topToolbar = new WebInspector.Toolbar('animation-timeline-toolbar', tool barContainer); 114 var topToolbar = new UI.Toolbar('animation-timeline-toolbar', toolbarContain er);
115 var clearButton = new WebInspector.ToolbarButton(WebInspector.UIString('Clea r all'), 'largeicon-clear'); 115 var clearButton = new UI.ToolbarButton(Common.UIString('Clear all'), 'largei con-clear');
116 clearButton.addEventListener('click', this._reset.bind(this)); 116 clearButton.addEventListener('click', this._reset.bind(this));
117 topToolbar.appendToolbarItem(clearButton); 117 topToolbar.appendToolbarItem(clearButton);
118 topToolbar.appendSeparator(); 118 topToolbar.appendSeparator();
119 119
120 this._pauseButton = new WebInspector.ToolbarToggle(WebInspector.UIString('Pa use all'), 'largeicon-pause', 'largeicon-resume'); 120 this._pauseButton = new UI.ToolbarToggle(Common.UIString('Pause all'), 'larg eicon-pause', 'largeicon-resume');
121 this._pauseButton.addEventListener('click', this._togglePauseAll.bind(this)) ; 121 this._pauseButton.addEventListener('click', this._togglePauseAll.bind(this)) ;
122 topToolbar.appendToolbarItem(this._pauseButton); 122 topToolbar.appendToolbarItem(this._pauseButton);
123 123
124 var playbackRateControl = toolbarContainer.createChild('div', 'animation-pla yback-rate-control'); 124 var playbackRateControl = toolbarContainer.createChild('div', 'animation-pla yback-rate-control');
125 this._playbackRateButtons = []; 125 this._playbackRateButtons = [];
126 for (var playbackRate of WebInspector.AnimationTimeline.GlobalPlaybackRates) { 126 for (var playbackRate of Animation.AnimationTimeline.GlobalPlaybackRates) {
127 var button = playbackRateControl.createChild('div', 'animation-playback-ra te-button'); 127 var button = playbackRateControl.createChild('div', 'animation-playback-ra te-button');
128 button.textContent = 128 button.textContent =
129 playbackRate ? WebInspector.UIString(playbackRate * 100 + '%') : WebIn spector.UIString('Pause'); 129 playbackRate ? Common.UIString(playbackRate * 100 + '%') : Common.UISt ring('Pause');
130 button.playbackRate = playbackRate; 130 button.playbackRate = playbackRate;
131 button.addEventListener('click', this._setPlaybackRate.bind(this, playback Rate)); 131 button.addEventListener('click', this._setPlaybackRate.bind(this, playback Rate));
132 button.title = WebInspector.UIString('Set speed to ') + button.textContent ; 132 button.title = Common.UIString('Set speed to ') + button.textContent;
133 this._playbackRateButtons.push(button); 133 this._playbackRateButtons.push(button);
134 } 134 }
135 this._updatePlaybackControls(); 135 this._updatePlaybackControls();
136 136
137 this._previewContainer = this.contentElement.createChild('div', 'animation-t imeline-buffer'); 137 this._previewContainer = this.contentElement.createChild('div', 'animation-t imeline-buffer');
138 this._popoverHelper = new WebInspector.PopoverHelper(this._previewContainer, true); 138 this._popoverHelper = new UI.PopoverHelper(this._previewContainer, true);
139 this._popoverHelper.initializeCallbacks( 139 this._popoverHelper.initializeCallbacks(
140 this._getPopoverAnchor.bind(this), this._showPopover.bind(this), this._o nHidePopover.bind(this)); 140 this._getPopoverAnchor.bind(this), this._showPopover.bind(this), this._o nHidePopover.bind(this));
141 this._popoverHelper.setTimeout(0); 141 this._popoverHelper.setTimeout(0);
142 var emptyBufferHint = this.contentElement.createChild('div', 'animation-time line-buffer-hint'); 142 var emptyBufferHint = this.contentElement.createChild('div', 'animation-time line-buffer-hint');
143 emptyBufferHint.textContent = WebInspector.UIString('Listening for animation s...'); 143 emptyBufferHint.textContent = Common.UIString('Listening for animations...') ;
144 var container = this.contentElement.createChild('div', 'animation-timeline-h eader'); 144 var container = this.contentElement.createChild('div', 'animation-timeline-h eader');
145 var controls = container.createChild('div', 'animation-controls'); 145 var controls = container.createChild('div', 'animation-controls');
146 this._currentTime = controls.createChild('div', 'animation-timeline-current- time monospace'); 146 this._currentTime = controls.createChild('div', 'animation-timeline-current- time monospace');
147 147
148 var toolbar = new WebInspector.Toolbar('animation-controls-toolbar', control s); 148 var toolbar = new UI.Toolbar('animation-controls-toolbar', controls);
149 this._controlButton = 149 this._controlButton =
150 new WebInspector.ToolbarToggle(WebInspector.UIString('Replay timeline'), 'largeicon-replay-animation'); 150 new UI.ToolbarToggle(Common.UIString('Replay timeline'), 'largeicon-repl ay-animation');
151 this._controlState = WebInspector.AnimationTimeline._ControlState.Replay; 151 this._controlState = Animation.AnimationTimeline._ControlState.Replay;
152 this._controlButton.setToggled(true); 152 this._controlButton.setToggled(true);
153 this._controlButton.addEventListener('click', this._controlButtonToggle.bind (this)); 153 this._controlButton.addEventListener('click', this._controlButtonToggle.bind (this));
154 toolbar.appendToolbarItem(this._controlButton); 154 toolbar.appendToolbarItem(this._controlButton);
155 155
156 var gridHeader = container.createChild('div', 'animation-grid-header'); 156 var gridHeader = container.createChild('div', 'animation-grid-header');
157 WebInspector.installDragHandle( 157 UI.installDragHandle(
158 gridHeader, this._repositionScrubber.bind(this), this._scrubberDragMove. bind(this), 158 gridHeader, this._repositionScrubber.bind(this), this._scrubberDragMove. bind(this),
159 this._scrubberDragEnd.bind(this), 'text'); 159 this._scrubberDragEnd.bind(this), 'text');
160 container.appendChild(this._createScrubber()); 160 container.appendChild(this._createScrubber());
161 WebInspector.installDragHandle( 161 UI.installDragHandle(
162 this._timelineScrubberLine, this._scrubberDragStart.bind(this), this._sc rubberDragMove.bind(this), 162 this._timelineScrubberLine, this._scrubberDragStart.bind(this), this._sc rubberDragMove.bind(this),
163 this._scrubberDragEnd.bind(this), 'col-resize'); 163 this._scrubberDragEnd.bind(this), 'col-resize');
164 this._currentTime.textContent = ''; 164 this._currentTime.textContent = '';
165 165
166 return container; 166 return container;
167 } 167 }
168 168
169 /** 169 /**
170 * @param {!Element} element 170 * @param {!Element} element
171 * @param {!Event} event 171 * @param {!Event} event
172 * @return {!Element|!AnchorBox|undefined} 172 * @return {!Element|!AnchorBox|undefined}
173 */ 173 */
174 _getPopoverAnchor(element, event) { 174 _getPopoverAnchor(element, event) {
175 if (element.isDescendant(this._previewContainer)) 175 if (element.isDescendant(this._previewContainer))
176 return element; 176 return element;
177 } 177 }
178 178
179 /** 179 /**
180 * @param {!Element} anchor 180 * @param {!Element} anchor
181 * @param {!WebInspector.Popover} popover 181 * @param {!UI.Popover} popover
182 */ 182 */
183 _showPopover(anchor, popover) { 183 _showPopover(anchor, popover) {
184 var animGroup; 184 var animGroup;
185 for (var group of this._previewMap.keysArray()) { 185 for (var group of this._previewMap.keysArray()) {
186 if (this._previewMap.get(group).element === anchor.parentElement) 186 if (this._previewMap.get(group).element === anchor.parentElement)
187 animGroup = group; 187 animGroup = group;
188 } 188 }
189 console.assert(animGroup); 189 console.assert(animGroup);
190 var screenshots = animGroup.screenshots(); 190 var screenshots = animGroup.screenshots();
191 if (!screenshots.length) 191 if (!screenshots.length)
192 return; 192 return;
193 193
194 if (!screenshots[0].complete) 194 if (!screenshots[0].complete)
195 screenshots[0].onload = onFirstScreenshotLoaded.bind(null, screenshots); 195 screenshots[0].onload = onFirstScreenshotLoaded.bind(null, screenshots);
196 else 196 else
197 onFirstScreenshotLoaded(screenshots); 197 onFirstScreenshotLoaded(screenshots);
198 198
199 /** 199 /**
200 * @param {!Array.<!Image>} screenshots 200 * @param {!Array.<!Image>} screenshots
201 */ 201 */
202 function onFirstScreenshotLoaded(screenshots) { 202 function onFirstScreenshotLoaded(screenshots) {
203 var content = new WebInspector.AnimationScreenshotPopover(screenshots); 203 var content = new Animation.AnimationScreenshotPopover(screenshots);
204 popover.setNoPadding(true); 204 popover.setNoPadding(true);
205 popover.showView(content, anchor); 205 popover.showView(content, anchor);
206 } 206 }
207 } 207 }
208 208
209 _onHidePopover() { 209 _onHidePopover() {
210 } 210 }
211 211
212 _togglePauseAll() { 212 _togglePauseAll() {
213 this._allPaused = !this._allPaused; 213 this._allPaused = !this._allPaused;
214 this._pauseButton.setToggled(this._allPaused); 214 this._pauseButton.setToggled(this._allPaused);
215 this._setPlaybackRate(this._playbackRate); 215 this._setPlaybackRate(this._playbackRate);
216 this._pauseButton.setTitle( 216 this._pauseButton.setTitle(
217 this._allPaused ? WebInspector.UIString('Resume all') : WebInspector.UIS tring('Pause all')); 217 this._allPaused ? Common.UIString('Resume all') : Common.UIString('Pause all'));
218 } 218 }
219 219
220 /** 220 /**
221 * @param {number} playbackRate 221 * @param {number} playbackRate
222 */ 222 */
223 _setPlaybackRate(playbackRate) { 223 _setPlaybackRate(playbackRate) {
224 this._playbackRate = playbackRate; 224 this._playbackRate = playbackRate;
225 var target = WebInspector.targetManager.mainTarget(); 225 var target = SDK.targetManager.mainTarget();
226 if (target) 226 if (target)
227 WebInspector.AnimationModel.fromTarget(target).setPlaybackRate(this._allPa used ? 0 : this._playbackRate); 227 Animation.AnimationModel.fromTarget(target).setPlaybackRate(this._allPause d ? 0 : this._playbackRate);
228 WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Action.Animati onsPlaybackRateChanged); 228 Host.userMetrics.actionTaken(Host.UserMetrics.Action.AnimationsPlaybackRateC hanged);
229 if (this._scrubberPlayer) 229 if (this._scrubberPlayer)
230 this._scrubberPlayer.playbackRate = this._effectivePlaybackRate(); 230 this._scrubberPlayer.playbackRate = this._effectivePlaybackRate();
231 231
232 this._updatePlaybackControls(); 232 this._updatePlaybackControls();
233 } 233 }
234 234
235 _updatePlaybackControls() { 235 _updatePlaybackControls() {
236 for (var button of this._playbackRateButtons) { 236 for (var button of this._playbackRateButtons) {
237 var selected = this._playbackRate === button.playbackRate; 237 var selected = this._playbackRate === button.playbackRate;
238 button.classList.toggle('selected', selected); 238 button.classList.toggle('selected', selected);
239 } 239 }
240 } 240 }
241 241
242 _controlButtonToggle() { 242 _controlButtonToggle() {
243 if (this._controlState === WebInspector.AnimationTimeline._ControlState.Play ) 243 if (this._controlState === Animation.AnimationTimeline._ControlState.Play)
244 this._togglePause(false); 244 this._togglePause(false);
245 else if (this._controlState === WebInspector.AnimationTimeline._ControlState .Replay) 245 else if (this._controlState === Animation.AnimationTimeline._ControlState.Re play)
246 this._replay(); 246 this._replay();
247 else 247 else
248 this._togglePause(true); 248 this._togglePause(true);
249 } 249 }
250 250
251 _updateControlButton() { 251 _updateControlButton() {
252 this._controlButton.setEnabled(!!this._selectedGroup); 252 this._controlButton.setEnabled(!!this._selectedGroup);
253 if (this._selectedGroup && this._selectedGroup.paused()) { 253 if (this._selectedGroup && this._selectedGroup.paused()) {
254 this._controlState = WebInspector.AnimationTimeline._ControlState.Play; 254 this._controlState = Animation.AnimationTimeline._ControlState.Play;
255 this._controlButton.setToggled(true); 255 this._controlButton.setToggled(true);
256 this._controlButton.setTitle(WebInspector.UIString('Play timeline')); 256 this._controlButton.setTitle(Common.UIString('Play timeline'));
257 this._controlButton.setGlyph('largeicon-play-animation'); 257 this._controlButton.setGlyph('largeicon-play-animation');
258 } else if (!this._scrubberPlayer || this._scrubberPlayer.currentTime >= this .duration()) { 258 } else if (!this._scrubberPlayer || this._scrubberPlayer.currentTime >= this .duration()) {
259 this._controlState = WebInspector.AnimationTimeline._ControlState.Replay; 259 this._controlState = Animation.AnimationTimeline._ControlState.Replay;
260 this._controlButton.setToggled(true); 260 this._controlButton.setToggled(true);
261 this._controlButton.setTitle(WebInspector.UIString('Replay timeline')); 261 this._controlButton.setTitle(Common.UIString('Replay timeline'));
262 this._controlButton.setGlyph('largeicon-replay-animation'); 262 this._controlButton.setGlyph('largeicon-replay-animation');
263 } else { 263 } else {
264 this._controlState = WebInspector.AnimationTimeline._ControlState.Pause; 264 this._controlState = Animation.AnimationTimeline._ControlState.Pause;
265 this._controlButton.setToggled(false); 265 this._controlButton.setToggled(false);
266 this._controlButton.setTitle(WebInspector.UIString('Pause timeline')); 266 this._controlButton.setTitle(Common.UIString('Pause timeline'));
267 this._controlButton.setGlyph('largeicon-pause-animation'); 267 this._controlButton.setGlyph('largeicon-pause-animation');
268 } 268 }
269 } 269 }
270 270
271 /** 271 /**
272 * @return {number} 272 * @return {number}
273 */ 273 */
274 _effectivePlaybackRate() { 274 _effectivePlaybackRate() {
275 return (this._allPaused || (this._selectedGroup && this._selectedGroup.pause d())) ? 0 : this._playbackRate; 275 return (this._allPaused || (this._selectedGroup && this._selectedGroup.pause d())) ? 0 : this._playbackRate;
276 } 276 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 for (var group of this._groupBuffer) 335 for (var group of this._groupBuffer)
336 group.release(); 336 group.release();
337 this._groupBuffer = []; 337 this._groupBuffer = [];
338 this._previewMap.clear(); 338 this._previewMap.clear();
339 this._previewContainer.removeChildren(); 339 this._previewContainer.removeChildren();
340 this._popoverHelper.hidePopover(); 340 this._popoverHelper.hidePopover();
341 this._renderGrid(); 341 this._renderGrid();
342 } 342 }
343 343
344 /** 344 /**
345 * @param {!WebInspector.Event} event 345 * @param {!Common.Event} event
346 */ 346 */
347 _animationGroupStarted(event) { 347 _animationGroupStarted(event) {
348 this._addAnimationGroup(/** @type {!WebInspector.AnimationModel.AnimationGro up} */ (event.data)); 348 this._addAnimationGroup(/** @type {!Animation.AnimationModel.AnimationGroup} */ (event.data));
349 } 349 }
350 350
351 /** 351 /**
352 * @param {!WebInspector.AnimationModel.AnimationGroup} group 352 * @param {!Animation.AnimationModel.AnimationGroup} group
353 */ 353 */
354 _addAnimationGroup(group) { 354 _addAnimationGroup(group) {
355 /** 355 /**
356 * @param {!WebInspector.AnimationModel.AnimationGroup} left 356 * @param {!Animation.AnimationModel.AnimationGroup} left
357 * @param {!WebInspector.AnimationModel.AnimationGroup} right 357 * @param {!Animation.AnimationModel.AnimationGroup} right
358 */ 358 */
359 function startTimeComparator(left, right) { 359 function startTimeComparator(left, right) {
360 return left.startTime() > right.startTime(); 360 return left.startTime() > right.startTime();
361 } 361 }
362 362
363 if (this._previewMap.get(group)) { 363 if (this._previewMap.get(group)) {
364 if (this._selectedGroup === group) 364 if (this._selectedGroup === group)
365 this._syncScrubber(); 365 this._syncScrubber();
366 else 366 else
367 this._previewMap.get(group).replay(); 367 this._previewMap.get(group).replay();
368 return; 368 return;
369 } 369 }
370 this._groupBuffer.sort(startTimeComparator); 370 this._groupBuffer.sort(startTimeComparator);
371 // Discard oldest groups from buffer if necessary 371 // Discard oldest groups from buffer if necessary
372 var groupsToDiscard = []; 372 var groupsToDiscard = [];
373 var bufferSize = this.width() / 50; 373 var bufferSize = this.width() / 50;
374 while (this._groupBuffer.length > bufferSize) { 374 while (this._groupBuffer.length > bufferSize) {
375 var toDiscard = this._groupBuffer.splice(this._groupBuffer[0] === this._se lectedGroup ? 1 : 0, 1); 375 var toDiscard = this._groupBuffer.splice(this._groupBuffer[0] === this._se lectedGroup ? 1 : 0, 1);
376 groupsToDiscard.push(toDiscard[0]); 376 groupsToDiscard.push(toDiscard[0]);
377 } 377 }
378 for (var g of groupsToDiscard) { 378 for (var g of groupsToDiscard) {
379 this._previewMap.get(g).element.remove(); 379 this._previewMap.get(g).element.remove();
380 this._previewMap.delete(g); 380 this._previewMap.delete(g);
381 g.release(); 381 g.release();
382 } 382 }
383 // Generate preview 383 // Generate preview
384 var preview = new WebInspector.AnimationGroupPreviewUI(group); 384 var preview = new Animation.AnimationGroupPreviewUI(group);
385 this._groupBuffer.push(group); 385 this._groupBuffer.push(group);
386 this._previewMap.set(group, preview); 386 this._previewMap.set(group, preview);
387 this._previewContainer.appendChild(preview.element); 387 this._previewContainer.appendChild(preview.element);
388 preview.removeButton().addEventListener('click', this._removeAnimationGroup. bind(this, group)); 388 preview.removeButton().addEventListener('click', this._removeAnimationGroup. bind(this, group));
389 preview.element.addEventListener('click', this._selectAnimationGroup.bind(th is, group)); 389 preview.element.addEventListener('click', this._selectAnimationGroup.bind(th is, group));
390 } 390 }
391 391
392 /** 392 /**
393 * @param {!WebInspector.AnimationModel.AnimationGroup} group 393 * @param {!Animation.AnimationModel.AnimationGroup} group
394 * @param {!Event} event 394 * @param {!Event} event
395 */ 395 */
396 _removeAnimationGroup(group, event) { 396 _removeAnimationGroup(group, event) {
397 this._groupBuffer.remove(group); 397 this._groupBuffer.remove(group);
398 this._previewMap.get(group).element.remove(); 398 this._previewMap.get(group).element.remove();
399 this._previewMap.delete(group); 399 this._previewMap.delete(group);
400 group.release(); 400 group.release();
401 event.consume(true); 401 event.consume(true);
402 402
403 if (this._selectedGroup === group) { 403 if (this._selectedGroup === group) {
404 this._clearTimeline(); 404 this._clearTimeline();
405 this._renderGrid(); 405 this._renderGrid();
406 } 406 }
407 } 407 }
408 408
409 /** 409 /**
410 * @param {!WebInspector.AnimationModel.AnimationGroup} group 410 * @param {!Animation.AnimationModel.AnimationGroup} group
411 */ 411 */
412 _selectAnimationGroup(group) { 412 _selectAnimationGroup(group) {
413 /** 413 /**
414 * @param {!WebInspector.AnimationGroupPreviewUI} ui 414 * @param {!Animation.AnimationGroupPreviewUI} ui
415 * @param {!WebInspector.AnimationModel.AnimationGroup} group 415 * @param {!Animation.AnimationModel.AnimationGroup} group
416 * @this {!WebInspector.AnimationTimeline} 416 * @this {!Animation.AnimationTimeline}
417 */ 417 */
418 function applySelectionClass(ui, group) { 418 function applySelectionClass(ui, group) {
419 ui.element.classList.toggle('selected', this._selectedGroup === group); 419 ui.element.classList.toggle('selected', this._selectedGroup === group);
420 } 420 }
421 421
422 if (this._selectedGroup === group) { 422 if (this._selectedGroup === group) {
423 this._togglePause(false); 423 this._togglePause(false);
424 this._replay(); 424 this._replay();
425 return; 425 return;
426 } 426 }
427 this._clearTimeline(); 427 this._clearTimeline();
428 this._selectedGroup = group; 428 this._selectedGroup = group;
429 this._previewMap.forEach(applySelectionClass, this); 429 this._previewMap.forEach(applySelectionClass, this);
430 this.setDuration(Math.max(500, group.finiteDuration() + 100)); 430 this.setDuration(Math.max(500, group.finiteDuration() + 100));
431 for (var anim of group.animations()) 431 for (var anim of group.animations())
432 this._addAnimation(anim); 432 this._addAnimation(anim);
433 this.scheduleRedraw(); 433 this.scheduleRedraw();
434 this._timelineScrubber.classList.remove('hidden'); 434 this._timelineScrubber.classList.remove('hidden');
435 this._togglePause(false); 435 this._togglePause(false);
436 this._replay(); 436 this._replay();
437 } 437 }
438 438
439 /** 439 /**
440 * @param {!WebInspector.AnimationModel.Animation} animation 440 * @param {!Animation.AnimationModel.Animation} animation
441 */ 441 */
442 _addAnimation(animation) { 442 _addAnimation(animation) {
443 /** 443 /**
444 * @param {?WebInspector.DOMNode} node 444 * @param {?SDK.DOMNode} node
445 * @this {WebInspector.AnimationTimeline} 445 * @this {Animation.AnimationTimeline}
446 */ 446 */
447 function nodeResolved(node) { 447 function nodeResolved(node) {
448 nodeUI.nodeResolved(node); 448 nodeUI.nodeResolved(node);
449 uiAnimation.setNode(node); 449 uiAnimation.setNode(node);
450 if (node) 450 if (node)
451 node[this._symbol] = nodeUI; 451 node[this._symbol] = nodeUI;
452 } 452 }
453 453
454 var nodeUI = this._nodesMap.get(animation.source().backendNodeId()); 454 var nodeUI = this._nodesMap.get(animation.source().backendNodeId());
455 if (!nodeUI) { 455 if (!nodeUI) {
456 nodeUI = new WebInspector.AnimationTimeline.NodeUI(animation.source()); 456 nodeUI = new Animation.AnimationTimeline.NodeUI(animation.source());
457 this._animationsContainer.appendChild(nodeUI.element); 457 this._animationsContainer.appendChild(nodeUI.element);
458 this._nodesMap.set(animation.source().backendNodeId(), nodeUI); 458 this._nodesMap.set(animation.source().backendNodeId(), nodeUI);
459 } 459 }
460 var nodeRow = nodeUI.createNewRow(); 460 var nodeRow = nodeUI.createNewRow();
461 var uiAnimation = new WebInspector.AnimationUI(animation, this, nodeRow); 461 var uiAnimation = new Animation.AnimationUI(animation, this, nodeRow);
462 animation.source().deferredNode().resolve(nodeResolved.bind(this)); 462 animation.source().deferredNode().resolve(nodeResolved.bind(this));
463 this._uiAnimations.push(uiAnimation); 463 this._uiAnimations.push(uiAnimation);
464 this._animationsMap.set(animation.id(), animation); 464 this._animationsMap.set(animation.id(), animation);
465 } 465 }
466 466
467 /** 467 /**
468 * @param {!WebInspector.Event} event 468 * @param {!Common.Event} event
469 */ 469 */
470 _nodeRemoved(event) { 470 _nodeRemoved(event) {
471 var node = event.data.node; 471 var node = event.data.node;
472 if (node[this._symbol]) 472 if (node[this._symbol])
473 node[this._symbol].nodeRemoved(); 473 node[this._symbol].nodeRemoved();
474 } 474 }
475 475
476 _renderGrid() { 476 _renderGrid() {
477 /** @const */ var gridSize = 250; 477 /** @const */ var gridSize = 250;
478 this._grid.setAttribute('width', this.width() + 10); 478 this._grid.setAttribute('width', this.width() + 10);
479 this._grid.setAttribute('height', this._cachedTimelineHeight + 30); 479 this._grid.setAttribute('height', this._cachedTimelineHeight + 30);
480 this._grid.setAttribute('shape-rendering', 'crispEdges'); 480 this._grid.setAttribute('shape-rendering', 'crispEdges');
481 this._grid.removeChildren(); 481 this._grid.removeChildren();
482 var lastDraw = undefined; 482 var lastDraw = undefined;
483 for (var time = 0; time < this.duration(); time += gridSize) { 483 for (var time = 0; time < this.duration(); time += gridSize) {
484 var line = this._grid.createSVGChild('rect', 'animation-timeline-grid-line '); 484 var line = this._grid.createSVGChild('rect', 'animation-timeline-grid-line ');
485 line.setAttribute('x', time * this.pixelMsRatio() + 10); 485 line.setAttribute('x', time * this.pixelMsRatio() + 10);
486 line.setAttribute('y', 23); 486 line.setAttribute('y', 23);
487 line.setAttribute('height', '100%'); 487 line.setAttribute('height', '100%');
488 line.setAttribute('width', 1); 488 line.setAttribute('width', 1);
489 } 489 }
490 for (var time = 0; time < this.duration(); time += gridSize) { 490 for (var time = 0; time < this.duration(); time += gridSize) {
491 var gridWidth = time * this.pixelMsRatio(); 491 var gridWidth = time * this.pixelMsRatio();
492 if (lastDraw === undefined || gridWidth - lastDraw > 50) { 492 if (lastDraw === undefined || gridWidth - lastDraw > 50) {
493 lastDraw = gridWidth; 493 lastDraw = gridWidth;
494 var label = this._grid.createSVGChild('text', 'animation-timeline-grid-l abel'); 494 var label = this._grid.createSVGChild('text', 'animation-timeline-grid-l abel');
495 label.textContent = WebInspector.UIString(Number.millisToString(time)); 495 label.textContent = Common.UIString(Number.millisToString(time));
496 label.setAttribute('x', gridWidth + 10); 496 label.setAttribute('x', gridWidth + 10);
497 label.setAttribute('y', 16); 497 label.setAttribute('y', 16);
498 } 498 }
499 } 499 }
500 } 500 }
501 501
502 scheduleRedraw() { 502 scheduleRedraw() {
503 this._renderQueue = []; 503 this._renderQueue = [];
504 for (var ui of this._uiAnimations) 504 for (var ui of this._uiAnimations)
505 this._renderQueue.push(ui); 505 this._renderQueue.push(ui);
(...skipping 29 matching lines...) Expand all
535 } 535 }
536 536
537 /** 537 /**
538 * @return {number} 538 * @return {number}
539 */ 539 */
540 width() { 540 width() {
541 return this._cachedTimelineWidth || 0; 541 return this._cachedTimelineWidth || 0;
542 } 542 }
543 543
544 /** 544 /**
545 * @param {!WebInspector.AnimationModel.Animation} animation 545 * @param {!Animation.AnimationModel.Animation} animation
546 * @return {boolean} 546 * @return {boolean}
547 */ 547 */
548 _resizeWindow(animation) { 548 _resizeWindow(animation) {
549 var resized = false; 549 var resized = false;
550 550
551 // This shows at most 3 iterations 551 // This shows at most 3 iterations
552 var duration = animation.source().duration() * Math.min(2, animation.source( ).iterations()); 552 var duration = animation.source().duration() * Math.min(2, animation.source( ).iterations());
553 var requiredDuration = animation.source().delay() + duration + animation.sou rce().endDelay(); 553 var requiredDuration = animation.source().delay() + duration + animation.sou rce().endDelay();
554 if (requiredDuration > this._duration) { 554 if (requiredDuration > this._duration) {
555 resized = true; 555 resized = true;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 pixelMsRatio() { 588 pixelMsRatio() {
589 return this.width() / this.duration() || 0; 589 return this.width() / this.duration() || 0;
590 } 590 }
591 591
592 /** 592 /**
593 * @param {number} timestamp 593 * @param {number} timestamp
594 */ 594 */
595 _updateScrubber(timestamp) { 595 _updateScrubber(timestamp) {
596 if (!this._scrubberPlayer) 596 if (!this._scrubberPlayer)
597 return; 597 return;
598 this._currentTime.textContent = WebInspector.UIString(Number.millisToString( this._scrubberPlayer.currentTime)); 598 this._currentTime.textContent = Common.UIString(Number.millisToString(this._ scrubberPlayer.currentTime));
599 if (this._scrubberPlayer.playState === 'pending' || this._scrubberPlayer.pla yState === 'running') { 599 if (this._scrubberPlayer.playState === 'pending' || this._scrubberPlayer.pla yState === 'running') {
600 this.element.window().requestAnimationFrame(this._updateScrubber.bind(this )); 600 this.element.window().requestAnimationFrame(this._updateScrubber.bind(this ));
601 } else if (this._scrubberPlayer.playState === 'finished') { 601 } else if (this._scrubberPlayer.playState === 'finished') {
602 this._currentTime.textContent = ''; 602 this._currentTime.textContent = '';
603 } 603 }
604 } 604 }
605 605
606 /** 606 /**
607 * @param {!Event} event 607 * @param {!Event} event
608 * @return {boolean} 608 * @return {boolean}
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 return true; 642 return true;
643 } 643 }
644 644
645 /** 645 /**
646 * @param {!Event} event 646 * @param {!Event} event
647 */ 647 */
648 _scrubberDragMove(event) { 648 _scrubberDragMove(event) {
649 var delta = event.x - this._originalMousePosition; 649 var delta = event.x - this._originalMousePosition;
650 var currentTime = Math.max(0, Math.min(this._originalScrubberTime + delta / this.pixelMsRatio(), this.duration())); 650 var currentTime = Math.max(0, Math.min(this._originalScrubberTime + delta / this.pixelMsRatio(), this.duration()));
651 this._scrubberPlayer.currentTime = currentTime; 651 this._scrubberPlayer.currentTime = currentTime;
652 this._currentTime.textContent = WebInspector.UIString(Number.millisToString( Math.round(currentTime))); 652 this._currentTime.textContent = Common.UIString(Number.millisToString(Math.r ound(currentTime)));
653 this._selectedGroup.seekTo(currentTime); 653 this._selectedGroup.seekTo(currentTime);
654 } 654 }
655 655
656 /** 656 /**
657 * @param {!Event} event 657 * @param {!Event} event
658 */ 658 */
659 _scrubberDragEnd(event) { 659 _scrubberDragEnd(event) {
660 var currentTime = Math.max(0, this._scrubberPlayer.currentTime); 660 var currentTime = Math.max(0, this._scrubberPlayer.currentTime);
661 this._scrubberPlayer.play(); 661 this._scrubberPlayer.play();
662 this._scrubberPlayer.currentTime = currentTime; 662 this._scrubberPlayer.currentTime = currentTime;
663 this._currentTime.window().requestAnimationFrame(this._updateScrubber.bind(t his)); 663 this._currentTime.window().requestAnimationFrame(this._updateScrubber.bind(t his));
664 } 664 }
665 }; 665 };
666 666
667 WebInspector.AnimationTimeline.GlobalPlaybackRates = [1, 0.25, 0.1]; 667 Animation.AnimationTimeline.GlobalPlaybackRates = [1, 0.25, 0.1];
668 668
669 /** @enum {string} */ 669 /** @enum {string} */
670 WebInspector.AnimationTimeline._ControlState = { 670 Animation.AnimationTimeline._ControlState = {
671 Play: 'play-outline', 671 Play: 'play-outline',
672 Replay: 'replay-outline', 672 Replay: 'replay-outline',
673 Pause: 'pause-outline' 673 Pause: 'pause-outline'
674 }; 674 };
675 675
676 /** 676 /**
677 * @unrestricted 677 * @unrestricted
678 */ 678 */
679 WebInspector.AnimationTimeline.NodeUI = class { 679 Animation.AnimationTimeline.NodeUI = class {
680 /** 680 /**
681 * @param {!WebInspector.AnimationModel.AnimationEffect} animationEffect 681 * @param {!Animation.AnimationModel.AnimationEffect} animationEffect
682 */ 682 */
683 constructor(animationEffect) { 683 constructor(animationEffect) {
684 this.element = createElementWithClass('div', 'animation-node-row'); 684 this.element = createElementWithClass('div', 'animation-node-row');
685 this._description = this.element.createChild('div', 'animation-node-descript ion'); 685 this._description = this.element.createChild('div', 'animation-node-descript ion');
686 this._timelineElement = this.element.createChild('div', 'animation-node-time line'); 686 this._timelineElement = this.element.createChild('div', 'animation-node-time line');
687 } 687 }
688 688
689 /** 689 /**
690 * @param {?WebInspector.DOMNode} node 690 * @param {?SDK.DOMNode} node
691 */ 691 */
692 nodeResolved(node) { 692 nodeResolved(node) {
693 if (!node) { 693 if (!node) {
694 this._description.createTextChild(WebInspector.UIString('<node>')); 694 this._description.createTextChild(Common.UIString('<node>'));
695 return; 695 return;
696 } 696 }
697 this._node = node; 697 this._node = node;
698 this._nodeChanged(); 698 this._nodeChanged();
699 this._description.appendChild(WebInspector.DOMPresentationUtils.linkifyNodeR eference(node)); 699 this._description.appendChild(Components.DOMPresentationUtils.linkifyNodeRef erence(node));
700 if (!node.ownerDocument) 700 if (!node.ownerDocument)
701 this.nodeRemoved(); 701 this.nodeRemoved();
702 } 702 }
703 703
704 /** 704 /**
705 * @return {!Element} 705 * @return {!Element}
706 */ 706 */
707 createNewRow() { 707 createNewRow() {
708 return this._timelineElement.createChild('div', 'animation-timeline-row'); 708 return this._timelineElement.createChild('div', 'animation-timeline-row');
709 } 709 }
710 710
711 nodeRemoved() { 711 nodeRemoved() {
712 this.element.classList.add('animation-node-removed'); 712 this.element.classList.add('animation-node-removed');
713 this._node = null; 713 this._node = null;
714 } 714 }
715 715
716 _nodeChanged() { 716 _nodeChanged() {
717 this.element.classList.toggle( 717 this.element.classList.toggle(
718 'animation-node-selected', this._node && this._node === WebInspector.con text.flavor(WebInspector.DOMNode)); 718 'animation-node-selected', this._node && this._node === UI.context.flavo r(SDK.DOMNode));
719 } 719 }
720 }; 720 };
721 721
722 /** 722 /**
723 * @unrestricted 723 * @unrestricted
724 */ 724 */
725 WebInspector.AnimationTimeline.StepTimingFunction = class { 725 Animation.AnimationTimeline.StepTimingFunction = class {
726 /** 726 /**
727 * @param {number} steps 727 * @param {number} steps
728 * @param {string} stepAtPosition 728 * @param {string} stepAtPosition
729 */ 729 */
730 constructor(steps, stepAtPosition) { 730 constructor(steps, stepAtPosition) {
731 this.steps = steps; 731 this.steps = steps;
732 this.stepAtPosition = stepAtPosition; 732 this.stepAtPosition = stepAtPosition;
733 } 733 }
734 734
735 /** 735 /**
736 * @param {string} text 736 * @param {string} text
737 * @return {?WebInspector.AnimationTimeline.StepTimingFunction} 737 * @return {?Animation.AnimationTimeline.StepTimingFunction}
738 */ 738 */
739 static parse(text) { 739 static parse(text) {
740 var match = text.match(/^steps\((\d+), (start|middle)\)$/); 740 var match = text.match(/^steps\((\d+), (start|middle)\)$/);
741 if (match) 741 if (match)
742 return new WebInspector.AnimationTimeline.StepTimingFunction(parseInt(matc h[1], 10), match[2]); 742 return new Animation.AnimationTimeline.StepTimingFunction(parseInt(match[1 ], 10), match[2]);
743 match = text.match(/^steps\((\d+)\)$/); 743 match = text.match(/^steps\((\d+)\)$/);
744 if (match) 744 if (match)
745 return new WebInspector.AnimationTimeline.StepTimingFunction(parseInt(matc h[1], 10), 'end'); 745 return new Animation.AnimationTimeline.StepTimingFunction(parseInt(match[1 ], 10), 'end');
746 return null; 746 return null;
747 } 747 }
748 }; 748 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698