Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 36 #include "core/animation/DocumentTimeline.h" | 36 #include "core/animation/DocumentTimeline.h" |
| 37 #include "core/animation/KeyframeAnimationEffect.h" | 37 #include "core/animation/KeyframeAnimationEffect.h" |
| 38 #include "core/animation/css/CSSAnimatableValueFactory.h" | 38 #include "core/animation/css/CSSAnimatableValueFactory.h" |
| 39 #include "core/css/CSSKeyframeRule.h" | 39 #include "core/css/CSSKeyframeRule.h" |
| 40 #include "core/css/resolver/StyleResolver.h" | 40 #include "core/css/resolver/StyleResolver.h" |
| 41 #include "core/dom/Element.h" | 41 #include "core/dom/Element.h" |
| 42 #include "core/events/ThreadLocalEventNames.h" | 42 #include "core/events/ThreadLocalEventNames.h" |
| 43 #include "core/events/TransitionEvent.h" | 43 #include "core/events/TransitionEvent.h" |
| 44 #include "core/events/WebKitAnimationEvent.h" | 44 #include "core/events/WebKitAnimationEvent.h" |
| 45 #include "core/frame/animation/CSSPropertyAnimation.h" | 45 #include "core/frame/animation/CSSPropertyAnimation.h" |
| 46 #include "core/page/UseCounter.h" | |
| 46 #include "core/platform/animation/CSSAnimationDataList.h" | 47 #include "core/platform/animation/CSSAnimationDataList.h" |
| 47 #include "core/platform/animation/TimingFunction.h" | 48 #include "core/platform/animation/TimingFunction.h" |
| 48 #include "core/rendering/style/KeyframeList.h" | 49 #include "core/rendering/style/KeyframeList.h" |
| 50 #include "public/platform/Platform.h" | |
| 49 #include "wtf/HashSet.h" | 51 #include "wtf/HashSet.h" |
| 50 | 52 |
| 51 namespace WebCore { | 53 namespace WebCore { |
| 52 | 54 |
| 53 struct CandidateTransition { | 55 struct CandidateTransition { |
| 54 CandidateTransition(PassRefPtr<AnimatableValue> from, PassRefPtr<AnimatableV alue> to, const CSSAnimationData* anim) | 56 CandidateTransition(PassRefPtr<AnimatableValue> from, PassRefPtr<AnimatableV alue> to, const CSSAnimationData* anim) |
| 55 : from(from) | 57 : from(from) |
| 56 , to(to) | 58 , to(to) |
| 57 , anim(anim) | 59 , anim(anim) |
| 58 { | 60 { |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 300 ASSERT(RuntimeEnabledFeatures::webAnimationsCSSEnabled()); | 302 ASSERT(RuntimeEnabledFeatures::webAnimationsCSSEnabled()); |
| 301 const StyleRuleKeyframes* keyframesRule = matchScopedKeyframesRule(element, name.impl(), resolver); | 303 const StyleRuleKeyframes* keyframesRule = matchScopedKeyframesRule(element, name.impl(), resolver); |
| 302 if (!keyframesRule) | 304 if (!keyframesRule) |
| 303 return; | 305 return; |
| 304 | 306 |
| 305 const Vector<RefPtr<StyleKeyframe> >& styleKeyframes = keyframesRule->keyfra mes(); | 307 const Vector<RefPtr<StyleKeyframe> >& styleKeyframes = keyframesRule->keyfra mes(); |
| 306 if (styleKeyframes.isEmpty()) | 308 if (styleKeyframes.isEmpty()) |
| 307 return; | 309 return; |
| 308 | 310 |
| 309 // Construct and populate the style for each keyframe | 311 // Construct and populate the style for each keyframe |
| 312 PropertySet specifiedProperties; | |
| 310 KeyframeAnimationEffect::KeyframeVector keyframes; | 313 KeyframeAnimationEffect::KeyframeVector keyframes; |
| 311 HashMap<double, RefPtr<TimingFunction> > perKeyframeTimingFunctions; | 314 HashMap<double, RefPtr<TimingFunction> > perKeyframeTimingFunctions; |
| 312 for (size_t i = 0; i < styleKeyframes.size(); ++i) { | 315 for (size_t i = 0; i < styleKeyframes.size(); ++i) { |
| 313 const StyleKeyframe* styleKeyframe = styleKeyframes[i].get(); | 316 const StyleKeyframe* styleKeyframe = styleKeyframes[i].get(); |
| 314 RefPtr<RenderStyle> keyframeStyle = styleForKeyframe(element, style, sty leKeyframe, resolver); | 317 RefPtr<RenderStyle> keyframeStyle = styleForKeyframe(element, style, sty leKeyframe, resolver); |
| 315 RefPtr<Keyframe> keyframe = Keyframe::create(); | 318 RefPtr<Keyframe> keyframe = Keyframe::create(); |
| 316 const Vector<double>& offsets = styleKeyframe->keys(); | 319 const Vector<double>& offsets = styleKeyframe->keys(); |
| 317 ASSERT(!offsets.isEmpty()); | 320 ASSERT(!offsets.isEmpty()); |
| 318 keyframe->setOffset(offsets[0]); | 321 keyframe->setOffset(offsets[0]); |
| 319 TimingFunction* timingFunction = defaultTimingFunction; | 322 TimingFunction* timingFunction = defaultTimingFunction; |
| 320 const StylePropertySet* properties = styleKeyframe->properties(); | 323 const StylePropertySet* properties = styleKeyframe->properties(); |
| 321 for (unsigned j = 0; j < properties->propertyCount(); j++) { | 324 for (unsigned j = 0; j < properties->propertyCount(); j++) { |
| 322 CSSPropertyID property = properties->propertyAt(j).id(); | 325 CSSPropertyID property = properties->propertyAt(j).id(); |
| 326 specifiedProperties.add(property); | |
| 323 if (property == CSSPropertyWebkitAnimationTimingFunction || property == CSSPropertyAnimationTimingFunction) { | 327 if (property == CSSPropertyWebkitAnimationTimingFunction || property == CSSPropertyAnimationTimingFunction) { |
| 324 // FIXME: This sometimes gets the wrong timing function. See crb ug.com/288540. | 328 // FIXME: This sometimes gets the wrong timing function. See crb ug.com/288540. |
| 325 timingFunction = KeyframeValue::timingFunction(keyframeStyle.get (), name); | 329 timingFunction = KeyframeValue::timingFunction(keyframeStyle.get (), name); |
| 326 } else if (CSSAnimations::isAnimatableProperty(property)) { | 330 } else if (CSSAnimations::isAnimatableProperty(property)) { |
| 327 keyframe->setPropertyValue(property, CSSAnimatableValueFactory:: create(property, keyframeStyle.get()).get()); | 331 keyframe->setPropertyValue(property, CSSAnimatableValueFactory:: create(property, keyframeStyle.get()).get()); |
| 328 } | 332 } |
| 329 } | 333 } |
| 330 keyframes.append(keyframe); | 334 keyframes.append(keyframe); |
| 331 // The last keyframe specified at a given offset is used. | 335 // The last keyframe specified at a given offset is used. |
| 332 perKeyframeTimingFunctions.set(offsets[0], timingFunction); | 336 perKeyframeTimingFunctions.set(offsets[0], timingFunction); |
| 333 for (size_t j = 1; j < offsets.size(); ++j) { | 337 for (size_t j = 1; j < offsets.size(); ++j) { |
| 334 keyframes.append(keyframe->cloneWithOffset(offsets[j])); | 338 keyframes.append(keyframe->cloneWithOffset(offsets[j])); |
| 335 perKeyframeTimingFunctions.set(offsets[j], timingFunction); | 339 perKeyframeTimingFunctions.set(offsets[j], timingFunction); |
| 336 } | 340 } |
| 337 } | 341 } |
| 338 ASSERT(!keyframes.isEmpty()); | 342 ASSERT(!keyframes.isEmpty()); |
| 339 | 343 |
| 340 if (!perKeyframeTimingFunctions.contains(0)) | 344 if (!perKeyframeTimingFunctions.contains(0)) |
| 341 perKeyframeTimingFunctions.set(0, defaultTimingFunction); | 345 perKeyframeTimingFunctions.set(0, defaultTimingFunction); |
| 342 | 346 |
| 347 // Update use counter. | |
|
dstockwell
2013/11/05 22:54:18
This comment is not necessary.
rjwright1
2013/11/11 12:18:25
Done.
| |
| 348 for (PropertySet::const_iterator iter = specifiedProperties.begin(); iter != specifiedProperties.end(); ++iter) { | |
| 349 const CSSPropertyID property = *iter; | |
| 350 ASSERT(property != CSSPropertyInvalid); | |
| 351 WebKit::Platform::current()->histogramSparse("WebCore.Animation.CSSPrope rties", UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(property)); | |
| 352 } | |
| 353 | |
| 343 // Remove duplicate keyframes. In CSS the last keyframe at a given offset ta kes priority. | 354 // Remove duplicate keyframes. In CSS the last keyframe at a given offset ta kes priority. |
| 344 std::stable_sort(keyframes.begin(), keyframes.end(), Keyframe::compareOffset s); | 355 std::stable_sort(keyframes.begin(), keyframes.end(), Keyframe::compareOffset s); |
| 345 size_t targetIndex = 0; | 356 size_t targetIndex = 0; |
| 346 for (size_t i = 1; i < keyframes.size(); i++) { | 357 for (size_t i = 1; i < keyframes.size(); i++) { |
| 347 if (keyframes[i]->offset() != keyframes[targetIndex]->offset()) | 358 if (keyframes[i]->offset() != keyframes[targetIndex]->offset()) |
| 348 targetIndex++; | 359 targetIndex++; |
| 349 if (targetIndex != i) | 360 if (targetIndex != i) |
| 350 keyframes[targetIndex] = keyframes[i]; | 361 keyframes[targetIndex] = keyframes[i]; |
| 351 } | 362 } |
| 352 keyframes.shrink(targetIndex + 1); | 363 keyframes.shrink(targetIndex + 1); |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 585 runningTransition.from = newTransition.from; | 596 runningTransition.from = newTransition.from; |
| 586 runningTransition.to = newTransition.to; | 597 runningTransition.to = newTransition.to; |
| 587 | 598 |
| 588 CSSPropertyID id = newTransition.id; | 599 CSSPropertyID id = newTransition.id; |
| 589 InertAnimation* inertAnimation = newTransition.animation.get(); | 600 InertAnimation* inertAnimation = newTransition.animation.get(); |
| 590 OwnPtr<TransitionEventDelegate> eventDelegate = adoptPtr(new TransitionE ventDelegate(element, id)); | 601 OwnPtr<TransitionEventDelegate> eventDelegate = adoptPtr(new TransitionE ventDelegate(element, id)); |
| 591 RefPtr<Animation> transition = Animation::create(element, inertAnimation ->effect(), inertAnimation->specified(), Animation::TransitionPriority, eventDel egate.release()); | 602 RefPtr<Animation> transition = Animation::create(element, inertAnimation ->effect(), inertAnimation->specified(), Animation::TransitionPriority, eventDel egate.release()); |
| 592 element->document().transitionTimeline()->play(transition.get()); | 603 element->document().transitionTimeline()->play(transition.get()); |
| 593 runningTransition.transition = transition.get(); | 604 runningTransition.transition = transition.get(); |
| 594 m_transitions.set(id, runningTransition); | 605 m_transitions.set(id, runningTransition); |
| 606 ASSERT(id != CSSPropertyInvalid); | |
| 607 WebKit::Platform::current()->histogramSparse("WebCore.Animation.CSSPrope rties", UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(id)); | |
| 595 } | 608 } |
| 596 } | 609 } |
| 597 | 610 |
| 598 void CSSAnimations::calculateTransitionUpdateForProperty(CSSAnimationUpdate* upd ate, CSSPropertyID id, const CandidateTransition& newTransition, const Transitio nMap* existingTransitions) | 611 void CSSAnimations::calculateTransitionUpdateForProperty(CSSAnimationUpdate* upd ate, CSSPropertyID id, const CandidateTransition& newTransition, const Transitio nMap* existingTransitions) |
| 599 { | 612 { |
| 600 if (existingTransitions) { | 613 if (existingTransitions) { |
| 601 TransitionMap::const_iterator existingTransitionIter = existingTransitio ns->find(id); | 614 TransitionMap::const_iterator existingTransitionIter = existingTransitio ns->find(id); |
| 602 | 615 |
| 603 if (existingTransitionIter != existingTransitions->end() && !update->can celledTransitions().contains(id)) { | 616 if (existingTransitionIter != existingTransitions->end() && !update->can celledTransitions().contains(id)) { |
| 604 const AnimatableValue* existingTo = existingTransitionIter->value.to ; | 617 const AnimatableValue* existingTo = existingTransitionIter->value.to ; |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 919 CSSPropertyID id = convertToCSSPropertyID(i); | 932 CSSPropertyID id = convertToCSSPropertyID(i); |
| 920 if (isAnimatableProperty(id)) | 933 if (isAnimatableProperty(id)) |
| 921 properties.append(id); | 934 properties.append(id); |
| 922 } | 935 } |
| 923 propertyShorthand = StylePropertyShorthand(CSSPropertyInvalid, propertie s.begin(), properties.size()); | 936 propertyShorthand = StylePropertyShorthand(CSSPropertyInvalid, propertie s.begin(), properties.size()); |
| 924 } | 937 } |
| 925 return propertyShorthand; | 938 return propertyShorthand; |
| 926 } | 939 } |
| 927 | 940 |
| 928 } // namespace WebCore | 941 } // namespace WebCore |
| OLD | NEW |