Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 145 CSSAnimations& cssAnimations = element->elementAnimations()->cssAnimations() ; | 146 CSSAnimations& cssAnimations = element->elementAnimations()->cssAnimations() ; |
| 146 RefPtr<TypeBuilder::Animation::KeyframesRule> keyframeRule = nullptr; | 147 RefPtr<TypeBuilder::Animation::KeyframesRule> keyframeRule = nullptr; |
| 147 AnimationType animationType; | 148 AnimationType animationType; |
| 148 | 149 |
| 149 if (cssAnimations.isTransitionAnimationForInspector(player)) { | 150 if (cssAnimations.isTransitionAnimationForInspector(player)) { |
| 150 // CSS Transitions | 151 // CSS Transitions |
| 151 animationType = AnimationType::CSSTransition; | 152 animationType = AnimationType::CSSTransition; |
| 152 } else { | 153 } else { |
| 153 // Keyframe based animations | 154 // Keyframe based animations |
| 154 keyframeRule = buildObjectForAnimationKeyframes(toKeyframeEffect(player. source())); | 155 keyframeRule = buildObjectForAnimationKeyframes(toKeyframeEffect(player. source())); |
| 155 animationType = cssAnimations.isAnimationForInspector(player) ? Animatio nType::WebAnimation : AnimationType::CSSAnimation; | 156 animationType = cssAnimations.isAnimationForInspector(player) ? Animatio nType::CSSAnimation : AnimationType::WebAnimation; |
|
dgozman
2015/05/28 11:04:03
What I meant is to add tests that cover the functi
| |
| 156 } | 157 } |
| 157 | 158 |
| 158 String id = String::number(player.sequenceNumber()); | 159 String id = String::number(player.sequenceNumber()); |
| 159 m_idToAnimation.set(id, &player); | 160 m_idToAnimation.set(id, &player); |
| 160 m_idToAnimationType.set(id, animationType); | 161 m_idToAnimationType.set(id, animationType); |
| 161 | 162 |
| 162 RefPtr<TypeBuilder::Animation::AnimationNode> animationObject = buildObjectF orAnimation(toKeyframeEffect(player.source()), animationType == AnimationType::C SSTransition); | 163 RefPtr<TypeBuilder::Animation::AnimationNode> animationObject = buildObjectF orAnimation(toKeyframeEffect(player.source()), animationType == AnimationType::C SSTransition); |
| 163 if (keyframeRule) | 164 if (keyframeRule) |
| 164 animationObject->setKeyframesRule(keyframeRule); | 165 animationObject->setKeyframesRule(keyframeRule); |
| 165 | 166 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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); |
| 259 } | 266 } |
| 260 } | 267 } |
| 261 | 268 |
| 269 void InspectorAnimationAgent::setEasing(ErrorString* errorString, const String& playerId, const String& easing) | |
| 270 { | |
| 271 Animation* animation = assertAnimation(errorString, playerId); | |
| 272 if (!animation) | |
| 273 return; | |
| 274 | |
| 275 AnimationType type = m_idToAnimationType.get(playerId); | |
| 276 if (type == AnimationType::CSSTransition) { | |
| 277 KeyframeEffect* effect = toKeyframeEffect(animation->source()); | |
| 278 KeyframeEffectModelBase* model = toKeyframeEffectModelBase(effect->model ()); | |
| 279 KeyframeVector newFrames = cloneTransitionFrames(model); | |
| 280 // Update easing of the transition, represented by the second keyframe. | |
| 281 if (RefPtr<TimingFunction> timingFunction = AnimationInputHelpers::parse TimingFunction(easing)) { | |
| 282 newFrames[1]->setEasing(timingFunction); | |
| 283 } else { | |
| 284 *errorString = "Could not parse timing function."; | |
| 285 return; | |
| 286 } | |
| 287 model->setFrames(newFrames); | |
| 288 } else if (type == AnimationType::WebAnimation) { | |
| 289 RefPtrWillBeRawPtr<AnimationEffectTiming> timing = animation->source()-> timing(); | |
| 290 timing->setEasing(easing); | |
| 291 } else { | |
| 292 *errorString = "Given animation is not a transition or web animation."; | |
|
dgozman
2015/05/28 11:04:03
I think, we should have similar error reporting ev
samli
2015/05/29 04:32:11
Acknowledged.
| |
| 293 } | |
| 294 } | |
| 295 | |
| 262 void InspectorAnimationAgent::didCreateAnimation(Animation* player) | 296 void InspectorAnimationAgent::didCreateAnimation(Animation* player) |
| 263 { | 297 { |
| 264 const String& playerId = String::number(player->sequenceNumber()); | 298 const String& playerId = String::number(player->sequenceNumber()); |
| 265 if (m_idToAnimation.get(playerId)) | 299 if (m_idToAnimation.get(playerId)) |
| 266 return; | 300 return; |
| 267 | 301 |
| 268 double threshold = 1000; | 302 double threshold = 1000; |
| 269 bool reset = normalizedStartTime(*player) - threshold > m_latestStartTime; | 303 bool reset = normalizedStartTime(*player) - threshold > m_latestStartTime; |
| 270 m_latestStartTime = normalizedStartTime(*player); | 304 m_latestStartTime = normalizedStartTime(*player); |
| 271 if (reset) { | 305 if (reset) { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 319 #if ENABLE(OILPAN) | 353 #if ENABLE(OILPAN) |
| 320 visitor->trace(m_pageAgent); | 354 visitor->trace(m_pageAgent); |
| 321 visitor->trace(m_domAgent); | 355 visitor->trace(m_domAgent); |
| 322 visitor->trace(m_idToAnimation); | 356 visitor->trace(m_idToAnimation); |
| 323 visitor->trace(m_idToAnimationType); | 357 visitor->trace(m_idToAnimationType); |
| 324 #endif | 358 #endif |
| 325 InspectorBaseAgent::trace(visitor); | 359 InspectorBaseAgent::trace(visitor); |
| 326 } | 360 } |
| 327 | 361 |
| 328 } | 362 } |
| OLD | NEW |