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

Side by Side Diff: Source/core/animation/css/CSSAnimations.cpp

Issue 211233003: CSS Transforms: Implement perspective (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase and update interpolation tests. Created 6 years, 9 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
OLDNEW
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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 return target < reference; 65 return target < reference;
66 } 66 }
67 67
68 bool isLaterPhase(TimedItem::Phase target, TimedItem::Phase reference) 68 bool isLaterPhase(TimedItem::Phase target, TimedItem::Phase reference)
69 { 69 {
70 ASSERT(target != TimedItem::PhaseNone); 70 ASSERT(target != TimedItem::PhaseNone);
71 ASSERT(reference != TimedItem::PhaseNone); 71 ASSERT(reference != TimedItem::PhaseNone);
72 return target > reference; 72 return target > reference;
73 } 73 }
74 74
75 CSSPropertyID propertyForAnimation(CSSPropertyID property)
76 {
77 switch (property) {
eseidel 2014/03/27 23:13:22 Why the switch? I guess your'e going to add more?
dstockwell 2014/03/27 23:21:09 Yes.
78 case CSSPropertyWebkitPerspective:
79 return CSSPropertyPerspective;
80 default:
81 break;
82 }
83 return property;
84 }
85
75 static void resolveKeyframes(StyleResolver* resolver, Element* element, const El ement& parentElement, const RenderStyle& style, RenderStyle* parentStyle, const AtomicString& name, TimingFunction* defaultTimingFunction, 86 static void resolveKeyframes(StyleResolver* resolver, Element* element, const El ement& parentElement, const RenderStyle& style, RenderStyle* parentStyle, const AtomicString& name, TimingFunction* defaultTimingFunction,
76 WillBeHeapVector<KeyframeEffectModel::KeyframeVector>& resolvedKeyframes) 87 WillBeHeapVector<KeyframeEffectModel::KeyframeVector>& resolvedKeyframes)
77 { 88 {
78 // When the element is null, use its parent for scoping purposes. 89 // When the element is null, use its parent for scoping purposes.
79 const Element* elementForScoping = element ? element : &parentElement; 90 const Element* elementForScoping = element ? element : &parentElement;
80 const StyleRuleKeyframes* keyframesRule = CSSAnimations::matchScopedKeyframe sRule(resolver, elementForScoping, name.impl()); 91 const StyleRuleKeyframes* keyframesRule = CSSAnimations::matchScopedKeyframe sRule(resolver, elementForScoping, name.impl());
81 if (!keyframesRule) 92 if (!keyframesRule)
82 return; 93 return;
83 94
84 const Vector<RefPtr<StyleKeyframe> >& styleKeyframes = keyframesRule->keyfra mes(); 95 const Vector<RefPtr<StyleKeyframe> >& styleKeyframes = keyframesRule->keyfra mes();
85 if (styleKeyframes.isEmpty()) 96 if (styleKeyframes.isEmpty())
86 return; 97 return;
87 98
88 // Construct and populate the style for each keyframe 99 // Construct and populate the style for each keyframe
89 PropertySet specifiedProperties; 100 PropertySet specifiedPropertiesForUseCounter;
90 KeyframeEffectModel::KeyframeVector keyframes; 101 KeyframeEffectModel::KeyframeVector keyframes;
91 for (size_t i = 0; i < styleKeyframes.size(); ++i) { 102 for (size_t i = 0; i < styleKeyframes.size(); ++i) {
92 const StyleKeyframe* styleKeyframe = styleKeyframes[i].get(); 103 const StyleKeyframe* styleKeyframe = styleKeyframes[i].get();
93 // It's OK to pass a null element here. 104 // It's OK to pass a null element here.
94 RefPtr<RenderStyle> keyframeStyle = resolver->styleForKeyframe(element, style, parentStyle, styleKeyframe, name); 105 RefPtr<RenderStyle> keyframeStyle = resolver->styleForKeyframe(element, style, parentStyle, styleKeyframe, name);
95 RefPtrWillBeRawPtr<Keyframe> keyframe = Keyframe::create(); 106 RefPtrWillBeRawPtr<Keyframe> keyframe = Keyframe::create();
96 const Vector<double>& offsets = styleKeyframe->keys(); 107 const Vector<double>& offsets = styleKeyframe->keys();
97 ASSERT(!offsets.isEmpty()); 108 ASSERT(!offsets.isEmpty());
98 keyframe->setOffset(offsets[0]); 109 keyframe->setOffset(offsets[0]);
99 keyframe->setEasing(defaultTimingFunction); 110 keyframe->setEasing(defaultTimingFunction);
100 const StylePropertySet& properties = styleKeyframe->properties(); 111 const StylePropertySet& properties = styleKeyframe->properties();
101 for (unsigned j = 0; j < properties.propertyCount(); j++) { 112 for (unsigned j = 0; j < properties.propertyCount(); j++) {
102 CSSPropertyID property = properties.propertyAt(j).id(); 113 specifiedPropertiesForUseCounter.add(properties.propertyAt(j).id());
103 specifiedProperties.add(property); 114 CSSPropertyID property = propertyForAnimation(properties.propertyAt( j).id());
104 if (property == CSSPropertyWebkitAnimationTimingFunction || property == CSSPropertyAnimationTimingFunction) 115 if (property == CSSPropertyWebkitAnimationTimingFunction || property == CSSPropertyAnimationTimingFunction) {
105 keyframe->setEasing(KeyframeValue::timingFunction(*keyframeStyle )); 116 keyframe->setEasing(KeyframeValue::timingFunction(*keyframeStyle ));
106 else if (CSSAnimations::isAnimatableProperty(property)) 117 } else if (CSSAnimations::isAnimatableProperty(property)) {
107 keyframe->setPropertyValue(property, CSSAnimatableValueFactory:: create(property, *keyframeStyle).get()); 118 keyframe->setPropertyValue(property, CSSAnimatableValueFactory:: create(property, *keyframeStyle).get());
119 }
108 } 120 }
109 keyframes.append(keyframe); 121 keyframes.append(keyframe);
110 // The last keyframe specified at a given offset is used. 122 // The last keyframe specified at a given offset is used.
111 for (size_t j = 1; j < offsets.size(); ++j) { 123 for (size_t j = 1; j < offsets.size(); ++j) {
112 keyframes.append(keyframe->cloneWithOffset(offsets[j])); 124 keyframes.append(keyframe->cloneWithOffset(offsets[j]));
113 } 125 }
114 } 126 }
115 ASSERT(!keyframes.isEmpty()); 127 ASSERT(!keyframes.isEmpty());
116 128
117 for (PropertySet::const_iterator iter = specifiedProperties.begin(); iter != specifiedProperties.end(); ++iter) { 129 for (PropertySet::const_iterator iter = specifiedPropertiesForUseCounter.beg in(); iter != specifiedPropertiesForUseCounter.end(); ++iter) {
118 const CSSPropertyID property = *iter; 130 const CSSPropertyID property = *iter;
119 ASSERT(property != CSSPropertyInvalid); 131 ASSERT(property != CSSPropertyInvalid);
120 blink::Platform::current()->histogramSparse("WebCore.Animation.CSSProper ties", UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(property)); 132 blink::Platform::current()->histogramSparse("WebCore.Animation.CSSProper ties", UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(property));
121 } 133 }
122 134
123 // Remove duplicate keyframes. In CSS the last keyframe at a given offset ta kes priority. 135 // Remove duplicate keyframes. In CSS the last keyframe at a given offset ta kes priority.
124 std::stable_sort(keyframes.begin(), keyframes.end(), Keyframe::compareOffset s); 136 std::stable_sort(keyframes.begin(), keyframes.end(), Keyframe::compareOffset s);
125 size_t targetIndex = 0; 137 size_t targetIndex = 0;
126 for (size_t i = 1; i < keyframes.size(); i++) { 138 for (size_t i = 1; i < keyframes.size(); i++) {
127 if (keyframes[i]->offset() != keyframes[targetIndex]->offset()) 139 if (keyframes[i]->offset() != keyframes[targetIndex]->offset())
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 488
477 for (CSSAnimationUpdate::NewTransitionMap::const_iterator iter = update->new Transitions().begin(); iter != update->newTransitions().end(); ++iter) { 489 for (CSSAnimationUpdate::NewTransitionMap::const_iterator iter = update->new Transitions().begin(); iter != update->newTransitions().end(); ++iter) {
478 const CSSAnimationUpdate::NewTransition& newTransition = iter->value; 490 const CSSAnimationUpdate::NewTransition& newTransition = iter->value;
479 491
480 RunningTransition runningTransition; 492 RunningTransition runningTransition;
481 runningTransition.from = newTransition.from; 493 runningTransition.from = newTransition.from;
482 runningTransition.to = newTransition.to; 494 runningTransition.to = newTransition.to;
483 495
484 CSSPropertyID id = newTransition.id; 496 CSSPropertyID id = newTransition.id;
485 InertAnimation* inertAnimation = newTransition.animation.get(); 497 InertAnimation* inertAnimation = newTransition.animation.get();
486 OwnPtr<TransitionEventDelegate> eventDelegate = adoptPtr(new TransitionE ventDelegate(element, id)); 498 OwnPtr<TransitionEventDelegate> eventDelegate = adoptPtr(new TransitionE ventDelegate(element, newTransition.eventId));
487 499
488 RefPtrWillBeRawPtr<AnimationEffect> effect = inertAnimation->effect(); 500 RefPtrWillBeRawPtr<AnimationEffect> effect = inertAnimation->effect();
489 501
490 if (retargetedCompositorTransitions.contains(id)) { 502 if (retargetedCompositorTransitions.contains(id)) {
491 const std::pair<RefPtr<Animation>, double>& oldTransition = retarget edCompositorTransitions.get(id); 503 const std::pair<RefPtr<Animation>, double>& oldTransition = retarget edCompositorTransitions.get(id);
492 RefPtr<Animation> oldAnimation = oldTransition.first; 504 RefPtr<Animation> oldAnimation = oldTransition.first;
493 double oldStartTime = oldTransition.second; 505 double oldStartTime = oldTransition.second;
494 double inheritedTime = isNull(oldStartTime) ? 0 : element->document( ).transitionTimeline().currentTime() - oldStartTime; 506 double inheritedTime = isNull(oldStartTime) ? 0 : element->document( ).transitionTimeline().currentTime() - oldStartTime;
495 oldAnimation->updateInheritedTime(inheritedTime); 507 oldAnimation->updateInheritedTime(inheritedTime);
496 KeyframeEffectModel* oldEffect = toKeyframeEffectModel(inertAnimatio n->effect()); 508 KeyframeEffectModel* oldEffect = toKeyframeEffectModel(inertAnimatio n->effect());
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 startKeyframe->setEasing(timingFunction); 571 startKeyframe->setEasing(timingFunction);
560 keyframes.append(startKeyframe); 572 keyframes.append(startKeyframe);
561 573
562 RefPtrWillBeRawPtr<Keyframe> endKeyframe = Keyframe::create(); 574 RefPtrWillBeRawPtr<Keyframe> endKeyframe = Keyframe::create();
563 endKeyframe->setPropertyValue(id, to.get()); 575 endKeyframe->setPropertyValue(id, to.get());
564 endKeyframe->setOffset(1); 576 endKeyframe->setOffset(1);
565 keyframes.append(endKeyframe); 577 keyframes.append(endKeyframe);
566 578
567 RefPtrWillBeRawPtr<KeyframeEffectModel> effect = KeyframeEffectModel::create (keyframes); 579 RefPtrWillBeRawPtr<KeyframeEffectModel> effect = KeyframeEffectModel::create (keyframes);
568 580
569 update->startTransition(id, from.get(), to.get(), InertAnimation::create(eff ect, timing, isPaused)); 581 CSSPropertyID eventId = anim->animationMode() == CSSAnimationData::AnimateAl l ? id : anim->property();
582 update->startTransition(id, eventId, from.get(), to.get(), InertAnimation::c reate(effect, timing, isPaused));
570 ASSERT(!element->activeAnimations() || !element->activeAnimations()->isAnima tionStyleChange()); 583 ASSERT(!element->activeAnimations() || !element->activeAnimations()->isAnima tionStyleChange());
571 } 584 }
572 585
573 void CSSAnimations::calculateTransitionUpdate(CSSAnimationUpdate* update, const Element* element, const RenderStyle& style) 586 void CSSAnimations::calculateTransitionUpdate(CSSAnimationUpdate* update, const Element* element, const RenderStyle& style)
574 { 587 {
575 if (!element) 588 if (!element)
576 return; 589 return;
577 590
578 ActiveAnimations* activeAnimations = element->activeAnimations(); 591 ActiveAnimations* activeAnimations = element->activeAnimations();
579 const TransitionMap* activeTransitions = activeAnimations ? &activeAnimation s->cssAnimations().m_transitions : 0; 592 const TransitionMap* activeTransitions = activeAnimations ? &activeAnimation s->cssAnimations().m_transitions : 0;
(...skipping 21 matching lines...) Expand all
601 bool animateAll = mode == CSSAnimationData::AnimateAll; 614 bool animateAll = mode == CSSAnimationData::AnimateAll;
602 ASSERT(animateAll || mode == CSSAnimationData::AnimateSingleProperty ); 615 ASSERT(animateAll || mode == CSSAnimationData::AnimateSingleProperty );
603 if (animateAll) 616 if (animateAll)
604 anyTransitionHadAnimateAll = true; 617 anyTransitionHadAnimateAll = true;
605 const StylePropertyShorthand& propertyList = animateAll ? CSSAnimati ons::animatableProperties() : shorthandForProperty(anim->property()); 618 const StylePropertyShorthand& propertyList = animateAll ? CSSAnimati ons::animatableProperties() : shorthandForProperty(anim->property());
606 // If not a shorthand we only execute one iteration of this loop, an d refer to the property directly. 619 // If not a shorthand we only execute one iteration of this loop, an d refer to the property directly.
607 for (unsigned j = 0; !j || j < propertyList.length(); ++j) { 620 for (unsigned j = 0; !j || j < propertyList.length(); ++j) {
608 CSSPropertyID id = propertyList.length() ? propertyList.properti es()[j] : anim->property(); 621 CSSPropertyID id = propertyList.length() ? propertyList.properti es()[j] : anim->property();
609 622
610 if (!animateAll) { 623 if (!animateAll) {
624 id = propertyForAnimation(id);
611 if (CSSAnimations::isAnimatableProperty(id)) 625 if (CSSAnimations::isAnimatableProperty(id))
612 listedProperties.set(id); 626 listedProperties.set(id);
613 else 627 else
614 continue; 628 continue;
615 } 629 }
616 630
617 // FIXME: We should transition if an !important property changes even when an animation is running, 631 // FIXME: We should transition if an !important property changes even when an animation is running,
618 // but this is a bit hard to do with the current applyMatchedPro perties system. 632 // but this is a bit hard to do with the current applyMatchedPro perties system.
619 if (!update->activeInterpolationsForAnimations().contains(id) 633 if (!update->activeInterpolationsForAnimations().contains(id)
620 && (!activeAnimations || !activeAnimations->cssAnimations(). m_previousActiveInterpolationsForAnimations.contains(id))) { 634 && (!activeAnimations || !activeAnimations->cssAnimations(). m_previousActiveInterpolationsForAnimations.contains(id))) {
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 case CSSPropertyWebkitColumnWidth: 864 case CSSPropertyWebkitColumnWidth:
851 case CSSPropertyWebkitFilter: 865 case CSSPropertyWebkitFilter:
852 case CSSPropertyWebkitMaskBoxImageOutset: 866 case CSSPropertyWebkitMaskBoxImageOutset:
853 case CSSPropertyWebkitMaskBoxImageSlice: 867 case CSSPropertyWebkitMaskBoxImageSlice:
854 case CSSPropertyWebkitMaskBoxImageSource: 868 case CSSPropertyWebkitMaskBoxImageSource:
855 case CSSPropertyWebkitMaskBoxImageWidth: 869 case CSSPropertyWebkitMaskBoxImageWidth:
856 case CSSPropertyWebkitMaskImage: 870 case CSSPropertyWebkitMaskImage:
857 case CSSPropertyWebkitMaskPositionX: 871 case CSSPropertyWebkitMaskPositionX:
858 case CSSPropertyWebkitMaskPositionY: 872 case CSSPropertyWebkitMaskPositionY:
859 case CSSPropertyWebkitMaskSize: 873 case CSSPropertyWebkitMaskSize:
860 case CSSPropertyWebkitPerspective: 874 case CSSPropertyPerspective:
861 case CSSPropertyWebkitPerspectiveOriginX: 875 case CSSPropertyWebkitPerspectiveOriginX:
862 case CSSPropertyWebkitPerspectiveOriginY: 876 case CSSPropertyWebkitPerspectiveOriginY:
863 case CSSPropertyShapeInside: 877 case CSSPropertyShapeInside:
864 case CSSPropertyShapeOutside: 878 case CSSPropertyShapeOutside:
865 case CSSPropertyShapeMargin: 879 case CSSPropertyShapeMargin:
866 case CSSPropertyShapeImageThreshold: 880 case CSSPropertyShapeImageThreshold:
867 case CSSPropertyWebkitTextStrokeColor: 881 case CSSPropertyWebkitTextStrokeColor:
868 case CSSPropertyWebkitTransform: 882 case CSSPropertyWebkitTransform:
869 case CSSPropertyWebkitTransformOriginX: 883 case CSSPropertyWebkitTransformOriginX:
870 case CSSPropertyWebkitTransformOriginY: 884 case CSSPropertyWebkitTransformOriginY:
(...skipping 18 matching lines...) Expand all
889 CSSPropertyID id = convertToCSSPropertyID(i); 903 CSSPropertyID id = convertToCSSPropertyID(i);
890 if (isAnimatableProperty(id)) 904 if (isAnimatableProperty(id))
891 properties.append(id); 905 properties.append(id);
892 } 906 }
893 propertyShorthand = StylePropertyShorthand(CSSPropertyInvalid, propertie s.begin(), properties.size()); 907 propertyShorthand = StylePropertyShorthand(CSSPropertyInvalid, propertie s.begin(), properties.size());
894 } 908 }
895 return propertyShorthand; 909 return propertyShorthand;
896 } 910 }
897 911
898 } // namespace WebCore 912 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/animation/css/CSSAnimations.h ('k') | Source/core/animation/css/CSSPropertyEquality.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698