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

Side by Side Diff: Source/core/inspector/InspectorAnimationAgent.cpp

Issue 1155773002: Devtools Animations: Add cubic bezier easing editor for animations (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase Created 5 years, 6 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 | « Source/core/inspector/InspectorAnimationAgent.h ('k') | Source/devtools/devtools.gypi » ('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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include "config.h" 5 #include "config.h"
6 6
7 #include "core/inspector/InspectorAnimationAgent.h" 7 #include "core/inspector/InspectorAnimationAgent.h"
8 8
9 #include "core/animation/Animation.h" 9 #include "core/animation/Animation.h"
10 #include "core/animation/AnimationEffect.h" 10 #include "core/animation/AnimationEffect.h"
11 #include "core/animation/AnimationEffectTiming.h" 11 #include "core/animation/AnimationEffectTiming.h"
12 #include "core/animation/AnimationInputHelpers.h"
12 #include "core/animation/ComputedTimingProperties.h" 13 #include "core/animation/ComputedTimingProperties.h"
13 #include "core/animation/EffectModel.h" 14 #include "core/animation/EffectModel.h"
14 #include "core/animation/ElementAnimation.h" 15 #include "core/animation/ElementAnimation.h"
15 #include "core/animation/KeyframeEffect.h" 16 #include "core/animation/KeyframeEffect.h"
16 #include "core/animation/KeyframeEffectModel.h" 17 #include "core/animation/KeyframeEffectModel.h"
17 #include "core/animation/StringKeyframe.h" 18 #include "core/animation/StringKeyframe.h"
18 #include "core/css/CSSKeyframeRule.h" 19 #include "core/css/CSSKeyframeRule.h"
19 #include "core/css/CSSKeyframesRule.h" 20 #include "core/css/CSSKeyframesRule.h"
20 #include "core/css/resolver/StyleResolver.h" 21 #include "core/css/resolver/StyleResolver.h"
21 #include "core/dom/DOMNodeIds.h" 22 #include "core/dom/DOMNodeIds.h"
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 { 219 {
219 double timeDelta = currentTime - referenceTimeline().currentTime(); 220 double timeDelta = currentTime - referenceTimeline().currentTime();
220 for (Frame* frame = m_pageAgent->inspectedFrame(); frame; frame = frame->tre e().traverseNext(m_pageAgent->inspectedFrame())) { 221 for (Frame* frame = m_pageAgent->inspectedFrame(); frame; frame = frame->tre e().traverseNext(m_pageAgent->inspectedFrame())) {
221 if (frame->isLocalFrame()) { 222 if (frame->isLocalFrame()) {
222 AnimationTimeline& timeline = toLocalFrame(frame)->document()->timel ine(); 223 AnimationTimeline& timeline = toLocalFrame(frame)->document()->timel ine();
223 timeline.setCurrentTime(timeline.currentTime() + timeDelta); 224 timeline.setCurrentTime(timeline.currentTime() + timeDelta);
224 } 225 }
225 } 226 }
226 } 227 }
227 228
229 static KeyframeVector cloneTransitionFrames(KeyframeEffectModelBase* model)
230 {
231 const AnimatableValueKeyframeEffectModel* oldModel = toAnimatableValueKeyfra meEffectModel(model);
232 // Refer to CSSAnimations::calculateTransitionUpdateForProperty() for the st ructure of transitions.
233 const KeyframeVector& frames = oldModel->getFrames();
234 ASSERT(frames.size() == 3);
235 KeyframeVector newFrames;
236 for (int i = 0; i < 3; i++)
237 newFrames.append(toAnimatableValueKeyframe(frames[i]->clone().get()));
238 return newFrames;
239 }
240
228 void InspectorAnimationAgent::setTiming(ErrorString* errorString, const String& playerId, double duration, double delay) 241 void InspectorAnimationAgent::setTiming(ErrorString* errorString, const String& playerId, double duration, double delay)
229 { 242 {
230 Animation* animation = assertAnimation(errorString, playerId); 243 Animation* animation = assertAnimation(errorString, playerId);
231 if (!animation) 244 if (!animation)
232 return; 245 return;
233 246
234 AnimationType type = m_idToAnimationType.get(playerId); 247 AnimationType type = m_idToAnimationType.get(playerId);
235 if (type == AnimationType::CSSTransition) { 248 if (type == AnimationType::CSSTransition) {
236 KeyframeEffect* effect = toKeyframeEffect(animation->source()); 249 KeyframeEffect* effect = toKeyframeEffect(animation->source());
237 KeyframeEffectModelBase* model = toKeyframeEffectModelBase(effect->model ()); 250 KeyframeEffectModelBase* model = toKeyframeEffectModelBase(effect->model ());
238 const AnimatableValueKeyframeEffectModel* oldModel = toAnimatableValueKe yframeEffectModel(model); 251 KeyframeVector newFrames = cloneTransitionFrames(model);
239 // Refer to CSSAnimations::calculateTransitionUpdateForProperty() for th e structure of transitions.
240 const KeyframeVector& frames = oldModel->getFrames();
241 ASSERT(frames.size() == 3);
242 KeyframeVector newFrames;
243 for (int i = 0; i < 3; i++)
244 newFrames.append(toAnimatableValueKeyframe(frames[i]->clone().get()) );
245 // Update delay, represented by the distance between the first two keyfr ames. 252 // Update delay, represented by the distance between the first two keyfr ames.
246 newFrames[1]->setOffset(delay / (delay + duration)); 253 newFrames[1]->setOffset(delay / (delay + duration));
247 model->setFrames(newFrames); 254 model->setFrames(newFrames);
248 255
249 RefPtrWillBeRawPtr<AnimationEffectTiming> timing = animation->source()-> timing(); 256 RefPtrWillBeRawPtr<AnimationEffectTiming> timing = animation->source()-> timing();
250 UnrestrictedDoubleOrString unrestrictedDuration; 257 UnrestrictedDoubleOrString unrestrictedDuration;
251 unrestrictedDuration.setUnrestrictedDouble(duration + delay); 258 unrestrictedDuration.setUnrestrictedDouble(duration + delay);
252 timing->setDuration(unrestrictedDuration); 259 timing->setDuration(unrestrictedDuration);
253 } else if (type == AnimationType::WebAnimation) { 260 } else if (type == AnimationType::WebAnimation) {
254 RefPtrWillBeRawPtr<AnimationEffectTiming> timing = animation->source()-> timing(); 261 RefPtrWillBeRawPtr<AnimationEffectTiming> timing = animation->source()-> timing();
255 UnrestrictedDoubleOrString unrestrictedDuration; 262 UnrestrictedDoubleOrString unrestrictedDuration;
256 unrestrictedDuration.setUnrestrictedDouble(duration); 263 unrestrictedDuration.setUnrestrictedDouble(duration);
257 timing->setDuration(unrestrictedDuration); 264 timing->setDuration(unrestrictedDuration);
258 timing->setDelay(delay); 265 timing->setDelay(delay);
266 } else {
267 *errorString = "Given animation is not a transition or web animation.";
259 } 268 }
260 } 269 }
261 270
271 void InspectorAnimationAgent::setEasing(ErrorString* errorString, const String& playerId, const String& easing)
272 {
273 Animation* animation = assertAnimation(errorString, playerId);
274 if (!animation)
275 return;
276
277 AnimationType type = m_idToAnimationType.get(playerId);
278 if (type == AnimationType::CSSTransition) {
279 KeyframeEffect* effect = toKeyframeEffect(animation->source());
280 KeyframeEffectModelBase* model = toKeyframeEffectModelBase(effect->model ());
281 KeyframeVector newFrames = cloneTransitionFrames(model);
282 // Update easing of the transition, represented by the second keyframe.
283 if (RefPtr<TimingFunction> timingFunction = AnimationInputHelpers::parse TimingFunction(easing)) {
284 newFrames[1]->setEasing(timingFunction);
285 } else {
286 *errorString = "Could not parse timing function.";
287 return;
288 }
289 model->setFrames(newFrames);
290 } else if (type == AnimationType::WebAnimation) {
291 RefPtrWillBeRawPtr<AnimationEffectTiming> timing = animation->source()-> timing();
292 timing->setEasing(easing);
293 } else {
294 *errorString = "Given animation is not a transition or web animation.";
295 }
296 }
297
262 void InspectorAnimationAgent::didCreateAnimation(Animation* player) 298 void InspectorAnimationAgent::didCreateAnimation(Animation* player)
263 { 299 {
264 const String& playerId = String::number(player->sequenceNumber()); 300 const String& playerId = String::number(player->sequenceNumber());
265 if (m_idToAnimation.get(playerId)) 301 if (m_idToAnimation.get(playerId))
266 return; 302 return;
267 303
268 double threshold = 1000; 304 double threshold = 1000;
269 bool reset = normalizedStartTime(*player) - threshold > m_latestStartTime; 305 bool reset = normalizedStartTime(*player) - threshold > m_latestStartTime;
270 m_latestStartTime = normalizedStartTime(*player); 306 m_latestStartTime = normalizedStartTime(*player);
271 if (reset) { 307 if (reset) {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 #if ENABLE(OILPAN) 368 #if ENABLE(OILPAN)
333 visitor->trace(m_pageAgent); 369 visitor->trace(m_pageAgent);
334 visitor->trace(m_domAgent); 370 visitor->trace(m_domAgent);
335 visitor->trace(m_idToAnimation); 371 visitor->trace(m_idToAnimation);
336 visitor->trace(m_idToAnimationType); 372 visitor->trace(m_idToAnimationType);
337 #endif 373 #endif
338 InspectorBaseAgent::trace(visitor); 374 InspectorBaseAgent::trace(visitor);
339 } 375 }
340 376
341 } 377 }
OLDNEW
« no previous file with comments | « Source/core/inspector/InspectorAnimationAgent.h ('k') | Source/devtools/devtools.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698