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

Side by Side Diff: sky/engine/core/css/resolver/AnimatedStyleBuilder.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/css/resolver/AnimatedStyleBuilder.h"
32
33 #include "sky/engine/core/animation/animatable/AnimatableClipPathOperation.h"
34 #include "sky/engine/core/animation/animatable/AnimatableColor.h"
35 #include "sky/engine/core/animation/animatable/AnimatableDouble.h"
36 #include "sky/engine/core/animation/animatable/AnimatableFilterOperations.h"
37 #include "sky/engine/core/animation/animatable/AnimatableLength.h"
38 #include "sky/engine/core/animation/animatable/AnimatableLengthBox.h"
39 #include "sky/engine/core/animation/animatable/AnimatableLengthBoxAndBool.h"
40 #include "sky/engine/core/animation/animatable/AnimatableLengthPoint.h"
41 #include "sky/engine/core/animation/animatable/AnimatableLengthPoint3D.h"
42 #include "sky/engine/core/animation/animatable/AnimatableLengthSize.h"
43 #include "sky/engine/core/animation/animatable/AnimatableRepeatable.h"
44 #include "sky/engine/core/animation/animatable/AnimatableShadow.h"
45 #include "sky/engine/core/animation/animatable/AnimatableShapeValue.h"
46 #include "sky/engine/core/animation/animatable/AnimatableTransform.h"
47 #include "sky/engine/core/animation/animatable/AnimatableUnknown.h"
48 #include "sky/engine/core/animation/animatable/AnimatableValue.h"
49 #include "sky/engine/core/css/CSSPrimitiveValueMappings.h"
50 #include "sky/engine/core/css/CSSPropertyMetadata.h"
51 #include "sky/engine/core/css/resolver/StyleBuilder.h"
52 #include "sky/engine/core/css/resolver/StyleResolverState.h"
53 #include "sky/engine/core/rendering/style/RenderStyle.h"
54 #include "sky/engine/wtf/MathExtras.h"
55 #include "sky/engine/wtf/TypeTraits.h"
56
57 namespace blink {
58
59 namespace {
60
61 Length animatableValueToLength(const AnimatableValue* value, const StyleResolver State& state, ValueRange range = ValueRangeAll)
62 {
63 if (value->isLength())
64 return toAnimatableLength(value)->length(range);
65 RefPtr<CSSValue> cssValue = toAnimatableUnknown(value)->toCSSValue();
66 CSSPrimitiveValue* cssPrimitiveValue = toCSSPrimitiveValue(cssValue.get());
67 return cssPrimitiveValue->convertToLength<AnyConversion>(state.cssToLengthCo nversionData());
68 }
69
70 BorderImageLength animatableValueToBorderImageLength(const AnimatableValue* valu e, const StyleResolverState& state)
71 {
72 if (value->isLength())
73 return BorderImageLength(toAnimatableLength(value)->length(ValueRangeNon Negative));
74 if (value->isDouble())
75 return BorderImageLength(clampTo<double>(toAnimatableDouble(value)->toDo uble(), 0));
76 RefPtr<CSSValue> cssValue = toAnimatableUnknown(value)->toCSSValue();
77 CSSPrimitiveValue* cssPrimitiveValue = toCSSPrimitiveValue(cssValue.get());
78 return BorderImageLength(cssPrimitiveValue->convertToLength<AnyConversion>(s tate.cssToLengthConversionData()));
79 }
80
81 template<typename T> T animatableValueRoundClampTo(const AnimatableValue* value, T min = defaultMinimumForClamp<T>(), T max = defaultMaximumForClamp<T>())
82 {
83 COMPILE_ASSERT(WTF::IsInteger<T>::value, ShouldUseIntegralTypeTWhenRoundingV alues);
84 return clampTo<T>(round(toAnimatableDouble(value)->toDouble()), min, max);
85 }
86
87 LengthBox animatableValueToLengthBox(const AnimatableValue* value, const StyleRe solverState& state, ValueRange range = ValueRangeAll)
88 {
89 const AnimatableLengthBox* animatableLengthBox = toAnimatableLengthBox(value );
90 return LengthBox(
91 animatableValueToLength(animatableLengthBox->top(), state, range),
92 animatableValueToLength(animatableLengthBox->right(), state, range),
93 animatableValueToLength(animatableLengthBox->bottom(), state, range),
94 animatableValueToLength(animatableLengthBox->left(), state, range));
95 }
96
97 BorderImageLengthBox animatableValueToBorderImageLengthBox(const AnimatableValue * value, const StyleResolverState& state)
98 {
99 const AnimatableLengthBox* animatableLengthBox = toAnimatableLengthBox(value );
100 return BorderImageLengthBox(
101 animatableValueToBorderImageLength(animatableLengthBox->top(), state),
102 animatableValueToBorderImageLength(animatableLengthBox->right(), state),
103 animatableValueToBorderImageLength(animatableLengthBox->bottom(), state) ,
104 animatableValueToBorderImageLength(animatableLengthBox->left(), state));
105 }
106
107 LengthPoint animatableValueToLengthPoint(const AnimatableValue* value, const Sty leResolverState& state, ValueRange range = ValueRangeAll)
108 {
109 const AnimatableLengthPoint* animatableLengthPoint = toAnimatableLengthPoint (value);
110 return LengthPoint(
111 animatableValueToLength(animatableLengthPoint->x(), state, range),
112 animatableValueToLength(animatableLengthPoint->y(), state, range));
113 }
114
115 LengthSize animatableValueToLengthSize(const AnimatableValue* value, const Style ResolverState& state, ValueRange range)
116 {
117 const AnimatableLengthSize* animatableLengthSize = toAnimatableLengthSize(va lue);
118 return LengthSize(
119 animatableValueToLength(animatableLengthSize->width(), state, range),
120 animatableValueToLength(animatableLengthSize->height(), state, range));
121 }
122
123 void setFillSize(FillLayer* fillLayer, const AnimatableValue* value, const Style ResolverState& state)
124 {
125 if (value->isLengthSize())
126 fillLayer->setSize(FillSize(SizeLength, animatableValueToLengthSize(valu e, state, ValueRangeNonNegative)));
127 else
128 state.styleMap().mapFillSize(fillLayer, toAnimatableUnknown(value)->toCS SValue().get());
129 }
130
131 template <CSSPropertyID property>
132 void setOnFillLayers(FillLayer& fillLayers, const AnimatableValue* value, StyleR esolverState& state)
133 {
134 const Vector<RefPtr<AnimatableValue> >& values = toAnimatableRepeatable(valu e)->values();
135 ASSERT(!values.isEmpty());
136 FillLayer* fillLayer = &fillLayers;
137 FillLayer* prev = 0;
138 for (size_t i = 0; i < values.size(); ++i) {
139 if (!fillLayer)
140 fillLayer = prev->ensureNext();
141 const AnimatableValue* layerValue = values[i].get();
142 switch (property) {
143 case CSSPropertyBackgroundImage:
144 fillLayer->setImage(nullptr);
145 break;
146 case CSSPropertyBackgroundPositionX:
147 fillLayer->setXPosition(animatableValueToLength(layerValue, state));
148 break;
149 case CSSPropertyBackgroundPositionY:
150 fillLayer->setYPosition(animatableValueToLength(layerValue, state));
151 break;
152 case CSSPropertyBackgroundSize:
153 case CSSPropertyWebkitBackgroundSize:
154 setFillSize(fillLayer, layerValue, state);
155 break;
156 default:
157 ASSERT_NOT_REACHED();
158 }
159 prev = fillLayer;
160 fillLayer = fillLayer->next();
161 }
162 while (fillLayer) {
163 switch (property) {
164 case CSSPropertyBackgroundImage:
165 fillLayer->clearImage();
166 break;
167 case CSSPropertyBackgroundPositionX:
168 fillLayer->clearXPosition();
169 break;
170 case CSSPropertyBackgroundPositionY:
171 fillLayer->clearYPosition();
172 break;
173 case CSSPropertyBackgroundSize:
174 case CSSPropertyWebkitBackgroundSize:
175 fillLayer->clearSize();
176 break;
177 default:
178 ASSERT_NOT_REACHED();
179 }
180 fillLayer = fillLayer->next();
181 }
182 }
183
184 FontStretch animatableValueToFontStretch(const AnimatableValue* value)
185 {
186 ASSERT(FontStretchUltraCondensed == 1 && FontStretchUltraExpanded == 9);
187 unsigned index = round(toAnimatableDouble(value)->toDouble()) - 1;
188 static const FontStretch stretchValues[] = {
189 FontStretchUltraCondensed,
190 FontStretchExtraCondensed,
191 FontStretchCondensed,
192 FontStretchSemiCondensed,
193 FontStretchNormal,
194 FontStretchSemiExpanded,
195 FontStretchExpanded,
196 FontStretchExtraExpanded,
197 FontStretchUltraExpanded
198 };
199
200 index = clampTo<unsigned>(index, 0, WTF_ARRAY_LENGTH(stretchValues) - 1);
201 return stretchValues[index];
202 }
203
204 FontWeight animatableValueToFontWeight(const AnimatableValue* value)
205 {
206 int index = round(toAnimatableDouble(value)->toDouble() / 100) - 1;
207
208 static const FontWeight weights[] = {
209 FontWeight100,
210 FontWeight200,
211 FontWeight300,
212 FontWeight400,
213 FontWeight500,
214 FontWeight600,
215 FontWeight700,
216 FontWeight800,
217 FontWeight900
218 };
219
220 index = clampTo<int>(index, 0, WTF_ARRAY_LENGTH(weights) - 1);
221
222 return weights[index];
223 }
224
225 } // namespace
226
227 // FIXME: Generate this function.
228 void AnimatedStyleBuilder::applyProperty(CSSPropertyID property, StyleResolverSt ate& state, const AnimatableValue* value)
229 {
230 ASSERT(CSSPropertyMetadata::isAnimatableProperty(property));
231 if (value->isUnknown()) {
232 StyleBuilder::applyProperty(property, state, toAnimatableUnknown(value)- >toCSSValue().get());
233 return;
234 }
235 RenderStyle* style = state.style();
236 switch (property) {
237 case CSSPropertyBackgroundColor:
238 style->setBackgroundColor(toAnimatableColor(value)->color());
239 return;
240 case CSSPropertyBackgroundImage:
241 setOnFillLayers<CSSPropertyBackgroundImage>(style->accessBackgroundLayer s(), value, state);
242 return;
243 case CSSPropertyBackgroundPositionX:
244 setOnFillLayers<CSSPropertyBackgroundPositionX>(style->accessBackgroundL ayers(), value, state);
245 return;
246 case CSSPropertyBackgroundPositionY:
247 setOnFillLayers<CSSPropertyBackgroundPositionY>(style->accessBackgroundL ayers(), value, state);
248 return;
249 case CSSPropertyBackgroundSize:
250 setOnFillLayers<CSSPropertyBackgroundSize>(style->accessBackgroundLayers (), value, state);
251 return;
252 case CSSPropertyBorderBottomColor:
253 style->setBorderBottomColor(toAnimatableColor(value)->color());
254 return;
255 case CSSPropertyBorderBottomLeftRadius:
256 style->setBorderBottomLeftRadius(animatableValueToLengthSize(value, stat e, ValueRangeNonNegative));
257 return;
258 case CSSPropertyBorderBottomRightRadius:
259 style->setBorderBottomRightRadius(animatableValueToLengthSize(value, sta te, ValueRangeNonNegative));
260 return;
261 case CSSPropertyBorderBottomWidth:
262 style->setBorderBottomWidth(animatableValueRoundClampTo<unsigned>(value) );
263 return;
264 case CSSPropertyBorderImageOutset:
265 style->setBorderImageOutset(animatableValueToBorderImageLengthBox(value, state));
266 return;
267 case CSSPropertyBorderImageSlice:
268 style->setBorderImageSlices(animatableValueToLengthBox(value, state, Val ueRangeNonNegative));
269 return;
270 case CSSPropertyBorderImageSource:
271 return;
272 case CSSPropertyBorderImageWidth:
273 style->setBorderImageWidth(animatableValueToBorderImageLengthBox(value, state));
274 return;
275 case CSSPropertyBorderLeftColor:
276 style->setBorderLeftColor(toAnimatableColor(value)->color());
277 return;
278 case CSSPropertyBorderLeftWidth:
279 style->setBorderLeftWidth(animatableValueRoundClampTo<unsigned>(value));
280 return;
281 case CSSPropertyBorderRightColor:
282 style->setBorderRightColor(toAnimatableColor(value)->color());
283 return;
284 case CSSPropertyBorderRightWidth:
285 style->setBorderRightWidth(animatableValueRoundClampTo<unsigned>(value)) ;
286 return;
287 case CSSPropertyBorderTopColor:
288 style->setBorderTopColor(toAnimatableColor(value)->color());
289 return;
290 case CSSPropertyBorderTopLeftRadius:
291 style->setBorderTopLeftRadius(animatableValueToLengthSize(value, state, ValueRangeNonNegative));
292 return;
293 case CSSPropertyBorderTopRightRadius:
294 style->setBorderTopRightRadius(animatableValueToLengthSize(value, state, ValueRangeNonNegative));
295 return;
296 case CSSPropertyBorderTopWidth:
297 style->setBorderTopWidth(animatableValueRoundClampTo<unsigned>(value));
298 return;
299 case CSSPropertyBottom:
300 style->setBottom(animatableValueToLength(value, state));
301 return;
302 case CSSPropertyBoxShadow:
303 case CSSPropertyWebkitBoxShadow:
304 style->setBoxShadow(toAnimatableShadow(value)->shadowList());
305 return;
306 case CSSPropertyClip:
307 style->setClip(animatableValueToLengthBox(value, state));
308 return;
309 case CSSPropertyColor:
310 style->setColor(toAnimatableColor(value)->color());
311 return;
312 case CSSPropertyFlexGrow:
313 style->setFlexGrow(clampTo<float>(toAnimatableDouble(value)->toDouble(), 0));
314 return;
315 case CSSPropertyFlexShrink:
316 style->setFlexShrink(clampTo<float>(toAnimatableDouble(value)->toDouble( ), 0));
317 return;
318 case CSSPropertyFlexBasis:
319 style->setFlexBasis(animatableValueToLength(value, state, ValueRangeNonN egative));
320 return;
321 case CSSPropertyFontSize:
322 style->setFontSize(clampTo<float>(toAnimatableDouble(value)->toDouble(), 0));
323 return;
324 case CSSPropertyFontStretch:
325 style->setFontStretch(animatableValueToFontStretch(value));
326 return;
327 case CSSPropertyFontWeight:
328 style->setFontWeight(animatableValueToFontWeight(value));
329 return;
330 case CSSPropertyHeight:
331 style->setHeight(animatableValueToLength(value, state, ValueRangeNonNega tive));
332 return;
333 case CSSPropertyLeft:
334 style->setLeft(animatableValueToLength(value, state));
335 return;
336 case CSSPropertyLineHeight:
337 if (value->isLength())
338 style->setLineHeight(animatableValueToLength(value, state, ValueRang eNonNegative));
339 else
340 style->setLineHeight(Length(clampTo<float>(toAnimatableDouble(value) ->toDouble(), 0), Percent));
341 return;
342 case CSSPropertyLetterSpacing:
343 style->setLetterSpacing(clampTo<float>(toAnimatableDouble(value)->toDoub le()));
344 return;
345 case CSSPropertyMarginBottom:
346 style->setMarginBottom(animatableValueToLength(value, state));
347 return;
348 case CSSPropertyMarginLeft:
349 style->setMarginLeft(animatableValueToLength(value, state));
350 return;
351 case CSSPropertyMarginRight:
352 style->setMarginRight(animatableValueToLength(value, state));
353 return;
354 case CSSPropertyMarginTop:
355 style->setMarginTop(animatableValueToLength(value, state));
356 return;
357 case CSSPropertyMaxHeight:
358 style->setMaxHeight(animatableValueToLength(value, state, ValueRangeNonN egative));
359 return;
360 case CSSPropertyMaxWidth:
361 style->setMaxWidth(animatableValueToLength(value, state, ValueRangeNonNe gative));
362 return;
363 case CSSPropertyMinHeight:
364 style->setMinHeight(animatableValueToLength(value, state, ValueRangeNonN egative));
365 return;
366 case CSSPropertyMinWidth:
367 style->setMinWidth(animatableValueToLength(value, state, ValueRangeNonNe gative));
368 return;
369 case CSSPropertyObjectPosition:
370 style->setObjectPosition(animatableValueToLengthPoint(value, state));
371 return;
372 case CSSPropertyOpacity:
373 // Avoiding a value of 1 forces a layer to be created.
374 style->setOpacity(clampTo<float>(toAnimatableDouble(value)->toDouble(), 0, nextafterf(1, 0)));
375 return;
376 case CSSPropertyOutlineColor:
377 style->setOutlineColor(toAnimatableColor(value)->color());
378 return;
379 case CSSPropertyOutlineOffset:
380 style->setOutlineOffset(animatableValueRoundClampTo<int>(value));
381 return;
382 case CSSPropertyOutlineWidth:
383 style->setOutlineWidth(animatableValueRoundClampTo<unsigned short>(value ));
384 return;
385 case CSSPropertyPaddingBottom:
386 style->setPaddingBottom(animatableValueToLength(value, state, ValueRange NonNegative));
387 return;
388 case CSSPropertyPaddingLeft:
389 style->setPaddingLeft(animatableValueToLength(value, state, ValueRangeNo nNegative));
390 return;
391 case CSSPropertyPaddingRight:
392 style->setPaddingRight(animatableValueToLength(value, state, ValueRangeN onNegative));
393 return;
394 case CSSPropertyPaddingTop:
395 style->setPaddingTop(animatableValueToLength(value, state, ValueRangeNon Negative));
396 return;
397 case CSSPropertyRight:
398 style->setRight(animatableValueToLength(value, state));
399 return;
400 case CSSPropertyTextDecorationColor:
401 style->setTextDecorationColor(toAnimatableColor(value)->color());
402 return;
403 case CSSPropertyTextIndent:
404 style->setTextIndent(animatableValueToLength(value, state));
405 return;
406 case CSSPropertyTextShadow:
407 style->setTextShadow(toAnimatableShadow(value)->shadowList());
408 return;
409 case CSSPropertyTop:
410 style->setTop(animatableValueToLength(value, state));
411 return;
412 case CSSPropertyWebkitBackgroundSize:
413 setOnFillLayers<CSSPropertyWebkitBackgroundSize>(style->accessBackground Layers(), value, state);
414 return;
415 case CSSPropertyWebkitBorderHorizontalSpacing:
416 style->setHorizontalBorderSpacing(animatableValueRoundClampTo<unsigned s hort>(value));
417 return;
418 case CSSPropertyWebkitBorderVerticalSpacing:
419 style->setVerticalBorderSpacing(animatableValueRoundClampTo<unsigned sho rt>(value));
420 return;
421 case CSSPropertyWebkitClipPath:
422 style->setClipPath(toAnimatableClipPathOperation(value)->clipPathOperati on());
423 return;
424 case CSSPropertyFilter:
425 style->setFilter(toAnimatableFilterOperations(value)->operations());
426 return;
427 case CSSPropertyPerspective:
428 style->setPerspective(clampTo<float>(toAnimatableDouble(value)->toDouble ()));
429 return;
430 case CSSPropertyPerspectiveOrigin: {
431 const AnimatableLengthPoint* animatableLengthPoint = toAnimatableLengthP oint(value);
432 style->setPerspectiveOriginX(animatableValueToLength(animatableLengthPoi nt->x(), state));
433 style->setPerspectiveOriginY(animatableValueToLength(animatableLengthPoi nt->y(), state));
434 return;
435 }
436 case CSSPropertyWebkitTextStrokeColor:
437 style->setTextStrokeColor(toAnimatableColor(value)->color());
438 return;
439 case CSSPropertyTransform: {
440 const TransformOperations& operations = toAnimatableTransform(value)->tr ansformOperations();
441 // FIXME: This normalization (handling of 'none') should be performed at input in AnimatableValueFactory.
442 style->setTransform(operations.size() ? operations : TransformOperations (true));
443 return;
444 }
445 case CSSPropertyTransformOrigin: {
446 const AnimatableLengthPoint3D* animatableLengthPoint3D = toAnimatableLen gthPoint3D(value);
447 style->setTransformOriginX(animatableValueToLength(animatableLengthPoint 3D->x(), state));
448 style->setTransformOriginY(animatableValueToLength(animatableLengthPoint 3D->y(), state));
449 style->setTransformOriginZ(clampTo<float>(toAnimatableDouble(animatableL engthPoint3D->z())->toDouble()));
450 return;
451 }
452 case CSSPropertyWidth:
453 style->setWidth(animatableValueToLength(value, state, ValueRangeNonNegat ive));
454 return;
455 case CSSPropertyWordSpacing:
456 style->setWordSpacing(clampTo<float>(toAnimatableDouble(value)->toDouble ()));
457 return;
458 case CSSPropertyVerticalAlign:
459 style->setVerticalAlignLength(animatableValueToLength(value, state));
460 return;
461 case CSSPropertyZIndex:
462 style->setZIndex(animatableValueRoundClampTo<unsigned>(value));
463 return;
464 default:
465 ASSERT_NOT_REACHED();
466 }
467 }
468
469 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/core/css/resolver/AnimatedStyleBuilder.h ('k') | sky/engine/core/css/resolver/CSSToStyleMap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698