| 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 * @unrestricted | 5 * @unrestricted |
| 6 */ | 6 */ |
| 7 WebInspector.AnimationUI = class { | 7 Animation.AnimationUI = class { |
| 8 /** | 8 /** |
| 9 * @param {!WebInspector.AnimationModel.Animation} animation | 9 * @param {!Animation.AnimationModel.Animation} animation |
| 10 * @param {!WebInspector.AnimationTimeline} timeline | 10 * @param {!Animation.AnimationTimeline} timeline |
| 11 * @param {!Element} parentElement | 11 * @param {!Element} parentElement |
| 12 */ | 12 */ |
| 13 constructor(animation, timeline, parentElement) { | 13 constructor(animation, timeline, parentElement) { |
| 14 this._animation = animation; | 14 this._animation = animation; |
| 15 this._timeline = timeline; | 15 this._timeline = timeline; |
| 16 this._parentElement = parentElement; | 16 this._parentElement = parentElement; |
| 17 | 17 |
| 18 if (this._animation.source().keyframesRule()) | 18 if (this._animation.source().keyframesRule()) |
| 19 this._keyframes = this._animation.source().keyframesRule().keyframes(); | 19 this._keyframes = this._animation.source().keyframesRule().keyframes(); |
| 20 | 20 |
| 21 this._nameElement = parentElement.createChild('div', 'animation-name'); | 21 this._nameElement = parentElement.createChild('div', 'animation-name'); |
| 22 this._nameElement.textContent = this._animation.name(); | 22 this._nameElement.textContent = this._animation.name(); |
| 23 | 23 |
| 24 this._svg = parentElement.createSVGChild('svg', 'animation-ui'); | 24 this._svg = parentElement.createSVGChild('svg', 'animation-ui'); |
| 25 this._svg.setAttribute('height', WebInspector.AnimationUI.Options.AnimationS
VGHeight); | 25 this._svg.setAttribute('height', Animation.AnimationUI.Options.AnimationSVGH
eight); |
| 26 this._svg.style.marginLeft = '-' + WebInspector.AnimationUI.Options.Animatio
nMargin + 'px'; | 26 this._svg.style.marginLeft = '-' + Animation.AnimationUI.Options.AnimationMa
rgin + 'px'; |
| 27 this._svg.addEventListener('contextmenu', this._onContextMenu.bind(this)); | 27 this._svg.addEventListener('contextmenu', this._onContextMenu.bind(this)); |
| 28 this._activeIntervalGroup = this._svg.createSVGChild('g'); | 28 this._activeIntervalGroup = this._svg.createSVGChild('g'); |
| 29 WebInspector.installDragHandle( | 29 UI.installDragHandle( |
| 30 this._activeIntervalGroup, this._mouseDown.bind(this, WebInspector.Anima
tionUI.MouseEvents.AnimationDrag, null), | 30 this._activeIntervalGroup, this._mouseDown.bind(this, Animation.Animatio
nUI.MouseEvents.AnimationDrag, null), |
| 31 this._mouseMove.bind(this), this._mouseUp.bind(this), '-webkit-grabbing'
, '-webkit-grab'); | 31 this._mouseMove.bind(this), this._mouseUp.bind(this), '-webkit-grabbing'
, '-webkit-grab'); |
| 32 | 32 |
| 33 /** @type {!Array.<{group: ?Element, animationLine: ?Element, keyframePoints
: !Object.<number, !Element>, keyframeRender: !Object.<number, !Element>}>} */ | 33 /** @type {!Array.<{group: ?Element, animationLine: ?Element, keyframePoints
: !Object.<number, !Element>, keyframeRender: !Object.<number, !Element>}>} */ |
| 34 this._cachedElements = []; | 34 this._cachedElements = []; |
| 35 | 35 |
| 36 this._movementInMs = 0; | 36 this._movementInMs = 0; |
| 37 this._color = WebInspector.AnimationUI.Color(this._animation); | 37 this._color = Animation.AnimationUI.Color(this._animation); |
| 38 } | 38 } |
| 39 | 39 |
| 40 /** | 40 /** |
| 41 * @param {!WebInspector.AnimationModel.Animation} animation | 41 * @param {!Animation.AnimationModel.Animation} animation |
| 42 * @return {string} | 42 * @return {string} |
| 43 */ | 43 */ |
| 44 static Color(animation) { | 44 static Color(animation) { |
| 45 var names = Object.keys(WebInspector.AnimationUI.Colors); | 45 var names = Object.keys(Animation.AnimationUI.Colors); |
| 46 var color = | 46 var color = |
| 47 WebInspector.AnimationUI.Colors[names[String.hashCode(animation.name() |
| animation.id()) % names.length]]; | 47 Animation.AnimationUI.Colors[names[String.hashCode(animation.name() || a
nimation.id()) % names.length]]; |
| 48 return color.asString(WebInspector.Color.Format.RGB); | 48 return color.asString(Common.Color.Format.RGB); |
| 49 } | 49 } |
| 50 | 50 |
| 51 /** | 51 /** |
| 52 * @return {!WebInspector.AnimationModel.Animation} | 52 * @return {!Animation.AnimationModel.Animation} |
| 53 */ | 53 */ |
| 54 animation() { | 54 animation() { |
| 55 return this._animation; | 55 return this._animation; |
| 56 } | 56 } |
| 57 | 57 |
| 58 /** | 58 /** |
| 59 * @param {?WebInspector.DOMNode} node | 59 * @param {?SDK.DOMNode} node |
| 60 */ | 60 */ |
| 61 setNode(node) { | 61 setNode(node) { |
| 62 this._node = node; | 62 this._node = node; |
| 63 } | 63 } |
| 64 | 64 |
| 65 /** | 65 /** |
| 66 * @param {!Element} parentElement | 66 * @param {!Element} parentElement |
| 67 * @param {string} className | 67 * @param {string} className |
| 68 */ | 68 */ |
| 69 _createLine(parentElement, className) { | 69 _createLine(parentElement, className) { |
| 70 var line = parentElement.createSVGChild('line', className); | 70 var line = parentElement.createSVGChild('line', className); |
| 71 line.setAttribute('x1', WebInspector.AnimationUI.Options.AnimationMargin); | 71 line.setAttribute('x1', Animation.AnimationUI.Options.AnimationMargin); |
| 72 line.setAttribute('y1', WebInspector.AnimationUI.Options.AnimationHeight); | 72 line.setAttribute('y1', Animation.AnimationUI.Options.AnimationHeight); |
| 73 line.setAttribute('y2', WebInspector.AnimationUI.Options.AnimationHeight); | 73 line.setAttribute('y2', Animation.AnimationUI.Options.AnimationHeight); |
| 74 line.style.stroke = this._color; | 74 line.style.stroke = this._color; |
| 75 return line; | 75 return line; |
| 76 } | 76 } |
| 77 | 77 |
| 78 /** | 78 /** |
| 79 * @param {number} iteration | 79 * @param {number} iteration |
| 80 * @param {!Element} parentElement | 80 * @param {!Element} parentElement |
| 81 */ | 81 */ |
| 82 _drawAnimationLine(iteration, parentElement) { | 82 _drawAnimationLine(iteration, parentElement) { |
| 83 var cache = this._cachedElements[iteration]; | 83 var cache = this._cachedElements[iteration]; |
| 84 if (!cache.animationLine) | 84 if (!cache.animationLine) |
| 85 cache.animationLine = this._createLine(parentElement, 'animation-line'); | 85 cache.animationLine = this._createLine(parentElement, 'animation-line'); |
| 86 cache.animationLine.setAttribute( | 86 cache.animationLine.setAttribute( |
| 87 'x2', (this._duration() * this._timeline.pixelMsRatio() + WebInspector.A
nimationUI.Options.AnimationMargin) | 87 'x2', (this._duration() * this._timeline.pixelMsRatio() + Animation.Anim
ationUI.Options.AnimationMargin) |
| 88 .toFixed(2)); | 88 .toFixed(2)); |
| 89 } | 89 } |
| 90 | 90 |
| 91 /** | 91 /** |
| 92 * @param {!Element} parentElement | 92 * @param {!Element} parentElement |
| 93 */ | 93 */ |
| 94 _drawDelayLine(parentElement) { | 94 _drawDelayLine(parentElement) { |
| 95 if (!this._delayLine) { | 95 if (!this._delayLine) { |
| 96 this._delayLine = this._createLine(parentElement, 'animation-delay-line'); | 96 this._delayLine = this._createLine(parentElement, 'animation-delay-line'); |
| 97 this._endDelayLine = this._createLine(parentElement, 'animation-delay-line
'); | 97 this._endDelayLine = this._createLine(parentElement, 'animation-delay-line
'); |
| 98 } | 98 } |
| 99 var fill = this._animation.source().fill(); | 99 var fill = this._animation.source().fill(); |
| 100 this._delayLine.classList.toggle('animation-fill', fill === 'backwards' || f
ill === 'both'); | 100 this._delayLine.classList.toggle('animation-fill', fill === 'backwards' || f
ill === 'both'); |
| 101 var margin = WebInspector.AnimationUI.Options.AnimationMargin; | 101 var margin = Animation.AnimationUI.Options.AnimationMargin; |
| 102 this._delayLine.setAttribute('x1', margin); | 102 this._delayLine.setAttribute('x1', margin); |
| 103 this._delayLine.setAttribute('x2', (this._delay() * this._timeline.pixelMsRa
tio() + margin).toFixed(2)); | 103 this._delayLine.setAttribute('x2', (this._delay() * this._timeline.pixelMsRa
tio() + margin).toFixed(2)); |
| 104 var forwardsFill = fill === 'forwards' || fill === 'both'; | 104 var forwardsFill = fill === 'forwards' || fill === 'both'; |
| 105 this._endDelayLine.classList.toggle('animation-fill', forwardsFill); | 105 this._endDelayLine.classList.toggle('animation-fill', forwardsFill); |
| 106 var leftMargin = Math.min( | 106 var leftMargin = Math.min( |
| 107 this._timeline.width(), | 107 this._timeline.width(), |
| 108 (this._delay() + this._duration() * this._animation.source().iterations(
)) * this._timeline.pixelMsRatio()); | 108 (this._delay() + this._duration() * this._animation.source().iterations(
)) * this._timeline.pixelMsRatio()); |
| 109 this._endDelayLine.style.transform = 'translateX(' + leftMargin.toFixed(2) +
'px)'; | 109 this._endDelayLine.style.transform = 'translateX(' + leftMargin.toFixed(2) +
'px)'; |
| 110 this._endDelayLine.setAttribute('x1', margin); | 110 this._endDelayLine.setAttribute('x1', margin); |
| 111 this._endDelayLine.setAttribute( | 111 this._endDelayLine.setAttribute( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 122 */ | 122 */ |
| 123 _drawPoint(iteration, parentElement, x, keyframeIndex, attachEvents) { | 123 _drawPoint(iteration, parentElement, x, keyframeIndex, attachEvents) { |
| 124 if (this._cachedElements[iteration].keyframePoints[keyframeIndex]) { | 124 if (this._cachedElements[iteration].keyframePoints[keyframeIndex]) { |
| 125 this._cachedElements[iteration].keyframePoints[keyframeIndex].setAttribute
('cx', x.toFixed(2)); | 125 this._cachedElements[iteration].keyframePoints[keyframeIndex].setAttribute
('cx', x.toFixed(2)); |
| 126 return; | 126 return; |
| 127 } | 127 } |
| 128 | 128 |
| 129 var circle = | 129 var circle = |
| 130 parentElement.createSVGChild('circle', keyframeIndex <= 0 ? 'animation-e
ndpoint' : 'animation-keyframe-point'); | 130 parentElement.createSVGChild('circle', keyframeIndex <= 0 ? 'animation-e
ndpoint' : 'animation-keyframe-point'); |
| 131 circle.setAttribute('cx', x.toFixed(2)); | 131 circle.setAttribute('cx', x.toFixed(2)); |
| 132 circle.setAttribute('cy', WebInspector.AnimationUI.Options.AnimationHeight); | 132 circle.setAttribute('cy', Animation.AnimationUI.Options.AnimationHeight); |
| 133 circle.style.stroke = this._color; | 133 circle.style.stroke = this._color; |
| 134 circle.setAttribute('r', WebInspector.AnimationUI.Options.AnimationMargin /
2); | 134 circle.setAttribute('r', Animation.AnimationUI.Options.AnimationMargin / 2); |
| 135 | 135 |
| 136 if (keyframeIndex <= 0) | 136 if (keyframeIndex <= 0) |
| 137 circle.style.fill = this._color; | 137 circle.style.fill = this._color; |
| 138 | 138 |
| 139 this._cachedElements[iteration].keyframePoints[keyframeIndex] = circle; | 139 this._cachedElements[iteration].keyframePoints[keyframeIndex] = circle; |
| 140 | 140 |
| 141 if (!attachEvents) | 141 if (!attachEvents) |
| 142 return; | 142 return; |
| 143 | 143 |
| 144 var eventType; | 144 var eventType; |
| 145 if (keyframeIndex === 0) | 145 if (keyframeIndex === 0) |
| 146 eventType = WebInspector.AnimationUI.MouseEvents.StartEndpointMove; | 146 eventType = Animation.AnimationUI.MouseEvents.StartEndpointMove; |
| 147 else if (keyframeIndex === -1) | 147 else if (keyframeIndex === -1) |
| 148 eventType = WebInspector.AnimationUI.MouseEvents.FinishEndpointMove; | 148 eventType = Animation.AnimationUI.MouseEvents.FinishEndpointMove; |
| 149 else | 149 else |
| 150 eventType = WebInspector.AnimationUI.MouseEvents.KeyframeMove; | 150 eventType = Animation.AnimationUI.MouseEvents.KeyframeMove; |
| 151 WebInspector.installDragHandle( | 151 UI.installDragHandle( |
| 152 circle, this._mouseDown.bind(this, eventType, keyframeIndex), this._mous
eMove.bind(this), | 152 circle, this._mouseDown.bind(this, eventType, keyframeIndex), this._mous
eMove.bind(this), |
| 153 this._mouseUp.bind(this), 'ew-resize'); | 153 this._mouseUp.bind(this), 'ew-resize'); |
| 154 } | 154 } |
| 155 | 155 |
| 156 /** | 156 /** |
| 157 * @param {number} iteration | 157 * @param {number} iteration |
| 158 * @param {number} keyframeIndex | 158 * @param {number} keyframeIndex |
| 159 * @param {!Element} parentElement | 159 * @param {!Element} parentElement |
| 160 * @param {number} leftDistance | 160 * @param {number} leftDistance |
| 161 * @param {number} width | 161 * @param {number} width |
| 162 * @param {string} easing | 162 * @param {string} easing |
| 163 */ | 163 */ |
| 164 _renderKeyframe(iteration, keyframeIndex, parentElement, leftDistance, width,
easing) { | 164 _renderKeyframe(iteration, keyframeIndex, parentElement, leftDistance, width,
easing) { |
| 165 /** | 165 /** |
| 166 * @param {!Element} parentElement | 166 * @param {!Element} parentElement |
| 167 * @param {number} x | 167 * @param {number} x |
| 168 * @param {string} strokeColor | 168 * @param {string} strokeColor |
| 169 */ | 169 */ |
| 170 function createStepLine(parentElement, x, strokeColor) { | 170 function createStepLine(parentElement, x, strokeColor) { |
| 171 var line = parentElement.createSVGChild('line'); | 171 var line = parentElement.createSVGChild('line'); |
| 172 line.setAttribute('x1', x); | 172 line.setAttribute('x1', x); |
| 173 line.setAttribute('x2', x); | 173 line.setAttribute('x2', x); |
| 174 line.setAttribute('y1', WebInspector.AnimationUI.Options.AnimationMargin); | 174 line.setAttribute('y1', Animation.AnimationUI.Options.AnimationMargin); |
| 175 line.setAttribute('y2', WebInspector.AnimationUI.Options.AnimationHeight); | 175 line.setAttribute('y2', Animation.AnimationUI.Options.AnimationHeight); |
| 176 line.style.stroke = strokeColor; | 176 line.style.stroke = strokeColor; |
| 177 } | 177 } |
| 178 | 178 |
| 179 var bezier = WebInspector.Geometry.CubicBezier.parse(easing); | 179 var bezier = Common.Geometry.CubicBezier.parse(easing); |
| 180 var cache = this._cachedElements[iteration].keyframeRender; | 180 var cache = this._cachedElements[iteration].keyframeRender; |
| 181 if (!cache[keyframeIndex]) | 181 if (!cache[keyframeIndex]) |
| 182 cache[keyframeIndex] = bezier ? parentElement.createSVGChild('path', 'anim
ation-keyframe') : | 182 cache[keyframeIndex] = bezier ? parentElement.createSVGChild('path', 'anim
ation-keyframe') : |
| 183 parentElement.createSVGChild('g', 'animati
on-keyframe-step'); | 183 parentElement.createSVGChild('g', 'animati
on-keyframe-step'); |
| 184 var group = cache[keyframeIndex]; | 184 var group = cache[keyframeIndex]; |
| 185 group.style.transform = 'translateX(' + leftDistance.toFixed(2) + 'px)'; | 185 group.style.transform = 'translateX(' + leftDistance.toFixed(2) + 'px)'; |
| 186 | 186 |
| 187 if (easing === 'linear') { | 187 if (easing === 'linear') { |
| 188 group.style.fill = this._color; | 188 group.style.fill = this._color; |
| 189 var height = WebInspector.BezierUI.Height; | 189 var height = UI.BezierUI.Height; |
| 190 group.setAttribute( | 190 group.setAttribute( |
| 191 'd', ['M', 0, height, 'L', 0, 5, 'L', width.toFixed(2), 5, 'L', width.
toFixed(2), height, 'Z'].join(' ')); | 191 'd', ['M', 0, height, 'L', 0, 5, 'L', width.toFixed(2), 5, 'L', width.
toFixed(2), height, 'Z'].join(' ')); |
| 192 } else if (bezier) { | 192 } else if (bezier) { |
| 193 group.style.fill = this._color; | 193 group.style.fill = this._color; |
| 194 WebInspector.BezierUI.drawVelocityChart(bezier, group, width); | 194 UI.BezierUI.drawVelocityChart(bezier, group, width); |
| 195 } else { | 195 } else { |
| 196 var stepFunction = WebInspector.AnimationTimeline.StepTimingFunction.parse
(easing); | 196 var stepFunction = Animation.AnimationTimeline.StepTimingFunction.parse(ea
sing); |
| 197 group.removeChildren(); | 197 group.removeChildren(); |
| 198 /** @const */ var offsetMap = {'start': 0, 'middle': 0.5, 'end': 1}; | 198 /** @const */ var offsetMap = {'start': 0, 'middle': 0.5, 'end': 1}; |
| 199 /** @const */ var offsetWeight = offsetMap[stepFunction.stepAtPosition]; | 199 /** @const */ var offsetWeight = offsetMap[stepFunction.stepAtPosition]; |
| 200 for (var i = 0; i < stepFunction.steps; i++) | 200 for (var i = 0; i < stepFunction.steps; i++) |
| 201 createStepLine(group, (i + offsetWeight) * width / stepFunction.steps, t
his._color); | 201 createStepLine(group, (i + offsetWeight) * width / stepFunction.steps, t
his._color); |
| 202 } | 202 } |
| 203 } | 203 } |
| 204 | 204 |
| 205 redraw() { | 205 redraw() { |
| 206 var durationWithDelay = | 206 var durationWithDelay = |
| 207 this._delay() + this._duration() * this._animation.source().iterations()
+ this._animation.source().endDelay(); | 207 this._delay() + this._duration() * this._animation.source().iterations()
+ this._animation.source().endDelay(); |
| 208 var maxWidth = this._timeline.width() - WebInspector.AnimationUI.Options.Ani
mationMargin; | 208 var maxWidth = this._timeline.width() - Animation.AnimationUI.Options.Animat
ionMargin; |
| 209 | 209 |
| 210 this._svg.setAttribute('width', (maxWidth + 2 * WebInspector.AnimationUI.Opt
ions.AnimationMargin).toFixed(2)); | 210 this._svg.setAttribute('width', (maxWidth + 2 * Animation.AnimationUI.Option
s.AnimationMargin).toFixed(2)); |
| 211 this._activeIntervalGroup.style.transform = | 211 this._activeIntervalGroup.style.transform = |
| 212 'translateX(' + (this._delay() * this._timeline.pixelMsRatio()).toFixed(
2) + 'px)'; | 212 'translateX(' + (this._delay() * this._timeline.pixelMsRatio()).toFixed(
2) + 'px)'; |
| 213 | 213 |
| 214 this._nameElement.style.transform = 'translateX(' + | 214 this._nameElement.style.transform = 'translateX(' + |
| 215 (this._delay() * this._timeline.pixelMsRatio() + WebInspector.AnimationU
I.Options.AnimationMargin).toFixed(2) + | 215 (this._delay() * this._timeline.pixelMsRatio() + Animation.AnimationUI.O
ptions.AnimationMargin).toFixed(2) + |
| 216 'px)'; | 216 'px)'; |
| 217 this._nameElement.style.width = (this._duration() * this._timeline.pixelMsRa
tio()).toFixed(2) + 'px'; | 217 this._nameElement.style.width = (this._duration() * this._timeline.pixelMsRa
tio()).toFixed(2) + 'px'; |
| 218 this._drawDelayLine(this._svg); | 218 this._drawDelayLine(this._svg); |
| 219 | 219 |
| 220 if (this._animation.type() === 'CSSTransition') { | 220 if (this._animation.type() === 'CSSTransition') { |
| 221 this._renderTransition(); | 221 this._renderTransition(); |
| 222 return; | 222 return; |
| 223 } | 223 } |
| 224 | 224 |
| 225 this._renderIteration(this._activeIntervalGroup, 0); | 225 this._renderIteration(this._activeIntervalGroup, 0); |
| 226 if (!this._tailGroup) | 226 if (!this._tailGroup) |
| 227 this._tailGroup = this._activeIntervalGroup.createSVGChild('g', 'animation
-tail-iterations'); | 227 this._tailGroup = this._activeIntervalGroup.createSVGChild('g', 'animation
-tail-iterations'); |
| 228 var iterationWidth = this._duration() * this._timeline.pixelMsRatio(); | 228 var iterationWidth = this._duration() * this._timeline.pixelMsRatio(); |
| 229 for (var iteration = 1; | 229 for (var iteration = 1; |
| 230 iteration < this._animation.source().iterations() && iterationWidth * (
iteration - 1) < this._timeline.width(); | 230 iteration < this._animation.source().iterations() && iterationWidth * (
iteration - 1) < this._timeline.width(); |
| 231 iteration++) | 231 iteration++) |
| 232 this._renderIteration(this._tailGroup, iteration); | 232 this._renderIteration(this._tailGroup, iteration); |
| 233 while (iteration < this._cachedElements.length) | 233 while (iteration < this._cachedElements.length) |
| 234 this._cachedElements.pop().group.remove(); | 234 this._cachedElements.pop().group.remove(); |
| 235 } | 235 } |
| 236 | 236 |
| 237 _renderTransition() { | 237 _renderTransition() { |
| 238 if (!this._cachedElements[0]) | 238 if (!this._cachedElements[0]) |
| 239 this._cachedElements[0] = {animationLine: null, keyframePoints: {}, keyfra
meRender: {}, group: null}; | 239 this._cachedElements[0] = {animationLine: null, keyframePoints: {}, keyfra
meRender: {}, group: null}; |
| 240 this._drawAnimationLine(0, this._activeIntervalGroup); | 240 this._drawAnimationLine(0, this._activeIntervalGroup); |
| 241 this._renderKeyframe( | 241 this._renderKeyframe( |
| 242 0, 0, this._activeIntervalGroup, WebInspector.AnimationUI.Options.Animat
ionMargin, | 242 0, 0, this._activeIntervalGroup, Animation.AnimationUI.Options.Animation
Margin, |
| 243 this._duration() * this._timeline.pixelMsRatio(), this._animation.source
().easing()); | 243 this._duration() * this._timeline.pixelMsRatio(), this._animation.source
().easing()); |
| 244 this._drawPoint(0, this._activeIntervalGroup, WebInspector.AnimationUI.Optio
ns.AnimationMargin, 0, true); | 244 this._drawPoint(0, this._activeIntervalGroup, Animation.AnimationUI.Options.
AnimationMargin, 0, true); |
| 245 this._drawPoint( | 245 this._drawPoint( |
| 246 0, this._activeIntervalGroup, | 246 0, this._activeIntervalGroup, |
| 247 this._duration() * this._timeline.pixelMsRatio() + WebInspector.Animatio
nUI.Options.AnimationMargin, -1, true); | 247 this._duration() * this._timeline.pixelMsRatio() + Animation.AnimationUI
.Options.AnimationMargin, -1, true); |
| 248 } | 248 } |
| 249 | 249 |
| 250 /** | 250 /** |
| 251 * @param {!Element} parentElement | 251 * @param {!Element} parentElement |
| 252 * @param {number} iteration | 252 * @param {number} iteration |
| 253 */ | 253 */ |
| 254 _renderIteration(parentElement, iteration) { | 254 _renderIteration(parentElement, iteration) { |
| 255 if (!this._cachedElements[iteration]) | 255 if (!this._cachedElements[iteration]) |
| 256 this._cachedElements[iteration] = | 256 this._cachedElements[iteration] = |
| 257 {animationLine: null, keyframePoints: {}, keyframeRender: {}, group: p
arentElement.createSVGChild('g')}; | 257 {animationLine: null, keyframePoints: {}, keyframeRender: {}, group: p
arentElement.createSVGChild('g')}; |
| 258 var group = this._cachedElements[iteration].group; | 258 var group = this._cachedElements[iteration].group; |
| 259 group.style.transform = | 259 group.style.transform = |
| 260 'translateX(' + (iteration * this._duration() * this._timeline.pixelMsRa
tio()).toFixed(2) + 'px)'; | 260 'translateX(' + (iteration * this._duration() * this._timeline.pixelMsRa
tio()).toFixed(2) + 'px)'; |
| 261 this._drawAnimationLine(iteration, group); | 261 this._drawAnimationLine(iteration, group); |
| 262 console.assert(this._keyframes.length > 1); | 262 console.assert(this._keyframes.length > 1); |
| 263 for (var i = 0; i < this._keyframes.length - 1; i++) { | 263 for (var i = 0; i < this._keyframes.length - 1; i++) { |
| 264 var leftDistance = this._offset(i) * this._duration() * this._timeline.pix
elMsRatio() + | 264 var leftDistance = this._offset(i) * this._duration() * this._timeline.pix
elMsRatio() + |
| 265 WebInspector.AnimationUI.Options.AnimationMargin; | 265 Animation.AnimationUI.Options.AnimationMargin; |
| 266 var width = this._duration() * (this._offset(i + 1) - this._offset(i)) * t
his._timeline.pixelMsRatio(); | 266 var width = this._duration() * (this._offset(i + 1) - this._offset(i)) * t
his._timeline.pixelMsRatio(); |
| 267 this._renderKeyframe(iteration, i, group, leftDistance, width, this._keyfr
ames[i].easing()); | 267 this._renderKeyframe(iteration, i, group, leftDistance, width, this._keyfr
ames[i].easing()); |
| 268 if (i || (!i && iteration === 0)) | 268 if (i || (!i && iteration === 0)) |
| 269 this._drawPoint(iteration, group, leftDistance, i, iteration === 0); | 269 this._drawPoint(iteration, group, leftDistance, i, iteration === 0); |
| 270 } | 270 } |
| 271 this._drawPoint( | 271 this._drawPoint( |
| 272 iteration, group, | 272 iteration, group, |
| 273 this._duration() * this._timeline.pixelMsRatio() + WebInspector.Animatio
nUI.Options.AnimationMargin, -1, | 273 this._duration() * this._timeline.pixelMsRatio() + Animation.AnimationUI
.Options.AnimationMargin, -1, |
| 274 iteration === 0); | 274 iteration === 0); |
| 275 } | 275 } |
| 276 | 276 |
| 277 /** | 277 /** |
| 278 * @return {number} | 278 * @return {number} |
| 279 */ | 279 */ |
| 280 _delay() { | 280 _delay() { |
| 281 var delay = this._animation.source().delay(); | 281 var delay = this._animation.source().delay(); |
| 282 if (this._mouseEventType === WebInspector.AnimationUI.MouseEvents.AnimationD
rag || | 282 if (this._mouseEventType === Animation.AnimationUI.MouseEvents.AnimationDrag
|| |
| 283 this._mouseEventType === WebInspector.AnimationUI.MouseEvents.StartEndpo
intMove) | 283 this._mouseEventType === Animation.AnimationUI.MouseEvents.StartEndpoint
Move) |
| 284 delay += this._movementInMs; | 284 delay += this._movementInMs; |
| 285 // FIXME: add support for negative start delay | 285 // FIXME: add support for negative start delay |
| 286 return Math.max(0, delay); | 286 return Math.max(0, delay); |
| 287 } | 287 } |
| 288 | 288 |
| 289 /** | 289 /** |
| 290 * @return {number} | 290 * @return {number} |
| 291 */ | 291 */ |
| 292 _duration() { | 292 _duration() { |
| 293 var duration = this._animation.source().duration(); | 293 var duration = this._animation.source().duration(); |
| 294 if (this._mouseEventType === WebInspector.AnimationUI.MouseEvents.FinishEndp
ointMove) | 294 if (this._mouseEventType === Animation.AnimationUI.MouseEvents.FinishEndpoin
tMove) |
| 295 duration += this._movementInMs; | 295 duration += this._movementInMs; |
| 296 else if (this._mouseEventType === WebInspector.AnimationUI.MouseEvents.Start
EndpointMove) | 296 else if (this._mouseEventType === Animation.AnimationUI.MouseEvents.StartEnd
pointMove) |
| 297 duration -= Math.max(this._movementInMs, -this._animation.source().delay()
); // Cannot have negative delay | 297 duration -= Math.max(this._movementInMs, -this._animation.source().delay()
); // Cannot have negative delay |
| 298 return Math.max(0, duration); | 298 return Math.max(0, duration); |
| 299 } | 299 } |
| 300 | 300 |
| 301 /** | 301 /** |
| 302 * @param {number} i | 302 * @param {number} i |
| 303 * @return {number} offset | 303 * @return {number} offset |
| 304 */ | 304 */ |
| 305 _offset(i) { | 305 _offset(i) { |
| 306 var offset = this._keyframes[i].offsetAsNumber(); | 306 var offset = this._keyframes[i].offsetAsNumber(); |
| 307 if (this._mouseEventType === WebInspector.AnimationUI.MouseEvents.KeyframeMo
ve && i === this._keyframeMoved) { | 307 if (this._mouseEventType === Animation.AnimationUI.MouseEvents.KeyframeMove
&& i === this._keyframeMoved) { |
| 308 console.assert(i > 0 && i < this._keyframes.length - 1, 'First and last ke
yframe cannot be moved'); | 308 console.assert(i > 0 && i < this._keyframes.length - 1, 'First and last ke
yframe cannot be moved'); |
| 309 offset += this._movementInMs / this._animation.source().duration(); | 309 offset += this._movementInMs / this._animation.source().duration(); |
| 310 offset = Math.max(offset, this._keyframes[i - 1].offsetAsNumber()); | 310 offset = Math.max(offset, this._keyframes[i - 1].offsetAsNumber()); |
| 311 offset = Math.min(offset, this._keyframes[i + 1].offsetAsNumber()); | 311 offset = Math.min(offset, this._keyframes[i + 1].offsetAsNumber()); |
| 312 } | 312 } |
| 313 return offset; | 313 return offset; |
| 314 } | 314 } |
| 315 | 315 |
| 316 /** | 316 /** |
| 317 * @param {!WebInspector.AnimationUI.MouseEvents} mouseEventType | 317 * @param {!Animation.AnimationUI.MouseEvents} mouseEventType |
| 318 * @param {?number} keyframeIndex | 318 * @param {?number} keyframeIndex |
| 319 * @param {!Event} event | 319 * @param {!Event} event |
| 320 */ | 320 */ |
| 321 _mouseDown(mouseEventType, keyframeIndex, event) { | 321 _mouseDown(mouseEventType, keyframeIndex, event) { |
| 322 if (event.buttons === 2) | 322 if (event.buttons === 2) |
| 323 return false; | 323 return false; |
| 324 if (this._svg.enclosingNodeOrSelfWithClass('animation-node-removed')) | 324 if (this._svg.enclosingNodeOrSelfWithClass('animation-node-removed')) |
| 325 return false; | 325 return false; |
| 326 this._mouseEventType = mouseEventType; | 326 this._mouseEventType = mouseEventType; |
| 327 this._keyframeMoved = keyframeIndex; | 327 this._keyframeMoved = keyframeIndex; |
| 328 this._downMouseX = event.clientX; | 328 this._downMouseX = event.clientX; |
| 329 event.consume(true); | 329 event.consume(true); |
| 330 if (this._node) | 330 if (this._node) |
| 331 WebInspector.Revealer.reveal(this._node); | 331 Common.Revealer.reveal(this._node); |
| 332 return true; | 332 return true; |
| 333 } | 333 } |
| 334 | 334 |
| 335 /** | 335 /** |
| 336 * @param {!Event} event | 336 * @param {!Event} event |
| 337 */ | 337 */ |
| 338 _mouseMove(event) { | 338 _mouseMove(event) { |
| 339 this._movementInMs = (event.clientX - this._downMouseX) / this._timeline.pix
elMsRatio(); | 339 this._movementInMs = (event.clientX - this._downMouseX) / this._timeline.pix
elMsRatio(); |
| 340 if (this._delay() + this._duration() > this._timeline.duration() * 0.8) | 340 if (this._delay() + this._duration() > this._timeline.duration() * 0.8) |
| 341 this._timeline.setDuration(this._timeline.duration() * 1.2); | 341 this._timeline.setDuration(this._timeline.duration() * 1.2); |
| 342 this.redraw(); | 342 this.redraw(); |
| 343 } | 343 } |
| 344 | 344 |
| 345 /** | 345 /** |
| 346 * @param {!Event} event | 346 * @param {!Event} event |
| 347 */ | 347 */ |
| 348 _mouseUp(event) { | 348 _mouseUp(event) { |
| 349 this._movementInMs = (event.clientX - this._downMouseX) / this._timeline.pix
elMsRatio(); | 349 this._movementInMs = (event.clientX - this._downMouseX) / this._timeline.pix
elMsRatio(); |
| 350 | 350 |
| 351 // Commit changes | 351 // Commit changes |
| 352 if (this._mouseEventType === WebInspector.AnimationUI.MouseEvents.KeyframeMo
ve) | 352 if (this._mouseEventType === Animation.AnimationUI.MouseEvents.KeyframeMove) |
| 353 this._keyframes[this._keyframeMoved].setOffset(this._offset(this._keyframe
Moved)); | 353 this._keyframes[this._keyframeMoved].setOffset(this._offset(this._keyframe
Moved)); |
| 354 else | 354 else |
| 355 this._animation.setTiming(this._duration(), this._delay()); | 355 this._animation.setTiming(this._duration(), this._delay()); |
| 356 | 356 |
| 357 this._movementInMs = 0; | 357 this._movementInMs = 0; |
| 358 this.redraw(); | 358 this.redraw(); |
| 359 | 359 |
| 360 delete this._mouseEventType; | 360 delete this._mouseEventType; |
| 361 delete this._downMouseX; | 361 delete this._downMouseX; |
| 362 delete this._keyframeMoved; | 362 delete this._keyframeMoved; |
| 363 } | 363 } |
| 364 | 364 |
| 365 /** | 365 /** |
| 366 * @param {!Event} event | 366 * @param {!Event} event |
| 367 */ | 367 */ |
| 368 _onContextMenu(event) { | 368 _onContextMenu(event) { |
| 369 /** | 369 /** |
| 370 * @param {?WebInspector.RemoteObject} remoteObject | 370 * @param {?SDK.RemoteObject} remoteObject |
| 371 */ | 371 */ |
| 372 function showContextMenu(remoteObject) { | 372 function showContextMenu(remoteObject) { |
| 373 if (!remoteObject) | 373 if (!remoteObject) |
| 374 return; | 374 return; |
| 375 var contextMenu = new WebInspector.ContextMenu(event); | 375 var contextMenu = new UI.ContextMenu(event); |
| 376 contextMenu.appendApplicableItems(remoteObject); | 376 contextMenu.appendApplicableItems(remoteObject); |
| 377 contextMenu.show(); | 377 contextMenu.show(); |
| 378 } | 378 } |
| 379 | 379 |
| 380 this._animation.remoteObjectPromise().then(showContextMenu); | 380 this._animation.remoteObjectPromise().then(showContextMenu); |
| 381 event.consume(true); | 381 event.consume(true); |
| 382 } | 382 } |
| 383 }; | 383 }; |
| 384 | 384 |
| 385 /** | 385 /** |
| 386 * @enum {string} | 386 * @enum {string} |
| 387 */ | 387 */ |
| 388 WebInspector.AnimationUI.MouseEvents = { | 388 Animation.AnimationUI.MouseEvents = { |
| 389 AnimationDrag: 'AnimationDrag', | 389 AnimationDrag: 'AnimationDrag', |
| 390 KeyframeMove: 'KeyframeMove', | 390 KeyframeMove: 'KeyframeMove', |
| 391 StartEndpointMove: 'StartEndpointMove', | 391 StartEndpointMove: 'StartEndpointMove', |
| 392 FinishEndpointMove: 'FinishEndpointMove' | 392 FinishEndpointMove: 'FinishEndpointMove' |
| 393 }; | 393 }; |
| 394 | 394 |
| 395 WebInspector.AnimationUI.Options = { | 395 Animation.AnimationUI.Options = { |
| 396 AnimationHeight: 26, | 396 AnimationHeight: 26, |
| 397 AnimationSVGHeight: 50, | 397 AnimationSVGHeight: 50, |
| 398 AnimationMargin: 7, | 398 AnimationMargin: 7, |
| 399 EndpointsClickRegionSize: 10, | 399 EndpointsClickRegionSize: 10, |
| 400 GridCanvasHeight: 40 | 400 GridCanvasHeight: 40 |
| 401 }; | 401 }; |
| 402 | 402 |
| 403 WebInspector.AnimationUI.Colors = { | 403 Animation.AnimationUI.Colors = { |
| 404 'Purple': WebInspector.Color.parse('#9C27B0'), | 404 'Purple': Common.Color.parse('#9C27B0'), |
| 405 'Light Blue': WebInspector.Color.parse('#03A9F4'), | 405 'Light Blue': Common.Color.parse('#03A9F4'), |
| 406 'Deep Orange': WebInspector.Color.parse('#FF5722'), | 406 'Deep Orange': Common.Color.parse('#FF5722'), |
| 407 'Blue': WebInspector.Color.parse('#5677FC'), | 407 'Blue': Common.Color.parse('#5677FC'), |
| 408 'Lime': WebInspector.Color.parse('#CDDC39'), | 408 'Lime': Common.Color.parse('#CDDC39'), |
| 409 'Blue Grey': WebInspector.Color.parse('#607D8B'), | 409 'Blue Grey': Common.Color.parse('#607D8B'), |
| 410 'Pink': WebInspector.Color.parse('#E91E63'), | 410 'Pink': Common.Color.parse('#E91E63'), |
| 411 'Green': WebInspector.Color.parse('#0F9D58'), | 411 'Green': Common.Color.parse('#0F9D58'), |
| 412 'Brown': WebInspector.Color.parse('#795548'), | 412 'Brown': Common.Color.parse('#795548'), |
| 413 'Cyan': WebInspector.Color.parse('#00BCD4') | 413 'Cyan': Common.Color.parse('#00BCD4') |
| 414 }; | 414 }; |
| OLD | NEW |