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

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

Issue 25082007: Web Animations CSS: Split AnimatableNumber into AnimatableDouble and AnimatableLength (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Review changes 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
(Empty)
1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
29 */
30
31 #ifndef AnimatableNumber_h
32 #define AnimatableNumber_h
33
34 #include "core/animation/AnimatableValue.h"
35 #include "core/css/CSSCalculationValue.h"
36 #include "core/css/CSSPrimitiveValue.h"
37
38 namespace WebCore {
39
40 enum NumberRange {
41 AllValues,
42 NonNegativeValues,
43 };
44
45 // Handles animation of CSSPrimitiveValues that can be represented by doubles in cluding CSSCalcValue.
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:
50 enum NumberUnitType {
51 UnitTypeNumber,
52 UnitTypeLength,
53 UnitTypeFontSize,
54 UnitTypeFontXSize,
55 UnitTypeRootFontSize,
56 UnitTypePercentage,
57 UnitTypeViewportWidth,
58 UnitTypeViewportHeight,
59 UnitTypeViewportMin,
60 UnitTypeViewportMax,
61 UnitTypeTime,
62 UnitTypeAngle,
63 UnitTypeFrequency,
64 UnitTypeResolution,
65 UnitTypeInvalid,
66 };
67
68 virtual ~AnimatableNumber() { }
69 static bool canCreateFrom(const CSSValue*);
70 static PassRefPtr<AnimatableNumber> create(CSSValue*);
71 static PassRefPtr<AnimatableNumber> create(double number, NumberUnitType uni tType, CSSPrimitiveValue* cssPrimitiveValue = 0)
72 {
73 return adoptRef(new AnimatableNumber(number, unitType, cssPrimitiveValue ));
74 }
75 PassRefPtr<CSSValue> toCSSValue(NumberRange = AllValues) const;
76 double toDouble() const;
77 Length toLength(const RenderStyle* currStyle, const RenderStyle* rootStyle, double zoom, NumberRange = AllValues) const;
78
79 protected:
80 virtual PassRefPtr<AnimatableValue> interpolateTo(const AnimatableValue*, do uble fraction) const OVERRIDE;
81 virtual PassRefPtr<AnimatableValue> addWith(const AnimatableValue*) const OV ERRIDE;
82
83 private:
84 AnimatableNumber(double number, NumberUnitType unitType, CSSPrimitiveValue* cssPrimitiveValue)
85 : m_number(number)
86 , m_unitType(unitType)
87 , m_isCalc(false)
88 , m_cachedCSSPrimitiveValue(cssPrimitiveValue)
89 {
90 ASSERT(m_unitType != UnitTypeInvalid);
91 }
92 AnimatableNumber(PassRefPtr<CSSCalcExpressionNode> calcExpression, CSSPrimit iveValue* cssPrimitiveValue)
93 : m_isCalc(true)
94 , m_calcExpression(calcExpression)
95 , m_cachedCSSPrimitiveValue(cssPrimitiveValue)
96 {
97 ASSERT(m_calcExpression);
98 }
99 virtual AnimatableType type() const OVERRIDE { return TypeNumber; }
100
101 static PassRefPtr<AnimatableNumber> create(PassRefPtr<CSSCalcExpressionNode> calcExpression, CSSPrimitiveValue* cssPrimitiveValue = 0)
102 {
103 return adoptRef(new AnimatableNumber(calcExpression, cssPrimitiveValue)) ;
104 }
105 static PassRefPtr<AnimatableNumber> create(const AnimatableNumber* leftAdden d, const AnimatableNumber* rightAddend);
106
107 PassRefPtr<CSSPrimitiveValue> toCSSPrimitiveValue(NumberRange) const;
108 PassRefPtr<CSSCalcExpressionNode> toCSSCalcExpressionNode() const;
109
110 PassRefPtr<AnimatableNumber> scale(double) const;
111 double clampedNumber(NumberRange range) const
112 {
113 ASSERT(!m_isCalc);
114 return (range == NonNegativeValues && m_number <= 0) ? 0 : m_number;
115 }
116 static NumberUnitType primitiveUnitToNumberType(unsigned short primitiveUnit );
117 static unsigned short numberTypeToPrimitiveUnit(NumberUnitType numberType);
118
119 double m_number;
120 NumberUnitType m_unitType;
121
122 bool m_isCalc;
123 RefPtr<CSSCalcExpressionNode> m_calcExpression;
124
125 mutable RefPtr<CSSPrimitiveValue> m_cachedCSSPrimitiveValue;
126 };
127
128 inline const AnimatableNumber* toAnimatableNumber(const AnimatableValue* value)
129 {
130 ASSERT_WITH_SECURITY_IMPLICATION(value && value->isNumber());
131 return static_cast<const AnimatableNumber*>(value);
132 }
133
134 } // namespace WebCore
135
136 #endif // AnimatableNumber_h
OLDNEW
« no previous file with comments | « Source/core/animation/AnimatableLengthTest.cpp ('k') | Source/core/animation/AnimatableNumber.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698