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

Side by Side Diff: Source/devtools/front_end/elements/AnimationTimeline.js

Issue 895783004: Devtools Animations: Timeline interactions change the underlying style (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix annotations Created 5 years, 10 months 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | Source/devtools/front_end/elements/AnimationsSidebarPane.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 /** 5 /**
6 * @constructor 6 * @constructor
7 * @extends {WebInspector.VBox} 7 * @extends {WebInspector.VBox}
8 * @param {!WebInspector.StylesSidebarPane} stylesPane
8 */ 9 */
9 WebInspector.AnimationTimeline = function() { 10 WebInspector.AnimationTimeline = function(stylesPane)
11 {
10 WebInspector.VBox.call(this, true); 12 WebInspector.VBox.call(this, true);
13 this._stylesPane = stylesPane;
11 this.registerRequiredCSS("elements/animationTimeline.css"); 14 this.registerRequiredCSS("elements/animationTimeline.css");
12 this.element.classList.add("animations-timeline"); 15 this.element.classList.add("animations-timeline");
16
13 this._animations = []; 17 this._animations = [];
14 this._uiAnimations = []; 18 this._uiAnimations = [];
15 this._duration = this._defaultDuration(); 19 this._duration = this._defaultDuration();
16 WebInspector.targetManager.addModelListener(WebInspector.ResourceTreeModel, WebInspector.ResourceTreeModel.EventTypes.MainFrameNavigated, this._mainFrameNav igated, this); 20 WebInspector.targetManager.addModelListener(WebInspector.ResourceTreeModel, WebInspector.ResourceTreeModel.EventTypes.MainFrameNavigated, this._mainFrameNav igated, this);
17 } 21 }
18 22
19 WebInspector.AnimationTimeline.prototype = { 23 WebInspector.AnimationTimeline.prototype = {
20 /** 24 /**
21 * @return {number} 25 * @return {number}
22 */ 26 */
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 */ 82 */
79 addAnimation: function(animation) 83 addAnimation: function(animation)
80 { 84 {
81 /** 85 /**
82 * @param {!Element} description 86 * @param {!Element} description
83 * @param {?WebInspector.DOMNode} node 87 * @param {?WebInspector.DOMNode} node
84 */ 88 */
85 function nodeResolved(description, node) 89 function nodeResolved(description, node)
86 { 90 {
87 description.appendChild(WebInspector.DOMPresentationUtils.linkifyNod eReference(node)); 91 description.appendChild(WebInspector.DOMPresentationUtils.linkifyNod eReference(node));
92 uiAnimation.setNode(node);
88 } 93 }
89 94
90 if (!this._inThreshold(animation)) 95 if (!this._inThreshold(animation))
91 this._reset(); 96 this._reset();
92 97
93 var row = this.contentElement.createChild("div", "animation-row"); 98 var row = this.contentElement.createChild("div", "animation-row");
94 var description = row.createChild("div", "animation-node-description"); 99 var description = row.createChild("div", "animation-node-description");
95 animation.source().getNode(nodeResolved.bind(null, description)); 100 animation.source().getNode(nodeResolved.bind(null, description));
96 var container = row.createChild("div", "animation-timeline-row"); 101 var container = row.createChild("div", "animation-timeline-row");
97 102
98 this._resizeWindow(animation); 103 this._resizeWindow(animation);
99 this._animations.push(animation); 104 this._animations.push(animation);
100 105
101 this._uiAnimations.push(new WebInspector.AnimationUI(animation, this, co ntainer)); 106 var uiAnimation = new WebInspector.AnimationUI(this._stylesPane, animati on, this, container);
107 this._uiAnimations.push(uiAnimation);
102 this.redraw(); 108 this.redraw();
103 }, 109 },
104 110
105 redraw: function() 111 redraw: function()
106 { 112 {
107 for (var i = 0; i < this._uiAnimations.length; i++) 113 for (var i = 0; i < this._uiAnimations.length; i++)
108 this._uiAnimations[i].redraw(); 114 this._uiAnimations[i].redraw();
109 }, 115 },
110 116
111 onResize: function() 117 onResize: function()
(...skipping 13 matching lines...) Expand all
125 var iterations = animation.source().iterations() || 1; 131 var iterations = animation.source().iterations() || 1;
126 var duration = animation.source().duration() * Math.min(2, iterations); 132 var duration = animation.source().duration() * Math.min(2, iterations);
127 this._duration = Math.max(this._duration, animation.startTime() + durati on + animation.source().delay() - this._startTime + 50); 133 this._duration = Math.max(this._duration, animation.startTime() + durati on + animation.source().delay() - this._startTime + 50);
128 }, 134 },
129 135
130 __proto__: WebInspector.VBox.prototype 136 __proto__: WebInspector.VBox.prototype
131 } 137 }
132 138
133 /** 139 /**
134 * @constructor 140 * @constructor
141 * @param {!WebInspector.StylesSidebarPane} stylesPane
135 * @param {!WebInspector.AnimationModel.AnimationPlayer} animation 142 * @param {!WebInspector.AnimationModel.AnimationPlayer} animation
136 * @param {!WebInspector.AnimationTimeline} timeline 143 * @param {!WebInspector.AnimationTimeline} timeline
137 * @param {!Element} parentElement 144 * @param {!Element} parentElement
138 */ 145 */
139 WebInspector.AnimationUI = function(animation, timeline, parentElement) { 146 WebInspector.AnimationUI = function(stylesPane, animation, timeline, parentEleme nt) {
147 this._stylesPane = stylesPane;
140 this._animation = animation; 148 this._animation = animation;
141 this._timeline = timeline; 149 this._timeline = timeline;
142 this._parentElement = parentElement; 150 this._parentElement = parentElement;
143 151
144 this._grid = parentElement.createChild("canvas", "animation-timeline-grid-ro w"); 152 this._grid = parentElement.createChild("canvas", "animation-timeline-grid-ro w");
145 if (this._animation.source().keyframesRule()) 153 if (this._animation.source().keyframesRule())
146 this._keyframes = this._animation.source().keyframesRule().keyframes(); 154 this._keyframes = this._animation.source().keyframesRule().keyframes();
147 155
148 this._nameElement = parentElement.createChild("div", "animation-name"); 156 this._nameElement = parentElement.createChild("div", "animation-name");
149 this._nameElement.textContent = this._animation.name(); 157 this._nameElement.textContent = this._animation.name();
(...skipping 12 matching lines...) Expand all
162 * @enum {string} 170 * @enum {string}
163 */ 171 */
164 WebInspector.AnimationUI.MouseEvents = { 172 WebInspector.AnimationUI.MouseEvents = {
165 AnimationDrag: "AnimationDrag", 173 AnimationDrag: "AnimationDrag",
166 KeyframeMove: "KeyframeMove", 174 KeyframeMove: "KeyframeMove",
167 StartEndpointMove: "StartEndpointMove", 175 StartEndpointMove: "StartEndpointMove",
168 FinishEndpointMove: "FinishEndpointMove" 176 FinishEndpointMove: "FinishEndpointMove"
169 } 177 }
170 178
171 WebInspector.AnimationUI.prototype = { 179 WebInspector.AnimationUI.prototype = {
180 /**
181 * @param {?WebInspector.DOMNode} node
182 */
183 setNode: function(node)
184 {
185 this._node = node;
186 },
187
172 _renderGrid: function() 188 _renderGrid: function()
173 { 189 {
174 var width = parseInt(window.getComputedStyle(this._parentElement).width, 10); 190 var width = parseInt(window.getComputedStyle(this._parentElement).width, 10);
175 const height = WebInspector.AnimationUI.Options.GridCanvasHeight; 191 const height = WebInspector.AnimationUI.Options.GridCanvasHeight;
176 const minorMs = this._timeline.duration() / 20; 192 const minorMs = this._timeline.duration() / 20;
177 const majorMs = minorMs * 5; 193 const majorMs = minorMs * 5;
178 194
179 this._grid.width = width * window.devicePixelRatio; 195 this._grid.width = width * window.devicePixelRatio;
180 this._grid.height = height * window.devicePixelRatio; 196 this._grid.height = height * window.devicePixelRatio;
181 this._grid.style.width = width + "px"; 197 this._grid.style.width = width + "px";
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 } 301 }
286 } 302 }
287 this._drawPoint(this._duration() * this._pixelMsRatio() + WebInspector. AnimationUI.Options.AnimationMargin, -1); 303 this._drawPoint(this._duration() * this._pixelMsRatio() + WebInspector. AnimationUI.Options.AnimationMargin, -1);
288 }, 304 },
289 305
290 /** 306 /**
291 * @return {number} 307 * @return {number}
292 */ 308 */
293 _pixelMsRatio: function() 309 _pixelMsRatio: function()
294 { 310 {
295 return parseInt(window.getComputedStyle(this._parentElement).width, 10) / this._timeline.duration(); 311 return parseInt(window.getComputedStyle(this._parentElement).width, 10) / this._timeline.duration() || 0;
296 }, 312 },
297 313
298 /** 314 /**
299 * @return {number} 315 * @return {number}
300 */ 316 */
301 _delay: function() 317 _delay: function()
302 { 318 {
303 var delay = this._animation.source().delay(); 319 var delay = this._animation.source().delay();
304 if (this._mouseEventType === WebInspector.AnimationUI.MouseEvents.Animat ionDrag || this._mouseEventType === WebInspector.AnimationUI.MouseEvents.Star tEndpointMove) 320 if (this._mouseEventType === WebInspector.AnimationUI.MouseEvents.Animat ionDrag || this._mouseEventType === WebInspector.AnimationUI.MouseEvents.Star tEndpointMove)
305 delay += this._movementInMs; 321 delay += this._movementInMs;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 { 361 {
346 this._mouseEventType = mouseEventType; 362 this._mouseEventType = mouseEventType;
347 this._keyframeMoved = keyframeIndex; 363 this._keyframeMoved = keyframeIndex;
348 this._downMouseX = event.clientX; 364 this._downMouseX = event.clientX;
349 this._mouseMoveHandler = this._mouseMove.bind(this); 365 this._mouseMoveHandler = this._mouseMove.bind(this);
350 this._mouseUpHandler = this._mouseUp.bind(this); 366 this._mouseUpHandler = this._mouseUp.bind(this);
351 this._parentElement.ownerDocument.addEventListener("mousemove", this._mo useMoveHandler); 367 this._parentElement.ownerDocument.addEventListener("mousemove", this._mo useMoveHandler);
352 this._parentElement.ownerDocument.addEventListener("mouseup", this._mous eUpHandler); 368 this._parentElement.ownerDocument.addEventListener("mouseup", this._mous eUpHandler);
353 event.preventDefault(); 369 event.preventDefault();
354 event.stopPropagation(); 370 event.stopPropagation();
371
372 if (this._node)
373 WebInspector.Revealer.reveal(this._node);
355 }, 374 },
356 375
357 /** 376 /**
358 * @param {!Event} event 377 * @param {!Event} event
359 */ 378 */
360 _mouseMove: function (event) 379 _mouseMove: function (event)
361 { 380 {
362 this._movementInMs = (event.clientX - this._downMouseX) / this._pixelMsR atio(); 381 this._movementInMs = (event.clientX - this._downMouseX) / this._pixelMsR atio();
363 this.redraw(); 382 this.redraw();
364 }, 383 },
365 384
366 /** 385 /**
367 * @param {!Event} event 386 * @param {!Event} event
368 */ 387 */
369 _mouseUp: function(event) 388 _mouseUp: function(event)
370 { 389 {
371 this._movementInMs = (event.clientX - this._downMouseX) / this._pixelMsR atio(); 390 this._movementInMs = (event.clientX - this._downMouseX) / this._pixelMsR atio();
372 391
373 // Commit changes 392 // Commit changes
374 if (this._mouseEventType === WebInspector.AnimationUI.MouseEvents.Keyfra meMove) { 393 if (this._mouseEventType === WebInspector.AnimationUI.MouseEvents.Keyfra meMove) {
375 this._keyframes[this._keyframeMoved].setOffset(this._offset(this._ke yframeMoved)); 394 this._keyframes[this._keyframeMoved].setOffset(this._offset(this._ke yframeMoved));
376 } else { 395 } else {
377 this._animation.source().setDelay(this._delay()); 396 this._setDelay(this._delay());
378 this._animation.source().setDuration(this._duration()); 397 this._setDuration(this._duration());
379 } 398 }
380 399
381 this._movementInMs = 0; 400 this._movementInMs = 0;
382 this.redraw(); 401 this.redraw();
383 402
384 this._parentElement.ownerDocument.removeEventListener("mousemove", this. _mouseMoveHandler); 403 this._parentElement.ownerDocument.removeEventListener("mousemove", this. _mouseMoveHandler);
385 this._parentElement.ownerDocument.removeEventListener("mouseup", this._m ouseUpHandler); 404 this._parentElement.ownerDocument.removeEventListener("mouseup", this._m ouseUpHandler);
386 delete this._mouseMoveHandler; 405 delete this._mouseMoveHandler;
387 delete this._mouseUpHandler; 406 delete this._mouseUpHandler;
388 delete this._mouseEventType; 407 delete this._mouseEventType;
389 delete this._downMouseX; 408 delete this._downMouseX;
390 delete this._keyframeMoved; 409 delete this._keyframeMoved;
391 }, 410 },
392 411
393 /** 412 /**
413 * @param {number} value
414 */
415 _setDelay: function(value)
416 {
417 if (!this._node || this._animation.source().delay() == this._delay())
418 return;
419
420 this._animation.source().setDelay(this._delay());
421 var propertyName;
422 if (this._animation.type() == "CSSTransition")
423 propertyName = "transition-delay";
424 else if (this._animation.type() == "CSSAnimation")
425 propertyName = "animation-delay";
426 else
427 return; // FIXME: support web animations
428 this._setNodeStyle(propertyName, this._delay() + "ms");
429 },
430
431 /**
432 * @param {number} value
433 */
434 _setDuration: function(value)
435 {
436 if (!this._node || this._animation.source().duration() == value)
437 return;
438
439 this._animation.source().setDuration(value);
440 var propertyName;
441 if (this._animation.type() == "CSSTransition")
442 propertyName = "transition-duration";
443 else if (this._animation.type() == "CSSAnimation")
444 propertyName = "animation-duration";
445 else
446 return; // FIXME: support web animations
447 this._setNodeStyle(propertyName, value + "ms");
448 },
449
450 /**
451 * @param {string} name
452 * @param {string} value
453 */
454 _setNodeStyle: function(name, value)
455 {
456 var style = this._node.getAttribute("style") || "";
457 if (style)
458 style = style.replace(new RegExp("\\s*(-webkit-)?" + name + ":[^;]*; ?\\s*", "g"), "");
459 var valueString = name + ": " + value;
460 this._node.setAttributeValue("style", style + " " + valueString + "; -we bkit-" + valueString);
pfeldman 2015/02/11 10:46:04 We should get the tests going at some point.
461 },
462
463 /**
394 * @return {!WebInspector.Color} 464 * @return {!WebInspector.Color}
395 */ 465 */
396 _color: function() 466 _color: function()
397 { 467 {
398 /** 468 /**
399 * @param {string} string 469 * @param {string} string
400 * @return {number} 470 * @return {number}
401 */ 471 */
402 function hash(string) 472 function hash(string)
403 { 473 {
(...skipping 24 matching lines...) Expand all
428 "Light Blue": WebInspector.Color.parse("#03A9F4"), 498 "Light Blue": WebInspector.Color.parse("#03A9F4"),
429 "Deep Orange": WebInspector.Color.parse("#FF5722"), 499 "Deep Orange": WebInspector.Color.parse("#FF5722"),
430 "Blue": WebInspector.Color.parse("#5677FC"), 500 "Blue": WebInspector.Color.parse("#5677FC"),
431 "Lime": WebInspector.Color.parse("#CDDC39"), 501 "Lime": WebInspector.Color.parse("#CDDC39"),
432 "Blue Grey": WebInspector.Color.parse("#607D8B"), 502 "Blue Grey": WebInspector.Color.parse("#607D8B"),
433 "Pink": WebInspector.Color.parse("#E91E63"), 503 "Pink": WebInspector.Color.parse("#E91E63"),
434 "Green": WebInspector.Color.parse("#0F9D58"), 504 "Green": WebInspector.Color.parse("#0F9D58"),
435 "Brown": WebInspector.Color.parse("#795548"), 505 "Brown": WebInspector.Color.parse("#795548"),
436 "Cyan": WebInspector.Color.parse("#00BCD4") 506 "Cyan": WebInspector.Color.parse("#00BCD4")
437 } 507 }
OLDNEW
« no previous file with comments | « no previous file | Source/devtools/front_end/elements/AnimationsSidebarPane.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698