WebInspector.AnimationModel=function(target) {WebInspector.SDKModel.call(this,WebInspector.AnimationModel,target);this._agent=target.animationAgent();target.registerAnimationDispatcher(new WebInspector.AnimationDispatcher(this));} WebInspector.AnimationModel.Events={AnimationCreated:"AnimationCreated",AnimationCanceled:"AnimationCanceled"} WebInspector.AnimationModel.prototype={animationCreated:function(payload,resetTimeline) {var player=WebInspector.AnimationModel.Animation.parsePayload(this.target(),payload);this.dispatchEventToListeners(WebInspector.AnimationModel.Events.AnimationCreated,{"player":player,"resetTimeline":resetTimeline});},animationCanceled:function(id) {this.dispatchEventToListeners(WebInspector.AnimationModel.Events.AnimationCanceled,{"id":id});},setPlaybackRate:function(playbackRate) {this._agent.setPlaybackRate(playbackRate);},ensureEnabled:function() {if(this._enabled) return;this._agent.enable();this._enabled=true;},__proto__:WebInspector.SDKModel.prototype} WebInspector.AnimationModel._symbol=Symbol("AnimationModel");WebInspector.AnimationModel.fromTarget=function(target) {if(!target[WebInspector.AnimationModel._symbol]) target[WebInspector.AnimationModel._symbol]=new WebInspector.AnimationModel(target);return target[WebInspector.AnimationModel._symbol];} WebInspector.AnimationModel.Animation=function(target,payload) {WebInspector.SDKObject.call(this,target);this._payload=payload;this._source=new WebInspector.AnimationModel.AnimationEffect(this.target(),this._payload.source);} WebInspector.AnimationModel.Animation.parsePayload=function(target,payload) {return new WebInspector.AnimationModel.Animation(target,payload);} WebInspector.AnimationModel.Animation.prototype={payload:function() {return this._payload;},id:function() {return this._payload.id;},name:function() {return this.source().name();},paused:function() {return this._payload.pausedState;},playState:function() {return this._playState||this._payload.playState;},setPlayState:function(playState) {this._playState=playState;},playbackRate:function() {return this._payload.playbackRate;},startTime:function() {return this._payload.startTime;},endTime:function() {if(!this.source().iterations) return Infinity;return this.startTime()+this.source().delay()+this.source().duration()*this.source().iterations()+this.source().endDelay();},currentTime:function() {return this._payload.currentTime;},source:function() {return this._source;},type:function() {return this._payload.type;},overlaps:function(animation) {if(!this.source().iterations()||!animation.source().iterations()) return true;var firstAnimation=this.startTime()=secondAnimation.startTime();},__proto__:WebInspector.SDKObject.prototype} WebInspector.AnimationModel.AnimationEffect=function(target,payload) {WebInspector.SDKObject.call(this,target);this._payload=payload;if(payload.keyframesRule) this._keyframesRule=new WebInspector.AnimationModel.KeyframesRule(target,payload.keyframesRule);this._delay=this._payload.delay;this._duration=this._payload.duration;} WebInspector.AnimationModel.AnimationEffect.prototype={delay:function() {return this._delay;},setDelay:function(delay) {this._delay=delay;},endDelay:function() {return this._payload.endDelay;},playbackRate:function() {return this._payload.playbackRate;},iterationStart:function() {return this._payload.iterationStart;},iterations:function() {return this._payload.iterations||Infinity;},duration:function() {return this._duration;},setDuration:function(duration) {this._duration=duration;},direction:function() {return this._payload.direction;},fill:function() {return this._payload.fill;},name:function() {return this._payload.name;},deferredNode:function() {return new WebInspector.DeferredDOMNode(this.target(),this.backendNodeId());},backendNodeId:function() {return this._payload.backendNodeId;},keyframesRule:function() {return this._keyframesRule;},easing:function() {return this._payload.easing;},__proto__:WebInspector.SDKObject.prototype} WebInspector.AnimationModel.KeyframesRule=function(target,payload) {WebInspector.SDKObject.call(this,target);this._payload=payload;this._keyframes=this._payload.keyframes.map(function(keyframeStyle){return new WebInspector.AnimationModel.KeyframeStyle(target,keyframeStyle);});} WebInspector.AnimationModel.KeyframesRule.prototype={_setKeyframesPayload:function(payload) {this._keyframes=payload.map(function(keyframeStyle){return new WebInspector.AnimationModel.KeyframeStyle(this._target,keyframeStyle);});},name:function() {return this._payload.name;},keyframes:function() {return this._keyframes;},__proto__:WebInspector.SDKObject.prototype} WebInspector.AnimationModel.KeyframeStyle=function(target,payload) {WebInspector.SDKObject.call(this,target);this._payload=payload;this._offset=this._payload.offset;} WebInspector.AnimationModel.KeyframeStyle.prototype={offset:function() {return this._offset;},setOffset:function(offset) {this._offset=offset*100+"%";},offsetAsNumber:function() {return parseFloat(this._offset)/100;},easing:function() {return this._payload.easing;},__proto__:WebInspector.SDKObject.prototype} WebInspector.AnimationDispatcher=function(animationModel) {this._animationModel=animationModel;} WebInspector.AnimationDispatcher.prototype={animationCreated:function(payload,resetTimeline) {this._animationModel.animationCreated(payload,resetTimeline);},animationCanceled:function(id) {this._animationModel.animationCanceled(id);}};WebInspector.AnimationTimeline=function() {WebInspector.VBox.call(this,true);this.registerRequiredCSS("animation/animationTimeline.css");this.element.classList.add("animations-timeline");this._grid=this.contentElement.createSVGChild("svg","animation-timeline-grid");this.contentElement.appendChild(this._createScrubber());WebInspector.installDragHandle(this._timelineScrubberHead,this._scrubberDragStart.bind(this),this._scrubberDragMove.bind(this),this._scrubberDragEnd.bind(this),"move");this._timelineScrubberHead.textContent=WebInspector.UIString(Number.millisToString(0));this._underlyingPlaybackRate=1;this.contentElement.appendChild(this._createHeader());this._animationsContainer=this.contentElement.createChild("div","animation-timeline-rows");this._duration=this._defaultDuration();this._scrubberRadius=25;this._timelineControlsWidth=200;this._nodesMap=new Map();this._symbol=Symbol("animationTimeline");this._animationsMap=new Map();WebInspector.targetManager.addModelListener(WebInspector.ResourceTreeModel,WebInspector.ResourceTreeModel.EventTypes.MainFrameNavigated,this._mainFrameNavigated,this);WebInspector.targetManager.addModelListener(WebInspector.DOMModel,WebInspector.DOMModel.Events.NodeRemoved,this._nodeRemoved,this);WebInspector.targetManager.observeTargets(this,WebInspector.Target.Type.Page);} WebInspector.AnimationTimeline.GlobalPlaybackRates=[0.1,0.25,0.5,1.0];WebInspector.AnimationTimeline.prototype={wasShown:function() {for(var target of WebInspector.targetManager.targets(WebInspector.Target.Type.Page)) this._addEventListeners(target);},willHide:function() {for(var target of WebInspector.targetManager.targets(WebInspector.Target.Type.Page)) this._removeEventListeners(target);},targetAdded:function(target) {if(this.isShowing()) this._addEventListeners(target);},targetRemoved:function(target) {this._removeEventListeners(target);},_addEventListeners:function(target) {var animationModel=WebInspector.AnimationModel.fromTarget(target);animationModel.ensureEnabled();animationModel.addEventListener(WebInspector.AnimationModel.Events.AnimationCreated,this._animationCreated,this);animationModel.addEventListener(WebInspector.AnimationModel.Events.AnimationCanceled,this._animationCanceled,this);},_removeEventListeners:function(target) {var animationModel=WebInspector.AnimationModel.fromTarget(target);animationModel.removeEventListener(WebInspector.AnimationModel.Events.AnimationCreated,this._animationCreated,this);animationModel.removeEventListener(WebInspector.AnimationModel.Events.AnimationCanceled,this._animationCanceled,this);},setNode:function(node) {for(var nodeUI of this._nodesMap.values()) nodeUI.setNode(node);},_createScrubber:function(){this._timelineScrubber=createElementWithClass("div","animation-scrubber hidden");this._timelineScrubber.createChild("div","animation-time-overlay");this._timelineScrubber.createChild("div","animation-scrubber-arrow");this._timelineScrubberHead=this._timelineScrubber.createChild("div","animation-scrubber-head");var timerContainer=this._timelineScrubber.createChild("div","animation-timeline-timer");this._timerSpinner=timerContainer.createChild("div","timer-spinner timer-hemisphere");this._timerFiller=timerContainer.createChild("div","timer-filler timer-hemisphere");this._timerMask=timerContainer.createChild("div","timer-mask");return this._timelineScrubber;},_createHeader:function() {function playbackSliderInputHandler(event) {this._underlyingPlaybackRate=WebInspector.AnimationTimeline.GlobalPlaybackRates[event.target.value];this._setPlaybackRate(this._playbackRate());this._playbackLabel.textContent=this._underlyingPlaybackRate+"✕";WebInspector.userMetrics.AnimationsPlaybackRateChanged.record();if(this._scrubberPlayer) this._scrubberPlayer.playbackRate=this._playbackRate();} var container=createElementWithClass("div","animation-timeline-header");var controls=container.createChild("div","animation-controls");container.createChild("div","animation-timeline-markers");var toolbar=new WebInspector.Toolbar(controls);toolbar.element.classList.add("animation-controls-toolbar");this._pauseButton=new WebInspector.ToolbarButton(WebInspector.UIString("Pause timeline"),"pause-toolbar-item");this._pauseButton.addEventListener("click",this._togglePause.bind(this));toolbar.appendToolbarItem(this._pauseButton);var replayButton=new WebInspector.ToolbarButton(WebInspector.UIString("Replay timeline"),"replay-toolbar-item");replayButton.addEventListener("click",this._replay.bind(this));toolbar.appendToolbarItem(replayButton);this._playbackLabel=controls.createChild("div","animation-playback-label");this._playbackLabel.createTextChild("1x");this._playbackSlider=controls.createChild("input","animation-playback-slider");this._playbackSlider.type="range";this._playbackSlider.min=0;this._playbackSlider.max=WebInspector.AnimationTimeline.GlobalPlaybackRates.length-1;this._playbackSlider.value=this._playbackSlider.max;this._playbackSlider.addEventListener("input",playbackSliderInputHandler.bind(this));this._updateAnimationsPlaybackRate();return container;},_updateAnimationsPlaybackRate:function() {function setPlaybackRate(error,playbackRate) {if(playbackRate===0){playbackRate=1;target.animationAgent().setPlaybackRate(1);} this._underlyingPlaybackRate=playbackRate;this._playbackSlider.value=WebInspector.AnimationTimeline.GlobalPlaybackRates.indexOf(playbackRate);this._playbackLabel.textContent=playbackRate+"✕";} var target=WebInspector.targetManager.mainTarget();if(target) target.animationAgent().getPlaybackRate(setPlaybackRate.bind(this));},_playbackRate:function() {return this._paused?0:this._underlyingPlaybackRate;},_togglePause:function() {this._paused=!this._paused;this._setPlaybackRate(this._playbackRate());WebInspector.userMetrics.AnimationsPlaybackRateChanged.record();this._pauseButton.element.classList.toggle("pause-toolbar-item");this._pauseButton.element.classList.toggle("play-toolbar-item");if(this._scrubberPlayer) this._scrubberPlayer.playbackRate=this._playbackRate();},_replay:function() {if(this.startTime()===undefined) return;var targets=WebInspector.targetManager.targets();for(var target of targets) target.animationAgent().setCurrentTime((this.startTime()));this._animateTime(0);},_defaultDuration:function() {return 100;},duration:function() {return this._duration;},setDuration:function(duration) {this._duration=duration;this.scheduleRedraw();},startTime:function() {return this._startTime;},_reset:function() {if(!this._nodesMap.size) return;this._nodesMap.clear();this._animationsMap.clear();this._animationsContainer.removeChildren();this._duration=this._defaultDuration();delete this._startTime;},_mainFrameNavigated:function(event) {this._reset();this._updateAnimationsPlaybackRate();if(this._scrubberPlayer) this._scrubberPlayer.cancel();delete this._scrubberPlayer;this._timelineScrubberHead.textContent=WebInspector.UIString(Number.millisToString(0));},_animationCreated:function(event) {this._addAnimation((event.data.player),event.data.resetTimeline)},_addAnimation:function(animation,resetTimeline) {function nodeResolved(node) {uiAnimation.setNode(node);node[this._symbol]=nodeUI;} if(resetTimeline) this._reset();if(animation.type()==="WebAnimation"&&animation.source().keyframesRule().keyframes().length===0) return;if(this._resizeWindow(animation)) this.scheduleRedraw();var nodeUI=this._nodesMap.get(animation.source().backendNodeId());if(!nodeUI){nodeUI=new WebInspector.AnimationTimeline.NodeUI(animation.source());this._animationsContainer.appendChild(nodeUI.element);this._nodesMap.set(animation.source().backendNodeId(),nodeUI);} var nodeRow=nodeUI.findRow(animation);var uiAnimation=new WebInspector.AnimationUI(animation,this,nodeRow.element);animation.source().deferredNode().resolve(nodeResolved.bind(this));nodeRow.animations.push(uiAnimation);this._animationsMap.set(animation.id(),animation);},_animationCanceled:function(event) {this._cancelAnimation((event.data.id));},_cancelAnimation:function(playerId) {var animation=this._animationsMap.get(playerId);if(!animation) return;animation.setPlayState("idle");this.scheduleRedraw();},_nodeRemoved:function(event) {var node=event.data.node;if(node[this._symbol]) node[this._symbol].nodeRemoved();},_renderGrid:function() {const gridSize=250;this._grid.setAttribute("width",this.width());this._grid.setAttribute("height",this._animationsContainer.offsetHeight+43);this._grid.setAttribute("shape-rendering","crispEdges");this._grid.removeChildren();var lastDraw=undefined;for(var time=0;time50)){lastDraw=gridWidth;var label=this._grid.createSVGChild("text","animation-timeline-grid-label");label.setAttribute("x",gridWidth+5);label.setAttribute("y",35);label.textContent=WebInspector.UIString(Number.millisToString(time));}}},scheduleRedraw:function(){if(this._redrawing) return;this._redrawing=true;this._animationsContainer.window().requestAnimationFrame(this._redraw.bind(this));},_redraw:function(timestamp) {delete this._redrawing;for(var nodeUI of this._nodesMap.values()) nodeUI.redraw();this._renderGrid();},onResize:function() {this._cachedTimelineWidth=Math.max(0,this._animationsContainer.offsetWidth-this._timelineControlsWidth)||0;this.scheduleRedraw();if(this._scrubberPlayer) this._animateTime();},width:function() {return this._cachedTimelineWidth||0;},_resizeWindow:function(animation) {var resized=false;if(!this._startTime) this._startTime=animation.startTime();var duration=animation.source().duration()*Math.min(3,animation.source().iterations());var requiredDuration=animation.startTime()+animation.source().delay()+duration+animation.source().endDelay()-this.startTime();if(requiredDuration>this._duration*0.8){resized=true;this._duration=requiredDuration*1.5;this._timelineScrubber.classList.remove("hidden");this._animateTime(animation.startTime()-this.startTime());} return resized;},_animateTime:function(time) {var oldPlayer=this._scrubberPlayer;this._scrubberPlayer=this._timelineScrubber.animate([{transform:"translateX(0px)"},{transform:"translateX("+(this.width()-this._scrubberRadius)+"px)"}],{duration:this.duration()-this._scrubberRadius/this.pixelMsRatio(),fill:"forwards"});this._scrubberPlayer.playbackRate=this._playbackRate();if(time!==undefined) this._scrubberPlayer.currentTime=time;else if(oldPlayer.playState==="finished") this._scrubberPlayer.finish();else this._scrubberPlayer.startTime=oldPlayer.startTime;if(oldPlayer) oldPlayer.cancel();this._timelineScrubber.classList.remove("animation-timeline-end");this._timelineScrubberHead.window().requestAnimationFrame(this._updateScrubber.bind(this));},pixelMsRatio:function() {return this.width()/this.duration()||0;},_updateScrubber:function(timestamp) {if(!this._scrubberPlayer) return;this._timelineScrubberHead.textContent=WebInspector.UIString(Number.millisToString(this._scrubberPlayer.currentTime));if(this._scrubberPlayer.playState==="pending"||this._scrubberPlayer.playState==="running"){this._timelineScrubberHead.window().requestAnimationFrame(this._updateScrubber.bind(this));}else if(this._scrubberPlayer.playState==="finished"){this._timelineScrubberHead.textContent=WebInspector.UIString(". . .");this._timelineScrubber.classList.add("animation-timeline-end");}},_scrubberDragStart:function(event) {if(!this._scrubberPlayer) return false;this._originalScrubberTime=this._scrubberPlayer.currentTime;this._timelineScrubber.classList.remove("animation-timeline-end");this._scrubberPlayer.pause();this._originalMousePosition=new WebInspector.Geometry.Point(event.x,event.y);this._setPlaybackRate(0);return true;},_scrubberDragMove:function(event) {var delta=event.x-this._originalMousePosition.x;this._scrubberPlayer.currentTime=Math.min(this._originalScrubberTime+delta/this.pixelMsRatio(),this.duration()-this._scrubberRadius/this.pixelMsRatio());var currentTime=Math.max(0,Math.round(this._scrubberPlayer.currentTime));this._timelineScrubberHead.textContent=WebInspector.UIString(Number.millisToString(currentTime));var targets=WebInspector.targetManager.targets();for(var target of targets) target.animationAgent().setCurrentTime((this.startTime()+currentTime));},_scrubberDragEnd:function(event) {if(this._scrubberPlayer.currentTime1);for(var i=0;i0&&ithis._timeline.duration()*0.8) this._timeline.setDuration(this._timeline.duration()*1.2);this.redraw();},_mouseUp:function(event) {this._movementInMs=(event.clientX-this._downMouseX)/this._timeline.pixelMsRatio();if(this._mouseEventType===WebInspector.AnimationUI.MouseEvents.KeyframeMove){this._keyframes[this._keyframeMoved].setOffset(this._offset(this._keyframeMoved));}else{var delay=this._delay();var duration=this._duration();this._setDelay(delay);this._setDuration(duration);if(this._animation.type()!=="CSSAnimation"){var target=WebInspector.targetManager.mainTarget();if(target) target.animationAgent().setTiming(this._animation.id(),duration,delay);}} this._movementInMs=0;this.redraw();this._parentElement.ownerDocument.removeEventListener("mousemove",this._mouseMoveHandler);this._parentElement.ownerDocument.removeEventListener("mouseup",this._mouseUpHandler);delete this._mouseMoveHandler;delete this._mouseUpHandler;delete this._mouseEventType;delete this._downMouseX;delete this._keyframeMoved;},_setDelay:function(value) {if(!this._node||this._animation.source().delay()==this._delay()) return;this._animation.source().setDelay(this._delay());var propertyName;if(this._animation.type()=="CSSTransition") propertyName="transition-delay";else if(this._animation.type()=="CSSAnimation") propertyName="animation-delay";else return;this._setNodeStyle(propertyName,Math.round(value)+"ms");},_setDuration:function(value) {if(!this._node||this._animation.source().duration()==value) return;this._animation.source().setDuration(value);var propertyName;if(this._animation.type()=="CSSTransition") propertyName="transition-duration";else if(this._animation.type()=="CSSAnimation") propertyName="animation-duration";else return;this._setNodeStyle(propertyName,Math.round(value)+"ms");},_setNodeStyle:function(name,value) {var style=this._node.getAttribute("style")||"";if(style) style=style.replace(new RegExp("\\s*(-webkit-)?"+name+":[^;]*;?\\s*","g"),"");var valueString=name+": "+value;this._node.setAttributeValue("style",style+" "+valueString+"; -webkit-"+valueString+";");},_color:function() {function hash(string) {var hash=0;for(var i=0;i