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

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

Issue 22799020: Web Animations CSS: Support Animation of StyleImage and LengthBox (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Update length conversion for keywords. Created 7 years, 3 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
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 13 matching lines...) Expand all
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 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. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "core/css/resolver/AnimatedStyleBuilder.h" 32 #include "core/css/resolver/AnimatedStyleBuilder.h"
33 33
34 #include "core/animation/AnimatableImage.h"
35 #include "core/animation/AnimatableLengthBox.h"
34 #include "core/animation/AnimatableNumber.h" 36 #include "core/animation/AnimatableNumber.h"
35 #include "core/animation/AnimatableTransform.h" 37 #include "core/animation/AnimatableTransform.h"
36 #include "core/animation/AnimatableUnknown.h" 38 #include "core/animation/AnimatableUnknown.h"
37 #include "core/animation/AnimatableValue.h" 39 #include "core/animation/AnimatableValue.h"
40 #include "core/animation/css/CSSAnimations.h"
41 #include "core/css/CSSPrimitiveValueMappings.h"
38 #include "core/css/resolver/StyleBuilder.h" 42 #include "core/css/resolver/StyleBuilder.h"
39 #include "core/css/resolver/StyleResolverState.h" 43 #include "core/css/resolver/StyleResolverState.h"
40 #include "core/rendering/style/RenderStyle.h" 44 #include "core/rendering/style/RenderStyle.h"
41 #include "wtf/MathExtras.h" 45 #include "wtf/MathExtras.h"
42 46
43 namespace WebCore { 47 namespace WebCore {
44 48
45 namespace { 49 namespace {
46 50
47 Length animatableValueToLength(const AnimatableValue* value, const StyleResolver State& state) 51 Length animatableValueToLength(const AnimatableValue* value, const StyleResolver State& state)
48 { 52 {
49 const RenderStyle* style = state.style(); 53 const RenderStyle* style = state.style();
50 return toAnimatableNumber(value)->toLength(style, state.rootElementStyle(), style->effectiveZoom()); 54 if (value->isNumber())
55 return toAnimatableNumber(value)->toLength(style, state.rootElementStyle (), style->effectiveZoom());
56 RefPtr<CSSValue> cssValue = toAnimatableUnknown(value)->toCSSValue();
57 CSSPrimitiveValue* cssPrimitiveValue = toCSSPrimitiveValue(cssValue.get());
58 return cssPrimitiveValue->convertToLength<AnyConversion>(style, state.rootEl ementStyle(), style->effectiveZoom());
51 } 59 }
52 60
53 unsigned animatableValueToUnsigned(const AnimatableValue* value) 61 unsigned animatableValueToUnsigned(const AnimatableValue* value)
54 { 62 {
55 return clampTo<unsigned>(round(toAnimatableNumber(value)->toDouble())); 63 return clampTo<unsigned>(round(toAnimatableNumber(value)->toDouble()));
56 } 64 }
57 65
66 LengthBox animatableValueToLengthBox(const AnimatableValue* value, const StyleRe solverState& state)
67 {
68 const AnimatableLengthBox* animatableLengthBox = toAnimatableLengthBox(value );
69 return LengthBox(
70 animatableValueToLength(animatableLengthBox->top(), state),
71 animatableValueToLength(animatableLengthBox->right(), state),
72 animatableValueToLength(animatableLengthBox->bottom(), state),
73 animatableValueToLength(animatableLengthBox->left(), state));
74 }
75
58 } // namespace 76 } // namespace
59 77
60 // FIXME: This should handle all animatable properties
61 // (see CSSAnimatableValueFactory for list of remaining)
62
63 // FIXME: Generate this function. 78 // FIXME: Generate this function.
64 void AnimatedStyleBuilder::applyProperty(CSSPropertyID property, StyleResolverSt ate& state, const AnimatableValue* value) 79 void AnimatedStyleBuilder::applyProperty(CSSPropertyID property, StyleResolverSt ate& state, const AnimatableValue* value)
65 { 80 {
66 if (value->isUnknown()) { 81 if (value->isUnknown()) {
67 StyleBuilder::applyProperty(property, state, toAnimatableUnknown(value)- >toCSSValue().get()); 82 StyleBuilder::applyProperty(property, state, toAnimatableUnknown(value)- >toCSSValue().get());
68 return; 83 return;
69 } 84 }
70 RenderStyle* style = state.style(); 85 RenderStyle* style = state.style();
71 switch (property) { 86 switch (property) {
72 case CSSPropertyBorderBottomWidth: 87 case CSSPropertyBorderBottomWidth:
73 style->setBorderBottomWidth(animatableValueToUnsigned(value)); 88 style->setBorderBottomWidth(animatableValueToUnsigned(value));
74 return; 89 return;
90 case CSSPropertyBorderImageOutset:
91 style->setBorderImageOutset(animatableValueToLengthBox(value, state));
92 return;
93 case CSSPropertyBorderImageSlice:
94 style->setBorderImageSlices(animatableValueToLengthBox(value, state));
95 return;
96 case CSSPropertyBorderImageSource:
97 style->setBorderImageSource(toAnimatableImage(value)->toStyleImage());
98 return;
99 case CSSPropertyBorderImageWidth:
100 style->setBorderImageWidth(animatableValueToLengthBox(value, state));
101 return;
75 case CSSPropertyBorderLeftWidth: 102 case CSSPropertyBorderLeftWidth:
76 style->setBorderLeftWidth(animatableValueToUnsigned(value)); 103 style->setBorderLeftWidth(animatableValueToUnsigned(value));
77 return; 104 return;
78 case CSSPropertyBorderRightWidth: 105 case CSSPropertyBorderRightWidth:
79 style->setBorderRightWidth(animatableValueToUnsigned(value)); 106 style->setBorderRightWidth(animatableValueToUnsigned(value));
80 return; 107 return;
81 case CSSPropertyBorderTopWidth: 108 case CSSPropertyBorderTopWidth:
82 style->setBorderTopWidth(animatableValueToUnsigned(value)); 109 style->setBorderTopWidth(animatableValueToUnsigned(value));
83 return; 110 return;
84 case CSSPropertyBottom: 111 case CSSPropertyBottom:
85 style->setBottom(animatableValueToLength(value, state)); 112 style->setBottom(animatableValueToLength(value, state));
86 return; 113 return;
114 case CSSPropertyClip:
115 style->setClip(animatableValueToLengthBox(value, state));
116 return;
87 case CSSPropertyHeight: 117 case CSSPropertyHeight:
88 style->setHeight(animatableValueToLength(value, state)); 118 style->setHeight(animatableValueToLength(value, state));
89 return; 119 return;
120 case CSSPropertyListStyleImage:
121 style->setListStyleImage(toAnimatableImage(value)->toStyleImage());
122 return;
90 case CSSPropertyLeft: 123 case CSSPropertyLeft:
91 style->setLeft(animatableValueToLength(value, state)); 124 style->setLeft(animatableValueToLength(value, state));
92 return; 125 return;
93 case CSSPropertyMarginBottom: 126 case CSSPropertyMarginBottom:
94 style->setMarginBottom(animatableValueToLength(value, state)); 127 style->setMarginBottom(animatableValueToLength(value, state));
95 return; 128 return;
96 case CSSPropertyMarginLeft: 129 case CSSPropertyMarginLeft:
97 style->setMarginLeft(animatableValueToLength(value, state)); 130 style->setMarginLeft(animatableValueToLength(value, state));
98 return; 131 return;
99 case CSSPropertyMarginRight: 132 case CSSPropertyMarginRight:
(...skipping 28 matching lines...) Expand all
128 return; 161 return;
129 case CSSPropertyPaddingTop: 162 case CSSPropertyPaddingTop:
130 style->setPaddingTop(animatableValueToLength(value, state)); 163 style->setPaddingTop(animatableValueToLength(value, state));
131 return; 164 return;
132 case CSSPropertyRight: 165 case CSSPropertyRight:
133 style->setRight(animatableValueToLength(value, state)); 166 style->setRight(animatableValueToLength(value, state));
134 return; 167 return;
135 case CSSPropertyTop: 168 case CSSPropertyTop:
136 style->setTop(animatableValueToLength(value, state)); 169 style->setTop(animatableValueToLength(value, state));
137 return; 170 return;
171 case CSSPropertyWebkitMaskBoxImageSource:
172 style->setMaskBoxImageSource(toAnimatableImage(value)->toStyleImage());
173 return;
174 case CSSPropertyWebkitMaskImage:
175 style->setMaskImage(toAnimatableImage(value)->toStyleImage());
176 return;
138 case CSSPropertyWebkitPerspectiveOriginX: 177 case CSSPropertyWebkitPerspectiveOriginX:
139 style->setPerspectiveOriginX(animatableValueToLength(value, state)); 178 style->setPerspectiveOriginX(animatableValueToLength(value, state));
140 return; 179 return;
141 case CSSPropertyWebkitPerspectiveOriginY: 180 case CSSPropertyWebkitPerspectiveOriginY:
142 style->setPerspectiveOriginY(animatableValueToLength(value, state)); 181 style->setPerspectiveOriginY(animatableValueToLength(value, state));
143 return; 182 return;
144 case CSSPropertyWebkitTransform: 183 case CSSPropertyWebkitTransform:
145 style->setTransform(toAnimatableTransform(value)->transformOperations()) ; 184 style->setTransform(toAnimatableTransform(value)->transformOperations()) ;
146 return; 185 return;
147 case CSSPropertyWebkitTransformOriginX: 186 case CSSPropertyWebkitTransformOriginX:
148 style->setTransformOriginX(animatableValueToLength(value, state)); 187 style->setTransformOriginX(animatableValueToLength(value, state));
149 return; 188 return;
150 case CSSPropertyWebkitTransformOriginY: 189 case CSSPropertyWebkitTransformOriginY:
151 style->setTransformOriginY(animatableValueToLength(value, state)); 190 style->setTransformOriginY(animatableValueToLength(value, state));
152 return; 191 return;
153 case CSSPropertyWidth: 192 case CSSPropertyWidth:
154 style->setWidth(animatableValueToLength(value, state)); 193 style->setWidth(animatableValueToLength(value, state));
155 return; 194 return;
156 default: 195 default:
157 RELEASE_ASSERT_WITH_MESSAGE(false, "Unable to apply AnimatableValue to R enderStyle, not yet implemented!"); 196 RELEASE_ASSERT_WITH_MESSAGE(!CSSAnimations::isAnimatableProperty(propert y), "Unable to apply AnimatableValue to RenderStyle, not yet implemented: %s", g etPropertyNameString(property).utf8().data());
Steve Block 2013/08/28 03:44:23 We should prefix the message with 'Web Animations
dstockwell 2013/08/28 08:21:22 Done.
158 return; 197 ASSERT_NOT_REACHED();
159 } 198 }
160 } 199 }
161 200
162 } // namespace WebCore 201 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698