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

Side by Side Diff: Source/core/animation/AnimatableLength.h

Issue 25082007: Web Animations CSS: Split AnimatableNumber into AnimatableDouble and AnimatableLength (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebased onto virtual enum change Created 7 years, 2 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) 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 10 matching lines...) Expand all
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #ifndef AnimatableNumber_h 31 #ifndef AnimatableLength_h
32 #define AnimatableNumber_h 32 #define AnimatableLength_h
33 33
34 #include "core/animation/AnimatableValue.h" 34 #include "core/animation/AnimatableValue.h"
35 #include "core/css/CSSCalculationValue.h" 35 #include "core/css/CSSCalculationValue.h"
36 #include "core/css/CSSPrimitiveValue.h" 36 #include "core/css/CSSPrimitiveValue.h"
37 #include "core/platform/Length.h"
37 38
38 namespace WebCore { 39 namespace WebCore {
39 40
40 enum NumberRange { 41 enum NumberRange {
41 AllValues, 42 AllValues,
42 NonNegativeValues, 43 NonNegativeValues,
43 }; 44 };
44 45
45 // Handles animation of CSSPrimitiveValues that can be represented by doubles in cluding CSSCalcValue. 46 class AnimatableLength : public AnimatableValue {
46 // See primitiveUnitToNumberType() for the list of supported units (with the exc eption of calc).
47 // If created from a CSSPrimitiveValue this class will cache it to be returned i n toCSSValue().
48 class AnimatableNumber : public AnimatableValue {
49 public: 47 public:
50 enum NumberUnitType { 48 enum NumberUnitType {
51 UnitTypeNumber,
52 UnitTypeLength, 49 UnitTypeLength,
53 UnitTypeFontSize, 50 UnitTypeFontSize,
54 UnitTypeFontXSize, 51 UnitTypeFontXSize,
55 UnitTypeRootFontSize, 52 UnitTypeRootFontSize,
56 UnitTypePercentage, 53 UnitTypePercentage,
57 UnitTypeViewportWidth, 54 UnitTypeViewportWidth,
58 UnitTypeViewportHeight, 55 UnitTypeViewportHeight,
59 UnitTypeViewportMin, 56 UnitTypeViewportMin,
60 UnitTypeViewportMax, 57 UnitTypeViewportMax,
61 UnitTypeTime,
62 UnitTypeAngle,
63 UnitTypeFrequency,
64 UnitTypeResolution,
65 UnitTypeInvalid, 58 UnitTypeInvalid,
66 }; 59 };
67 60
68 virtual ~AnimatableNumber() { } 61 virtual ~AnimatableLength() { }
69 static bool canCreateFrom(const CSSValue*); 62 static bool canCreateFrom(const CSSValue*);
70 static PassRefPtr<AnimatableNumber> create(CSSValue*); 63 static PassRefPtr<AnimatableLength> create(CSSValue*);
71 static PassRefPtr<AnimatableNumber> create(double number, NumberUnitType uni tType, CSSPrimitiveValue* cssPrimitiveValue = 0) 64 static PassRefPtr<AnimatableLength> create(double number, NumberUnitType uni tType, CSSPrimitiveValue* cssPrimitiveValue = 0)
72 { 65 {
73 return adoptRef(new AnimatableNumber(number, unitType, cssPrimitiveValue )); 66 return adoptRef(new AnimatableLength(number, unitType, cssPrimitiveValue ));
74 } 67 }
75 PassRefPtr<CSSValue> toCSSValue(NumberRange = AllValues) const; 68 PassRefPtr<CSSValue> toCSSValue(NumberRange = AllValues) const;
76 double toDouble() const;
77 Length toLength(const RenderStyle* currStyle, const RenderStyle* rootStyle, double zoom, NumberRange = AllValues) const; 69 Length toLength(const RenderStyle* currStyle, const RenderStyle* rootStyle, double zoom, NumberRange = AllValues) const;
78 70
79 protected: 71 protected:
80 virtual PassRefPtr<AnimatableValue> interpolateTo(const AnimatableValue*, do uble fraction) const OVERRIDE; 72 virtual PassRefPtr<AnimatableValue> interpolateTo(const AnimatableValue*, do uble fraction) const OVERRIDE;
81 virtual PassRefPtr<AnimatableValue> addWith(const AnimatableValue*) const OV ERRIDE; 73 virtual PassRefPtr<AnimatableValue> addWith(const AnimatableValue*) const OV ERRIDE;
82 74
83 private: 75 private:
84 AnimatableNumber(double number, NumberUnitType unitType, CSSPrimitiveValue* cssPrimitiveValue) 76 AnimatableLength(double number, NumberUnitType unitType, CSSPrimitiveValue* cssPrimitiveValue)
85 : m_number(number) 77 : m_isCalc(false)
78 , m_number(number)
86 , m_unitType(unitType) 79 , m_unitType(unitType)
87 , m_isCalc(false)
88 , m_cachedCSSPrimitiveValue(cssPrimitiveValue) 80 , m_cachedCSSPrimitiveValue(cssPrimitiveValue)
89 { 81 {
90 ASSERT(m_unitType != UnitTypeInvalid);
Timothy Loh 2013/09/30 23:27:59 Why is this line removed?
alancutter (OOO until 2018) 2013/10/01 09:32:24 Mistake. Line put back.
91 } 82 }
92 AnimatableNumber(PassRefPtr<CSSCalcExpressionNode> calcExpression, CSSPrimit iveValue* cssPrimitiveValue) 83 AnimatableLength(PassRefPtr<CSSCalcExpressionNode> calcExpression, CSSPrimit iveValue* cssPrimitiveValue)
93 : m_isCalc(true) 84 : m_isCalc(true)
94 , m_calcExpression(calcExpression) 85 , m_calcExpression(calcExpression)
95 , m_cachedCSSPrimitiveValue(cssPrimitiveValue) 86 , m_cachedCSSPrimitiveValue(cssPrimitiveValue)
96 { 87 {
97 ASSERT(m_calcExpression); 88 ASSERT(m_calcExpression);
98 } 89 }
99 virtual AnimatableType type() const OVERRIDE { return TypeNumber; } 90 virtual AnimatableType type() const OVERRIDE { return TypeLength; }
100 91
101 static PassRefPtr<AnimatableNumber> create(PassRefPtr<CSSCalcExpressionNode> calcExpression, CSSPrimitiveValue* cssPrimitiveValue = 0) 92 static PassRefPtr<AnimatableLength> create(PassRefPtr<CSSCalcExpressionNode> calcExpression, CSSPrimitiveValue* cssPrimitiveValue = 0)
102 { 93 {
103 return adoptRef(new AnimatableNumber(calcExpression, cssPrimitiveValue)) ; 94 return adoptRef(new AnimatableLength(calcExpression, cssPrimitiveValue)) ;
104 } 95 }
105 static PassRefPtr<AnimatableNumber> create(const AnimatableNumber* leftAdden d, const AnimatableNumber* rightAddend); 96 static PassRefPtr<AnimatableLength> create(const AnimatableLength* leftAdden d, const AnimatableLength* rightAddend);
106 97
107 PassRefPtr<CSSPrimitiveValue> toCSSPrimitiveValue(NumberRange) const; 98 PassRefPtr<CSSPrimitiveValue> toCSSPrimitiveValue(NumberRange) const;
108 PassRefPtr<CSSCalcExpressionNode> toCSSCalcExpressionNode() const; 99 PassRefPtr<CSSCalcExpressionNode> toCSSCalcExpressionNode() const;
109 100
110 PassRefPtr<AnimatableNumber> scale(double) const; 101 PassRefPtr<AnimatableLength> scale(double) const;
111 double clampedNumber(NumberRange range) const 102 double clampedNumber(NumberRange range) const
112 { 103 {
113 ASSERT(!m_isCalc); 104 ASSERT(!m_isCalc);
114 return (range == NonNegativeValues && m_number <= 0) ? 0 : m_number; 105 return (range == NonNegativeValues && m_number <= 0) ? 0 : m_number;
115 } 106 }
116 static NumberUnitType primitiveUnitToNumberType(unsigned short primitiveUnit ); 107 static NumberUnitType primitiveUnitToNumberType(unsigned short primitiveUnit );
117 static unsigned short numberTypeToPrimitiveUnit(NumberUnitType numberType); 108 static unsigned short numberTypeToPrimitiveUnit(NumberUnitType numberType);
118 109
110 bool m_isCalc;
111
119 double m_number; 112 double m_number;
120 NumberUnitType m_unitType; 113 NumberUnitType m_unitType;
121 114
122 bool m_isCalc;
123 RefPtr<CSSCalcExpressionNode> m_calcExpression; 115 RefPtr<CSSCalcExpressionNode> m_calcExpression;
124 116
125 mutable RefPtr<CSSPrimitiveValue> m_cachedCSSPrimitiveValue; 117 mutable RefPtr<CSSPrimitiveValue> m_cachedCSSPrimitiveValue;
126 }; 118 };
127 119
128 inline const AnimatableNumber* toAnimatableNumber(const AnimatableValue* value) 120 inline const AnimatableLength* toAnimatableLength(const AnimatableValue* value)
129 { 121 {
130 ASSERT_WITH_SECURITY_IMPLICATION(value && value->isNumber()); 122 ASSERT_WITH_SECURITY_IMPLICATION(value && value->isLength());
131 return static_cast<const AnimatableNumber*>(value); 123 return static_cast<const AnimatableLength*>(value);
132 } 124 }
133 125
134 } // namespace WebCore 126 } // namespace WebCore
135 127
136 #endif // AnimatableNumber_h 128 #endif // AnimatableLength_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698