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 10 matching lines...) Expand all Loading... |
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 // Handles animation of CSS length and percentage values including CSS calc. |
46 // See primitiveUnitToNumberType() for the list of supported units (with the exc
eption of calc). | 47 // 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 // If created from a CSSPrimitiveValue this class will cache it to be returned i
n toCSSValue(). |
48 class AnimatableNumber : public AnimatableValue { | 49 class AnimatableLength : public AnimatableValue { |
49 public: | 50 public: |
50 enum NumberUnitType { | 51 enum NumberUnitType { |
51 UnitTypeNumber, | 52 UnitTypePixels, |
52 UnitTypeLength, | 53 UnitTypePercentage, |
53 UnitTypeFontSize, | 54 UnitTypeFontSize, |
54 UnitTypeFontXSize, | 55 UnitTypeFontXSize, |
55 UnitTypeRootFontSize, | 56 UnitTypeRootFontSize, |
56 UnitTypePercentage, | |
57 UnitTypeViewportWidth, | 57 UnitTypeViewportWidth, |
58 UnitTypeViewportHeight, | 58 UnitTypeViewportHeight, |
59 UnitTypeViewportMin, | 59 UnitTypeViewportMin, |
60 UnitTypeViewportMax, | 60 UnitTypeViewportMax, |
61 UnitTypeTime, | |
62 UnitTypeAngle, | |
63 UnitTypeFrequency, | |
64 UnitTypeResolution, | |
65 UnitTypeInvalid, | 61 UnitTypeInvalid, |
66 }; | 62 }; |
67 | 63 |
68 virtual ~AnimatableNumber() { } | 64 virtual ~AnimatableLength() { } |
69 static bool canCreateFrom(const CSSValue*); | 65 static bool canCreateFrom(const CSSValue*); |
70 static PassRefPtr<AnimatableNumber> create(CSSValue*); | 66 static PassRefPtr<AnimatableLength> create(CSSValue*); |
71 static PassRefPtr<AnimatableNumber> create(double number, NumberUnitType uni
tType, CSSPrimitiveValue* cssPrimitiveValue = 0) | 67 static PassRefPtr<AnimatableLength> create(double number, NumberUnitType uni
tType, CSSPrimitiveValue* cssPrimitiveValue = 0) |
72 { | 68 { |
73 return adoptRef(new AnimatableNumber(number, unitType, cssPrimitiveValue
)); | 69 return adoptRef(new AnimatableLength(number, unitType, cssPrimitiveValue
)); |
74 } | 70 } |
75 PassRefPtr<CSSValue> toCSSValue(NumberRange = AllValues) const; | 71 PassRefPtr<CSSValue> toCSSValue(NumberRange = AllValues) const; |
76 double toDouble() const; | |
77 Length toLength(const RenderStyle* currStyle, const RenderStyle* rootStyle,
double zoom, NumberRange = AllValues) const; | 72 Length toLength(const RenderStyle* currStyle, const RenderStyle* rootStyle,
double zoom, NumberRange = AllValues) const; |
78 | 73 |
79 protected: | 74 protected: |
80 virtual PassRefPtr<AnimatableValue> interpolateTo(const AnimatableValue*, do
uble fraction) const OVERRIDE; | 75 virtual PassRefPtr<AnimatableValue> interpolateTo(const AnimatableValue*, do
uble fraction) const OVERRIDE; |
81 virtual PassRefPtr<AnimatableValue> addWith(const AnimatableValue*) const OV
ERRIDE; | 76 virtual PassRefPtr<AnimatableValue> addWith(const AnimatableValue*) const OV
ERRIDE; |
82 | 77 |
83 private: | 78 private: |
84 AnimatableNumber(double number, NumberUnitType unitType, CSSPrimitiveValue*
cssPrimitiveValue) | 79 AnimatableLength(double number, NumberUnitType unitType, CSSPrimitiveValue*
cssPrimitiveValue) |
85 : m_number(number) | 80 : m_isCalc(false) |
| 81 , m_number(number) |
86 , m_unitType(unitType) | 82 , m_unitType(unitType) |
87 , m_isCalc(false) | |
88 , m_cachedCSSPrimitiveValue(cssPrimitiveValue) | 83 , m_cachedCSSPrimitiveValue(cssPrimitiveValue) |
89 { | 84 { |
90 ASSERT(m_unitType != UnitTypeInvalid); | 85 ASSERT(m_unitType != UnitTypeInvalid); |
91 } | 86 } |
92 AnimatableNumber(PassRefPtr<CSSCalcExpressionNode> calcExpression, CSSPrimit
iveValue* cssPrimitiveValue) | 87 AnimatableLength(PassRefPtr<CSSCalcExpressionNode> calcExpression, CSSPrimit
iveValue* cssPrimitiveValue) |
93 : m_isCalc(true) | 88 : m_isCalc(true) |
94 , m_calcExpression(calcExpression) | 89 , m_calcExpression(calcExpression) |
95 , m_cachedCSSPrimitiveValue(cssPrimitiveValue) | 90 , m_cachedCSSPrimitiveValue(cssPrimitiveValue) |
96 { | 91 { |
97 ASSERT(m_calcExpression); | 92 ASSERT(m_calcExpression); |
98 } | 93 } |
99 virtual AnimatableType type() const OVERRIDE { return TypeNumber; } | 94 virtual AnimatableType type() const OVERRIDE { return TypeLength; } |
100 | 95 |
101 static PassRefPtr<AnimatableNumber> create(PassRefPtr<CSSCalcExpressionNode>
calcExpression, CSSPrimitiveValue* cssPrimitiveValue = 0) | 96 static PassRefPtr<AnimatableLength> create(PassRefPtr<CSSCalcExpressionNode>
calcExpression, CSSPrimitiveValue* cssPrimitiveValue = 0) |
102 { | 97 { |
103 return adoptRef(new AnimatableNumber(calcExpression, cssPrimitiveValue))
; | 98 return adoptRef(new AnimatableLength(calcExpression, cssPrimitiveValue))
; |
104 } | 99 } |
105 static PassRefPtr<AnimatableNumber> create(const AnimatableNumber* leftAdden
d, const AnimatableNumber* rightAddend); | 100 static PassRefPtr<AnimatableLength> create(const AnimatableLength* leftAdden
d, const AnimatableLength* rightAddend); |
106 | 101 |
107 PassRefPtr<CSSPrimitiveValue> toCSSPrimitiveValue(NumberRange) const; | 102 PassRefPtr<CSSPrimitiveValue> toCSSPrimitiveValue(NumberRange) const; |
108 PassRefPtr<CSSCalcExpressionNode> toCSSCalcExpressionNode() const; | 103 PassRefPtr<CSSCalcExpressionNode> toCSSCalcExpressionNode() const; |
109 | 104 |
110 PassRefPtr<AnimatableNumber> scale(double) const; | 105 PassRefPtr<AnimatableLength> scale(double) const; |
111 double clampedNumber(NumberRange range) const | 106 double clampedNumber(NumberRange range) const |
112 { | 107 { |
113 ASSERT(!m_isCalc); | 108 ASSERT(!m_isCalc); |
114 return (range == NonNegativeValues && m_number <= 0) ? 0 : m_number; | 109 return (range == NonNegativeValues && m_number <= 0) ? 0 : m_number; |
115 } | 110 } |
116 static NumberUnitType primitiveUnitToNumberType(unsigned short primitiveUnit
); | 111 static NumberUnitType primitiveUnitToNumberType(unsigned short primitiveUnit
); |
117 static unsigned short numberTypeToPrimitiveUnit(NumberUnitType numberType); | 112 static unsigned short numberTypeToPrimitiveUnit(NumberUnitType numberType); |
118 | 113 |
| 114 bool m_isCalc; |
| 115 |
119 double m_number; | 116 double m_number; |
120 NumberUnitType m_unitType; | 117 NumberUnitType m_unitType; |
121 | 118 |
122 bool m_isCalc; | |
123 RefPtr<CSSCalcExpressionNode> m_calcExpression; | 119 RefPtr<CSSCalcExpressionNode> m_calcExpression; |
124 | 120 |
125 mutable RefPtr<CSSPrimitiveValue> m_cachedCSSPrimitiveValue; | 121 mutable RefPtr<CSSPrimitiveValue> m_cachedCSSPrimitiveValue; |
126 }; | 122 }; |
127 | 123 |
128 inline const AnimatableNumber* toAnimatableNumber(const AnimatableValue* value) | 124 inline const AnimatableLength* toAnimatableLength(const AnimatableValue* value) |
129 { | 125 { |
130 ASSERT_WITH_SECURITY_IMPLICATION(value && value->isNumber()); | 126 ASSERT_WITH_SECURITY_IMPLICATION(value && value->isLength()); |
131 return static_cast<const AnimatableNumber*>(value); | 127 return static_cast<const AnimatableLength*>(value); |
132 } | 128 } |
133 | 129 |
134 } // namespace WebCore | 130 } // namespace WebCore |
135 | 131 |
136 #endif // AnimatableNumber_h | 132 #endif // AnimatableLength_h |
OLD | NEW |