| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 #include "core/css/CSSPropertyMetadata.h" | 57 #include "core/css/CSSPropertyMetadata.h" |
| 58 #include "core/css/resolver/StyleBuilder.h" | 58 #include "core/css/resolver/StyleBuilder.h" |
| 59 #include "core/css/resolver/StyleResolverState.h" | 59 #include "core/css/resolver/StyleResolverState.h" |
| 60 #include "core/style/ComputedStyle.h" | 60 #include "core/style/ComputedStyle.h" |
| 61 #include "wtf/MathExtras.h" | 61 #include "wtf/MathExtras.h" |
| 62 | 62 |
| 63 #include <type_traits> | 63 #include <type_traits> |
| 64 | 64 |
| 65 namespace blink { | 65 namespace blink { |
| 66 | 66 |
| 67 namespace { | |
| 68 | |
| 69 Length animatableValueToLengthWithZoom(const AnimatableValue* value, | |
| 70 float zoom, | |
| 71 ValueRange range = ValueRangeAll) { | |
| 72 if (value->isLength()) | |
| 73 return toAnimatableLength(value)->getLength(zoom, range); | |
| 74 ASSERT(toAnimatableUnknown(value)->toCSSValueID() == CSSValueAuto); | |
| 75 return Length(Auto); | |
| 76 } | |
| 77 | |
| 78 Length animatableValueToLength(const AnimatableValue* value, | |
| 79 const StyleResolverState& state, | |
| 80 ValueRange range = ValueRangeAll) { | |
| 81 return animatableValueToLengthWithZoom(value, state.style()->effectiveZoom(), | |
| 82 range); | |
| 83 } | |
| 84 | |
| 85 UnzoomedLength animatableValueToUnzoomedLength( | |
| 86 const AnimatableValue* value, | |
| 87 const StyleResolverState&, | |
| 88 ValueRange range = ValueRangeAll) { | |
| 89 return UnzoomedLength(animatableValueToLengthWithZoom(value, 1, range)); | |
| 90 } | |
| 91 | |
| 92 BorderImageLength animatableValueToBorderImageLength( | |
| 93 const AnimatableValue* value, | |
| 94 const StyleResolverState& state) { | |
| 95 if (value->isLength()) | |
| 96 return BorderImageLength(toAnimatableLength(value)->getLength( | |
| 97 state.style()->effectiveZoom(), ValueRangeNonNegative)); | |
| 98 if (value->isDouble()) | |
| 99 return BorderImageLength( | |
| 100 clampTo<double>(toAnimatableDouble(value)->toDouble(), 0)); | |
| 101 ASSERT(toAnimatableUnknown(value)->toCSSValueID() == CSSValueAuto); | |
| 102 return Length(Auto); | |
| 103 } | |
| 104 | |
| 105 double animatableValueToPixels(const AnimatableValue* value, | |
| 106 const StyleResolverState& state) { | |
| 107 return toAnimatableLength(value) | |
| 108 ->getLength(state.style()->effectiveZoom(), ValueRangeAll) | |
| 109 .pixels(); | |
| 110 } | |
| 111 | |
| 112 template <typename T> | |
| 113 T roundedClampTo(double value) { | |
| 114 static_assert(std::is_integral<T>::value, | |
| 115 "should use integral type T when rounding values"); | |
| 116 return clampTo<T>(roundForImpreciseConversion<T>(value)); | |
| 117 } | |
| 118 | |
| 119 template <typename T> | |
| 120 T animatableValueClampTo(const AnimatableValue* value) { | |
| 121 return roundedClampTo<T>(toAnimatableDouble(value)->toDouble()); | |
| 122 } | |
| 123 | |
| 124 template <typename T> | |
| 125 T animatableLineWidthClamp(const AnimatableValue* value, | |
| 126 const StyleResolverState& state) { | |
| 127 double lineWidth = animatableValueToPixels(value, state); | |
| 128 // This matches StyleBuilderConverter::convertLineWidth(). | |
| 129 return (lineWidth > 0 && lineWidth < 1) ? 1 : roundedClampTo<T>(lineWidth); | |
| 130 } | |
| 131 | |
| 132 float animatableLineWidth(const AnimatableValue* value, | |
| 133 const StyleResolverState& state) { | |
| 134 double lineWidth = | |
| 135 toAnimatableLength(value) | |
| 136 ->getLength(state.style()->effectiveZoom(), ValueRangeNonNegative) | |
| 137 .pixels(); | |
| 138 // This matches StyleBuilderConverter::convertLineWidth(). | |
| 139 return (lineWidth > 0 && lineWidth < 1) ? 1 : lineWidth; | |
| 140 } | |
| 141 | |
| 142 LengthBox animatableValueToLengthBox(const AnimatableValue* value, | |
| 143 const StyleResolverState& state, | |
| 144 ValueRange range = ValueRangeAll) { | |
| 145 const AnimatableLengthBox* animatableLengthBox = toAnimatableLengthBox(value); | |
| 146 return LengthBox( | |
| 147 animatableValueToLength(animatableLengthBox->top(), state, range), | |
| 148 animatableValueToLength(animatableLengthBox->right(), state, range), | |
| 149 animatableValueToLength(animatableLengthBox->bottom(), state, range), | |
| 150 animatableValueToLength(animatableLengthBox->left(), state, range)); | |
| 151 } | |
| 152 | |
| 153 BorderImageLengthBox animatableValueToBorderImageLengthBox( | |
| 154 const AnimatableValue* value, | |
| 155 const StyleResolverState& state) { | |
| 156 const AnimatableLengthBox* animatableLengthBox = toAnimatableLengthBox(value); | |
| 157 return BorderImageLengthBox( | |
| 158 animatableValueToBorderImageLength(animatableLengthBox->top(), state), | |
| 159 animatableValueToBorderImageLength(animatableLengthBox->right(), state), | |
| 160 animatableValueToBorderImageLength(animatableLengthBox->bottom(), state), | |
| 161 animatableValueToBorderImageLength(animatableLengthBox->left(), state)); | |
| 162 } | |
| 163 | |
| 164 LengthPoint animatableValueToLengthPoint(const AnimatableValue* value, | |
| 165 const StyleResolverState& state, | |
| 166 ValueRange range = ValueRangeAll) { | |
| 167 const AnimatableLengthPoint* animatableLengthPoint = | |
| 168 toAnimatableLengthPoint(value); | |
| 169 return LengthPoint( | |
| 170 animatableValueToLength(animatableLengthPoint->x(), state, range), | |
| 171 animatableValueToLength(animatableLengthPoint->y(), state, range)); | |
| 172 } | |
| 173 | |
| 174 TransformOrigin animatableValueToTransformOrigin( | |
| 175 const AnimatableValue* value, | |
| 176 const StyleResolverState& state, | |
| 177 ValueRange range = ValueRangeAll) { | |
| 178 const AnimatableLengthPoint3D* animatableLengthPoint3D = | |
| 179 toAnimatableLengthPoint3D(value); | |
| 180 return TransformOrigin( | |
| 181 animatableValueToLength(animatableLengthPoint3D->x(), state), | |
| 182 animatableValueToLength(animatableLengthPoint3D->y(), state), | |
| 183 animatableValueToPixels(animatableLengthPoint3D->z(), state)); | |
| 184 } | |
| 185 | |
| 186 LengthSize animatableValueToLengthSize(const AnimatableValue* value, | |
| 187 const StyleResolverState& state, | |
| 188 ValueRange range) { | |
| 189 const AnimatableLengthSize* animatableLengthSize = | |
| 190 toAnimatableLengthSize(value); | |
| 191 return LengthSize( | |
| 192 animatableValueToLength(animatableLengthSize->width(), state, range), | |
| 193 animatableValueToLength(animatableLengthSize->height(), state, range)); | |
| 194 } | |
| 195 | |
| 196 void setFillSize(FillLayer* fillLayer, | |
| 197 const AnimatableValue* value, | |
| 198 StyleResolverState& state) { | |
| 199 if (value->isLengthSize()) | |
| 200 fillLayer->setSize(FillSize( | |
| 201 SizeLength, | |
| 202 animatableValueToLengthSize(value, state, ValueRangeNonNegative))); | |
| 203 else | |
| 204 CSSToStyleMap::mapFillSize(state, fillLayer, | |
| 205 *toAnimatableUnknown(value)->toCSSValue()); | |
| 206 } | |
| 207 | |
| 208 template <CSSPropertyID property> | |
| 209 void setOnFillLayers(FillLayer& fillLayers, | |
| 210 const AnimatableValue* value, | |
| 211 StyleResolverState& state) { | |
| 212 const Vector<RefPtr<AnimatableValue>>& values = | |
| 213 toAnimatableRepeatable(value)->values(); | |
| 214 ASSERT(!values.isEmpty()); | |
| 215 FillLayer* fillLayer = &fillLayers; | |
| 216 FillLayer* prev = 0; | |
| 217 for (size_t i = 0; i < values.size(); ++i) { | |
| 218 if (!fillLayer) | |
| 219 fillLayer = prev->ensureNext(); | |
| 220 const AnimatableValue* layerValue = values[i].get(); | |
| 221 switch (property) { | |
| 222 case CSSPropertyBackgroundImage: | |
| 223 case CSSPropertyWebkitMaskImage: | |
| 224 if (layerValue->isImage()) { | |
| 225 fillLayer->setImage(state.styleImage( | |
| 226 property, *toAnimatableImage(layerValue)->toCSSValue())); | |
| 227 } else { | |
| 228 ASSERT(toAnimatableUnknown(layerValue)->toCSSValueID() == | |
| 229 CSSValueNone); | |
| 230 fillLayer->setImage(nullptr); | |
| 231 } | |
| 232 break; | |
| 233 case CSSPropertyBackgroundPositionX: | |
| 234 case CSSPropertyWebkitMaskPositionX: | |
| 235 fillLayer->setXPosition(animatableValueToLength(layerValue, state)); | |
| 236 break; | |
| 237 case CSSPropertyBackgroundPositionY: | |
| 238 case CSSPropertyWebkitMaskPositionY: | |
| 239 fillLayer->setYPosition(animatableValueToLength(layerValue, state)); | |
| 240 break; | |
| 241 case CSSPropertyBackgroundSize: | |
| 242 case CSSPropertyWebkitMaskSize: | |
| 243 setFillSize(fillLayer, layerValue, state); | |
| 244 break; | |
| 245 default: | |
| 246 ASSERT_NOT_REACHED(); | |
| 247 } | |
| 248 prev = fillLayer; | |
| 249 fillLayer = fillLayer->next(); | |
| 250 } | |
| 251 while (fillLayer) { | |
| 252 switch (property) { | |
| 253 case CSSPropertyBackgroundImage: | |
| 254 case CSSPropertyWebkitMaskImage: | |
| 255 fillLayer->clearImage(); | |
| 256 break; | |
| 257 case CSSPropertyBackgroundPositionX: | |
| 258 case CSSPropertyWebkitMaskPositionX: | |
| 259 fillLayer->clearXPosition(); | |
| 260 break; | |
| 261 case CSSPropertyBackgroundPositionY: | |
| 262 case CSSPropertyWebkitMaskPositionY: | |
| 263 fillLayer->clearYPosition(); | |
| 264 break; | |
| 265 case CSSPropertyBackgroundSize: | |
| 266 case CSSPropertyWebkitMaskSize: | |
| 267 fillLayer->clearSize(); | |
| 268 break; | |
| 269 default: | |
| 270 ASSERT_NOT_REACHED(); | |
| 271 } | |
| 272 fillLayer = fillLayer->next(); | |
| 273 } | |
| 274 } | |
| 275 | |
| 276 FontStretch animatableValueToFontStretch(const AnimatableValue* value) { | |
| 277 ASSERT(FontStretchUltraCondensed == 1 && FontStretchUltraExpanded == 9); | |
| 278 unsigned index = round(toAnimatableDouble(value)->toDouble()) - 1; | |
| 279 static const FontStretch stretchValues[] = { | |
| 280 FontStretchUltraCondensed, FontStretchExtraCondensed, | |
| 281 FontStretchCondensed, FontStretchSemiCondensed, | |
| 282 FontStretchNormal, FontStretchSemiExpanded, | |
| 283 FontStretchExpanded, FontStretchExtraExpanded, | |
| 284 FontStretchUltraExpanded}; | |
| 285 | |
| 286 index = clampTo<unsigned>(index, 0, WTF_ARRAY_LENGTH(stretchValues) - 1); | |
| 287 return stretchValues[index]; | |
| 288 } | |
| 289 | |
| 290 FontWeight animatableValueToFontWeight(const AnimatableValue* value) { | |
| 291 int index = round(toAnimatableDouble(value)->toDouble() / 100) - 1; | |
| 292 | |
| 293 static const FontWeight weights[] = { | |
| 294 FontWeight100, FontWeight200, FontWeight300, FontWeight400, FontWeight500, | |
| 295 FontWeight600, FontWeight700, FontWeight800, FontWeight900}; | |
| 296 | |
| 297 index = clampTo<int>(index, 0, WTF_ARRAY_LENGTH(weights) - 1); | |
| 298 | |
| 299 return weights[index]; | |
| 300 } | |
| 301 | |
| 302 FontDescription::Size animatableValueToFontSize(const AnimatableValue* value) { | |
| 303 float size = clampTo<float>(toAnimatableDouble(value)->toDouble(), 0); | |
| 304 return FontDescription::Size(0, size, true); | |
| 305 } | |
| 306 | |
| 307 TransformOperation* animatableValueToTransformOperation( | |
| 308 const AnimatableValue* value, | |
| 309 TransformOperation::OperationType type) { | |
| 310 const TransformOperations& transformList = | |
| 311 toAnimatableTransform(value)->transformOperations(); | |
| 312 if (transformList.size() == 0) | |
| 313 return nullptr; | |
| 314 ASSERT(transformList.size() == 1); | |
| 315 ASSERT(transformList.operations()[0].get()->type() == type); | |
| 316 return transformList.operations()[0].get(); | |
| 317 } | |
| 318 | |
| 319 } // namespace | |
| 320 | |
| 321 // FIXME: Generate this function. | |
| 322 void AnimatedStyleBuilder::applyProperty(CSSPropertyID property, | 67 void AnimatedStyleBuilder::applyProperty(CSSPropertyID property, |
| 323 StyleResolverState& state, | 68 ComputedStyle& style, |
| 324 const AnimatableValue* value) { | 69 const AnimatableValue* value) { |
| 325 ASSERT(CSSPropertyMetadata::isInterpolableProperty(property)); | 70 ASSERT(CSSPropertyMetadata::isInterpolableProperty(property)); |
| 326 if (value->isUnknown()) { | |
| 327 StyleBuilder::applyProperty(property, state, | |
| 328 *toAnimatableUnknown(value)->toCSSValue()); | |
| 329 return; | |
| 330 } | |
| 331 ComputedStyle* style = state.style(); | |
| 332 switch (property) { | 71 switch (property) { |
| 333 case CSSPropertyBackgroundColor: | |
| 334 style->setBackgroundColor(toAnimatableColor(value)->getColor()); | |
| 335 style->setVisitedLinkBackgroundColor( | |
| 336 toAnimatableColor(value)->visitedLinkColor()); | |
| 337 return; | |
| 338 case CSSPropertyBackgroundImage: | |
| 339 setOnFillLayers<CSSPropertyBackgroundImage>( | |
| 340 style->accessBackgroundLayers(), value, state); | |
| 341 return; | |
| 342 case CSSPropertyBackgroundPositionX: | |
| 343 setOnFillLayers<CSSPropertyBackgroundPositionX>( | |
| 344 style->accessBackgroundLayers(), value, state); | |
| 345 return; | |
| 346 case CSSPropertyBackgroundPositionY: | |
| 347 setOnFillLayers<CSSPropertyBackgroundPositionY>( | |
| 348 style->accessBackgroundLayers(), value, state); | |
| 349 return; | |
| 350 case CSSPropertyBackgroundSize: | |
| 351 setOnFillLayers<CSSPropertyBackgroundSize>( | |
| 352 style->accessBackgroundLayers(), value, state); | |
| 353 return; | |
| 354 case CSSPropertyBaselineShift: | |
| 355 style->accessSVGStyle().setBaselineShift(BS_LENGTH); | |
| 356 style->accessSVGStyle().setBaselineShiftValue( | |
| 357 animatableValueToLength(value, state)); | |
| 358 return; | |
| 359 case CSSPropertyBorderBottomColor: | |
| 360 style->setBorderBottomColor(toAnimatableColor(value)->getColor()); | |
| 361 style->setVisitedLinkBorderBottomColor( | |
| 362 toAnimatableColor(value)->visitedLinkColor()); | |
| 363 return; | |
| 364 case CSSPropertyBorderBottomLeftRadius: | |
| 365 style->setBorderBottomLeftRadius( | |
| 366 animatableValueToLengthSize(value, state, ValueRangeNonNegative)); | |
| 367 return; | |
| 368 case CSSPropertyBorderBottomRightRadius: | |
| 369 style->setBorderBottomRightRadius( | |
| 370 animatableValueToLengthSize(value, state, ValueRangeNonNegative)); | |
| 371 return; | |
| 372 case CSSPropertyBorderBottomWidth: | |
| 373 style->setBorderBottomWidth(animatableLineWidth(value, state)); | |
| 374 return; | |
| 375 case CSSPropertyBorderImageOutset: | |
| 376 style->setBorderImageOutset( | |
| 377 animatableValueToBorderImageLengthBox(value, state)); | |
| 378 return; | |
| 379 case CSSPropertyBorderImageSlice: | |
| 380 style->setBorderImageSlices( | |
| 381 animatableValueToLengthBox(toAnimatableLengthBoxAndBool(value)->box(), | |
| 382 state, ValueRangeNonNegative)); | |
| 383 style->setBorderImageSlicesFill( | |
| 384 toAnimatableLengthBoxAndBool(value)->flag()); | |
| 385 return; | |
| 386 case CSSPropertyBorderImageSource: | |
| 387 style->setBorderImageSource( | |
| 388 state.styleImage(property, *toAnimatableImage(value)->toCSSValue())); | |
| 389 return; | |
| 390 case CSSPropertyBorderImageWidth: | |
| 391 style->setBorderImageWidth( | |
| 392 animatableValueToBorderImageLengthBox(value, state)); | |
| 393 return; | |
| 394 case CSSPropertyBorderLeftColor: | |
| 395 style->setBorderLeftColor(toAnimatableColor(value)->getColor()); | |
| 396 style->setVisitedLinkBorderLeftColor( | |
| 397 toAnimatableColor(value)->visitedLinkColor()); | |
| 398 return; | |
| 399 case CSSPropertyBorderLeftWidth: | |
| 400 style->setBorderLeftWidth(animatableLineWidth(value, state)); | |
| 401 return; | |
| 402 case CSSPropertyBorderRightColor: | |
| 403 style->setBorderRightColor(toAnimatableColor(value)->getColor()); | |
| 404 style->setVisitedLinkBorderRightColor( | |
| 405 toAnimatableColor(value)->visitedLinkColor()); | |
| 406 return; | |
| 407 case CSSPropertyBorderRightWidth: | |
| 408 style->setBorderRightWidth(animatableLineWidth(value, state)); | |
| 409 return; | |
| 410 case CSSPropertyBorderTopColor: | |
| 411 style->setBorderTopColor(toAnimatableColor(value)->getColor()); | |
| 412 style->setVisitedLinkBorderTopColor( | |
| 413 toAnimatableColor(value)->visitedLinkColor()); | |
| 414 return; | |
| 415 case CSSPropertyBorderTopLeftRadius: | |
| 416 style->setBorderTopLeftRadius( | |
| 417 animatableValueToLengthSize(value, state, ValueRangeNonNegative)); | |
| 418 return; | |
| 419 case CSSPropertyBorderTopRightRadius: | |
| 420 style->setBorderTopRightRadius( | |
| 421 animatableValueToLengthSize(value, state, ValueRangeNonNegative)); | |
| 422 return; | |
| 423 case CSSPropertyBorderTopWidth: | |
| 424 style->setBorderTopWidth(animatableLineWidth(value, state)); | |
| 425 return; | |
| 426 case CSSPropertyBottom: | |
| 427 style->setBottom(animatableValueToLength(value, state)); | |
| 428 return; | |
| 429 case CSSPropertyBoxShadow: | |
| 430 style->setBoxShadow(toAnimatableShadow(value)->getShadowList()); | |
| 431 return; | |
| 432 case CSSPropertyCaretColor: | |
| 433 style->setCaretColor(toAnimatableColor(value)->getColor()); | |
| 434 style->setVisitedLinkCaretColor( | |
| 435 toAnimatableColor(value)->visitedLinkColor()); | |
| 436 return; | |
| 437 case CSSPropertyClip: | |
| 438 style->setClip(animatableValueToLengthBox(value, state)); | |
| 439 return; | |
| 440 case CSSPropertyColor: | |
| 441 style->setColor(toAnimatableColor(value)->getColor()); | |
| 442 style->setVisitedLinkColor(toAnimatableColor(value)->visitedLinkColor()); | |
| 443 return; | |
| 444 case CSSPropertyFillOpacity: | |
| 445 style->setFillOpacity( | |
| 446 clampTo<float>(toAnimatableDouble(value)->toDouble(), 0, 1)); | |
| 447 return; | |
| 448 case CSSPropertyFill: { | |
| 449 const AnimatableSVGPaint* svgPaint = toAnimatableSVGPaint(value); | |
| 450 style->accessSVGStyle().setFillPaint(svgPaint->paintType(), | |
| 451 svgPaint->getColor(), | |
| 452 svgPaint->uri(), true, false); | |
| 453 style->accessSVGStyle().setFillPaint( | |
| 454 svgPaint->visitedLinkPaintType(), svgPaint->visitedLinkColor(), | |
| 455 svgPaint->visitedLinkURI(), false, true); | |
| 456 } | |
| 457 return; | |
| 458 case CSSPropertyFlexGrow: | |
| 459 style->setFlexGrow( | |
| 460 clampTo<float>(toAnimatableDouble(value)->toDouble(), 0)); | |
| 461 return; | |
| 462 case CSSPropertyFlexShrink: | |
| 463 style->setFlexShrink( | |
| 464 clampTo<float>(toAnimatableDouble(value)->toDouble(), 0)); | |
| 465 return; | |
| 466 case CSSPropertyFlexBasis: | |
| 467 style->setFlexBasis( | |
| 468 animatableValueToLength(value, state, ValueRangeNonNegative)); | |
| 469 return; | |
| 470 case CSSPropertyFloodColor: | |
| 471 style->setFloodColor(toAnimatableColor(value)->getColor()); | |
| 472 return; | |
| 473 case CSSPropertyFloodOpacity: | |
| 474 style->setFloodOpacity( | |
| 475 clampTo<float>(toAnimatableDouble(value)->toDouble(), 0, 1)); | |
| 476 return; | |
| 477 case CSSPropertyFontSize: | |
| 478 state.fontBuilder().setSize(animatableValueToFontSize(value)); | |
| 479 return; | |
| 480 case CSSPropertyFontSizeAdjust: | |
| 481 state.fontBuilder().setSizeAdjust( | |
| 482 clampTo<float>(toAnimatableDouble(value)->toDouble(), 0)); | |
| 483 return; | |
| 484 case CSSPropertyFontStretch: | |
| 485 state.fontBuilder().setStretch(animatableValueToFontStretch(value)); | |
| 486 return; | |
| 487 case CSSPropertyFontWeight: | |
| 488 state.fontBuilder().setWeight(animatableValueToFontWeight(value)); | |
| 489 return; | |
| 490 case CSSPropertyHeight: | |
| 491 style->setHeight( | |
| 492 animatableValueToLength(value, state, ValueRangeNonNegative)); | |
| 493 return; | |
| 494 case CSSPropertyLeft: | |
| 495 style->setLeft(animatableValueToLength(value, state)); | |
| 496 return; | |
| 497 case CSSPropertyLightingColor: | |
| 498 style->setLightingColor(toAnimatableColor(value)->getColor()); | |
| 499 return; | |
| 500 case CSSPropertyLineHeight: | |
| 501 if (value->isLength()) | |
| 502 style->setLineHeight( | |
| 503 animatableValueToLength(value, state, ValueRangeNonNegative)); | |
| 504 else | |
| 505 style->setLineHeight(Length( | |
| 506 clampTo<float>(toAnimatableDouble(value)->toDouble(), 0), Percent)); | |
| 507 return; | |
| 508 case CSSPropertyListStyleImage: | |
| 509 style->setListStyleImage( | |
| 510 state.styleImage(property, *toAnimatableImage(value)->toCSSValue())); | |
| 511 return; | |
| 512 case CSSPropertyLetterSpacing: | |
| 513 style->setLetterSpacing( | |
| 514 clampTo<float>(animatableValueToPixels(value, state))); | |
| 515 return; | |
| 516 case CSSPropertyMarginBottom: | |
| 517 style->setMarginBottom(animatableValueToLength(value, state)); | |
| 518 return; | |
| 519 case CSSPropertyMarginLeft: | |
| 520 style->setMarginLeft(animatableValueToLength(value, state)); | |
| 521 return; | |
| 522 case CSSPropertyMarginRight: | |
| 523 style->setMarginRight(animatableValueToLength(value, state)); | |
| 524 return; | |
| 525 case CSSPropertyMarginTop: | |
| 526 style->setMarginTop(animatableValueToLength(value, state)); | |
| 527 return; | |
| 528 case CSSPropertyMaxHeight: | |
| 529 style->setMaxHeight( | |
| 530 animatableValueToLength(value, state, ValueRangeNonNegative)); | |
| 531 return; | |
| 532 case CSSPropertyMaxWidth: | |
| 533 style->setMaxWidth( | |
| 534 animatableValueToLength(value, state, ValueRangeNonNegative)); | |
| 535 return; | |
| 536 case CSSPropertyMinHeight: | |
| 537 style->setMinHeight( | |
| 538 animatableValueToLength(value, state, ValueRangeNonNegative)); | |
| 539 return; | |
| 540 case CSSPropertyMinWidth: | |
| 541 style->setMinWidth( | |
| 542 animatableValueToLength(value, state, ValueRangeNonNegative)); | |
| 543 return; | |
| 544 case CSSPropertyObjectPosition: | |
| 545 style->setObjectPosition(animatableValueToLengthPoint(value, state)); | |
| 546 return; | |
| 547 case CSSPropertyOpacity: | 72 case CSSPropertyOpacity: |
| 548 // Avoiding a value of 1 forces a layer to be created. | 73 // Avoiding a value of 1 forces a layer to be created. |
| 549 style->setOpacity(clampTo<float>(toAnimatableDouble(value)->toDouble(), 0, | 74 style.setOpacity(clampTo<float>(toAnimatableDouble(value)->toDouble(), 0, |
| 550 nextafterf(1, 0))); | 75 nextafterf(1, 0))); |
| 551 return; | |
| 552 case CSSPropertyOrder: | |
| 553 style->setOrder( | |
| 554 clampTo<int>(round(toAnimatableDouble(value)->toDouble()))); | |
| 555 return; | |
| 556 case CSSPropertyOrphans: | |
| 557 style->setOrphans( | |
| 558 clampTo<short>(round(toAnimatableDouble(value)->toDouble()), 1)); | |
| 559 return; | |
| 560 case CSSPropertyOutlineColor: | |
| 561 style->setOutlineColor(toAnimatableColor(value)->getColor()); | |
| 562 style->setVisitedLinkOutlineColor( | |
| 563 toAnimatableColor(value)->visitedLinkColor()); | |
| 564 return; | |
| 565 case CSSPropertyOutlineOffset: | |
| 566 style->setOutlineOffset( | |
| 567 roundedClampTo<int>(animatableValueToPixels(value, state))); | |
| 568 return; | |
| 569 case CSSPropertyOutlineWidth: | |
| 570 style->setOutlineWidth( | |
| 571 animatableLineWidthClamp<unsigned short>(value, state)); | |
| 572 return; | |
| 573 case CSSPropertyPaddingBottom: | |
| 574 style->setPaddingBottom( | |
| 575 animatableValueToLength(value, state, ValueRangeNonNegative)); | |
| 576 return; | |
| 577 case CSSPropertyPaddingLeft: | |
| 578 style->setPaddingLeft( | |
| 579 animatableValueToLength(value, state, ValueRangeNonNegative)); | |
| 580 return; | |
| 581 case CSSPropertyPaddingRight: | |
| 582 style->setPaddingRight( | |
| 583 animatableValueToLength(value, state, ValueRangeNonNegative)); | |
| 584 return; | |
| 585 case CSSPropertyPaddingTop: | |
| 586 style->setPaddingTop( | |
| 587 animatableValueToLength(value, state, ValueRangeNonNegative)); | |
| 588 return; | |
| 589 case CSSPropertyRight: | |
| 590 style->setRight(animatableValueToLength(value, state)); | |
| 591 return; | |
| 592 case CSSPropertyStrokeWidth: | |
| 593 style->setStrokeWidth( | |
| 594 animatableValueToUnzoomedLength(value, state, ValueRangeNonNegative)); | |
| 595 return; | |
| 596 case CSSPropertyStopColor: | |
| 597 style->setStopColor(toAnimatableColor(value)->getColor()); | |
| 598 return; | |
| 599 case CSSPropertyStopOpacity: | |
| 600 style->setStopOpacity( | |
| 601 clampTo<float>(toAnimatableDouble(value)->toDouble(), 0, 1)); | |
| 602 return; | |
| 603 case CSSPropertyStrokeDasharray: | |
| 604 style->setStrokeDashArray( | |
| 605 toAnimatableStrokeDasharrayList(value)->toSVGDashArray( | |
| 606 style->effectiveZoom())); | |
| 607 return; | |
| 608 case CSSPropertyStrokeDashoffset: | |
| 609 style->setStrokeDashOffset(animatableValueToLength(value, state)); | |
| 610 return; | |
| 611 case CSSPropertyStrokeMiterlimit: | |
| 612 style->setStrokeMiterLimit( | |
| 613 clampTo<float>(toAnimatableDouble(value)->toDouble(), 1)); | |
| 614 return; | |
| 615 case CSSPropertyStrokeOpacity: | |
| 616 style->setStrokeOpacity( | |
| 617 clampTo<float>(toAnimatableDouble(value)->toDouble(), 0, 1)); | |
| 618 return; | |
| 619 case CSSPropertyStroke: { | |
| 620 const AnimatableSVGPaint* svgPaint = toAnimatableSVGPaint(value); | |
| 621 style->accessSVGStyle().setStrokePaint(svgPaint->paintType(), | |
| 622 svgPaint->getColor(), | |
| 623 svgPaint->uri(), true, false); | |
| 624 style->accessSVGStyle().setStrokePaint( | |
| 625 svgPaint->visitedLinkPaintType(), svgPaint->visitedLinkColor(), | |
| 626 svgPaint->visitedLinkURI(), false, true); | |
| 627 } | |
| 628 return; | |
| 629 case CSSPropertyTextDecorationColor: | |
| 630 style->setTextDecorationColor(toAnimatableColor(value)->getColor()); | |
| 631 style->setVisitedLinkTextDecorationColor( | |
| 632 toAnimatableColor(value)->visitedLinkColor()); | |
| 633 return; | |
| 634 case CSSPropertyTextIndent: | |
| 635 style->setTextIndent(animatableValueToLength(value, state)); | |
| 636 return; | |
| 637 case CSSPropertyTextShadow: | |
| 638 style->setTextShadow(toAnimatableShadow(value)->getShadowList()); | |
| 639 return; | |
| 640 case CSSPropertyTop: | |
| 641 style->setTop(animatableValueToLength(value, state)); | |
| 642 return; | |
| 643 case CSSPropertyWebkitBorderHorizontalSpacing: | |
| 644 style->setHorizontalBorderSpacing(roundedClampTo<unsigned short>( | |
| 645 animatableValueToPixels(value, state))); | |
| 646 return; | |
| 647 case CSSPropertyWebkitBorderVerticalSpacing: | |
| 648 style->setVerticalBorderSpacing(roundedClampTo<unsigned short>( | |
| 649 animatableValueToPixels(value, state))); | |
| 650 return; | |
| 651 case CSSPropertyClipPath: | |
| 652 style->setClipPath( | |
| 653 toAnimatableClipPathOperation(value)->getClipPathOperation()); | |
| 654 return; | |
| 655 case CSSPropertyColumnCount: | |
| 656 style->setColumnCount(clampTo<unsigned short>( | |
| 657 round(toAnimatableDouble(value)->toDouble()), 1)); | |
| 658 return; | |
| 659 case CSSPropertyColumnGap: | |
| 660 style->setColumnGap(clampTo(animatableValueToPixels(value, state), 0)); | |
| 661 return; | |
| 662 case CSSPropertyColumnRuleColor: | |
| 663 style->setColumnRuleColor(toAnimatableColor(value)->getColor()); | |
| 664 style->setVisitedLinkColumnRuleColor( | |
| 665 toAnimatableColor(value)->visitedLinkColor()); | |
| 666 return; | |
| 667 case CSSPropertyColumnWidth: | |
| 668 style->setColumnWidth(clampTo(animatableValueToPixels(value, state), | |
| 669 std::numeric_limits<float>::epsilon())); | |
| 670 return; | |
| 671 case CSSPropertyColumnRuleWidth: | |
| 672 style->setColumnRuleWidth( | |
| 673 animatableLineWidthClamp<unsigned short>(value, state)); | |
| 674 return; | |
| 675 case CSSPropertyFilter: | |
| 676 style->setFilter(toAnimatableFilterOperations(value)->operations()); | |
| 677 return; | |
| 678 case CSSPropertyBackdropFilter: | |
| 679 style->setBackdropFilter( | |
| 680 toAnimatableFilterOperations(value)->operations()); | |
| 681 return; | |
| 682 case CSSPropertyWebkitMaskBoxImageOutset: | |
| 683 style->setMaskBoxImageOutset( | |
| 684 animatableValueToBorderImageLengthBox(value, state)); | |
| 685 return; | |
| 686 case CSSPropertyWebkitMaskBoxImageSlice: | |
| 687 style->setMaskBoxImageSlices( | |
| 688 animatableValueToLengthBox(toAnimatableLengthBoxAndBool(value)->box(), | |
| 689 state, ValueRangeNonNegative)); | |
| 690 style->setMaskBoxImageSlicesFill( | |
| 691 toAnimatableLengthBoxAndBool(value)->flag()); | |
| 692 return; | |
| 693 case CSSPropertyWebkitMaskBoxImageSource: | |
| 694 style->setMaskBoxImageSource( | |
| 695 state.styleImage(property, *toAnimatableImage(value)->toCSSValue())); | |
| 696 return; | |
| 697 case CSSPropertyWebkitMaskBoxImageWidth: | |
| 698 style->setMaskBoxImageWidth( | |
| 699 animatableValueToBorderImageLengthBox(value, state)); | |
| 700 return; | |
| 701 case CSSPropertyWebkitMaskImage: | |
| 702 setOnFillLayers<CSSPropertyWebkitMaskImage>(style->accessMaskLayers(), | |
| 703 value, state); | |
| 704 return; | |
| 705 case CSSPropertyWebkitMaskPositionX: | |
| 706 setOnFillLayers<CSSPropertyWebkitMaskPositionX>(style->accessMaskLayers(), | |
| 707 value, state); | |
| 708 return; | |
| 709 case CSSPropertyWebkitMaskPositionY: | |
| 710 setOnFillLayers<CSSPropertyWebkitMaskPositionY>(style->accessMaskLayers(), | |
| 711 value, state); | |
| 712 return; | |
| 713 case CSSPropertyWebkitMaskSize: | |
| 714 setOnFillLayers<CSSPropertyWebkitMaskSize>(style->accessMaskLayers(), | |
| 715 value, state); | |
| 716 return; | |
| 717 case CSSPropertyPerspective: | |
| 718 style->setPerspective( | |
| 719 value->isLength() | |
| 720 ? clampTo<float>(animatableValueToPixels(value, state)) | |
| 721 : 0); | |
| 722 return; | |
| 723 case CSSPropertyPerspectiveOrigin: | |
| 724 style->setPerspectiveOrigin(animatableValueToLengthPoint(value, state)); | |
| 725 return; | |
| 726 case CSSPropertyShapeOutside: | |
| 727 style->setShapeOutside(toAnimatableShapeValue(value)->getShapeValue()); | |
| 728 return; | |
| 729 case CSSPropertyShapeMargin: | |
| 730 style->setShapeMargin( | |
| 731 animatableValueToLength(value, state, ValueRangeNonNegative)); | |
| 732 return; | |
| 733 case CSSPropertyShapeImageThreshold: | |
| 734 style->setShapeImageThreshold( | |
| 735 clampTo<float>(toAnimatableDouble(value)->toDouble(), 0, 1)); | |
| 736 return; | |
| 737 case CSSPropertyWebkitTextStrokeColor: | |
| 738 style->setTextStrokeColor(toAnimatableColor(value)->getColor()); | |
| 739 style->setVisitedLinkTextStrokeColor( | |
| 740 toAnimatableColor(value)->visitedLinkColor()); | |
| 741 return; | 76 return; |
| 742 case CSSPropertyTransform: { | 77 case CSSPropertyTransform: { |
| 743 const TransformOperations& operations = | 78 const TransformOperations& operations = |
| 744 toAnimatableTransform(value)->transformOperations(); | 79 toAnimatableTransform(value)->transformOperations(); |
| 745 // FIXME: This normalization (handling of 'none') should be performed at | 80 // FIXME: This normalization (handling of 'none') should be performed at |
| 746 // input in AnimatableValueFactory. | 81 // input in AnimatableValueFactory. |
| 747 if (operations.size() == 0) { | 82 if (operations.size() == 0) { |
| 748 style->setTransform(TransformOperations(true)); | 83 style.setTransform(TransformOperations(true)); |
| 749 return; | 84 return; |
| 750 } | 85 } |
| 751 double sourceZoom = toAnimatableTransform(value)->zoom(); | 86 double sourceZoom = toAnimatableTransform(value)->zoom(); |
| 752 double destinationZoom = style->effectiveZoom(); | 87 double destinationZoom = style.effectiveZoom(); |
| 753 style->setTransform(sourceZoom == destinationZoom | 88 style.setTransform(sourceZoom == destinationZoom |
| 754 ? operations | 89 ? operations |
| 755 : operations.zoom(destinationZoom / sourceZoom)); | 90 : operations.zoom(destinationZoom / sourceZoom)); |
| 756 return; | 91 return; |
| 757 } | 92 } |
| 758 case CSSPropertyTranslate: { | 93 case CSSPropertyFilter: |
| 759 TranslateTransformOperation* translate = | 94 style.setFilter(toAnimatableFilterOperations(value)->operations()); |
| 760 toTranslateTransformOperation(animatableValueToTransformOperation( | |
| 761 value, TransformOperation::Translate3D)); | |
| 762 if (!translate) { | |
| 763 style->setTranslate(nullptr); | |
| 764 return; | |
| 765 } | |
| 766 double sourceZoom = toAnimatableTransform(value)->zoom(); | |
| 767 double destinationZoom = style->effectiveZoom(); | |
| 768 style->setTranslate( | |
| 769 sourceZoom == destinationZoom | |
| 770 ? translate | |
| 771 : translate->zoomTranslate(destinationZoom / sourceZoom)); | |
| 772 return; | |
| 773 } | |
| 774 case CSSPropertyRotate: { | |
| 775 style->setRotate( | |
| 776 toRotateTransformOperation(animatableValueToTransformOperation( | |
| 777 value, TransformOperation::Rotate3D))); | |
| 778 return; | |
| 779 } | |
| 780 case CSSPropertyScale: { | |
| 781 style->setScale( | |
| 782 toScaleTransformOperation(animatableValueToTransformOperation( | |
| 783 value, TransformOperation::Scale3D))); | |
| 784 return; | |
| 785 } | |
| 786 case CSSPropertyTransformOrigin: | |
| 787 style->setTransformOrigin(animatableValueToTransformOrigin(value, state)); | |
| 788 return; | |
| 789 case CSSPropertyOffsetAnchor: | |
| 790 style->setOffsetAnchor(animatableValueToLengthPoint(value, state)); | |
| 791 return; | |
| 792 case CSSPropertyOffsetDistance: | |
| 793 style->setOffsetDistance(animatableValueToLength(value, state)); | |
| 794 return; | |
| 795 case CSSPropertyOffsetPosition: | |
| 796 style->setOffsetPosition(animatableValueToLengthPoint(value, state)); | |
| 797 return; | |
| 798 case CSSPropertyOffsetRotate: | |
| 799 case CSSPropertyOffsetRotation: | |
| 800 style->setOffsetRotation(StyleOffsetRotation( | |
| 801 toAnimatableDoubleAndBool(value)->toDouble(), | |
| 802 toAnimatableDoubleAndBool(value)->flag() ? OffsetRotationAuto | |
| 803 : OffsetRotationFixed)); | |
| 804 return; | |
| 805 case CSSPropertyWebkitPerspectiveOriginX: | |
| 806 style->setPerspectiveOriginX(animatableValueToLength(value, state)); | |
| 807 return; | |
| 808 case CSSPropertyWebkitPerspectiveOriginY: | |
| 809 style->setPerspectiveOriginY(animatableValueToLength(value, state)); | |
| 810 return; | |
| 811 case CSSPropertyWebkitTransformOriginX: | |
| 812 style->setTransformOriginX(animatableValueToLength(value, state)); | |
| 813 return; | |
| 814 case CSSPropertyWebkitTransformOriginY: | |
| 815 style->setTransformOriginY(animatableValueToLength(value, state)); | |
| 816 return; | |
| 817 case CSSPropertyWebkitTransformOriginZ: | |
| 818 style->setTransformOriginZ(animatableValueToPixels(value, state)); | |
| 819 return; | |
| 820 case CSSPropertyWidows: | |
| 821 style->setWidows( | |
| 822 clampTo<short>(round(toAnimatableDouble(value)->toDouble()), 1)); | |
| 823 return; | |
| 824 case CSSPropertyWidth: | |
| 825 style->setWidth( | |
| 826 animatableValueToLength(value, state, ValueRangeNonNegative)); | |
| 827 return; | |
| 828 case CSSPropertyWordSpacing: | |
| 829 style->setWordSpacing( | |
| 830 clampTo<float>(animatableValueToPixels(value, state))); | |
| 831 return; | |
| 832 case CSSPropertyVerticalAlign: | |
| 833 style->setVerticalAlignLength(animatableValueToLength(value, state)); | |
| 834 return; | |
| 835 case CSSPropertyVisibility: | |
| 836 style->setVisibility(toAnimatableVisibility(value)->visibility()); | |
| 837 return; | |
| 838 case CSSPropertyZIndex: | |
| 839 style->setZIndex( | |
| 840 clampTo<int>(round(toAnimatableDouble(value)->toDouble()))); | |
| 841 return; | |
| 842 case CSSPropertyD: | |
| 843 style->setD(toAnimatablePath(value)->path()); | |
| 844 return; | |
| 845 case CSSPropertyCx: | |
| 846 style->setCx(animatableValueToLength(value, state)); | |
| 847 return; | |
| 848 case CSSPropertyCy: | |
| 849 style->setCy(animatableValueToLength(value, state)); | |
| 850 return; | |
| 851 case CSSPropertyX: | |
| 852 style->setX(animatableValueToLength(value, state)); | |
| 853 return; | |
| 854 case CSSPropertyY: | |
| 855 style->setY(animatableValueToLength(value, state)); | |
| 856 return; | |
| 857 case CSSPropertyR: | |
| 858 style->setR(animatableValueToLength(value, state, ValueRangeNonNegative)); | |
| 859 return; | |
| 860 case CSSPropertyRx: | |
| 861 style->setRx( | |
| 862 animatableValueToLength(value, state, ValueRangeNonNegative)); | |
| 863 return; | |
| 864 case CSSPropertyRy: | |
| 865 style->setRy( | |
| 866 animatableValueToLength(value, state, ValueRangeNonNegative)); | |
| 867 return; | 95 return; |
| 868 | 96 |
| 869 default: | 97 default: |
| 870 ASSERT_NOT_REACHED(); | 98 NOTREACHED(); |
| 871 } | 99 } |
| 872 } | 100 } |
| 873 | 101 |
| 874 } // namespace blink | 102 } // namespace blink |
| OLD | NEW |