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

Side by Side Diff: Source/core/page/animation/CSSPropertyAnimation.cpp

Issue 23581008: Revert r154797: "Move isValid/isCurrentColor from Color to StyleColor" (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 3 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) 2007, 2008, 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2007, 2008, 2009 Apple Inc. All rights reserved.
3 * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved. 3 * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 static inline double blendFunc(const AnimationBase*, double from, double to, dou ble progress) 62 static inline double blendFunc(const AnimationBase*, double from, double to, dou ble progress)
63 { 63 {
64 return blend(from, to, progress); 64 return blend(from, to, progress);
65 } 65 }
66 66
67 static inline float blendFunc(const AnimationBase*, float from, float to, double progress) 67 static inline float blendFunc(const AnimationBase*, float from, float to, double progress)
68 { 68 {
69 return narrowPrecisionToFloat(from + (to - from) * progress); 69 return narrowPrecisionToFloat(from + (to - from) * progress);
70 } 70 }
71 71
72 static inline Color blendFunc(const AnimationBase* animation, const StyleColor& from, const StyleColor& to, double progress) 72 static inline Color blendFunc(const AnimationBase*, const Color& from, const Col or& to, double progress)
73 { 73 {
74 Color fromColor = animation->renderer()->resolveColor(from); 74 return blend(from, to, progress);
75 Color toColor = animation->renderer()->resolveColor(to);
76 return blend(fromColor, toColor, progress);
77 } 75 }
78 76
79 static inline Length blendFunc(const AnimationBase*, const Length& from, const L ength& to, double progress) 77 static inline Length blendFunc(const AnimationBase*, const Length& from, const L ength& to, double progress)
80 { 78 {
81 return to.blend(from, narrowPrecisionToFloat(progress)); 79 return to.blend(from, narrowPrecisionToFloat(progress));
82 } 80 }
83 81
84 static inline LengthSize blendFunc(const AnimationBase* anim, const LengthSize& from, const LengthSize& to, double progress) 82 static inline LengthSize blendFunc(const AnimationBase* anim, const LengthSize& from, const LengthSize& to, double progress)
85 { 83 {
86 return LengthSize(blendFunc(anim, from.width(), to.width(), progress), 84 return LengthSize(blendFunc(anim, from.width(), to.width(), progress),
(...skipping 16 matching lines...) Expand all
103 double result = blendFunc(anim, fromVal, toVal, progress); 101 double result = blendFunc(anim, fromVal, toVal, progress);
104 return result > 0 ? Normal : Inset; 102 return result > 0 ? Normal : Inset;
105 } 103 }
106 104
107 static inline PassOwnPtr<ShadowData> blendFunc(const AnimationBase* anim, const ShadowData* from, const ShadowData* to, double progress) 105 static inline PassOwnPtr<ShadowData> blendFunc(const AnimationBase* anim, const ShadowData* from, const ShadowData* to, double progress)
108 { 106 {
109 ASSERT(from && to); 107 ASSERT(from && to);
110 if (from->style() != to->style()) 108 if (from->style() != to->style())
111 return to->clone(); 109 return to->clone();
112 110
113 Color fromColor = anim->renderer()->resolveColor(from->color());
114 Color toColor = anim->renderer()->resolveColor(to->color());
115
116 return ShadowData::create(blend(from->location(), to->location(), progress), 111 return ShadowData::create(blend(from->location(), to->location(), progress),
117 blend(from->blur(), to->blur(), progress), 112 blend(from->blur(), to->blur(), progress),
118 blend(from->spread(), to->spread(), progress), 113 blend(from->spread(), to->spread(), progress),
119 blendFunc(anim, from->style(), to->style(), progress), 114 blendFunc(anim, from->style(), to->style(), progress),
120 blend(fromColor, toColor, progress)); 115 blend(from->color(), to->color(), progress));
121 } 116 }
122 117
123 static inline TransformOperations blendFunc(const AnimationBase* anim, const Tra nsformOperations& from, const TransformOperations& to, double progress) 118 static inline TransformOperations blendFunc(const AnimationBase* anim, const Tra nsformOperations& from, const TransformOperations& to, double progress)
124 { 119 {
125 if (anim->isTransformFunctionListValid()) 120 if (anim->isTransformFunctionListValid())
126 return to.blendByMatchingOperations(from, progress); 121 return to.blendByMatchingOperations(from, progress);
127 return to.blendByUsingMatrixInterpolation(from, progress); 122 return to.blendByUsingMatrixInterpolation(from, progress);
128 } 123 }
129 124
130 static inline PassRefPtr<ClipPathOperation> blendFunc(const AnimationBase*, Clip PathOperation* from, ClipPathOperation* to, double progress) 125 static inline PassRefPtr<ClipPathOperation> blendFunc(const AnimationBase*, Clip PathOperation* from, ClipPathOperation* to, double progress)
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 return true; 440 return true;
446 if (!a || !b) 441 if (!a || !b)
447 return false; 442 return false;
448 443
449 StyleImage* imageA = (a->*m_getter)(); 444 StyleImage* imageA = (a->*m_getter)();
450 StyleImage* imageB = (b->*m_getter)(); 445 StyleImage* imageB = (b->*m_getter)();
451 return StyleImage::imagesEquivalent(imageA, imageB); 446 return StyleImage::imagesEquivalent(imageA, imageB);
452 } 447 }
453 }; 448 };
454 449
455 class PropertyWrapperColor : public PropertyWrapperGetter<StyleColor> { 450 class PropertyWrapperColor : public PropertyWrapperGetter<Color> {
456 public: 451 public:
457 PropertyWrapperColor(CSSPropertyID prop, StyleColor (RenderStyle::*getter)() const, void (RenderStyle::*setter)(const StyleColor&)) 452 PropertyWrapperColor(CSSPropertyID prop, Color (RenderStyle::*getter)() cons t, void (RenderStyle::*setter)(const Color&))
458 : PropertyWrapperGetter<StyleColor>(prop, getter) 453 : PropertyWrapperGetter<Color>(prop, getter)
459 , m_setter(setter) 454 , m_setter(setter)
460 { 455 {
461 } 456 }
462 457
463 virtual void blend(const AnimationBase* anim, RenderStyle* dst, const Render Style* a, const RenderStyle* b, double progress) const 458 virtual void blend(const AnimationBase* anim, RenderStyle* dst, const Render Style* a, const RenderStyle* b, double progress) const
464 { 459 {
465 (dst->*m_setter)(blendFunc(anim, (a->*PropertyWrapperGetter<StyleColor>: :m_getter)(), (b->*PropertyWrapperGetter<StyleColor>::m_getter)(), progress)); 460 (dst->*m_setter)(blendFunc(anim, (a->*PropertyWrapperGetter<Color>::m_ge tter)(), (b->*PropertyWrapperGetter<Color>::m_getter)(), progress));
466 } 461 }
467 462
468 protected: 463 protected:
469 void (RenderStyle::*m_setter)(const StyleColor&); 464 void (RenderStyle::*m_setter)(const Color&);
470 }; 465 };
471 466
472 class PropertyWrapperAcceleratedOpacity : public PropertyWrapper<float> { 467 class PropertyWrapperAcceleratedOpacity : public PropertyWrapper<float> {
473 public: 468 public:
474 PropertyWrapperAcceleratedOpacity() 469 PropertyWrapperAcceleratedOpacity()
475 : PropertyWrapper<float>(CSSPropertyOpacity, &RenderStyle::opacity, &Ren derStyle::setOpacity) 470 : PropertyWrapper<float>(CSSPropertyOpacity, &RenderStyle::opacity, &Ren derStyle::setOpacity)
476 { 471 {
477 } 472 }
478 473
479 virtual bool animationIsAccelerated() const { return true; } 474 virtual bool animationIsAccelerated() const { return true; }
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 644
650 return newShadowData.release(); 645 return newShadowData.release();
651 } 646 }
652 647
653 const ShadowData* (RenderStyle::*m_getter)() const; 648 const ShadowData* (RenderStyle::*m_getter)() const;
654 void (RenderStyle::*m_setter)(PassOwnPtr<ShadowData>, bool); 649 void (RenderStyle::*m_setter)(PassOwnPtr<ShadowData>, bool);
655 }; 650 };
656 651
657 class PropertyWrapperMaybeInvalidColor : public AnimationPropertyWrapperBase { 652 class PropertyWrapperMaybeInvalidColor : public AnimationPropertyWrapperBase {
658 public: 653 public:
659 PropertyWrapperMaybeInvalidColor(CSSPropertyID prop, StyleColor (RenderStyle ::*getter)() const, void (RenderStyle::*setter)(const StyleColor&)) 654 PropertyWrapperMaybeInvalidColor(CSSPropertyID prop, Color (RenderStyle::*ge tter)() const, void (RenderStyle::*setter)(const Color&))
660 : AnimationPropertyWrapperBase(prop) 655 : AnimationPropertyWrapperBase(prop)
661 , m_getter(getter) 656 , m_getter(getter)
662 , m_setter(setter) 657 , m_setter(setter)
663 { 658 {
664 } 659 }
665 660
666 virtual bool equals(const RenderStyle* a, const RenderStyle* b) const 661 virtual bool equals(const RenderStyle* a, const RenderStyle* b) const
667 { 662 {
668 StyleColor fromColor = (a->*m_getter)(); 663 Color fromColor = (a->*m_getter)();
669 StyleColor toColor = (b->*m_getter)(); 664 Color toColor = (b->*m_getter)();
670 665
671 if (!fromColor.isValid() && !toColor.isValid()) 666 if (!fromColor.isValid() && !toColor.isValid())
672 return true; 667 return true;
673 668
674 if (!fromColor.isValid()) 669 if (!fromColor.isValid())
675 fromColor = a->color(); 670 fromColor = a->color();
676 if (!toColor.isValid()) 671 if (!toColor.isValid())
677 toColor = b->color(); 672 toColor = b->color();
678 673
679 return fromColor == toColor; 674 return fromColor == toColor;
680 } 675 }
681 676
682 virtual void blend(const AnimationBase* anim, RenderStyle* dst, const Render Style* a, const RenderStyle* b, double progress) const 677 virtual void blend(const AnimationBase* anim, RenderStyle* dst, const Render Style* a, const RenderStyle* b, double progress) const
683 { 678 {
684 StyleColor fromColor = (a->*m_getter)(); 679 Color fromColor = (a->*m_getter)();
685 StyleColor toColor = (b->*m_getter)(); 680 Color toColor = (b->*m_getter)();
686 681
687 if (!fromColor.isValid() && !toColor.isValid()) 682 if (!fromColor.isValid() && !toColor.isValid())
688 return; 683 return;
689 684
690 if (!fromColor.isValid()) 685 if (!fromColor.isValid())
691 fromColor = a->color(); 686 fromColor = a->color();
692 if (!toColor.isValid()) 687 if (!toColor.isValid())
693 toColor = b->color(); 688 toColor = b->color();
694 (dst->*m_setter)(blendFunc(anim, fromColor, toColor, progress)); 689 (dst->*m_setter)(blendFunc(anim, fromColor, toColor, progress));
695 } 690 }
696 691
697 private: 692 private:
698 StyleColor (RenderStyle::*m_getter)() const; 693 Color (RenderStyle::*m_getter)() const;
699 void (RenderStyle::*m_setter)(const StyleColor&); 694 void (RenderStyle::*m_setter)(const Color&);
700 }; 695 };
701 696
702 697
703 enum MaybeInvalidColorTag { MaybeInvalidColor }; 698 enum MaybeInvalidColorTag { MaybeInvalidColor };
704 class PropertyWrapperVisitedAffectedColor : public AnimationPropertyWrapperBase { 699 class PropertyWrapperVisitedAffectedColor : public AnimationPropertyWrapperBase {
705 public: 700 public:
706 PropertyWrapperVisitedAffectedColor(CSSPropertyID prop, StyleColor (RenderSt yle::*getter)() const, void (RenderStyle::*setter)(const StyleColor&), 701 PropertyWrapperVisitedAffectedColor(CSSPropertyID prop, Color (RenderStyle:: *getter)() const, void (RenderStyle::*setter)(const Color&),
707 StyleColor (RenderStyle::*visitedGetter)() const, void (RenderStyle::*vi sitedSetter)(const StyleColor&)) 702 Color (RenderStyle::*visitedGetter)() const, void (RenderStyle::*visited Setter)(const Color&))
708 : AnimationPropertyWrapperBase(prop) 703 : AnimationPropertyWrapperBase(prop)
709 , m_wrapper(adoptPtr(new PropertyWrapperColor(prop, getter, setter))) 704 , m_wrapper(adoptPtr(new PropertyWrapperColor(prop, getter, setter)))
710 , m_visitedWrapper(adoptPtr(new PropertyWrapperColor(prop, visitedGetter , visitedSetter))) 705 , m_visitedWrapper(adoptPtr(new PropertyWrapperColor(prop, visitedGetter , visitedSetter)))
711 { 706 {
712 } 707 }
713 PropertyWrapperVisitedAffectedColor(CSSPropertyID prop, MaybeInvalidColorTag , StyleColor (RenderStyle::*getter)() const, void (RenderStyle::*setter)(const S tyleColor&), 708 PropertyWrapperVisitedAffectedColor(CSSPropertyID prop, MaybeInvalidColorTag , Color (RenderStyle::*getter)() const, void (RenderStyle::*setter)(const Color& ),
714 StyleColor (RenderStyle::*visitedGetter)() const, void (RenderStyle::*vi sitedSetter)(const StyleColor&)) 709 Color (RenderStyle::*visitedGetter)() const, void (RenderStyle::*visited Setter)(const Color&))
715 : AnimationPropertyWrapperBase(prop) 710 : AnimationPropertyWrapperBase(prop)
716 , m_wrapper(adoptPtr(new PropertyWrapperMaybeInvalidColor(prop, getter, setter))) 711 , m_wrapper(adoptPtr(new PropertyWrapperMaybeInvalidColor(prop, getter, setter)))
717 , m_visitedWrapper(adoptPtr(new PropertyWrapperMaybeInvalidColor(prop, v isitedGetter, visitedSetter))) 712 , m_visitedWrapper(adoptPtr(new PropertyWrapperMaybeInvalidColor(prop, v isitedGetter, visitedSetter)))
718 { 713 {
719 } 714 }
720 virtual bool equals(const RenderStyle* a, const RenderStyle* b) const 715 virtual bool equals(const RenderStyle* a, const RenderStyle* b) const
721 { 716 {
722 return m_wrapper->equals(a, b) && m_visitedWrapper->equals(a, b); 717 return m_wrapper->equals(a, b) && m_visitedWrapper->equals(a, b);
723 } 718 }
724 virtual void blend(const AnimationBase* anim, RenderStyle* dst, const Render Style* a, const RenderStyle* b, double progress) const 719 virtual void blend(const AnimationBase* anim, RenderStyle* dst, const Render Style* a, const RenderStyle* b, double progress) const
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
956 virtual void blend(const AnimationBase* anim, RenderStyle* dst, const Render Style* a, const RenderStyle* b, double progress) const 951 virtual void blend(const AnimationBase* anim, RenderStyle* dst, const Render Style* a, const RenderStyle* b, double progress) const
957 { 952 {
958 dst->setFlexBasis(blendFunc(anim, a->flexBasis(), b->flexBasis(), progre ss)); 953 dst->setFlexBasis(blendFunc(anim, a->flexBasis(), b->flexBasis(), progre ss));
959 dst->setFlexGrow(blendFunc(anim, a->flexGrow(), b->flexGrow(), progress) ); 954 dst->setFlexGrow(blendFunc(anim, a->flexGrow(), b->flexGrow(), progress) );
960 dst->setFlexShrink(blendFunc(anim, a->flexShrink(), b->flexShrink(), pro gress)); 955 dst->setFlexShrink(blendFunc(anim, a->flexShrink(), b->flexShrink(), pro gress));
961 } 956 }
962 }; 957 };
963 958
964 class PropertyWrapperSVGPaint : public AnimationPropertyWrapperBase { 959 class PropertyWrapperSVGPaint : public AnimationPropertyWrapperBase {
965 public: 960 public:
966 PropertyWrapperSVGPaint(CSSPropertyID prop, const SVGPaint::SVGPaintType& (R enderStyle::*paintTypeGetter)() const, StyleColor (RenderStyle::*getter)() const , void (RenderStyle::*setter)(const StyleColor&)) 961 PropertyWrapperSVGPaint(CSSPropertyID prop, const SVGPaint::SVGPaintType& (R enderStyle::*paintTypeGetter)() const, Color (RenderStyle::*getter)() const, voi d (RenderStyle::*setter)(const Color&))
967 : AnimationPropertyWrapperBase(prop) 962 : AnimationPropertyWrapperBase(prop)
968 , m_paintTypeGetter(paintTypeGetter) 963 , m_paintTypeGetter(paintTypeGetter)
969 , m_getter(getter) 964 , m_getter(getter)
970 , m_setter(setter) 965 , m_setter(setter)
971 { 966 {
972 } 967 }
973 968
974 virtual bool equals(const RenderStyle* a, const RenderStyle* b) const 969 virtual bool equals(const RenderStyle* a, const RenderStyle* b) const
975 { 970 {
976 if ((a->*m_paintTypeGetter)() != (b->*m_paintTypeGetter)()) 971 if ((a->*m_paintTypeGetter)() != (b->*m_paintTypeGetter)())
977 return false; 972 return false;
978 973
979 // We only support animations between SVGPaints that are pure StyleColor values. 974 // We only support animations between SVGPaints that are pure Color valu es.
980 // For everything else we must return true for this method, otherwise 975 // For everything else we must return true for this method, otherwise
981 // we will try to animate between values forever. 976 // we will try to animate between values forever.
982 if ((a->*m_paintTypeGetter)() == SVGPaint::SVG_PAINTTYPE_RGBCOLOR) { 977 if ((a->*m_paintTypeGetter)() == SVGPaint::SVG_PAINTTYPE_RGBCOLOR) {
983 StyleColor fromColor = (a->*m_getter)(); 978 Color fromColor = (a->*m_getter)();
984 StyleColor toColor = (b->*m_getter)(); 979 Color toColor = (b->*m_getter)();
985 980
986 if (!fromColor.isValid() && !toColor.isValid()) 981 if (!fromColor.isValid() && !toColor.isValid())
987 return true; 982 return true;
988 983
989 if (!fromColor.isValid()) 984 if (!fromColor.isValid())
990 fromColor = StyleColor(); 985 fromColor = Color();
991 if (!toColor.isValid()) 986 if (!toColor.isValid())
992 toColor = StyleColor(); 987 toColor = Color();
993 988
994 return fromColor == toColor; 989 return fromColor == toColor;
995 } 990 }
996 return true; 991 return true;
997 } 992 }
998 993
999 virtual void blend(const AnimationBase* anim, RenderStyle* dst, const Render Style* a, const RenderStyle* b, double progress) const 994 virtual void blend(const AnimationBase* anim, RenderStyle* dst, const Render Style* a, const RenderStyle* b, double progress) const
1000 { 995 {
1001 if ((a->*m_paintTypeGetter)() != SVGPaint::SVG_PAINTTYPE_RGBCOLOR 996 if ((a->*m_paintTypeGetter)() != SVGPaint::SVG_PAINTTYPE_RGBCOLOR
1002 || (b->*m_paintTypeGetter)() != SVGPaint::SVG_PAINTTYPE_RGBCOLOR) 997 || (b->*m_paintTypeGetter)() != SVGPaint::SVG_PAINTTYPE_RGBCOLOR)
1003 return; 998 return;
1004 999
1005 StyleColor fromColor = (a->*m_getter)(); 1000 Color fromColor = (a->*m_getter)();
1006 StyleColor toColor = (b->*m_getter)(); 1001 Color toColor = (b->*m_getter)();
1007 1002
1008 if (!fromColor.isValid() && !toColor.isValid()) 1003 if (!fromColor.isValid() && !toColor.isValid())
1009 return; 1004 return;
1010 1005
1011 if (!fromColor.isValid()) 1006 if (!fromColor.isValid())
1012 fromColor = StyleColor(); 1007 fromColor = Color();
1013 if (!toColor.isValid()) 1008 if (!toColor.isValid())
1014 toColor = StyleColor(); 1009 toColor = Color();
1015 (dst->*m_setter)(blendFunc(anim, fromColor, toColor, progress)); 1010 (dst->*m_setter)(blendFunc(anim, fromColor, toColor, progress));
1016 } 1011 }
1017 1012
1018 private: 1013 private:
1019 const SVGPaint::SVGPaintType& (RenderStyle::*m_paintTypeGetter)() const; 1014 const SVGPaint::SVGPaintType& (RenderStyle::*m_paintTypeGetter)() const;
1020 StyleColor (RenderStyle::*m_getter)() const; 1015 Color (RenderStyle::*m_getter)() const;
1021 void (RenderStyle::*m_setter)(const StyleColor&); 1016 void (RenderStyle::*m_setter)(const Color&);
1022 }; 1017 };
1023 1018
1024 static void addShorthandProperties() 1019 static void addShorthandProperties()
1025 { 1020 {
1026 static const CSSPropertyID animatableShorthandProperties[] = { 1021 static const CSSPropertyID animatableShorthandProperties[] = {
1027 CSSPropertyBackground, // for background-color, background-position, bac kground-image 1022 CSSPropertyBackground, // for background-color, background-position, bac kground-image
1028 CSSPropertyBackgroundPosition, 1023 CSSPropertyBackgroundPosition,
1029 CSSPropertyFont, // for font-size, font-weight 1024 CSSPropertyFont, // for font-size, font-weight
1030 CSSPropertyWebkitMask, // for mask-position 1025 CSSPropertyWebkitMask, // for mask-position
1031 CSSPropertyWebkitMaskPosition, 1026 CSSPropertyWebkitMaskPosition,
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
1268 } 1263 }
1269 1264
1270 int CSSPropertyAnimation::getNumProperties() 1265 int CSSPropertyAnimation::getNumProperties()
1271 { 1266 {
1272 ensurePropertyMap(); 1267 ensurePropertyMap();
1273 1268
1274 return gPropertyWrappers->size(); 1269 return gPropertyWrappers->size();
1275 } 1270 }
1276 1271
1277 } 1272 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698