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

Side by Side Diff: sky/engine/core/animation/css/CSSAnimatableValueFactory.cpp

Issue 1229273004: Remove Animations and Transitions. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 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
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 "sky/engine/core/animation/css/CSSAnimatableValueFactory.h"
32
33 #include "gen/sky/core/CSSValueKeywords.h"
34 #include "sky/engine/core/animation/animatable/AnimatableClipPathOperation.h"
35 #include "sky/engine/core/animation/animatable/AnimatableColor.h"
36 #include "sky/engine/core/animation/animatable/AnimatableDouble.h"
37 #include "sky/engine/core/animation/animatable/AnimatableFilterOperations.h"
38 #include "sky/engine/core/animation/animatable/AnimatableLength.h"
39 #include "sky/engine/core/animation/animatable/AnimatableLengthBox.h"
40 #include "sky/engine/core/animation/animatable/AnimatableLengthBoxAndBool.h"
41 #include "sky/engine/core/animation/animatable/AnimatableLengthPoint.h"
42 #include "sky/engine/core/animation/animatable/AnimatableLengthPoint3D.h"
43 #include "sky/engine/core/animation/animatable/AnimatableLengthSize.h"
44 #include "sky/engine/core/animation/animatable/AnimatableRepeatable.h"
45 #include "sky/engine/core/animation/animatable/AnimatableShadow.h"
46 #include "sky/engine/core/animation/animatable/AnimatableShapeValue.h"
47 #include "sky/engine/core/animation/animatable/AnimatableTransform.h"
48 #include "sky/engine/core/animation/animatable/AnimatableUnknown.h"
49 #include "sky/engine/core/css/CSSCalculationValue.h"
50 #include "sky/engine/core/css/CSSPrimitiveValue.h"
51 #include "sky/engine/core/css/CSSPrimitiveValueMappings.h"
52 #include "sky/engine/core/css/CSSPropertyMetadata.h"
53 #include "sky/engine/core/rendering/style/RenderStyle.h"
54 #include "sky/engine/platform/Length.h"
55 #include "sky/engine/platform/LengthBox.h"
56
57 namespace blink {
58
59 static PassRefPtr<AnimatableValue> createFromLength(const Length& length, const RenderStyle& style)
60 {
61 switch (length.type()) {
62 case Fixed:
63 case Percent:
64 case Calculated:
65 return AnimatableLength::create(length);
66 case Auto:
67 case Intrinsic:
68 case MinIntrinsic:
69 case MinContent:
70 case MaxContent:
71 case FillAvailable:
72 case FitContent:
73 return AnimatableUnknown::create(CSSPrimitiveValue::create(length));
74 case MaxSizeNone:
75 return AnimatableUnknown::create(CSSValueNone);
76 case DeviceWidth:
77 case DeviceHeight:
78 ASSERT_NOT_REACHED();
79 return nullptr;
80 }
81 ASSERT_NOT_REACHED();
82 return nullptr;
83 }
84
85 static PassRefPtr<AnimatableValue> createFromLineHeight(const Length& length, co nst RenderStyle& style)
86 {
87 if (length.type() == Percent) {
88 double value = length.value();
89 // -100% is used to represent "normal" line height.
90 if (value == -100)
91 return AnimatableUnknown::create(CSSValueNormal);
92 return AnimatableDouble::create(value);
93 }
94 return createFromLength(length, style);
95 }
96
97 inline static PassRefPtr<AnimatableValue> createFromDouble(double value, Animata bleDouble::Constraint constraint = AnimatableDouble::Unconstrained)
98 {
99 return AnimatableDouble::create(value, constraint);
100 }
101
102 inline static PassRefPtr<AnimatableValue> createFromLengthBox(const LengthBox& l engthBox, const RenderStyle& style)
103 {
104 return AnimatableLengthBox::create(
105 createFromLength(lengthBox.left(), style),
106 createFromLength(lengthBox.right(), style),
107 createFromLength(lengthBox.top(), style),
108 createFromLength(lengthBox.bottom(), style));
109 }
110
111 static PassRefPtr<AnimatableValue> createFromBorderImageLength(const BorderImage Length& borderImageLength, const RenderStyle& style)
112 {
113 if (borderImageLength.isNumber())
114 return createFromDouble(borderImageLength.number());
115 return createFromLength(borderImageLength.length(), style);
116 }
117
118 inline static PassRefPtr<AnimatableValue> createFromBorderImageLengthBox(const B orderImageLengthBox& borderImageLengthBox, const RenderStyle& style)
119 {
120 return AnimatableLengthBox::create(
121 createFromBorderImageLength(borderImageLengthBox.left(), style),
122 createFromBorderImageLength(borderImageLengthBox.right(), style),
123 createFromBorderImageLength(borderImageLengthBox.top(), style),
124 createFromBorderImageLength(borderImageLengthBox.bottom(), style));
125 }
126
127 inline static PassRefPtr<AnimatableValue> createFromLengthPoint(const LengthPoin t& lengthPoint, const RenderStyle& style)
128 {
129 return AnimatableLengthPoint::create(
130 createFromLength(lengthPoint.x(), style),
131 createFromLength(lengthPoint.y(), style));
132 }
133
134 inline static PassRefPtr<AnimatableValue> createFromLengthSize(const LengthSize& lengthSize, const RenderStyle& style)
135 {
136 return AnimatableLengthSize::create(
137 createFromLength(lengthSize.width(), style),
138 createFromLength(lengthSize.height(), style));
139 }
140
141 inline static PassRefPtr<AnimatableValue> createFromStyleImage(StyleImage* image )
142 {
143 return AnimatableUnknown::create(CSSValueNone);
144 }
145
146 inline static PassRefPtr<AnimatableValue> createFromFillSize(const FillSize& fil lSize, const RenderStyle& style)
147 {
148 switch (fillSize.type) {
149 case SizeLength:
150 return createFromLengthSize(fillSize.size, style);
151 case Contain:
152 case Cover:
153 case SizeNone:
154 return AnimatableUnknown::create(CSSPrimitiveValue::create(fillSize.type ));
155 default:
156 ASSERT_NOT_REACHED();
157 return nullptr;
158 }
159 }
160
161 inline static PassRefPtr<AnimatableValue> createFromBackgroundPosition(const Len gth& length, bool originIsSet, BackgroundEdgeOrigin origin, const RenderStyle& s tyle)
162 {
163 if (!originIsSet || origin == LeftEdge || origin == TopEdge)
164 return createFromLength(length, style);
165 return createFromLength(length.subtractFromOneHundredPercent(), style);
166 }
167
168 template<CSSPropertyID property>
169 inline static PassRefPtr<AnimatableValue> createFromFillLayers(const FillLayer& fillLayers, const RenderStyle& style)
170 {
171 Vector<RefPtr<AnimatableValue> > values;
172 for (const FillLayer* fillLayer = &fillLayers; fillLayer; fillLayer = fillLa yer->next()) {
173 if (property == CSSPropertyBackgroundImage) {
174 if (!fillLayer->isImageSet())
175 break;
176 values.append(createFromStyleImage(fillLayer->image()));
177 } else if (property == CSSPropertyBackgroundPositionX) {
178 if (!fillLayer->isXPositionSet())
179 break;
180 values.append(createFromBackgroundPosition(fillLayer->xPosition(), f illLayer->isBackgroundXOriginSet(), fillLayer->backgroundXOrigin(), style));
181 } else if (property == CSSPropertyBackgroundPositionY) {
182 if (!fillLayer->isYPositionSet())
183 break;
184 values.append(createFromBackgroundPosition(fillLayer->yPosition(), f illLayer->isBackgroundYOriginSet(), fillLayer->backgroundYOrigin(), style));
185 } else if (property == CSSPropertyBackgroundSize) {
186 if (!fillLayer->isSizeSet())
187 break;
188 values.append(createFromFillSize(fillLayer->size(), style));
189 } else {
190 ASSERT_NOT_REACHED();
191 }
192 }
193 return AnimatableRepeatable::create(values);
194 }
195
196 PassRefPtr<AnimatableValue> CSSAnimatableValueFactory::createFromColor(CSSProper tyID property, const RenderStyle& style)
197 {
198 Color color = style.colorIncludingFallback(property);
199 return AnimatableColor::create(color);
200 }
201
202 static double fontStretchToDouble(FontStretch fontStretch)
203 {
204 return static_cast<unsigned>(fontStretch);
205 }
206
207 static PassRefPtr<AnimatableValue> createFromFontStretch(FontStretch fontStretch )
208 {
209 return createFromDouble(fontStretchToDouble(fontStretch));
210 }
211
212 static double fontWeightToDouble(FontWeight fontWeight)
213 {
214 switch (fontWeight) {
215 case FontWeight100:
216 return 100;
217 case FontWeight200:
218 return 200;
219 case FontWeight300:
220 return 300;
221 case FontWeight400:
222 return 400;
223 case FontWeight500:
224 return 500;
225 case FontWeight600:
226 return 600;
227 case FontWeight700:
228 return 700;
229 case FontWeight800:
230 return 800;
231 case FontWeight900:
232 return 900;
233 }
234
235 ASSERT_NOT_REACHED();
236 return 400;
237 }
238
239 static PassRefPtr<AnimatableValue> createFromFontWeight(FontWeight fontWeight)
240 {
241 return createFromDouble(fontWeightToDouble(fontWeight));
242 }
243
244 // FIXME: Generate this function.
245 PassRefPtr<AnimatableValue> CSSAnimatableValueFactory::create(CSSPropertyID prop erty, const RenderStyle& style)
246 {
247 ASSERT(CSSPropertyMetadata::isAnimatableProperty(property));
248 switch (property) {
249 case CSSPropertyBackgroundColor:
250 return createFromColor(property, style);
251 case CSSPropertyBackgroundImage:
252 return createFromFillLayers<CSSPropertyBackgroundImage>(style.background Layers(), style);
253 case CSSPropertyBackgroundPositionX:
254 return createFromFillLayers<CSSPropertyBackgroundPositionX>(style.backgr oundLayers(), style);
255 case CSSPropertyBackgroundPositionY:
256 return createFromFillLayers<CSSPropertyBackgroundPositionY>(style.backgr oundLayers(), style);
257 case CSSPropertyBackgroundSize:
258 case CSSPropertyWebkitBackgroundSize:
259 return createFromFillLayers<CSSPropertyBackgroundSize>(style.backgroundL ayers(), style);
260 case CSSPropertyBorderBottomColor:
261 return createFromColor(property, style);
262 case CSSPropertyBorderBottomLeftRadius:
263 return createFromLengthSize(style.borderBottomLeftRadius(), style);
264 case CSSPropertyBorderBottomRightRadius:
265 return createFromLengthSize(style.borderBottomRightRadius(), style);
266 case CSSPropertyBorderBottomWidth:
267 return createFromDouble(style.borderBottomWidth());
268 case CSSPropertyBorderImageOutset:
269 return createFromBorderImageLengthBox(style.borderImageOutset(), style);
270 case CSSPropertyBorderImageSlice:
271 return createFromLengthBox(style.borderImageSlices(), style);
272 case CSSPropertyBorderImageSource:
273 return createFromStyleImage(style.borderImageSource());
274 case CSSPropertyBorderImageWidth:
275 return createFromBorderImageLengthBox(style.borderImageWidth(), style);
276 case CSSPropertyBorderLeftColor:
277 return createFromColor(property, style);
278 case CSSPropertyBorderLeftWidth:
279 return createFromDouble(style.borderLeftWidth());
280 case CSSPropertyBorderRightColor:
281 return createFromColor(property, style);
282 case CSSPropertyBorderRightWidth:
283 return createFromDouble(style.borderRightWidth());
284 case CSSPropertyBorderTopColor:
285 return createFromColor(property, style);
286 case CSSPropertyBorderTopLeftRadius:
287 return createFromLengthSize(style.borderTopLeftRadius(), style);
288 case CSSPropertyBorderTopRightRadius:
289 return createFromLengthSize(style.borderTopRightRadius(), style);
290 case CSSPropertyBorderTopWidth:
291 return createFromDouble(style.borderTopWidth());
292 case CSSPropertyBottom:
293 return createFromLength(style.bottom(), style);
294 case CSSPropertyBoxShadow:
295 case CSSPropertyWebkitBoxShadow:
296 return AnimatableShadow::create(style.boxShadow());
297 case CSSPropertyClip:
298 if (style.hasAutoClip())
299 return AnimatableUnknown::create(CSSPrimitiveValue::create(CSSValueA uto));
300 return createFromLengthBox(style.clip(), style);
301 case CSSPropertyColor:
302 return createFromColor(property, style);
303 case CSSPropertyFilter:
304 return AnimatableFilterOperations::create(style.filter());
305 case CSSPropertyFlexGrow:
306 return createFromDouble(style.flexGrow(), AnimatableDouble::Interpolatio nIsNonContinuousWithZero);
307 case CSSPropertyFlexShrink:
308 return createFromDouble(style.flexShrink(), AnimatableDouble::Interpolat ionIsNonContinuousWithZero);
309 case CSSPropertyFlexBasis:
310 return createFromLength(style.flexBasis(), style);
311 case CSSPropertyFontSize:
312 // Must pass a specified size to setFontSize if Text Autosizing is enabl ed, but a computed size
313 // if text zoom is enabled (if neither is enabled it's irrelevant as the y're probably the same).
314 // FIXME: Should we introduce an option to pass the computed font size h ere, allowing consumers to
315 // enable text zoom rather than Text Autosizing? See http://crbug.com/22 7545.
316 return createFromDouble(style.specifiedFontSize());
317 case CSSPropertyFontStretch:
318 return createFromFontStretch(style.fontStretch());
319 case CSSPropertyFontWeight:
320 return createFromFontWeight(style.fontWeight());
321 case CSSPropertyHeight:
322 return createFromLength(style.height(), style);
323 case CSSPropertyLeft:
324 return createFromLength(style.left(), style);
325 case CSSPropertyLetterSpacing:
326 return createFromDouble(style.letterSpacing());
327 case CSSPropertyLineHeight:
328 return createFromLineHeight(style.specifiedLineHeight(), style);
329 case CSSPropertyMarginBottom:
330 return createFromLength(style.marginBottom(), style);
331 case CSSPropertyMarginLeft:
332 return createFromLength(style.marginLeft(), style);
333 case CSSPropertyMarginRight:
334 return createFromLength(style.marginRight(), style);
335 case CSSPropertyMarginTop:
336 return createFromLength(style.marginTop(), style);
337 case CSSPropertyMaxHeight:
338 return createFromLength(style.maxHeight(), style);
339 case CSSPropertyMaxWidth:
340 return createFromLength(style.maxWidth(), style);
341 case CSSPropertyMinHeight:
342 return createFromLength(style.minHeight(), style);
343 case CSSPropertyMinWidth:
344 return createFromLength(style.minWidth(), style);
345 case CSSPropertyObjectPosition:
346 return createFromLengthPoint(style.objectPosition(), style);
347 case CSSPropertyOpacity:
348 return createFromDouble(style.opacity());
349 case CSSPropertyOutlineColor:
350 return createFromColor(property, style);
351 case CSSPropertyOutlineOffset:
352 return createFromDouble(style.outlineOffset());
353 case CSSPropertyOutlineWidth:
354 return createFromDouble(style.outlineWidth());
355 case CSSPropertyPaddingBottom:
356 return createFromLength(style.paddingBottom(), style);
357 case CSSPropertyPaddingLeft:
358 return createFromLength(style.paddingLeft(), style);
359 case CSSPropertyPaddingRight:
360 return createFromLength(style.paddingRight(), style);
361 case CSSPropertyPaddingTop:
362 return createFromLength(style.paddingTop(), style);
363 case CSSPropertyRight:
364 return createFromLength(style.right(), style);
365 case CSSPropertyTextDecorationColor:
366 return AnimatableColor::create(style.textDecorationColor().resolve(style .color()));
367 case CSSPropertyTextIndent:
368 return createFromLength(style.textIndent(), style);
369 case CSSPropertyTextShadow:
370 return AnimatableShadow::create(style.textShadow());
371 case CSSPropertyTop:
372 return createFromLength(style.top(), style);
373 case CSSPropertyWebkitBorderHorizontalSpacing:
374 return createFromDouble(style.horizontalBorderSpacing());
375 case CSSPropertyWebkitBorderVerticalSpacing:
376 return createFromDouble(style.verticalBorderSpacing());
377 case CSSPropertyWebkitClipPath:
378 if (ClipPathOperation* operation = style.clipPath())
379 return AnimatableClipPathOperation::create(operation);
380 return AnimatableUnknown::create(CSSValueNone);
381 case CSSPropertyPerspective:
382 return createFromDouble(style.perspective());
383 case CSSPropertyPerspectiveOrigin:
384 return AnimatableLengthPoint::create(
385 createFromLength(style.perspectiveOriginX(), style),
386 createFromLength(style.perspectiveOriginY(), style));
387 case CSSPropertyWebkitTextStrokeColor:
388 return createFromColor(property, style);
389 case CSSPropertyTransform:
390 return AnimatableTransform::create(style.transform());
391 case CSSPropertyTransformOrigin:
392 return AnimatableLengthPoint3D::create(
393 createFromLength(style.transformOriginX(), style),
394 createFromLength(style.transformOriginY(), style),
395 createFromDouble(style.transformOriginZ()));
396 case CSSPropertyWidth:
397 return createFromLength(style.width(), style);
398 case CSSPropertyWordSpacing:
399 return createFromDouble(style.wordSpacing());
400 case CSSPropertyVerticalAlign:
401 if (style.verticalAlign() == LENGTH)
402 return createFromLength(style.verticalAlignLength(), style);
403 return AnimatableUnknown::create(CSSPrimitiveValue::create(style.vertica lAlign()));
404 case CSSPropertyZIndex:
405 return createFromDouble(style.zIndex());
406 default:
407 ASSERT_NOT_REACHED();
408 // This return value is to avoid a release crash if possible.
409 return AnimatableUnknown::create(nullptr);
410 }
411 }
412
413 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/core/animation/css/CSSAnimatableValueFactory.h ('k') | sky/engine/core/animation/css/CSSAnimationData.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698