OLD | NEW |
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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 #include "core/animation/css/CSSAnimations.h" | 54 #include "core/animation/css/CSSAnimations.h" |
55 #include "core/css/CSSCalculationValue.h" | 55 #include "core/css/CSSCalculationValue.h" |
56 #include "core/css/CSSPrimitiveValue.h" | 56 #include "core/css/CSSPrimitiveValue.h" |
57 #include "core/css/CSSPrimitiveValueMappings.h" | 57 #include "core/css/CSSPrimitiveValueMappings.h" |
58 #include "core/rendering/style/RenderStyle.h" | 58 #include "core/rendering/style/RenderStyle.h" |
59 #include "platform/Length.h" | 59 #include "platform/Length.h" |
60 #include "platform/LengthBox.h" | 60 #include "platform/LengthBox.h" |
61 | 61 |
62 namespace WebCore { | 62 namespace WebCore { |
63 | 63 |
64 static PassRefPtr<AnimatableValue> createFromLength(const Length& length, const
RenderStyle& style) | 64 static PassRefPtrWillBeRawPtr<AnimatableValue> createFromLength(const Length& le
ngth, const RenderStyle& style) |
65 { | 65 { |
66 switch (length.type()) { | 66 switch (length.type()) { |
67 case Fixed: | 67 case Fixed: |
68 return AnimatableLength::create(adjustFloatForAbsoluteZoom(length.value(
), style), AnimatableLength::UnitTypePixels); | 68 return AnimatableLength::create(adjustFloatForAbsoluteZoom(length.value(
), style), AnimatableLength::UnitTypePixels); |
69 case Percent: | 69 case Percent: |
70 return AnimatableLength::create(length.value(), AnimatableLength::UnitTy
pePercentage); | 70 return AnimatableLength::create(length.value(), AnimatableLength::UnitTy
pePercentage); |
71 case Calculated: | 71 case Calculated: |
72 return AnimatableLength::create(CSSCalcValue::createExpressionNode(lengt
h.calculationValue()->expression(), style.effectiveZoom())); | 72 return AnimatableLength::create(CSSCalcValue::createExpressionNode(lengt
h.calculationValue()->expression(), style.effectiveZoom())); |
73 case Auto: | 73 case Auto: |
74 case Intrinsic: | 74 case Intrinsic: |
75 case MinIntrinsic: | 75 case MinIntrinsic: |
76 case MinContent: | 76 case MinContent: |
77 case MaxContent: | 77 case MaxContent: |
78 case FillAvailable: | 78 case FillAvailable: |
79 case FitContent: | 79 case FitContent: |
80 return AnimatableUnknown::create(CSSPrimitiveValue::create(length)); | 80 return AnimatableUnknown::create(CSSPrimitiveValue::create(length)); |
81 case Undefined: | 81 case Undefined: |
82 return AnimatableUnknown::create(CSSValueNone); | 82 return AnimatableUnknown::create(CSSValueNone); |
83 case ExtendToZoom: // Does not apply to elements. | 83 case ExtendToZoom: // Does not apply to elements. |
84 case DeviceWidth: | 84 case DeviceWidth: |
85 case DeviceHeight: | 85 case DeviceHeight: |
86 ASSERT_NOT_REACHED(); | 86 ASSERT_NOT_REACHED(); |
87 return nullptr; | 87 return nullptr; |
88 } | 88 } |
89 ASSERT_NOT_REACHED(); | 89 ASSERT_NOT_REACHED(); |
90 return nullptr; | 90 return nullptr; |
91 } | 91 } |
92 | 92 |
93 static PassRefPtr<AnimatableValue> createFromLineHeight(const Length& length, co
nst RenderStyle& style) | 93 static PassRefPtrWillBeRawPtr<AnimatableValue> createFromLineHeight(const Length
& length, const RenderStyle& style) |
94 { | 94 { |
95 if (length.type() == Percent) { | 95 if (length.type() == Percent) { |
96 double value = length.value(); | 96 double value = length.value(); |
97 // -100% is used to represent "normal" line height. | 97 // -100% is used to represent "normal" line height. |
98 if (value == -100) | 98 if (value == -100) |
99 return AnimatableUnknown::create(CSSValueNormal); | 99 return AnimatableUnknown::create(CSSValueNormal); |
100 return AnimatableDouble::create(value); | 100 return AnimatableDouble::create(value); |
101 } | 101 } |
102 return createFromLength(length, style); | 102 return createFromLength(length, style); |
103 } | 103 } |
104 | 104 |
105 inline static PassRefPtr<AnimatableValue> createFromDouble(double value, Animata
bleDouble::Constraint constraint = AnimatableDouble::Unconstrained) | 105 inline static PassRefPtrWillBeRawPtr<AnimatableValue> createFromDouble(double va
lue, AnimatableDouble::Constraint constraint = AnimatableDouble::Unconstrained) |
106 { | 106 { |
107 return AnimatableDouble::create(value, constraint); | 107 return AnimatableDouble::create(value, constraint); |
108 } | 108 } |
109 | 109 |
110 inline static PassRefPtr<AnimatableValue> createFromLengthBox(const LengthBox& l
engthBox, const RenderStyle& style) | 110 inline static PassRefPtrWillBeRawPtr<AnimatableValue> createFromLengthBox(const
LengthBox& lengthBox, const RenderStyle& style) |
111 { | 111 { |
112 return AnimatableLengthBox::create( | 112 return AnimatableLengthBox::create( |
113 createFromLength(lengthBox.left(), style), | 113 createFromLength(lengthBox.left(), style), |
114 createFromLength(lengthBox.right(), style), | 114 createFromLength(lengthBox.right(), style), |
115 createFromLength(lengthBox.top(), style), | 115 createFromLength(lengthBox.top(), style), |
116 createFromLength(lengthBox.bottom(), style)); | 116 createFromLength(lengthBox.bottom(), style)); |
117 } | 117 } |
118 | 118 |
119 static PassRefPtr<AnimatableValue> createFromBorderImageLength(const BorderImage
Length& borderImageLength, const RenderStyle& style) | 119 static PassRefPtrWillBeRawPtr<AnimatableValue> createFromBorderImageLength(const
BorderImageLength& borderImageLength, const RenderStyle& style) |
120 { | 120 { |
121 if (borderImageLength.isNumber()) | 121 if (borderImageLength.isNumber()) |
122 return createFromDouble(borderImageLength.number()); | 122 return createFromDouble(borderImageLength.number()); |
123 return createFromLength(borderImageLength.length(), style); | 123 return createFromLength(borderImageLength.length(), style); |
124 } | 124 } |
125 | 125 |
126 inline static PassRefPtr<AnimatableValue> createFromBorderImageLengthBox(const B
orderImageLengthBox& borderImageLengthBox, const RenderStyle& style) | 126 inline static PassRefPtrWillBeRawPtr<AnimatableValue> createFromBorderImageLengt
hBox(const BorderImageLengthBox& borderImageLengthBox, const RenderStyle& style) |
127 { | 127 { |
128 return AnimatableLengthBox::create( | 128 return AnimatableLengthBox::create( |
129 createFromBorderImageLength(borderImageLengthBox.left(), style), | 129 createFromBorderImageLength(borderImageLengthBox.left(), style), |
130 createFromBorderImageLength(borderImageLengthBox.right(), style), | 130 createFromBorderImageLength(borderImageLengthBox.right(), style), |
131 createFromBorderImageLength(borderImageLengthBox.top(), style), | 131 createFromBorderImageLength(borderImageLengthBox.top(), style), |
132 createFromBorderImageLength(borderImageLengthBox.bottom(), style)); | 132 createFromBorderImageLength(borderImageLengthBox.bottom(), style)); |
133 } | 133 } |
134 | 134 |
135 inline static PassRefPtr<AnimatableValue> createFromLengthBoxAndBool(const Lengt
hBox lengthBox, const bool flag, const RenderStyle& style) | 135 inline static PassRefPtrWillBeRawPtr<AnimatableValue> createFromLengthBoxAndBool
(const LengthBox lengthBox, const bool flag, const RenderStyle& style) |
136 { | 136 { |
137 return AnimatableLengthBoxAndBool::create( | 137 return AnimatableLengthBoxAndBool::create( |
138 createFromLengthBox(lengthBox, style), | 138 createFromLengthBox(lengthBox, style), |
139 flag); | 139 flag); |
140 } | 140 } |
141 | 141 |
142 inline static PassRefPtr<AnimatableValue> createFromLengthPoint(const LengthPoin
t& lengthPoint, const RenderStyle& style) | 142 inline static PassRefPtrWillBeRawPtr<AnimatableValue> createFromLengthPoint(cons
t LengthPoint& lengthPoint, const RenderStyle& style) |
143 { | 143 { |
144 return AnimatableLengthPoint::create( | 144 return AnimatableLengthPoint::create( |
145 createFromLength(lengthPoint.x(), style), | 145 createFromLength(lengthPoint.x(), style), |
146 createFromLength(lengthPoint.y(), style)); | 146 createFromLength(lengthPoint.y(), style)); |
147 } | 147 } |
148 | 148 |
149 inline static PassRefPtr<AnimatableValue> createFromLengthSize(const LengthSize&
lengthSize, const RenderStyle& style) | 149 inline static PassRefPtrWillBeRawPtr<AnimatableValue> createFromLengthSize(const
LengthSize& lengthSize, const RenderStyle& style) |
150 { | 150 { |
151 return AnimatableLengthSize::create( | 151 return AnimatableLengthSize::create( |
152 createFromLength(lengthSize.width(), style), | 152 createFromLength(lengthSize.width(), style), |
153 createFromLength(lengthSize.height(), style)); | 153 createFromLength(lengthSize.height(), style)); |
154 } | 154 } |
155 | 155 |
156 inline static PassRefPtr<AnimatableValue> createFromStyleImage(StyleImage* image
) | 156 inline static PassRefPtrWillBeRawPtr<AnimatableValue> createFromStyleImage(Style
Image* image) |
157 { | 157 { |
158 if (image) | 158 if (image) |
159 return AnimatableImage::create(*image); | 159 return AnimatableImage::create(*image); |
160 return AnimatableUnknown::create(CSSValueNone); | 160 return AnimatableUnknown::create(CSSValueNone); |
161 } | 161 } |
162 | 162 |
163 inline static PassRefPtr<AnimatableValue> createFromFillSize(const FillSize& fil
lSize, const RenderStyle& style) | 163 inline static PassRefPtrWillBeRawPtr<AnimatableValue> createFromFillSize(const F
illSize& fillSize, const RenderStyle& style) |
164 { | 164 { |
165 switch (fillSize.type) { | 165 switch (fillSize.type) { |
166 case SizeLength: | 166 case SizeLength: |
167 return createFromLengthSize(fillSize.size, style); | 167 return createFromLengthSize(fillSize.size, style); |
168 case Contain: | 168 case Contain: |
169 case Cover: | 169 case Cover: |
170 case SizeNone: | 170 case SizeNone: |
171 return AnimatableUnknown::create(CSSPrimitiveValue::create(fillSize.type
)); | 171 return AnimatableUnknown::create(CSSPrimitiveValue::create(fillSize.type
)); |
172 default: | 172 default: |
173 ASSERT_NOT_REACHED(); | 173 ASSERT_NOT_REACHED(); |
174 return nullptr; | 174 return nullptr; |
175 } | 175 } |
176 } | 176 } |
177 | 177 |
178 inline static PassRefPtr<AnimatableValue> createFromBackgroundPosition(const Len
gth& length, bool originIsSet, BackgroundEdgeOrigin origin, const RenderStyle& s
tyle) | 178 inline static PassRefPtrWillBeRawPtr<AnimatableValue> createFromBackgroundPositi
on(const Length& length, bool originIsSet, BackgroundEdgeOrigin origin, const Re
nderStyle& style) |
179 { | 179 { |
180 if (!originIsSet || origin == LeftEdge || origin == TopEdge) | 180 if (!originIsSet || origin == LeftEdge || origin == TopEdge) |
181 return createFromLength(length, style); | 181 return createFromLength(length, style); |
182 | 182 |
183 return AnimatableLength::create(CSSCalcValue::createExpressionNode( | 183 return AnimatableLength::create(CSSCalcValue::createExpressionNode( |
184 CSSCalcValue::createExpressionNode(CSSPrimitiveValue::create(100, CSSPri
mitiveValue::CSS_PERCENTAGE), true), | 184 CSSCalcValue::createExpressionNode(CSSPrimitiveValue::create(100, CSSPri
mitiveValue::CSS_PERCENTAGE), true), |
185 CSSCalcValue::createExpressionNode(length, style.effectiveZoom()), | 185 CSSCalcValue::createExpressionNode(length, style.effectiveZoom()), |
186 CalcSubtract)); | 186 CalcSubtract)); |
187 } | 187 } |
188 | 188 |
189 template<CSSPropertyID property> | 189 template<CSSPropertyID property> |
190 inline static PassRefPtr<AnimatableValue> createFromFillLayers(const FillLayer*
fillLayer, const RenderStyle& style) | 190 inline static PassRefPtrWillBeRawPtr<AnimatableValue> createFromFillLayers(const
FillLayer* fillLayer, const RenderStyle& style) |
191 { | 191 { |
192 ASSERT(fillLayer); | 192 ASSERT(fillLayer); |
193 Vector<RefPtr<AnimatableValue> > values; | 193 WillBeHeapVector<RefPtrWillBeMember<AnimatableValue> > values; |
194 while (fillLayer) { | 194 while (fillLayer) { |
195 if (property == CSSPropertyBackgroundImage || property == CSSPropertyWeb
kitMaskImage) { | 195 if (property == CSSPropertyBackgroundImage || property == CSSPropertyWeb
kitMaskImage) { |
196 if (!fillLayer->isImageSet()) | 196 if (!fillLayer->isImageSet()) |
197 break; | 197 break; |
198 values.append(createFromStyleImage(fillLayer->image())); | 198 values.append(createFromStyleImage(fillLayer->image())); |
199 } else if (property == CSSPropertyBackgroundPositionX || property == CSS
PropertyWebkitMaskPositionX) { | 199 } else if (property == CSSPropertyBackgroundPositionX || property == CSS
PropertyWebkitMaskPositionX) { |
200 if (!fillLayer->isXPositionSet()) | 200 if (!fillLayer->isXPositionSet()) |
201 break; | 201 break; |
202 values.append(createFromBackgroundPosition(fillLayer->xPosition(), f
illLayer->isBackgroundXOriginSet(), fillLayer->backgroundXOrigin(), style)); | 202 values.append(createFromBackgroundPosition(fillLayer->xPosition(), f
illLayer->isBackgroundXOriginSet(), fillLayer->backgroundXOrigin(), style)); |
203 } else if (property == CSSPropertyBackgroundPositionY || property == CSS
PropertyWebkitMaskPositionY) { | 203 } else if (property == CSSPropertyBackgroundPositionY || property == CSS
PropertyWebkitMaskPositionY) { |
204 if (!fillLayer->isYPositionSet()) | 204 if (!fillLayer->isYPositionSet()) |
205 break; | 205 break; |
206 values.append(createFromBackgroundPosition(fillLayer->yPosition(), f
illLayer->isBackgroundYOriginSet(), fillLayer->backgroundYOrigin(), style)); | 206 values.append(createFromBackgroundPosition(fillLayer->yPosition(), f
illLayer->isBackgroundYOriginSet(), fillLayer->backgroundYOrigin(), style)); |
207 } else if (property == CSSPropertyBackgroundSize || property == CSSPrope
rtyWebkitMaskSize) { | 207 } else if (property == CSSPropertyBackgroundSize || property == CSSPrope
rtyWebkitMaskSize) { |
208 if (!fillLayer->isSizeSet()) | 208 if (!fillLayer->isSizeSet()) |
209 break; | 209 break; |
210 values.append(createFromFillSize(fillLayer->size(), style)); | 210 values.append(createFromFillSize(fillLayer->size(), style)); |
211 } else { | 211 } else { |
212 ASSERT_NOT_REACHED(); | 212 ASSERT_NOT_REACHED(); |
213 } | 213 } |
214 fillLayer = fillLayer->next(); | 214 fillLayer = fillLayer->next(); |
215 } | 215 } |
216 return AnimatableRepeatable::create(values); | 216 return AnimatableRepeatable::create(values); |
217 } | 217 } |
218 | 218 |
219 PassRefPtr<AnimatableValue> CSSAnimatableValueFactory::createFromColor(CSSProper
tyID property, const RenderStyle& style) | 219 PassRefPtrWillBeRawPtr<AnimatableValue> CSSAnimatableValueFactory::createFromCol
or(CSSPropertyID property, const RenderStyle& style) |
220 { | 220 { |
221 Color color = style.colorIncludingFallback(property, false); | 221 Color color = style.colorIncludingFallback(property, false); |
222 Color visitedLinkColor = style.colorIncludingFallback(property, true); | 222 Color visitedLinkColor = style.colorIncludingFallback(property, true); |
223 return AnimatableColor::create(color, visitedLinkColor); | 223 return AnimatableColor::create(color, visitedLinkColor); |
224 } | 224 } |
225 | 225 |
226 inline static PassRefPtr<AnimatableValue> createFromShapeValue(ShapeValue* value
) | 226 inline static PassRefPtrWillBeRawPtr<AnimatableValue> createFromShapeValue(Shape
Value* value) |
227 { | 227 { |
228 if (value) | 228 if (value) |
229 return AnimatableShapeValue::create(value); | 229 return AnimatableShapeValue::create(value); |
230 return AnimatableUnknown::create(CSSValueAuto); | 230 return AnimatableUnknown::create(CSSValueAuto); |
231 } | 231 } |
232 | 232 |
233 static double fontWeightToDouble(FontWeight fontWeight) | 233 static double fontWeightToDouble(FontWeight fontWeight) |
234 { | 234 { |
235 switch (fontWeight) { | 235 switch (fontWeight) { |
236 case FontWeight100: | 236 case FontWeight100: |
(...skipping 13 matching lines...) Expand all Loading... |
250 case FontWeight800: | 250 case FontWeight800: |
251 return 800; | 251 return 800; |
252 case FontWeight900: | 252 case FontWeight900: |
253 return 900; | 253 return 900; |
254 } | 254 } |
255 | 255 |
256 ASSERT_NOT_REACHED(); | 256 ASSERT_NOT_REACHED(); |
257 return 400; | 257 return 400; |
258 } | 258 } |
259 | 259 |
260 static PassRefPtr<AnimatableValue> createFromFontWeight(FontWeight fontWeight) | 260 static PassRefPtrWillBeRawPtr<AnimatableValue> createFromFontWeight(FontWeight f
ontWeight) |
261 { | 261 { |
262 return createFromDouble(fontWeightToDouble(fontWeight)); | 262 return createFromDouble(fontWeightToDouble(fontWeight)); |
263 } | 263 } |
264 | 264 |
265 // FIXME: Generate this function. | 265 // FIXME: Generate this function. |
266 PassRefPtr<AnimatableValue> CSSAnimatableValueFactory::create(CSSPropertyID prop
erty, const RenderStyle& style) | 266 PassRefPtrWillBeRawPtr<AnimatableValue> CSSAnimatableValueFactory::create(CSSPro
pertyID property, const RenderStyle& style) |
267 { | 267 { |
268 ASSERT(CSSAnimations::isAnimatableProperty(property)); | 268 ASSERT(CSSAnimations::isAnimatableProperty(property)); |
269 switch (property) { | 269 switch (property) { |
270 case CSSPropertyBackgroundColor: | 270 case CSSPropertyBackgroundColor: |
271 return createFromColor(property, style); | 271 return createFromColor(property, style); |
272 case CSSPropertyBackgroundImage: | 272 case CSSPropertyBackgroundImage: |
273 return createFromFillLayers<CSSPropertyBackgroundImage>(style.background
Layers(), style); | 273 return createFromFillLayers<CSSPropertyBackgroundImage>(style.background
Layers(), style); |
274 case CSSPropertyBackgroundPositionX: | 274 case CSSPropertyBackgroundPositionX: |
275 return createFromFillLayers<CSSPropertyBackgroundPositionX>(style.backgr
oundLayers(), style); | 275 return createFromFillLayers<CSSPropertyBackgroundPositionX>(style.backgr
oundLayers(), style); |
276 case CSSPropertyBackgroundPositionY: | 276 case CSSPropertyBackgroundPositionY: |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 case CSSPropertyZoom: | 494 case CSSPropertyZoom: |
495 return createFromDouble(style.zoom()); | 495 return createFromDouble(style.zoom()); |
496 default: | 496 default: |
497 ASSERT_NOT_REACHED(); | 497 ASSERT_NOT_REACHED(); |
498 // This return value is to avoid a release crash if possible. | 498 // This return value is to avoid a release crash if possible. |
499 return AnimatableUnknown::create(nullptr); | 499 return AnimatableUnknown::create(nullptr); |
500 } | 500 } |
501 } | 501 } |
502 | 502 |
503 } // namespace WebCore | 503 } // namespace WebCore |
OLD | NEW |