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 19 matching lines...) Expand all Loading... |
30 | 30 |
31 #include "core/animation/css/CSSAnimations.h" | 31 #include "core/animation/css/CSSAnimations.h" |
32 | 32 |
33 #include "core/StylePropertyShorthand.h" | 33 #include "core/StylePropertyShorthand.h" |
34 #include "core/animation/Animation.h" | 34 #include "core/animation/Animation.h" |
35 #include "core/animation/AnimationTimeline.h" | 35 #include "core/animation/AnimationTimeline.h" |
36 #include "core/animation/CompositorAnimations.h" | 36 #include "core/animation/CompositorAnimations.h" |
37 #include "core/animation/ElementAnimations.h" | 37 #include "core/animation/ElementAnimations.h" |
38 #include "core/animation/InertEffect.h" | 38 #include "core/animation/InertEffect.h" |
39 #include "core/animation/Interpolation.h" | 39 #include "core/animation/Interpolation.h" |
| 40 #include "core/animation/InterpolationEnvironment.h" |
| 41 #include "core/animation/InterpolationType.h" |
40 #include "core/animation/KeyframeEffectModel.h" | 42 #include "core/animation/KeyframeEffectModel.h" |
41 #include "core/animation/LegacyStyleInterpolation.h" | 43 #include "core/animation/LegacyStyleInterpolation.h" |
| 44 #include "core/animation/PairwiseInterpolationValue.h" |
| 45 #include "core/animation/PrimitiveInterpolation.h" |
| 46 #include "core/animation/PropertyInterpolationTypesMapping.h" |
| 47 #include "core/animation/TransitionEffectModel.h" |
42 #include "core/animation/css/CSSAnimatableValueFactory.h" | 48 #include "core/animation/css/CSSAnimatableValueFactory.h" |
43 #include "core/css/CSSKeyframeRule.h" | 49 #include "core/css/CSSKeyframeRule.h" |
44 #include "core/css/CSSPropertyEquality.h" | 50 #include "core/css/CSSPropertyEquality.h" |
45 #include "core/css/CSSPropertyMetadata.h" | 51 #include "core/css/CSSPropertyMetadata.h" |
46 #include "core/css/CSSValueList.h" | 52 #include "core/css/CSSValueList.h" |
47 #include "core/css/resolver/CSSToStyleMap.h" | 53 #include "core/css/resolver/CSSToStyleMap.h" |
48 #include "core/css/resolver/StyleResolver.h" | 54 #include "core/css/resolver/StyleResolver.h" |
49 #include "core/dom/Element.h" | 55 #include "core/dom/Element.h" |
50 #include "core/dom/PseudoElement.h" | 56 #include "core/dom/PseudoElement.h" |
51 #include "core/dom/StyleEngine.h" | 57 #include "core/dom/StyleEngine.h" |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 clearPendingUpdate(); | 536 clearPendingUpdate(); |
531 } | 537 } |
532 | 538 |
533 void CSSAnimations::calculateTransitionUpdateForProperty(CSSPropertyID id, const
CSSTransitionData& transitionData, size_t transitionIndex, const ComputedStyle&
oldStyle, const ComputedStyle& style, const TransitionMap* activeTransitions, C
SSAnimationUpdate& update, const Element* element) | 539 void CSSAnimations::calculateTransitionUpdateForProperty(CSSPropertyID id, const
CSSTransitionData& transitionData, size_t transitionIndex, const ComputedStyle&
oldStyle, const ComputedStyle& style, const TransitionMap* activeTransitions, C
SSAnimationUpdate& update, const Element* element) |
534 { | 540 { |
535 RefPtr<AnimatableValue> to = nullptr; | 541 RefPtr<AnimatableValue> to = nullptr; |
536 const RunningTransition* interruptedTransition = nullptr; | 542 const RunningTransition* interruptedTransition = nullptr; |
537 if (activeTransitions) { | 543 if (activeTransitions) { |
538 TransitionMap::const_iterator activeTransitionIter = activeTransitions->
find(id); | 544 TransitionMap::const_iterator activeTransitionIter = activeTransitions->
find(id); |
539 if (activeTransitionIter != activeTransitions->end()) { | 545 if (activeTransitionIter != activeTransitions->end()) { |
540 const RunningTransition* runningTransition = &activeTransitionIter->
value; | 546 const RunningTransition& runningTransition = activeTransitionIter->v
alue; |
541 to = CSSAnimatableValueFactory::create(id, style); | 547 to = CSSAnimatableValueFactory::create(id, style); |
542 const AnimatableValue* activeTo = runningTransition->to; | 548 if (to->equals(runningTransition.to.get())) |
543 if (to->equals(activeTo)) | |
544 return; | 549 return; |
545 update.cancelTransition(id); | 550 update.cancelTransition(id); |
546 ASSERT(!element->elementAnimations() || !element->elementAnimations(
)->isAnimationStyleChange()); | 551 ASSERT(!element->elementAnimations() || !element->elementAnimations(
)->isAnimationStyleChange()); |
547 | 552 |
548 if (to->equals(runningTransition->reversingAdjustedStartValue.get())
) | 553 if (to->equals(runningTransition.reversingAdjustedStartValue.get())) |
549 interruptedTransition = runningTransition; | 554 interruptedTransition = &runningTransition; |
550 } | 555 } |
551 } | 556 } |
552 | 557 |
553 if (CSSPropertyEquality::propertiesEqual(id, oldStyle, style)) | 558 if (CSSPropertyEquality::propertiesEqual(id, oldStyle, style)) |
554 return; | 559 return; |
| 560 |
| 561 RefPtr<PairwiseInterpolation> pairwiseInterpolation; |
| 562 InterpolationEnvironment oldEnvironment(oldStyle); |
| 563 InterpolationEnvironment newEnvironment(style); |
| 564 for (const std::unique_ptr<const InterpolationType>& interpolationType : Pro
pertyInterpolationTypesMapping::get(PropertyHandle(id))) { |
| 565 InterpolationValue start = interpolationType->maybeConvertUnderlyingValu
e(oldEnvironment); |
| 566 if (!start) |
| 567 continue; |
| 568 InterpolationValue end = interpolationType->maybeConvertUnderlyingValue(
newEnvironment); |
| 569 if (!end) |
| 570 continue; |
| 571 if ((pairwiseInterpolation = PairwiseInterpolation::maybeCreate(*interpo
lationType, std::move(start), std::move(end)))) |
| 572 break; |
| 573 } |
| 574 |
| 575 // No smooth interpolation exists between these values so don't start a tran
sition. |
| 576 if (!pairwiseInterpolation) |
| 577 return; |
| 578 |
555 if (!to) | 579 if (!to) |
556 to = CSSAnimatableValueFactory::create(id, style); | 580 to = CSSAnimatableValueFactory::create(id, style); |
| 581 RefPtr<AnimatableValue> from = CSSAnimatableValueFactory::create(id, oldStyl
e); |
557 | 582 |
558 RefPtr<AnimatableValue> from = CSSAnimatableValueFactory::create(id, oldStyl
e); | |
559 // If we have multiple transitions on the same property, we will use the | 583 // If we have multiple transitions on the same property, we will use the |
560 // last one since we iterate over them in order. | 584 // last one since we iterate over them in order. |
561 if (AnimatableValue::usesDefaultInterpolation(to.get(), from.get())) | |
562 return; | |
563 | 585 |
564 Timing timing = transitionData.convertToTiming(transitionIndex); | 586 Timing timing = transitionData.convertToTiming(transitionIndex); |
565 if (timing.startDelay + timing.iterationDuration <= 0) | 587 if (timing.startDelay + timing.iterationDuration <= 0) |
566 return; | 588 return; |
567 | 589 |
568 AnimatableValue* reversingAdjustedStartValue = from.get(); | 590 AnimatableValue* reversingAdjustedStartValue = from.get(); |
569 double reversingShorteningFactor = 1; | 591 double reversingShorteningFactor = 1; |
570 if (interruptedTransition) { | 592 if (interruptedTransition) { |
571 const double interruptedProgress = interruptedTransition->animation->eff
ect()->progress(); | 593 const double interruptedProgress = interruptedTransition->animation->eff
ect()->progress(); |
572 if (!std::isnan(interruptedProgress)) { | 594 if (!std::isnan(interruptedProgress)) { |
573 // const_cast because we need to take a ref later when passing to st
artTransition. | 595 // const_cast because we need to take a ref later when passing to st
artTransition. |
574 reversingAdjustedStartValue = const_cast<AnimatableValue*>(interrupt
edTransition->to); | 596 reversingAdjustedStartValue = const_cast<AnimatableValue*>(interrupt
edTransition->to.get()); |
575 reversingShorteningFactor = clampTo( | 597 reversingShorteningFactor = clampTo( |
576 (interruptedProgress * interruptedTransition->reversingShortenin
gFactor) + | 598 (interruptedProgress * interruptedTransition->reversingShortenin
gFactor) + |
577 (1 - interruptedTransition->reversingShorteningFactor), 0.0, 1.0
); | 599 (1 - interruptedTransition->reversingShorteningFactor), 0.0, 1.0
); |
578 timing.iterationDuration *= reversingShorteningFactor; | 600 timing.iterationDuration *= reversingShorteningFactor; |
579 if (timing.startDelay < 0) { | 601 if (timing.startDelay < 0) { |
580 timing.startDelay *= reversingShorteningFactor; | 602 timing.startDelay *= reversingShorteningFactor; |
581 } | 603 } |
582 } | 604 } |
583 } | 605 } |
584 | 606 |
585 AnimatableValueKeyframeVector keyframes; | 607 double delayOffset = 0; |
586 double startKeyframeOffset = 0; | |
587 | |
588 if (timing.startDelay > 0) { | 608 if (timing.startDelay > 0) { |
589 timing.iterationDuration += timing.startDelay; | 609 timing.iterationDuration += timing.startDelay; |
590 startKeyframeOffset = timing.startDelay / timing.iterationDuration; | 610 delayOffset = timing.startDelay / timing.iterationDuration; |
591 timing.startDelay = 0; | 611 timing.startDelay = 0; |
592 } | 612 } |
593 | 613 |
594 RefPtr<AnimatableValueKeyframe> delayKeyframe = AnimatableValueKeyframe::cre
ate(); | 614 TransitionEffectModel* model = TransitionEffectModel::create(pairwiseInterpo
lation.release(), delayOffset, timing.timingFunction.release()); |
595 delayKeyframe->setPropertyValue(id, from.get()); | |
596 delayKeyframe->setOffset(0); | |
597 keyframes.append(delayKeyframe); | |
598 | |
599 RefPtr<AnimatableValueKeyframe> startKeyframe = AnimatableValueKeyframe::cre
ate(); | |
600 startKeyframe->setPropertyValue(id, from.get()); | |
601 startKeyframe->setOffset(startKeyframeOffset); | |
602 startKeyframe->setEasing(timing.timingFunction.release()); | |
603 timing.timingFunction = LinearTimingFunction::shared(); | 615 timing.timingFunction = LinearTimingFunction::shared(); |
604 keyframes.append(startKeyframe); | |
605 | |
606 RefPtr<AnimatableValueKeyframe> endKeyframe = AnimatableValueKeyframe::creat
e(); | |
607 endKeyframe->setPropertyValue(id, to.get()); | |
608 endKeyframe->setOffset(1); | |
609 keyframes.append(endKeyframe); | |
610 | |
611 AnimatableValueKeyframeEffectModel* model = AnimatableValueKeyframeEffectMod
el::create(keyframes); | |
612 update.startTransition( | 616 update.startTransition( |
613 id, from.get(), to.get(), reversingAdjustedStartValue, reversingShorteni
ngFactor, | 617 id, from.release(), to.release(), reversingAdjustedStartValue, reversing
ShorteningFactor, |
614 *InertEffect::create(model, timing, false, 0)); | 618 *InertEffect::create(model, timing, false, 0)); |
615 ASSERT(!element->elementAnimations() || !element->elementAnimations()->isAni
mationStyleChange()); | 619 ASSERT(!element->elementAnimations() || !element->elementAnimations()->isAni
mationStyleChange()); |
616 } | 620 } |
617 | 621 |
618 void CSSAnimations::calculateTransitionUpdate(CSSAnimationUpdate& update, const
Element* animatingElement, const ComputedStyle& style) | 622 void CSSAnimations::calculateTransitionUpdate(CSSAnimationUpdate& update, const
Element* animatingElement, const ComputedStyle& style) |
619 { | 623 { |
620 if (!animatingElement) | 624 if (!animatingElement) |
621 return; | 625 return; |
622 | 626 |
623 if (animatingElement->document().printing() || animatingElement->document().
wasPrinting()) | 627 if (animatingElement->document().printing() || animatingElement->document().
wasPrinting()) |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
897 } | 901 } |
898 | 902 |
899 DEFINE_TRACE(CSSAnimations) | 903 DEFINE_TRACE(CSSAnimations) |
900 { | 904 { |
901 visitor->trace(m_transitions); | 905 visitor->trace(m_transitions); |
902 visitor->trace(m_pendingUpdate); | 906 visitor->trace(m_pendingUpdate); |
903 visitor->trace(m_runningAnimations); | 907 visitor->trace(m_runningAnimations); |
904 } | 908 } |
905 | 909 |
906 } // namespace blink | 910 } // namespace blink |
OLD | NEW |