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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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) { |
| 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 KeyframeEffectModel::KeyframeVector& keyframes) | 87 KeyframeEffectModel::KeyframeVector& keyframes) |
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 WillBeHeapVector<RefPtrWillBeMember<StyleKeyframe> >& styleKeyframes =
keyframesRule->keyframes(); | 95 const WillBeHeapVector<RefPtrWillBeMember<StyleKeyframe> >& styleKeyframes =
keyframesRule->keyframes(); |
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 for (size_t i = 0; i < styleKeyframes.size(); ++i) { | 101 for (size_t i = 0; i < styleKeyframes.size(); ++i) { |
91 const StyleKeyframe* styleKeyframe = styleKeyframes[i].get(); | 102 const StyleKeyframe* styleKeyframe = styleKeyframes[i].get(); |
92 // It's OK to pass a null element here. | 103 // It's OK to pass a null element here. |
93 RefPtr<RenderStyle> keyframeStyle = resolver->styleForKeyframe(element,
style, parentStyle, styleKeyframe, name); | 104 RefPtr<RenderStyle> keyframeStyle = resolver->styleForKeyframe(element,
style, parentStyle, styleKeyframe, name); |
94 RefPtrWillBeRawPtr<Keyframe> keyframe = Keyframe::create(); | 105 RefPtrWillBeRawPtr<Keyframe> keyframe = Keyframe::create(); |
95 const Vector<double>& offsets = styleKeyframe->keys(); | 106 const Vector<double>& offsets = styleKeyframe->keys(); |
96 ASSERT(!offsets.isEmpty()); | 107 ASSERT(!offsets.isEmpty()); |
97 keyframe->setOffset(offsets[0]); | 108 keyframe->setOffset(offsets[0]); |
98 keyframe->setEasing(defaultTimingFunction); | 109 keyframe->setEasing(defaultTimingFunction); |
99 const StylePropertySet& properties = styleKeyframe->properties(); | 110 const StylePropertySet& properties = styleKeyframe->properties(); |
100 for (unsigned j = 0; j < properties.propertyCount(); j++) { | 111 for (unsigned j = 0; j < properties.propertyCount(); j++) { |
101 CSSPropertyID property = properties.propertyAt(j).id(); | 112 specifiedPropertiesForUseCounter.add(properties.propertyAt(j).id()); |
102 specifiedProperties.add(property); | 113 CSSPropertyID property = propertyForAnimation(properties.propertyAt(
j).id()); |
103 if (property == CSSPropertyWebkitAnimationTimingFunction || property
== CSSPropertyAnimationTimingFunction) | 114 if (property == CSSPropertyWebkitAnimationTimingFunction || property
== CSSPropertyAnimationTimingFunction) { |
104 keyframe->setEasing(KeyframeValue::timingFunction(*keyframeStyle
)); | 115 keyframe->setEasing(KeyframeValue::timingFunction(*keyframeStyle
)); |
105 else if (CSSAnimations::isAnimatableProperty(property)) | 116 } else if (CSSAnimations::isAnimatableProperty(property)) { |
106 keyframe->setPropertyValue(property, CSSAnimatableValueFactory::
create(property, *keyframeStyle).get()); | 117 keyframe->setPropertyValue(property, CSSAnimatableValueFactory::
create(property, *keyframeStyle).get()); |
| 118 } |
107 } | 119 } |
108 keyframes.append(keyframe); | 120 keyframes.append(keyframe); |
109 // The last keyframe specified at a given offset is used. | 121 // The last keyframe specified at a given offset is used. |
110 for (size_t j = 1; j < offsets.size(); ++j) { | 122 for (size_t j = 1; j < offsets.size(); ++j) { |
111 keyframes.append(keyframe->cloneWithOffset(offsets[j])); | 123 keyframes.append(keyframe->cloneWithOffset(offsets[j])); |
112 } | 124 } |
113 } | 125 } |
114 ASSERT(!keyframes.isEmpty()); | 126 ASSERT(!keyframes.isEmpty()); |
115 | 127 |
116 for (PropertySet::const_iterator iter = specifiedProperties.begin(); iter !=
specifiedProperties.end(); ++iter) { | 128 for (PropertySet::const_iterator iter = specifiedPropertiesForUseCounter.beg
in(); iter != specifiedPropertiesForUseCounter.end(); ++iter) { |
117 const CSSPropertyID property = *iter; | 129 const CSSPropertyID property = *iter; |
118 ASSERT(property != CSSPropertyInvalid); | 130 ASSERT(property != CSSPropertyInvalid); |
119 blink::Platform::current()->histogramSparse("WebCore.Animation.CSSProper
ties", UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(property)); | 131 blink::Platform::current()->histogramSparse("WebCore.Animation.CSSProper
ties", UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(property)); |
120 } | 132 } |
121 | 133 |
122 // Remove duplicate keyframes. In CSS the last keyframe at a given offset ta
kes priority. | 134 // Remove duplicate keyframes. In CSS the last keyframe at a given offset ta
kes priority. |
123 std::stable_sort(keyframes.begin(), keyframes.end(), Keyframe::compareOffset
s); | 135 std::stable_sort(keyframes.begin(), keyframes.end(), Keyframe::compareOffset
s); |
124 size_t targetIndex = 0; | 136 size_t targetIndex = 0; |
125 for (size_t i = 1; i < keyframes.size(); i++) { | 137 for (size_t i = 1; i < keyframes.size(); i++) { |
126 if (keyframes[i]->offset() != keyframes[targetIndex]->offset()) | 138 if (keyframes[i]->offset() != keyframes[targetIndex]->offset()) |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 | 402 |
391 for (CSSAnimationUpdate::NewTransitionMap::const_iterator iter = update->new
Transitions().begin(); iter != update->newTransitions().end(); ++iter) { | 403 for (CSSAnimationUpdate::NewTransitionMap::const_iterator iter = update->new
Transitions().begin(); iter != update->newTransitions().end(); ++iter) { |
392 const CSSAnimationUpdate::NewTransition& newTransition = iter->value; | 404 const CSSAnimationUpdate::NewTransition& newTransition = iter->value; |
393 | 405 |
394 RunningTransition runningTransition; | 406 RunningTransition runningTransition; |
395 runningTransition.from = newTransition.from; | 407 runningTransition.from = newTransition.from; |
396 runningTransition.to = newTransition.to; | 408 runningTransition.to = newTransition.to; |
397 | 409 |
398 CSSPropertyID id = newTransition.id; | 410 CSSPropertyID id = newTransition.id; |
399 InertAnimation* inertAnimation = newTransition.animation.get(); | 411 InertAnimation* inertAnimation = newTransition.animation.get(); |
400 OwnPtr<TransitionEventDelegate> eventDelegate = adoptPtr(new TransitionE
ventDelegate(element, id)); | 412 OwnPtr<TransitionEventDelegate> eventDelegate = adoptPtr(new TransitionE
ventDelegate(element, newTransition.eventId)); |
401 | 413 |
402 RefPtrWillBeRawPtr<AnimationEffect> effect = inertAnimation->effect(); | 414 RefPtrWillBeRawPtr<AnimationEffect> effect = inertAnimation->effect(); |
403 | 415 |
404 if (retargetedCompositorTransitions.contains(id)) { | 416 if (retargetedCompositorTransitions.contains(id)) { |
405 const std::pair<RefPtr<Animation>, double>& oldTransition = retarget
edCompositorTransitions.get(id); | 417 const std::pair<RefPtr<Animation>, double>& oldTransition = retarget
edCompositorTransitions.get(id); |
406 RefPtr<Animation> oldAnimation = oldTransition.first; | 418 RefPtr<Animation> oldAnimation = oldTransition.first; |
407 double oldStartTime = oldTransition.second; | 419 double oldStartTime = oldTransition.second; |
408 double inheritedTime = isNull(oldStartTime) ? 0 : element->document(
).transitionTimeline().currentTime() - oldStartTime; | 420 double inheritedTime = isNull(oldStartTime) ? 0 : element->document(
).transitionTimeline().currentTime() - oldStartTime; |
409 oldAnimation->updateInheritedTime(inheritedTime); | 421 oldAnimation->updateInheritedTime(inheritedTime); |
410 KeyframeEffectModel* oldEffect = toKeyframeEffectModel(inertAnimatio
n->effect()); | 422 KeyframeEffectModel* oldEffect = toKeyframeEffectModel(inertAnimatio
n->effect()); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 startKeyframe->setEasing(timingFunction); | 485 startKeyframe->setEasing(timingFunction); |
474 keyframes.append(startKeyframe); | 486 keyframes.append(startKeyframe); |
475 | 487 |
476 RefPtrWillBeRawPtr<Keyframe> endKeyframe = Keyframe::create(); | 488 RefPtrWillBeRawPtr<Keyframe> endKeyframe = Keyframe::create(); |
477 endKeyframe->setPropertyValue(id, to.get()); | 489 endKeyframe->setPropertyValue(id, to.get()); |
478 endKeyframe->setOffset(1); | 490 endKeyframe->setOffset(1); |
479 keyframes.append(endKeyframe); | 491 keyframes.append(endKeyframe); |
480 | 492 |
481 RefPtrWillBeRawPtr<KeyframeEffectModel> effect = KeyframeEffectModel::create
(keyframes); | 493 RefPtrWillBeRawPtr<KeyframeEffectModel> effect = KeyframeEffectModel::create
(keyframes); |
482 | 494 |
483 update->startTransition(id, from.get(), to.get(), InertAnimation::create(eff
ect, timing, isPaused)); | 495 CSSPropertyID eventId = anim->animationMode() == CSSAnimationData::AnimateAl
l ? id : anim->property(); |
| 496 update->startTransition(id, eventId, from.get(), to.get(), InertAnimation::c
reate(effect, timing, isPaused)); |
484 ASSERT(!element->activeAnimations() || !element->activeAnimations()->isAnima
tionStyleChange()); | 497 ASSERT(!element->activeAnimations() || !element->activeAnimations()->isAnima
tionStyleChange()); |
485 } | 498 } |
486 | 499 |
487 void CSSAnimations::calculateTransitionUpdate(CSSAnimationUpdate* update, const
Element* element, const RenderStyle& style) | 500 void CSSAnimations::calculateTransitionUpdate(CSSAnimationUpdate* update, const
Element* element, const RenderStyle& style) |
488 { | 501 { |
489 if (!element) | 502 if (!element) |
490 return; | 503 return; |
491 | 504 |
492 ActiveAnimations* activeAnimations = element->activeAnimations(); | 505 ActiveAnimations* activeAnimations = element->activeAnimations(); |
493 const TransitionMap* activeTransitions = activeAnimations ? &activeAnimation
s->cssAnimations().m_transitions : 0; | 506 const TransitionMap* activeTransitions = activeAnimations ? &activeAnimation
s->cssAnimations().m_transitions : 0; |
(...skipping 21 matching lines...) Expand all Loading... |
515 bool animateAll = mode == CSSAnimationData::AnimateAll; | 528 bool animateAll = mode == CSSAnimationData::AnimateAll; |
516 ASSERT(animateAll || mode == CSSAnimationData::AnimateSingleProperty
); | 529 ASSERT(animateAll || mode == CSSAnimationData::AnimateSingleProperty
); |
517 if (animateAll) | 530 if (animateAll) |
518 anyTransitionHadAnimateAll = true; | 531 anyTransitionHadAnimateAll = true; |
519 const StylePropertyShorthand& propertyList = animateAll ? CSSAnimati
ons::animatableProperties() : shorthandForProperty(anim->property()); | 532 const StylePropertyShorthand& propertyList = animateAll ? CSSAnimati
ons::animatableProperties() : shorthandForProperty(anim->property()); |
520 // If not a shorthand we only execute one iteration of this loop, an
d refer to the property directly. | 533 // If not a shorthand we only execute one iteration of this loop, an
d refer to the property directly. |
521 for (unsigned j = 0; !j || j < propertyList.length(); ++j) { | 534 for (unsigned j = 0; !j || j < propertyList.length(); ++j) { |
522 CSSPropertyID id = propertyList.length() ? propertyList.properti
es()[j] : anim->property(); | 535 CSSPropertyID id = propertyList.length() ? propertyList.properti
es()[j] : anim->property(); |
523 | 536 |
524 if (!animateAll) { | 537 if (!animateAll) { |
| 538 id = propertyForAnimation(id); |
525 if (CSSAnimations::isAnimatableProperty(id)) | 539 if (CSSAnimations::isAnimatableProperty(id)) |
526 listedProperties.set(id); | 540 listedProperties.set(id); |
527 else | 541 else |
528 continue; | 542 continue; |
529 } | 543 } |
530 | 544 |
531 // FIXME: We should transition if an !important property changes
even when an animation is running, | 545 // FIXME: We should transition if an !important property changes
even when an animation is running, |
532 // but this is a bit hard to do with the current applyMatchedPro
perties system. | 546 // but this is a bit hard to do with the current applyMatchedPro
perties system. |
533 if (!update->activeInterpolationsForAnimations().contains(id) | 547 if (!update->activeInterpolationsForAnimations().contains(id) |
534 && (!activeAnimations || !activeAnimations->cssAnimations().
m_previousActiveInterpolationsForAnimations.contains(id))) { | 548 && (!activeAnimations || !activeAnimations->cssAnimations().
m_previousActiveInterpolationsForAnimations.contains(id))) { |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
759 case CSSPropertyWebkitColumnWidth: | 773 case CSSPropertyWebkitColumnWidth: |
760 case CSSPropertyWebkitFilter: | 774 case CSSPropertyWebkitFilter: |
761 case CSSPropertyWebkitMaskBoxImageOutset: | 775 case CSSPropertyWebkitMaskBoxImageOutset: |
762 case CSSPropertyWebkitMaskBoxImageSlice: | 776 case CSSPropertyWebkitMaskBoxImageSlice: |
763 case CSSPropertyWebkitMaskBoxImageSource: | 777 case CSSPropertyWebkitMaskBoxImageSource: |
764 case CSSPropertyWebkitMaskBoxImageWidth: | 778 case CSSPropertyWebkitMaskBoxImageWidth: |
765 case CSSPropertyWebkitMaskImage: | 779 case CSSPropertyWebkitMaskImage: |
766 case CSSPropertyWebkitMaskPositionX: | 780 case CSSPropertyWebkitMaskPositionX: |
767 case CSSPropertyWebkitMaskPositionY: | 781 case CSSPropertyWebkitMaskPositionY: |
768 case CSSPropertyWebkitMaskSize: | 782 case CSSPropertyWebkitMaskSize: |
769 case CSSPropertyWebkitPerspective: | 783 case CSSPropertyPerspective: |
770 case CSSPropertyWebkitPerspectiveOriginX: | 784 case CSSPropertyWebkitPerspectiveOriginX: |
771 case CSSPropertyWebkitPerspectiveOriginY: | 785 case CSSPropertyWebkitPerspectiveOriginY: |
772 case CSSPropertyShapeOutside: | 786 case CSSPropertyShapeOutside: |
773 case CSSPropertyShapeMargin: | 787 case CSSPropertyShapeMargin: |
774 case CSSPropertyShapeImageThreshold: | 788 case CSSPropertyShapeImageThreshold: |
775 case CSSPropertyWebkitTextStrokeColor: | 789 case CSSPropertyWebkitTextStrokeColor: |
776 case CSSPropertyWebkitTransform: | 790 case CSSPropertyWebkitTransform: |
777 case CSSPropertyWebkitTransformOriginX: | 791 case CSSPropertyWebkitTransformOriginX: |
778 case CSSPropertyWebkitTransformOriginY: | 792 case CSSPropertyWebkitTransformOriginY: |
779 case CSSPropertyWebkitTransformOriginZ: | 793 case CSSPropertyWebkitTransformOriginZ: |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
811 } | 825 } |
812 | 826 |
813 void CSSAnimationUpdate::trace(Visitor* visitor) | 827 void CSSAnimationUpdate::trace(Visitor* visitor) |
814 { | 828 { |
815 visitor->trace(m_newTransitions); | 829 visitor->trace(m_newTransitions); |
816 visitor->trace(m_activeInterpolationsForAnimations); | 830 visitor->trace(m_activeInterpolationsForAnimations); |
817 visitor->trace(m_activeInterpolationsForTransitions); | 831 visitor->trace(m_activeInterpolationsForTransitions); |
818 } | 832 } |
819 | 833 |
820 } // namespace WebCore | 834 } // namespace WebCore |
OLD | NEW |