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 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
426 snapshot(new_animation.effect.Get()); | 426 snapshot(new_animation.effect.Get()); |
427 | 427 |
428 for (const auto& updated_animation : update.AnimationsWithUpdates()) | 428 for (const auto& updated_animation : update.AnimationsWithUpdates()) |
429 snapshot(updated_animation.effect.Get()); | 429 snapshot(updated_animation.effect.Get()); |
430 | 430 |
431 for (const auto& new_transition : update.NewTransitions()) | 431 for (const auto& new_transition : update.NewTransitions()) |
432 snapshot(new_transition.value.effect.Get()); | 432 snapshot(new_transition.value.effect.Get()); |
433 } | 433 } |
434 | 434 |
435 void CSSAnimations::MaybeApplyPendingUpdate(Element* element) { | 435 void CSSAnimations::MaybeApplyPendingUpdate(Element* element) { |
436 previous_active_interpolations_for_animations_.clear(); | 436 previous_active_interpolations_for_custom_animations_.clear(); |
437 previous_active_interpolations_for_standard_animations_.clear(); | |
437 if (pending_update_.IsEmpty()) | 438 if (pending_update_.IsEmpty()) |
438 return; | 439 return; |
439 | 440 |
440 previous_active_interpolations_for_animations_.swap( | 441 previous_active_interpolations_for_custom_animations_.swap( |
441 pending_update_.ActiveInterpolationsForAnimations()); | 442 pending_update_.ActiveInterpolationsForCustomAnimations()); |
443 previous_active_interpolations_for_standard_animations_.swap( | |
444 pending_update_.ActiveInterpolationsForStandardAnimations()); | |
442 | 445 |
443 // FIXME: cancelling, pausing, unpausing animations all query | 446 // FIXME: cancelling, pausing, unpausing animations all query |
444 // compositingState, which is not necessarily up to date here | 447 // compositingState, which is not necessarily up to date here |
445 // since we call this from recalc style. | 448 // since we call this from recalc style. |
446 // https://code.google.com/p/chromium/issues/detail?id=339847 | 449 // https://code.google.com/p/chromium/issues/detail?id=339847 |
447 DisableCompositingQueryAsserts disabler; | 450 DisableCompositingQueryAsserts disabler; |
448 | 451 |
449 for (size_t paused_index : | 452 for (size_t paused_index : |
450 pending_update_.AnimationIndicesWithPauseToggled()) { | 453 pending_update_.AnimationIndicesWithPauseToggled()) { |
451 Animation& animation = *running_animations_[paused_index]->animation; | 454 Animation& animation = *running_animations_[paused_index]->animation; |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
629 | 632 |
630 void CSSAnimations::CalculateTransitionUpdateForProperty( | 633 void CSSAnimations::CalculateTransitionUpdateForProperty( |
631 TransitionUpdateState& state, | 634 TransitionUpdateState& state, |
632 const PropertyHandle& property, | 635 const PropertyHandle& property, |
633 size_t transition_index) { | 636 size_t transition_index) { |
634 state.listed_properties.insert(property); | 637 state.listed_properties.insert(property); |
635 | 638 |
636 // FIXME: We should transition if an !important property changes even when an | 639 // FIXME: We should transition if an !important property changes even when an |
637 // animation is running, but this is a bit hard to do with the current | 640 // animation is running, but this is a bit hard to do with the current |
638 // applyMatchedProperties system. | 641 // applyMatchedProperties system. |
639 if (state.update.ActiveInterpolationsForAnimations().Contains(property) || | 642 if (property.IsCSSCustomProperty()) { |
640 (state.animating_element->GetElementAnimations() && | 643 if (state.update.ActiveInterpolationsForCustomAnimations().Contains( |
641 state.animating_element->GetElementAnimations() | 644 property) || |
642 ->CssAnimations() | 645 (state.animating_element->GetElementAnimations() && |
643 .previous_active_interpolations_for_animations_.Contains( | 646 state.animating_element->GetElementAnimations() |
644 property))) { | 647 ->CssAnimations() |
648 .previous_active_interpolations_for_custom_animations_.Contains( | |
649 property))) { | |
650 return; | |
651 } | |
652 } else if (state.update.ActiveInterpolationsForStandardAnimations().Contains( | |
653 property) || | |
654 (state.animating_element->GetElementAnimations() && | |
655 state.animating_element->GetElementAnimations() | |
656 ->CssAnimations() | |
657 .previous_active_interpolations_for_standard_animations_ | |
658 .Contains(property))) { | |
645 return; | 659 return; |
646 } | 660 } |
647 | 661 |
648 RefPtr<AnimatableValue> to = nullptr; | 662 RefPtr<AnimatableValue> to = nullptr; |
649 const RunningTransition* interrupted_transition = nullptr; | 663 const RunningTransition* interrupted_transition = nullptr; |
650 if (state.active_transitions) { | 664 if (state.active_transitions) { |
651 TransitionMap::const_iterator active_transition_iter = | 665 TransitionMap::const_iterator active_transition_iter = |
652 state.active_transitions->find(property); | 666 state.active_transitions->find(property); |
653 if (active_transition_iter != state.active_transitions->end()) { | 667 if (active_transition_iter != state.active_transitions->end()) { |
654 const RunningTransition* running_transition = | 668 const RunningTransition* running_transition = |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
928 for (const auto& entry : transitions_) { | 942 for (const auto& entry : transitions_) { |
929 entry.value.animation->cancel(); | 943 entry.value.animation->cancel(); |
930 entry.value.animation->Update(kTimingUpdateOnDemand); | 944 entry.value.animation->Update(kTimingUpdateOnDemand); |
931 } | 945 } |
932 | 946 |
933 running_animations_.clear(); | 947 running_animations_.clear(); |
934 transitions_.clear(); | 948 transitions_.clear(); |
935 ClearPendingUpdate(); | 949 ClearPendingUpdate(); |
936 } | 950 } |
937 | 951 |
952 static bool IsCustomPropertyHandle(const PropertyHandle& property) { | |
suzyh_UTC10 (ex-contributor)
2017/05/26 01:56:00
If this is not inside the CSSAnimations class, why
alancutter (OOO until 2018)
2017/05/26 03:09:14
If you don't make it static then it becomes availa
suzyh_UTC10 (ex-contributor)
2017/05/26 04:02:09
I thought without having it in the header then tha
| |
953 return property.IsCSSCustomProperty(); | |
954 } | |
955 | |
938 // TODO(alancutter): CSS properties and presentation attributes may have | 956 // TODO(alancutter): CSS properties and presentation attributes may have |
939 // identical effects. By grouping them in the same set we introduce a bug where | 957 // identical effects. By grouping them in the same set we introduce a bug where |
940 // arbitrary hash iteration will determine the order the apply in and thus which | 958 // arbitrary hash iteration will determine the order the apply in and thus which |
941 // one "wins". We should be more deliberate about the order of application in | 959 // one "wins". We should be more deliberate about the order of application in |
942 // the case of effect collisions. | 960 // the case of effect collisions. |
943 // Example: Both 'color' and 'svg-color' set the color on ComputedStyle but are | 961 // Example: Both 'color' and 'svg-color' set the color on ComputedStyle but are |
944 // considered distinct properties in the ActiveInterpolationsMap. | 962 // considered distinct properties in the ActiveInterpolationsMap. |
945 static bool IsStylePropertyHandle(const PropertyHandle& property_handle) { | 963 static bool IsStandardPropertyHandle(const PropertyHandle& property) { |
946 return property_handle.IsCSSProperty() || | 964 return (property.IsCSSProperty() && !property.IsCSSCustomProperty()) || |
947 property_handle.IsPresentationAttribute(); | 965 property.IsPresentationAttribute(); |
948 } | 966 } |
949 | 967 |
950 void CSSAnimations::CalculateAnimationActiveInterpolations( | 968 void CSSAnimations::CalculateAnimationActiveInterpolations( |
951 CSSAnimationUpdate& update, | 969 CSSAnimationUpdate& update, |
952 const Element* animating_element) { | 970 const Element* animating_element) { |
953 ElementAnimations* element_animations = | 971 ElementAnimations* element_animations = |
954 animating_element ? animating_element->GetElementAnimations() : nullptr; | 972 animating_element ? animating_element->GetElementAnimations() : nullptr; |
955 EffectStack* effect_stack = | 973 EffectStack* effect_stack = |
956 element_animations ? &element_animations->GetEffectStack() : nullptr; | 974 element_animations ? &element_animations->GetEffectStack() : nullptr; |
957 | 975 |
976 const auto& adoptActiveInterpolations = | |
suzyh_UTC10 (ex-contributor)
2017/05/26 01:56:00
I find this difficult to read. What do you see as
alancutter (OOO until 2018)
2017/05/26 03:09:14
I don't see any major advantages to it, just minor
| |
977 [effect_stack, &update]( | |
978 const HeapVector<Member<const InertEffect>>* new_animations, | |
979 const HeapHashSet<Member<const Animation>>* suppressed_animations) { | |
980 ActiveInterpolationsMap custom_interpolations( | |
981 EffectStack::ActiveInterpolations( | |
suzyh_UTC10 (ex-contributor)
2017/05/26 01:56:00
Would this be simplified if EffectStack knew about
alancutter (OOO until 2018)
2017/05/26 03:09:14
It's a distiction that would be out of place in Ef
| |
982 effect_stack, new_animations, suppressed_animations, | |
983 KeyframeEffectReadOnly::kDefaultPriority, | |
984 IsCustomPropertyHandle)); | |
985 update.AdoptActiveInterpolationsForCustomAnimations( | |
986 custom_interpolations); | |
987 | |
988 ActiveInterpolationsMap standard_interpolations( | |
989 EffectStack::ActiveInterpolations( | |
990 effect_stack, new_animations, suppressed_animations, | |
991 KeyframeEffectReadOnly::kDefaultPriority, | |
992 IsStandardPropertyHandle)); | |
993 update.AdoptActiveInterpolationsForStandardAnimations( | |
994 standard_interpolations); | |
995 }; | |
996 | |
958 if (update.NewAnimations().IsEmpty() && | 997 if (update.NewAnimations().IsEmpty() && |
959 update.SuppressedAnimations().IsEmpty()) { | 998 update.SuppressedAnimations().IsEmpty()) { |
960 ActiveInterpolationsMap active_interpolations_for_animations( | 999 adoptActiveInterpolations(nullptr, nullptr); |
961 EffectStack::ActiveInterpolations( | |
962 effect_stack, nullptr, nullptr, | |
963 KeyframeEffectReadOnly::kDefaultPriority, IsStylePropertyHandle)); | |
964 update.AdoptActiveInterpolationsForAnimations( | |
965 active_interpolations_for_animations); | |
966 return; | 1000 return; |
967 } | 1001 } |
968 | 1002 |
969 HeapVector<Member<const InertEffect>> new_effects; | 1003 HeapVector<Member<const InertEffect>> new_effects; |
970 for (const auto& new_animation : update.NewAnimations()) | 1004 for (const auto& new_animation : update.NewAnimations()) |
971 new_effects.push_back(new_animation.effect); | 1005 new_effects.push_back(new_animation.effect); |
972 | 1006 |
973 // Animations with updates use a temporary InertEffect for the current frame. | 1007 // Animations with updates use a temporary InertEffect for the current frame. |
974 for (const auto& updated_animation : update.AnimationsWithUpdates()) | 1008 for (const auto& updated_animation : update.AnimationsWithUpdates()) |
975 new_effects.push_back(updated_animation.effect); | 1009 new_effects.push_back(updated_animation.effect); |
976 | 1010 |
977 ActiveInterpolationsMap active_interpolations_for_animations( | 1011 adoptActiveInterpolations(&new_effects, &update.SuppressedAnimations()); |
978 EffectStack::ActiveInterpolations( | |
979 effect_stack, &new_effects, &update.SuppressedAnimations(), | |
980 KeyframeEffectReadOnly::kDefaultPriority, IsStylePropertyHandle)); | |
981 update.AdoptActiveInterpolationsForAnimations( | |
982 active_interpolations_for_animations); | |
983 } | 1012 } |
984 | 1013 |
985 static bool IsCustomStylePropertyHandle(const PropertyHandle& property) { | 1014 static EffectStack::PropertyHandleFilter PropertyFilter( |
986 return property.IsCSSCustomProperty(); | |
987 } | |
988 | |
989 static bool IsStandardStylePropertyHandle(const PropertyHandle& property) { | |
990 return IsStylePropertyHandle(property) && !property.IsCSSCustomProperty(); | |
991 } | |
992 | |
993 static EffectStack::PropertyHandleFilter StylePropertyFilter( | |
994 CSSAnimations::PropertyPass property_pass) { | 1015 CSSAnimations::PropertyPass property_pass) { |
995 if (property_pass == CSSAnimations::PropertyPass::kCustom) { | 1016 if (property_pass == CSSAnimations::PropertyPass::kCustom) { |
996 return IsCustomStylePropertyHandle; | 1017 return IsCustomPropertyHandle; |
997 } | 1018 } |
998 DCHECK_EQ(property_pass, CSSAnimations::PropertyPass::kStandard); | 1019 DCHECK_EQ(property_pass, CSSAnimations::PropertyPass::kStandard); |
999 return IsStandardStylePropertyHandle; | 1020 return IsStandardPropertyHandle; |
1000 } | 1021 } |
1001 | 1022 |
1002 void CSSAnimations::CalculateTransitionActiveInterpolations( | 1023 void CSSAnimations::CalculateTransitionActiveInterpolations( |
1003 CSSAnimationUpdate& update, | 1024 CSSAnimationUpdate& update, |
1004 PropertyPass property_pass, | 1025 PropertyPass property_pass, |
1005 const Element* animating_element) { | 1026 const Element* animating_element) { |
1006 ElementAnimations* element_animations = | 1027 ElementAnimations* element_animations = |
1007 animating_element ? animating_element->GetElementAnimations() : nullptr; | 1028 animating_element ? animating_element->GetElementAnimations() : nullptr; |
1008 EffectStack* effect_stack = | 1029 EffectStack* effect_stack = |
1009 element_animations ? &element_animations->GetEffectStack() : nullptr; | 1030 element_animations ? &element_animations->GetEffectStack() : nullptr; |
1010 | 1031 |
1011 ActiveInterpolationsMap active_interpolations_for_transitions; | 1032 ActiveInterpolationsMap active_interpolations_for_transitions; |
1012 if (update.NewTransitions().IsEmpty() && | 1033 if (update.NewTransitions().IsEmpty() && |
1013 update.CancelledTransitions().IsEmpty()) { | 1034 update.CancelledTransitions().IsEmpty()) { |
1014 active_interpolations_for_transitions = EffectStack::ActiveInterpolations( | 1035 active_interpolations_for_transitions = EffectStack::ActiveInterpolations( |
1015 effect_stack, nullptr, nullptr, | 1036 effect_stack, nullptr, nullptr, |
1016 KeyframeEffectReadOnly::kTransitionPriority, | 1037 KeyframeEffectReadOnly::kTransitionPriority, |
1017 StylePropertyFilter(property_pass)); | 1038 PropertyFilter(property_pass)); |
1018 } else { | 1039 } else { |
1019 HeapVector<Member<const InertEffect>> new_transitions; | 1040 HeapVector<Member<const InertEffect>> new_transitions; |
1020 for (const auto& entry : update.NewTransitions()) | 1041 for (const auto& entry : update.NewTransitions()) |
1021 new_transitions.push_back(entry.value.effect.Get()); | 1042 new_transitions.push_back(entry.value.effect.Get()); |
1022 | 1043 |
1023 HeapHashSet<Member<const Animation>> cancelled_animations; | 1044 HeapHashSet<Member<const Animation>> cancelled_animations; |
1024 if (!update.CancelledTransitions().IsEmpty()) { | 1045 if (!update.CancelledTransitions().IsEmpty()) { |
1025 DCHECK(element_animations); | 1046 DCHECK(element_animations); |
1026 const TransitionMap& transition_map = | 1047 const TransitionMap& transition_map = |
1027 element_animations->CssAnimations().transitions_; | 1048 element_animations->CssAnimations().transitions_; |
1028 for (const PropertyHandle& property : update.CancelledTransitions()) { | 1049 for (const PropertyHandle& property : update.CancelledTransitions()) { |
1029 DCHECK(transition_map.Contains(property)); | 1050 DCHECK(transition_map.Contains(property)); |
1030 cancelled_animations.insert( | 1051 cancelled_animations.insert( |
1031 transition_map.at(property).animation.Get()); | 1052 transition_map.at(property).animation.Get()); |
1032 } | 1053 } |
1033 } | 1054 } |
1034 | 1055 |
1035 active_interpolations_for_transitions = EffectStack::ActiveInterpolations( | 1056 active_interpolations_for_transitions = EffectStack::ActiveInterpolations( |
1036 effect_stack, &new_transitions, &cancelled_animations, | 1057 effect_stack, &new_transitions, &cancelled_animations, |
1037 KeyframeEffectReadOnly::kTransitionPriority, | 1058 KeyframeEffectReadOnly::kTransitionPriority, |
1038 StylePropertyFilter(property_pass)); | 1059 PropertyFilter(property_pass)); |
1039 } | 1060 } |
1040 | 1061 |
1062 const ActiveInterpolationsMap& animations = | |
1063 property_pass == PropertyPass::kCustom | |
1064 ? update.ActiveInterpolationsForCustomAnimations() | |
1065 : update.ActiveInterpolationsForStandardAnimations(); | |
1041 // Properties being animated by animations don't get values from transitions | 1066 // Properties being animated by animations don't get values from transitions |
1042 // applied. | 1067 // applied. |
1043 if (!update.ActiveInterpolationsForAnimations().IsEmpty() && | 1068 if (!animations.IsEmpty() && |
1044 !active_interpolations_for_transitions.IsEmpty()) { | 1069 !active_interpolations_for_transitions.IsEmpty()) { |
1045 for (const auto& entry : update.ActiveInterpolationsForAnimations()) | 1070 for (const auto& entry : animations) |
1046 active_interpolations_for_transitions.erase(entry.key); | 1071 active_interpolations_for_transitions.erase(entry.key); |
1047 } | 1072 } |
1048 | 1073 |
1049 if (property_pass == PropertyPass::kCustom) { | 1074 if (property_pass == PropertyPass::kCustom) { |
1050 update.AdoptActiveInterpolationsForCustomTransitions( | 1075 update.AdoptActiveInterpolationsForCustomTransitions( |
1051 active_interpolations_for_transitions); | 1076 active_interpolations_for_transitions); |
1052 } else { | 1077 } else { |
1053 DCHECK_EQ(property_pass, PropertyPass::kStandard); | 1078 DCHECK_EQ(property_pass, PropertyPass::kStandard); |
1054 update.AdoptActiveInterpolationsForStandardTransitions( | 1079 update.AdoptActiveInterpolationsForStandardTransitions( |
1055 active_interpolations_for_transitions); | 1080 active_interpolations_for_transitions); |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1211 // and from their shadow sub-trees if they are shadow hosts. | 1236 // and from their shadow sub-trees if they are shadow hosts. |
1212 if (element.GetTreeScope() == tree_scope) | 1237 if (element.GetTreeScope() == tree_scope) |
1213 return true; | 1238 return true; |
1214 if (!IsShadowHost(element)) | 1239 if (!IsShadowHost(element)) |
1215 return false; | 1240 return false; |
1216 if (tree_scope.RootNode() == tree_scope.GetDocument()) | 1241 if (tree_scope.RootNode() == tree_scope.GetDocument()) |
1217 return false; | 1242 return false; |
1218 return ToShadowRoot(tree_scope.RootNode()).host() == element; | 1243 return ToShadowRoot(tree_scope.RootNode()).host() == element; |
1219 } | 1244 } |
1220 | 1245 |
1221 bool CSSAnimations::IsCustomPropertyHandle(const PropertyHandle& property) { | |
1222 return property.IsCSSProperty() && | |
1223 property.CssProperty() == CSSPropertyVariable; | |
1224 } | |
1225 | |
1226 bool CSSAnimations::IsAnimatingCustomProperties( | 1246 bool CSSAnimations::IsAnimatingCustomProperties( |
1227 const ElementAnimations* element_animations) { | 1247 const ElementAnimations* element_animations) { |
1228 return element_animations && | 1248 return element_animations && |
1229 element_animations->GetEffectStack().AffectsProperties( | 1249 element_animations->GetEffectStack().AffectsProperties( |
1230 IsCustomPropertyHandle); | 1250 IsCustomPropertyHandle); |
1231 } | 1251 } |
1232 | 1252 |
1233 DEFINE_TRACE(CSSAnimations) { | 1253 DEFINE_TRACE(CSSAnimations) { |
1234 visitor->Trace(transitions_); | 1254 visitor->Trace(transitions_); |
1235 visitor->Trace(pending_update_); | 1255 visitor->Trace(pending_update_); |
1236 visitor->Trace(running_animations_); | 1256 visitor->Trace(running_animations_); |
1237 } | 1257 } |
1238 | 1258 |
1239 } // namespace blink | 1259 } // namespace blink |
OLD | NEW |