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

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

Issue 20061003: Move isValid/isCurrentColor from Color to StyleColor (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 5 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 static inline double blendFunc(const AnimationBase*, double from, double to, dou ble progress) 61 static inline double blendFunc(const AnimationBase*, double from, double to, dou ble progress)
62 { 62 {
63 return blend(from, to, progress); 63 return blend(from, to, progress);
64 } 64 }
65 65
66 static inline float blendFunc(const AnimationBase*, float from, float to, double progress) 66 static inline float blendFunc(const AnimationBase*, float from, float to, double progress)
67 { 67 {
68 return narrowPrecisionToFloat(from + (to - from) * progress); 68 return narrowPrecisionToFloat(from + (to - from) * progress);
69 } 69 }
70 70
71 static inline Color blendFunc(const AnimationBase*, const Color& from, const Col or& to, double progress) 71 static inline Color blendFunc(const AnimationBase* animation, const StyleColor& from, const StyleColor& to, double progress)
72 { 72 {
73 return blend(from, to, progress); 73 Color fromColor = animation->renderer()->resolveColor(from);
74 Color toColor = animation->renderer()->resolveColor(to);
75 return blend(fromColor, toColor, progress);
74 } 76 }
75 77
76 static inline Length blendFunc(const AnimationBase*, const Length& from, const L ength& to, double progress) 78 static inline Length blendFunc(const AnimationBase*, const Length& from, const L ength& to, double progress)
77 { 79 {
78 return to.blend(from, narrowPrecisionToFloat(progress)); 80 return to.blend(from, narrowPrecisionToFloat(progress));
79 } 81 }
80 82
81 static inline LengthSize blendFunc(const AnimationBase* anim, const LengthSize& from, const LengthSize& to, double progress) 83 static inline LengthSize blendFunc(const AnimationBase* anim, const LengthSize& from, const LengthSize& to, double progress)
82 { 84 {
83 return LengthSize(blendFunc(anim, from.width(), to.width(), progress), 85 return LengthSize(blendFunc(anim, from.width(), to.width(), progress),
(...skipping 16 matching lines...) Expand all
100 double result = blendFunc(anim, fromVal, toVal, progress); 102 double result = blendFunc(anim, fromVal, toVal, progress);
101 return result > 0 ? Normal : Inset; 103 return result > 0 ? Normal : Inset;
102 } 104 }
103 105
104 static inline PassOwnPtr<ShadowData> blendFunc(const AnimationBase* anim, const ShadowData* from, const ShadowData* to, double progress) 106 static inline PassOwnPtr<ShadowData> blendFunc(const AnimationBase* anim, const ShadowData* from, const ShadowData* to, double progress)
105 { 107 {
106 ASSERT(from && to); 108 ASSERT(from && to);
107 if (from->style() != to->style()) 109 if (from->style() != to->style())
108 return to->clone(); 110 return to->clone();
109 111
112 Color fromColor = anim->renderer()->resolveColor(from->color());
113 Color toColor = anim->renderer()->resolveColor(to->color());
114
110 return ShadowData::create(blend(from->location(), to->location(), progress), 115 return ShadowData::create(blend(from->location(), to->location(), progress),
111 blend(from->blur(), to->blur(), progress), 116 blend(from->blur(), to->blur(), progress),
112 blend(from->spread(), to->spread(), progress), 117 blend(from->spread(), to->spread(), progress),
113 blendFunc(anim, from->style(), to->style(), progress), 118 blendFunc(anim, from->style(), to->style(), progress),
114 blend(from->color(), to->color(), progress)); 119 blend(fromColor, toColor, progress));
115 } 120 }
116 121
117 static inline TransformOperations blendFunc(const AnimationBase* anim, const Tra nsformOperations& from, const TransformOperations& to, double progress) 122 static inline TransformOperations blendFunc(const AnimationBase* anim, const Tra nsformOperations& from, const TransformOperations& to, double progress)
118 { 123 {
119 if (anim->isTransformFunctionListValid()) 124 if (anim->isTransformFunctionListValid())
120 return to.blendByMatchingOperations(from, progress); 125 return to.blendByMatchingOperations(from, progress);
121 return to.blendByUsingMatrixInterpolation(from, progress, anim->renderer()-> isBox() ? toRenderBox(anim->renderer())->borderBoxRect().size() : LayoutSize()); 126 return to.blendByUsingMatrixInterpolation(from, progress, anim->renderer()-> isBox() ? toRenderBox(anim->renderer())->borderBoxRect().size() : LayoutSize());
122 } 127 }
123 128
124 static inline PassRefPtr<ClipPathOperation> blendFunc(const AnimationBase*, Clip PathOperation* from, ClipPathOperation* to, double progress) 129 static inline PassRefPtr<ClipPathOperation> blendFunc(const AnimationBase*, Clip PathOperation* from, ClipPathOperation* to, double progress)
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 return true; 424 return true;
420 if (!a || !b) 425 if (!a || !b)
421 return false; 426 return false;
422 427
423 StyleImage* imageA = (a->*m_getter)(); 428 StyleImage* imageA = (a->*m_getter)();
424 StyleImage* imageB = (b->*m_getter)(); 429 StyleImage* imageB = (b->*m_getter)();
425 return StyleImage::imagesEquivalent(imageA, imageB); 430 return StyleImage::imagesEquivalent(imageA, imageB);
426 } 431 }
427 }; 432 };
428 433
429 class PropertyWrapperColor : public PropertyWrapperGetter<Color> { 434 class PropertyWrapperColor : public PropertyWrapperGetter<StyleColor> {
430 public: 435 public:
431 PropertyWrapperColor(CSSPropertyID prop, Color (RenderStyle::*getter)() cons t, void (RenderStyle::*setter)(const Color&)) 436 PropertyWrapperColor(CSSPropertyID prop, StyleColor (RenderStyle::*getter)() const, void (RenderStyle::*setter)(const StyleColor&))
432 : PropertyWrapperGetter<Color>(prop, getter) 437 : PropertyWrapperGetter<StyleColor>(prop, getter)
433 , m_setter(setter) 438 , m_setter(setter)
434 { 439 {
435 } 440 }
436 441
437 virtual void blend(const AnimationBase* anim, RenderStyle* dst, const Render Style* a, const RenderStyle* b, double progress) const 442 virtual void blend(const AnimationBase* anim, RenderStyle* dst, const Render Style* a, const RenderStyle* b, double progress) const
438 { 443 {
439 (dst->*m_setter)(blendFunc(anim, (a->*PropertyWrapperGetter<Color>::m_ge tter)(), (b->*PropertyWrapperGetter<Color>::m_getter)(), progress)); 444 (dst->*m_setter)(blendFunc(anim, (a->*PropertyWrapperGetter<StyleColor>: :m_getter)(), (b->*PropertyWrapperGetter<StyleColor>::m_getter)(), progress));
440 } 445 }
441 446
442 protected: 447 protected:
443 void (RenderStyle::*m_setter)(const Color&); 448 void (RenderStyle::*m_setter)(const StyleColor&);
444 }; 449 };
445 450
446 class PropertyWrapperAcceleratedOpacity : public PropertyWrapper<float> { 451 class PropertyWrapperAcceleratedOpacity : public PropertyWrapper<float> {
447 public: 452 public:
448 PropertyWrapperAcceleratedOpacity() 453 PropertyWrapperAcceleratedOpacity()
449 : PropertyWrapper<float>(CSSPropertyOpacity, &RenderStyle::opacity, &Ren derStyle::setOpacity) 454 : PropertyWrapper<float>(CSSPropertyOpacity, &RenderStyle::opacity, &Ren derStyle::setOpacity)
450 { 455 {
451 } 456 }
452 457
453 virtual bool animationIsAccelerated() const { return true; } 458 virtual bool animationIsAccelerated() const { return true; }
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 628
624 return newShadowData.release(); 629 return newShadowData.release();
625 } 630 }
626 631
627 const ShadowData* (RenderStyle::*m_getter)() const; 632 const ShadowData* (RenderStyle::*m_getter)() const;
628 void (RenderStyle::*m_setter)(PassOwnPtr<ShadowData>, bool); 633 void (RenderStyle::*m_setter)(PassOwnPtr<ShadowData>, bool);
629 }; 634 };
630 635
631 class PropertyWrapperMaybeInvalidColor : public AnimationPropertyWrapperBase { 636 class PropertyWrapperMaybeInvalidColor : public AnimationPropertyWrapperBase {
632 public: 637 public:
633 PropertyWrapperMaybeInvalidColor(CSSPropertyID prop, Color (RenderStyle::*ge tter)() const, void (RenderStyle::*setter)(const Color&)) 638 PropertyWrapperMaybeInvalidColor(CSSPropertyID prop, StyleColor (RenderStyle ::*getter)() const, void (RenderStyle::*setter)(const StyleColor&))
634 : AnimationPropertyWrapperBase(prop) 639 : AnimationPropertyWrapperBase(prop)
635 , m_getter(getter) 640 , m_getter(getter)
636 , m_setter(setter) 641 , m_setter(setter)
637 { 642 {
638 } 643 }
639 644
640 virtual bool equals(const RenderStyle* a, const RenderStyle* b) const 645 virtual bool equals(const RenderStyle* a, const RenderStyle* b) const
641 { 646 {
642 Color fromColor = (a->*m_getter)(); 647 StyleColor fromColor = (a->*m_getter)();
643 Color toColor = (b->*m_getter)(); 648 StyleColor toColor = (b->*m_getter)();
644 649
645 if (!fromColor.isValid() && !toColor.isValid()) 650 if (!fromColor.isValid() && !toColor.isValid())
646 return true; 651 return true;
647 652
648 if (!fromColor.isValid()) 653 if (!fromColor.isValid())
649 fromColor = a->color(); 654 fromColor = a->color();
650 if (!toColor.isValid()) 655 if (!toColor.isValid())
651 toColor = b->color(); 656 toColor = b->color();
652 657
653 return fromColor == toColor; 658 return fromColor == toColor;
654 } 659 }
655 660
656 virtual void blend(const AnimationBase* anim, RenderStyle* dst, const Render Style* a, const RenderStyle* b, double progress) const 661 virtual void blend(const AnimationBase* anim, RenderStyle* dst, const Render Style* a, const RenderStyle* b, double progress) const
657 { 662 {
658 Color fromColor = (a->*m_getter)(); 663 StyleColor fromColor = (a->*m_getter)();
659 Color toColor = (b->*m_getter)(); 664 StyleColor toColor = (b->*m_getter)();
660 665
661 if (!fromColor.isValid() && !toColor.isValid()) 666 if (!fromColor.isValid() && !toColor.isValid())
662 return; 667 return;
663 668
664 if (!fromColor.isValid()) 669 if (!fromColor.isValid())
665 fromColor = a->color(); 670 fromColor = a->color();
666 if (!toColor.isValid()) 671 if (!toColor.isValid())
667 toColor = b->color(); 672 toColor = b->color();
668 (dst->*m_setter)(blendFunc(anim, fromColor, toColor, progress)); 673 (dst->*m_setter)(blendFunc(anim, fromColor, toColor, progress));
669 } 674 }
670 675
671 private: 676 private:
672 Color (RenderStyle::*m_getter)() const; 677 StyleColor (RenderStyle::*m_getter)() const;
673 void (RenderStyle::*m_setter)(const Color&); 678 void (RenderStyle::*m_setter)(const StyleColor&);
674 }; 679 };
675 680
676 681
677 enum MaybeInvalidColorTag { MaybeInvalidColor }; 682 enum MaybeInvalidColorTag { MaybeInvalidColor };
678 class PropertyWrapperVisitedAffectedColor : public AnimationPropertyWrapperBase { 683 class PropertyWrapperVisitedAffectedColor : public AnimationPropertyWrapperBase {
679 public: 684 public:
680 PropertyWrapperVisitedAffectedColor(CSSPropertyID prop, Color (RenderStyle:: *getter)() const, void (RenderStyle::*setter)(const Color&), 685 PropertyWrapperVisitedAffectedColor(CSSPropertyID prop, StyleColor (RenderSt yle::*getter)() const, void (RenderStyle::*setter)(const StyleColor&),
681 Color (RenderStyle::*visitedGetter)() co nst, void (RenderStyle::*visitedSetter)(const Color&)) 686 StyleColor (RenderStyle::*visitedGetter)() const, void (RenderStyle::*vi sitedSetter)(const StyleColor&))
682 : AnimationPropertyWrapperBase(prop) 687 : AnimationPropertyWrapperBase(prop)
683 , m_wrapper(adoptPtr(new PropertyWrapperColor(prop, getter, setter))) 688 , m_wrapper(adoptPtr(new PropertyWrapperColor(prop, getter, setter)))
684 , m_visitedWrapper(adoptPtr(new PropertyWrapperColor(prop, visitedGetter , visitedSetter))) 689 , m_visitedWrapper(adoptPtr(new PropertyWrapperColor(prop, visitedGetter , visitedSetter)))
685 { 690 {
686 } 691 }
687 PropertyWrapperVisitedAffectedColor(CSSPropertyID prop, MaybeInvalidColorTag , Color (RenderStyle::*getter)() const, void (RenderStyle::*setter)(const Color& ), 692 PropertyWrapperVisitedAffectedColor(CSSPropertyID prop, MaybeInvalidColorTag , StyleColor (RenderStyle::*getter)() const, void (RenderStyle::*setter)(const S tyleColor&),
688 Color (RenderStyle::*visitedGetter)() co nst, void (RenderStyle::*visitedSetter)(const Color&)) 693 StyleColor (RenderStyle::*visitedGetter)() const, void (RenderStyle::*vi sitedSetter)(const StyleColor&))
689 : AnimationPropertyWrapperBase(prop) 694 : AnimationPropertyWrapperBase(prop)
690 , m_wrapper(adoptPtr(new PropertyWrapperMaybeInvalidColor(prop, getter, setter))) 695 , m_wrapper(adoptPtr(new PropertyWrapperMaybeInvalidColor(prop, getter, setter)))
691 , m_visitedWrapper(adoptPtr(new PropertyWrapperMaybeInvalidColor(prop, v isitedGetter, visitedSetter))) 696 , m_visitedWrapper(adoptPtr(new PropertyWrapperMaybeInvalidColor(prop, v isitedGetter, visitedSetter)))
692 { 697 {
693 } 698 }
694 virtual bool equals(const RenderStyle* a, const RenderStyle* b) const 699 virtual bool equals(const RenderStyle* a, const RenderStyle* b) const
695 { 700 {
696 return m_wrapper->equals(a, b) && m_visitedWrapper->equals(a, b); 701 return m_wrapper->equals(a, b) && m_visitedWrapper->equals(a, b);
697 } 702 }
698 virtual void blend(const AnimationBase* anim, RenderStyle* dst, const Render Style* a, const RenderStyle* b, double progress) const 703 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
930 virtual void blend(const AnimationBase* anim, RenderStyle* dst, const Render Style* a, const RenderStyle* b, double progress) const 935 virtual void blend(const AnimationBase* anim, RenderStyle* dst, const Render Style* a, const RenderStyle* b, double progress) const
931 { 936 {
932 dst->setFlexBasis(blendFunc(anim, a->flexBasis(), b->flexBasis(), progre ss)); 937 dst->setFlexBasis(blendFunc(anim, a->flexBasis(), b->flexBasis(), progre ss));
933 dst->setFlexGrow(blendFunc(anim, a->flexGrow(), b->flexGrow(), progress) ); 938 dst->setFlexGrow(blendFunc(anim, a->flexGrow(), b->flexGrow(), progress) );
934 dst->setFlexShrink(blendFunc(anim, a->flexShrink(), b->flexShrink(), pro gress)); 939 dst->setFlexShrink(blendFunc(anim, a->flexShrink(), b->flexShrink(), pro gress));
935 } 940 }
936 }; 941 };
937 942
938 class PropertyWrapperSVGPaint : public AnimationPropertyWrapperBase { 943 class PropertyWrapperSVGPaint : public AnimationPropertyWrapperBase {
939 public: 944 public:
940 PropertyWrapperSVGPaint(CSSPropertyID prop, const SVGPaint::SVGPaintType& (R enderStyle::*paintTypeGetter)() const, Color (RenderStyle::*getter)() const, voi d (RenderStyle::*setter)(const Color&)) 945 PropertyWrapperSVGPaint(CSSPropertyID prop, const SVGPaint::SVGPaintType& (R enderStyle::*paintTypeGetter)() const, StyleColor (RenderStyle::*getter)() const , void (RenderStyle::*setter)(const StyleColor&))
941 : AnimationPropertyWrapperBase(prop) 946 : AnimationPropertyWrapperBase(prop)
942 , m_paintTypeGetter(paintTypeGetter) 947 , m_paintTypeGetter(paintTypeGetter)
943 , m_getter(getter) 948 , m_getter(getter)
944 , m_setter(setter) 949 , m_setter(setter)
945 { 950 {
946 } 951 }
947 952
948 virtual bool equals(const RenderStyle* a, const RenderStyle* b) const 953 virtual bool equals(const RenderStyle* a, const RenderStyle* b) const
949 { 954 {
950 if ((a->*m_paintTypeGetter)() != (b->*m_paintTypeGetter)()) 955 if ((a->*m_paintTypeGetter)() != (b->*m_paintTypeGetter)())
951 return false; 956 return false;
952 957
953 // We only support animations between SVGPaints that are pure Color valu es. 958 // We only support animations between SVGPaints that are pure StyleColor values.
954 // For everything else we must return true for this method, otherwise 959 // For everything else we must return true for this method, otherwise
955 // we will try to animate between values forever. 960 // we will try to animate between values forever.
956 if ((a->*m_paintTypeGetter)() == SVGPaint::SVG_PAINTTYPE_RGBCOLOR) { 961 if ((a->*m_paintTypeGetter)() == SVGPaint::SVG_PAINTTYPE_RGBCOLOR) {
957 Color fromColor = (a->*m_getter)(); 962 StyleColor fromColor = (a->*m_getter)();
958 Color toColor = (b->*m_getter)(); 963 StyleColor toColor = (b->*m_getter)();
959 964
960 if (!fromColor.isValid() && !toColor.isValid()) 965 if (!fromColor.isValid() && !toColor.isValid())
961 return true; 966 return true;
962 967
963 if (!fromColor.isValid()) 968 if (!fromColor.isValid())
964 fromColor = Color(); 969 fromColor = StyleColor();
965 if (!toColor.isValid()) 970 if (!toColor.isValid())
966 toColor = Color(); 971 toColor = StyleColor();
967 972
968 return fromColor == toColor; 973 return fromColor == toColor;
969 } 974 }
970 return true; 975 return true;
971 } 976 }
972 977
973 virtual void blend(const AnimationBase* anim, RenderStyle* dst, const Render Style* a, const RenderStyle* b, double progress) const 978 virtual void blend(const AnimationBase* anim, RenderStyle* dst, const Render Style* a, const RenderStyle* b, double progress) const
974 { 979 {
975 if ((a->*m_paintTypeGetter)() != SVGPaint::SVG_PAINTTYPE_RGBCOLOR 980 if ((a->*m_paintTypeGetter)() != SVGPaint::SVG_PAINTTYPE_RGBCOLOR
976 || (b->*m_paintTypeGetter)() != SVGPaint::SVG_PAINTTYPE_RGBCOLOR) 981 || (b->*m_paintTypeGetter)() != SVGPaint::SVG_PAINTTYPE_RGBCOLOR)
977 return; 982 return;
978 983
979 Color fromColor = (a->*m_getter)(); 984 StyleColor fromColor = (a->*m_getter)();
980 Color toColor = (b->*m_getter)(); 985 StyleColor toColor = (b->*m_getter)();
981 986
982 if (!fromColor.isValid() && !toColor.isValid()) 987 if (!fromColor.isValid() && !toColor.isValid())
983 return; 988 return;
984 989
985 if (!fromColor.isValid()) 990 if (!fromColor.isValid())
986 fromColor = Color(); 991 fromColor = StyleColor();
987 if (!toColor.isValid()) 992 if (!toColor.isValid())
988 toColor = Color(); 993 toColor = StyleColor();
989 (dst->*m_setter)(blendFunc(anim, fromColor, toColor, progress)); 994 (dst->*m_setter)(blendFunc(anim, fromColor, toColor, progress));
990 } 995 }
991 996
992 private: 997 private:
993 const SVGPaint::SVGPaintType& (RenderStyle::*m_paintTypeGetter)() const; 998 const SVGPaint::SVGPaintType& (RenderStyle::*m_paintTypeGetter)() const;
994 Color (RenderStyle::*m_getter)() const; 999 StyleColor (RenderStyle::*m_getter)() const;
995 void (RenderStyle::*m_setter)(const Color&); 1000 void (RenderStyle::*m_setter)(const StyleColor&);
996 }; 1001 };
997 1002
998 static void addShorthandProperties() 1003 static void addShorthandProperties()
999 { 1004 {
1000 static const CSSPropertyID animatableShorthandProperties[] = { 1005 static const CSSPropertyID animatableShorthandProperties[] = {
1001 CSSPropertyBackground, // for background-color, background-position, bac kground-image 1006 CSSPropertyBackground, // for background-color, background-position, bac kground-image
1002 CSSPropertyBackgroundPosition, 1007 CSSPropertyBackgroundPosition,
1003 CSSPropertyFont, // for font-size, font-weight 1008 CSSPropertyFont, // for font-size, font-weight
1004 CSSPropertyWebkitMask, // for mask-position 1009 CSSPropertyWebkitMask, // for mask-position
1005 CSSPropertyWebkitMaskPosition, 1010 CSSPropertyWebkitMaskPosition,
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
1239 } 1244 }
1240 1245
1241 int CSSPropertyAnimation::getNumProperties() 1246 int CSSPropertyAnimation::getNumProperties()
1242 { 1247 {
1243 ensurePropertyMap(); 1248 ensurePropertyMap();
1244 1249
1245 return gPropertyWrappers->size(); 1250 return gPropertyWrappers->size();
1246 } 1251 }
1247 1252
1248 } 1253 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698