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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 UnitTypeViewportMax, | 61 UnitTypeViewportMax, |
62 }; | 62 }; |
63 | 63 |
64 virtual ~AnimatableLength() { } | 64 virtual ~AnimatableLength() { } |
65 static bool canCreateFrom(const CSSValue*); | 65 static bool canCreateFrom(const CSSValue*); |
66 static PassRefPtr<AnimatableLength> create(CSSValue*); | 66 static PassRefPtr<AnimatableLength> create(CSSValue*); |
67 static PassRefPtr<AnimatableLength> create(double number, NumberUnitType uni
tType, CSSPrimitiveValue* cssPrimitiveValue = 0) | 67 static PassRefPtr<AnimatableLength> create(double number, NumberUnitType uni
tType, CSSPrimitiveValue* cssPrimitiveValue = 0) |
68 { | 68 { |
69 return adoptRef(new AnimatableLength(number, unitType, cssPrimitiveValue
)); | 69 return adoptRef(new AnimatableLength(number, unitType, cssPrimitiveValue
)); |
70 } | 70 } |
71 static PassRefPtr<AnimatableLength> create(PassRefPtr<CSSCalcExpressionNode>
calcExpression, CSSPrimitiveValue* cssPrimitiveValue = 0) | 71 static PassRefPtr<AnimatableLength> create(PassRefPtrWillBeRawPtr<CSSCalcExp
ressionNode> calcExpression, CSSPrimitiveValue* cssPrimitiveValue = 0) |
72 { | 72 { |
73 return adoptRef(new AnimatableLength(calcExpression, cssPrimitiveValue))
; | 73 return adoptRef(new AnimatableLength(calcExpression, cssPrimitiveValue))
; |
74 } | 74 } |
75 PassRefPtr<CSSValue> toCSSValue(NumberRange = AllValues) const; | 75 PassRefPtr<CSSValue> toCSSValue(NumberRange = AllValues) const; |
76 Length toLength(const CSSToLengthConversionData&, NumberRange = AllValues) c
onst; | 76 Length toLength(const CSSToLengthConversionData&, NumberRange = AllValues) c
onst; |
77 | 77 |
78 protected: | 78 protected: |
79 virtual PassRefPtr<AnimatableValue> interpolateTo(const AnimatableValue*, do
uble fraction) const OVERRIDE; | 79 virtual PassRefPtr<AnimatableValue> interpolateTo(const AnimatableValue*, do
uble fraction) const OVERRIDE; |
80 virtual PassRefPtr<AnimatableValue> addWith(const AnimatableValue*) const OV
ERRIDE; | 80 virtual PassRefPtr<AnimatableValue> addWith(const AnimatableValue*) const OV
ERRIDE; |
81 virtual bool usesDefaultInterpolationWith(const AnimatableValue*) const OVER
RIDE; | 81 virtual bool usesDefaultInterpolationWith(const AnimatableValue*) const OVER
RIDE; |
82 | 82 |
83 private: | 83 private: |
84 AnimatableLength(double number, NumberUnitType unitType, CSSPrimitiveValue*
cssPrimitiveValue) | 84 AnimatableLength(double number, NumberUnitType unitType, CSSPrimitiveValue*
cssPrimitiveValue) |
85 : m_number(number) | 85 : m_number(number) |
86 , m_unitType(unitType) | 86 , m_unitType(unitType) |
87 , m_cachedCSSPrimitiveValue(cssPrimitiveValue) | 87 , m_cachedCSSPrimitiveValue(cssPrimitiveValue) |
88 { | 88 { |
89 ASSERT(m_unitType != UnitTypeCalc); | 89 ASSERT(m_unitType != UnitTypeCalc); |
90 } | 90 } |
91 AnimatableLength(PassRefPtr<CSSCalcExpressionNode> calcExpression, CSSPrimit
iveValue* cssPrimitiveValue) | 91 AnimatableLength(PassRefPtrWillBeRawPtr<CSSCalcExpressionNode> calcExpressio
n, CSSPrimitiveValue* cssPrimitiveValue) |
92 : m_unitType(UnitTypeCalc) | 92 : m_unitType(UnitTypeCalc) |
93 , m_calcExpression(calcExpression) | 93 , m_calcExpression(calcExpression) |
94 , m_cachedCSSPrimitiveValue(cssPrimitiveValue) | 94 , m_cachedCSSPrimitiveValue(cssPrimitiveValue) |
95 { | 95 { |
96 ASSERT(m_calcExpression); | 96 ASSERT(m_calcExpression); |
97 } | 97 } |
98 virtual AnimatableType type() const OVERRIDE { return TypeLength; } | 98 virtual AnimatableType type() const OVERRIDE { return TypeLength; } |
99 virtual bool equalTo(const AnimatableValue*) const OVERRIDE; | 99 virtual bool equalTo(const AnimatableValue*) const OVERRIDE; |
100 | 100 |
101 bool isCalc() const | 101 bool isCalc() const |
102 { | 102 { |
103 return m_unitType == UnitTypeCalc; | 103 return m_unitType == UnitTypeCalc; |
104 } | 104 } |
105 | 105 |
106 bool isViewportUnit() const | 106 bool isViewportUnit() const |
107 { | 107 { |
108 return m_unitType == UnitTypeViewportWidth || m_unitType == UnitTypeView
portHeight || m_unitType == UnitTypeViewportMin || m_unitType == UnitTypeViewpor
tMax; | 108 return m_unitType == UnitTypeViewportWidth || m_unitType == UnitTypeView
portHeight || m_unitType == UnitTypeViewportMin || m_unitType == UnitTypeViewpor
tMax; |
109 } | 109 } |
110 | 110 |
111 static PassRefPtr<AnimatableLength> create(const AnimatableLength* leftAdden
d, const AnimatableLength* rightAddend) | 111 static PassRefPtr<AnimatableLength> create(const AnimatableLength* leftAdden
d, const AnimatableLength* rightAddend) |
112 { | 112 { |
113 ASSERT(leftAddend && rightAddend); | 113 ASSERT(leftAddend && rightAddend); |
114 return create(CSSCalcValue::createExpressionNode(leftAddend->toCSSCalcEx
pressionNode(), rightAddend->toCSSCalcExpressionNode(), CalcAdd)); | 114 return create(CSSCalcValue::createExpressionNode(leftAddend->toCSSCalcEx
pressionNode(), rightAddend->toCSSCalcExpressionNode(), CalcAdd)); |
115 } | 115 } |
116 | 116 |
117 PassRefPtrWillBeRawPtr<CSSPrimitiveValue> toCSSPrimitiveValue(NumberRange) c
onst; | 117 PassRefPtrWillBeRawPtr<CSSPrimitiveValue> toCSSPrimitiveValue(NumberRange) c
onst; |
118 PassRefPtr<CSSCalcExpressionNode> toCSSCalcExpressionNode() const; | 118 PassRefPtrWillBeRawPtr<CSSCalcExpressionNode> toCSSCalcExpressionNode() cons
t; |
119 | 119 |
120 PassRefPtr<AnimatableLength> scale(double) const; | 120 PassRefPtr<AnimatableLength> scale(double) const; |
121 double clampedNumber(NumberRange range) const | 121 double clampedNumber(NumberRange range) const |
122 { | 122 { |
123 ASSERT(!isCalc()); | 123 ASSERT(!isCalc()); |
124 return (range == NonNegativeValues && m_number <= 0) ? 0 : m_number; | 124 return (range == NonNegativeValues && m_number <= 0) ? 0 : m_number; |
125 } | 125 } |
126 | 126 |
127 // Returns true and populates numberType, if primitiveUnit is a primitive le
ngth unit. Otherwise, returns false. | 127 // Returns true and populates numberType, if primitiveUnit is a primitive le
ngth unit. Otherwise, returns false. |
128 static bool primitiveUnitToNumberType(unsigned short primitiveUnit, NumberUn
itType& numberType); | 128 static bool primitiveUnitToNumberType(unsigned short primitiveUnit, NumberUn
itType& numberType); |
(...skipping 17 matching lines...) Expand all Loading... |
146 return length->m_unitType; | 146 return length->m_unitType; |
147 if (length->isUnitlessZero()) | 147 if (length->isUnitlessZero()) |
148 return m_unitType; | 148 return m_unitType; |
149 | 149 |
150 return UnitTypeCalc; | 150 return UnitTypeCalc; |
151 } | 151 } |
152 | 152 |
153 double m_number; | 153 double m_number; |
154 const NumberUnitType m_unitType; | 154 const NumberUnitType m_unitType; |
155 | 155 |
156 RefPtr<CSSCalcExpressionNode> m_calcExpression; | 156 RefPtrWillBePersistent<CSSCalcExpressionNode> m_calcExpression; |
157 | 157 |
158 mutable RefPtrWillBePersistent<CSSPrimitiveValue> m_cachedCSSPrimitiveValue; | 158 mutable RefPtrWillBePersistent<CSSPrimitiveValue> m_cachedCSSPrimitiveValue; |
159 | 159 |
160 friend class AnimationAnimatableLengthTest; | 160 friend class AnimationAnimatableLengthTest; |
161 }; | 161 }; |
162 | 162 |
163 DEFINE_ANIMATABLE_VALUE_TYPE_CASTS(AnimatableLength, isLength()); | 163 DEFINE_ANIMATABLE_VALUE_TYPE_CASTS(AnimatableLength, isLength()); |
164 | 164 |
165 } // namespace WebCore | 165 } // namespace WebCore |
166 | 166 |
167 #endif // AnimatableLength_h | 167 #endif // AnimatableLength_h |
OLD | NEW |