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

Side by Side Diff: Source/core/css/resolver/CSSAnimatableValueFactory.cpp

Issue 19744002: Web Animations: Add CSSAnimatableValueFactory API (partial implementation) (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
(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 #include "config.h"
32 #include "core/css/resolver/CSSAnimatableValueFactory.h"
33
34 #include "CSSValueKeywords.h"
35 #include "core/animation/AnimatableNumber.h"
36 #include "core/animation/AnimatableUnknown.h"
37 #include "core/rendering/style/RenderStyle.h"
38
39
40 namespace WebCore {
dstockwell 2013/07/18 07:43:12 Fixme, generate this file?
41
42 // FIXME: Handle remaining animatable properties:
43 // CSSPropertyBackgroundColor
44 // CSSPropertyBackgroundPosition
45 // CSSPropertyBorderBottomColor
46 // CSSPropertyBorderBottomWidth
47 // CSSPropertyBorderLeftColor
48 // CSSPropertyBorderLeftWidth
49 // CSSPropertyBorderRightColor
50 // CSSPropertyBorderRightWidth
51 // CSSPropertyBorderSpacing
52 // CSSPropertyBorderTopColor
53 // CSSPropertyBorderTopWidth
54 // CSSPropertyBottom
55 // CSSPropertyClip
56 // CSSPropertyColor
57 // CSSPropertyFontSize
58 // CSSPropertyFontWeight
59 // CSSPropertyLetterSpacing
60 // CSSPropertyLineHeight
61 // CSSPropertyOpacity
62 // CSSPropertyOutlineColor
63 // CSSPropertyOutlineOffset
64 // CSSPropertyOutlineWidth
65 // CSSPropertyTextIndent
66 // CSSPropertyTextShadow
67 // CSSPropertyVerticalAlign
68 // CSSPropertyVisibility
69 // CSSPropertyWebkitTransform
70 // CSSPropertyWordSpacing
71 // CSSPropertyZIndex
72
73 PassRefPtr<AnimatableValue> CSSAnimatableValueFactory::createFromCSSValue(CSSVal ue* value, CSSPropertyID property)
74 {
75 switch (property) {
76 case CSSPropertyBottom:
77 case CSSPropertyHeight:
78 case CSSPropertyLeft:
79 case CSSPropertyMarginBottom:
80 case CSSPropertyMarginLeft:
81 case CSSPropertyMarginRight:
82 case CSSPropertyMarginTop:
83 case CSSPropertyMaxHeight:
84 case CSSPropertyMaxWidth:
85 case CSSPropertyMinHeight:
86 case CSSPropertyMinWidth:
87 case CSSPropertyPaddingBottom:
88 case CSSPropertyPaddingLeft:
89 case CSSPropertyPaddingRight:
90 case CSSPropertyPaddingTop:
91 case CSSPropertyRight:
92 case CSSPropertyTop:
93 case CSSPropertyWebkitPerspectiveOriginX:
94 case CSSPropertyWebkitPerspectiveOriginY:
95 case CSSPropertyWebkitTransformOriginX:
96 case CSSPropertyWebkitTransformOriginY:
97 case CSSPropertyWidth:
98 if (AnimatableNumber::canCreateFrom(value))
99 return AnimatableNumber::create(value);
100 default:
101 return AnimatableUnknown::create(value);
102 }
103 ASSERT_NOT_REACHED();
104 return 0;
105 }
106
107 PassRefPtr<AnimatableValue> CSSAnimatableValueFactory::createFromRenderStyle(Ren derStyle* style, CSSPropertyID property)
108 {
109 switch (property) {
110 case CSSPropertyBottom:
111 return createFromLength(style->bottom(), style);
112 case CSSPropertyHeight:
113 return createFromLength(style->height(), style);
114 case CSSPropertyLeft:
115 return createFromLength(style->left(), style);
116 case CSSPropertyMarginBottom:
117 return createFromLength(style->marginBottom(), style);
118 case CSSPropertyMarginLeft:
119 return createFromLength(style->marginLeft(), style);
120 case CSSPropertyMarginRight:
121 return createFromLength(style->marginRight(), style);
122 case CSSPropertyMarginTop:
123 return createFromLength(style->marginTop(), style);
124 case CSSPropertyMaxHeight:
125 return createFromLength(style->maxHeight(), style);
126 case CSSPropertyMaxWidth:
127 return createFromLength(style->maxWidth(), style);
128 case CSSPropertyMinHeight:
129 return createFromLength(style->minHeight(), style);
130 case CSSPropertyMinWidth:
131 return createFromLength(style->minWidth(), style);
132 case CSSPropertyPaddingBottom:
133 return createFromLength(style->paddingBottom(), style);
134 case CSSPropertyPaddingLeft:
135 return createFromLength(style->paddingLeft(), style);
136 case CSSPropertyPaddingRight:
137 return createFromLength(style->paddingRight(), style);
138 case CSSPropertyPaddingTop:
139 return createFromLength(style->paddingTop(), style);
140 case CSSPropertyRight:
141 return createFromLength(style->right(), style);
142 case CSSPropertyTop:
143 return createFromLength(style->top(), style);
144 case CSSPropertyWebkitPerspectiveOriginX:
145 return createFromLength(style->perspectiveOriginX(), style);
146 case CSSPropertyWebkitPerspectiveOriginY:
147 return createFromLength(style->perspectiveOriginY(), style);
148 case CSSPropertyWebkitTransformOriginX:
149 return createFromLength(style->transformOriginX(), style);
150 case CSSPropertyWebkitTransformOriginY:
151 return createFromLength(style->transformOriginY(), style);
152 case CSSPropertyWidth:
153 return createFromLength(style->width(), style);
154 default:
155 // FIXME: Generate CSS values for all non-animatable properties and crea te AnimatableUnknown values out of them.
156 ASSERT_NOT_REACHED();
157 return 0;
158 }
159 ASSERT_NOT_REACHED();
160 return 0;
161 }
162
163 PassRefPtr<AnimatableValue> CSSAnimatableValueFactory::createFromLength(const Le ngth& length, RenderStyle* style)
164 {
165 switch (length.type()) {
166 case Relative:
167 return AnimatableNumber::create(length.value(), AnimatableNumber::UnitTy peNumber);
168 case Fixed:
169 return AnimatableNumber::create(adjustFloatForAbsoluteZoom(length.value( ), style), AnimatableNumber::UnitTypeLength);
170 case Percent:
171 return AnimatableNumber::create(length.value(), AnimatableNumber::UnitTy pePercentage);
172 case ViewportPercentageWidth:
173 return AnimatableNumber::create(length.value(), AnimatableNumber::UnitTy peViewportWidth);
174 case ViewportPercentageHeight:
175 return AnimatableNumber::create(length.value(), AnimatableNumber::UnitTy peViewportHeight);
176 case ViewportPercentageMin:
177 return AnimatableNumber::create(length.value(), AnimatableNumber::UnitTy peViewportMin);
178 case ViewportPercentageMax:
179 return AnimatableNumber::create(length.value(), AnimatableNumber::UnitTy peViewportMax);
180 case Calculated:
181 // FIXME: Convert platform calcs to CSS calcs.
182 ASSERT_NOT_REACHED();
183 return 0;
184 case Auto:
185 case Intrinsic:
186 case MinIntrinsic:
187 case MinContent:
188 case MaxContent:
189 case FillAvailable:
190 case FitContent:
191 return AnimatableUnknown::create(CSSPrimitiveValue::create(length));
192 case Undefined:
193 return AnimatableUnknown::create(CSSPrimitiveValue::create(CSSValueNone) );
194 }
195 ASSERT_NOT_REACHED();
196 return 0;
197 }
198
199 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698