| /* |
| * Copyright (C) 2007, 2008, 2009, 2013, 2016 Apple Inc. All rights reserved. |
| * Copyright (C) 2012, 2013 Adobe Systems Incorporated. All rights reserved. |
| * |
| * Redistribution and use in source and binary forms, with or without |
| * modification, are permitted provided that the following conditions |
| * are met: |
| * |
| * 1. Redistributions of source code must retain the above copyright |
| * notice, this list of conditions and the following disclaimer. |
| * 2. Redistributions in binary form must reproduce the above copyright |
| * notice, this list of conditions and the following disclaimer in the |
| * documentation and/or other materials provided with the distribution. |
| * 3. Neither the name of Apple Inc. ("Apple") nor the names of |
| * its contributors may be used to endorse or promote products derived |
| * from this software without specific prior written permission. |
| * |
| * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
| * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
| * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| */ |
| |
| #include "config.h" |
| #include "CSSPropertyAnimation.h" |
| |
| #include "CSSComputedStyleDeclaration.h" |
| #include "CSSCrossfadeValue.h" |
| #include "CSSFilterImageValue.h" |
| #include "CSSImageGeneratorValue.h" |
| #include "CSSImageValue.h" |
| #include "CSSPrimitiveValue.h" |
| #include "CSSPropertyBlendingClient.h" |
| #include "CSSPropertyNames.h" |
| #include "CachedImage.h" |
| #include "CalculationValue.h" |
| #include "ClipPathOperation.h" |
| #include "ColorBlending.h" |
| #include "FloatConversion.h" |
| #include "FontCascade.h" |
| #include "FontSelectionAlgorithm.h" |
| #include "FontTaggedSettings.h" |
| #include "GapLength.h" |
| #include "IdentityTransformOperation.h" |
| #include "LengthPoint.h" |
| #include "Logging.h" |
| #include "Matrix3DTransformOperation.h" |
| #include "MatrixTransformOperation.h" |
| #include "RenderBox.h" |
| #include "RenderStyle.h" |
| #include "StyleCachedImage.h" |
| #include "StyleGeneratedImage.h" |
| #include "StylePropertyShorthand.h" |
| #include "StyleResolver.h" |
| #include "TabSize.h" |
| #include <algorithm> |
| #include <memory> |
| #include <wtf/MathExtras.h> |
| #include <wtf/NeverDestroyed.h> |
| #include <wtf/Noncopyable.h> |
| #include <wtf/PointerComparison.h> |
| #include <wtf/RefCounted.h> |
| #include <wtf/text/TextStream.h> |
| |
| namespace WebCore { |
| |
| static inline int blendFunc(const CSSPropertyBlendingClient*, int from, int to, double progress) |
| { |
| return blend(from, to, progress); |
| } |
| |
| static inline double blendFunc(const CSSPropertyBlendingClient*, double from, double to, double progress) |
| { |
| return blend(from, to, progress); |
| } |
| |
| static inline float blendFunc(const CSSPropertyBlendingClient*, float from, float to, double progress) |
| { |
| return narrowPrecisionToFloat(from + (to - from) * progress); |
| } |
| |
| static inline Color blendFunc(const CSSPropertyBlendingClient*, const Color& from, const Color& to, double progress) |
| { |
| return blend(from, to, progress); |
| } |
| |
| static inline Length blendFunc(const CSSPropertyBlendingClient*, const Length& from, const Length& to, double progress, ValueRange valueRange = ValueRangeAll) |
| { |
| return blend(from, to, progress, valueRange); |
| } |
| |
| static inline GapLength blendFunc(const CSSPropertyBlendingClient*, const GapLength& from, const GapLength& to, double progress) |
| { |
| if (from.isNormal() || to.isNormal()) |
| return progress < 0.5 ? from : to; |
| return blend(from.length(), to.length(), progress, ValueRangeNonNegative); |
| } |
| |
| static inline TabSize blendFunc(const CSSPropertyBlendingClient*, const TabSize& from, const TabSize& to, double progress) |
| { |
| auto blendedValue = blend(from.value(), to.value(), progress); |
| return { blendedValue < 0 ? 0 : blendedValue, from.isSpaces() ? SpaceValueType : LengthValueType }; |
| } |
| |
| static inline LengthSize blendFunc(const CSSPropertyBlendingClient* client, const LengthSize& from, const LengthSize& to, double progress) |
| { |
| return { blendFunc(client, from.width, to.width, progress, ValueRangeNonNegative), |
| blendFunc(client, from.height, to.height, progress, ValueRangeNonNegative) }; |
| } |
| |
| static inline LengthPoint blendFunc(const CSSPropertyBlendingClient*, const LengthPoint& from, const LengthPoint& to, double progress) |
| { |
| return blend(from, to, progress); |
| } |
| |
| static inline ShadowStyle blendFunc(const CSSPropertyBlendingClient* client, ShadowStyle from, ShadowStyle to, double progress) |
| { |
| if (from == to) |
| return to; |
| |
| double fromVal = from == ShadowStyle::Normal ? 1 : 0; |
| double toVal = to == ShadowStyle::Normal ? 1 : 0; |
| double result = blendFunc(client, fromVal, toVal, progress); |
| return result > 0 ? ShadowStyle::Normal : ShadowStyle::Inset; |
| } |
| |
| static inline std::unique_ptr<ShadowData> blendFunc(const CSSPropertyBlendingClient* client, const ShadowData* from, const ShadowData* to, double progress) |
| { |
| ASSERT(from && to); |
| ASSERT(from->style() == to->style()); |
| |
| return makeUnique<ShadowData>(blend(from->location(), to->location(), progress), |
| std::max(0, blend(from->radius(), to->radius(), progress)), |
| blend(from->spread(), to->spread(), progress), |
| blendFunc(client, from->style(), to->style(), progress), |
| from->isWebkitBoxShadow(), |
| blend(from->color(), to->color(), progress)); |
| } |
| |
| static inline TransformOperations blendFunc(const CSSPropertyBlendingClient* client, const TransformOperations& from, const TransformOperations& to, double progress) |
| { |
| if (client->transformFunctionListsMatch()) |
| return to.blendByMatchingOperations(from, progress); |
| return to.blendByUsingMatrixInterpolation(from, progress, is<RenderBox>(client->renderer()) ? downcast<RenderBox>(*client->renderer()).borderBoxRect().size() : LayoutSize()); |
| } |
| |
| static RefPtr<ScaleTransformOperation> blendFunc(const CSSPropertyBlendingClient* client, ScaleTransformOperation* from, ScaleTransformOperation* to, double progress) |
| { |
| if (!from && !to) |
| return nullptr; |
| |
| RefPtr<ScaleTransformOperation> identity; |
| if (!from) { |
| identity = ScaleTransformOperation::create(1, 1, 1, to->type()); |
| from = identity.get(); |
| } else if (!to) { |
| identity = ScaleTransformOperation::create(1, 1, 1, from->type()); |
| to = identity.get(); |
| } |
| |
| // Ensure the two transforms have the same type. |
| if (!from->isSameType(*to)) { |
| RefPtr<ScaleTransformOperation> normalizedFrom; |
| RefPtr<ScaleTransformOperation> normalizedTo; |
| if (from->is3DOperation() || to->is3DOperation()) { |
| normalizedFrom = ScaleTransformOperation::create(from->x(), from->y(), from->z(), TransformOperation::SCALE_3D); |
| normalizedTo = ScaleTransformOperation::create(to->x(), to->y(), to->z(), TransformOperation::SCALE_3D); |
| } else { |
| normalizedFrom = ScaleTransformOperation::create(from->x(), from->y(), TransformOperation::SCALE); |
| normalizedTo = ScaleTransformOperation::create(to->x(), to->y(), TransformOperation::SCALE); |
| } |
| return blendFunc(client, normalizedFrom.get(), normalizedTo.get(), progress); |
| } |
| |
| auto blendedOperation = to->blend(from, progress); |
| if (is<ScaleTransformOperation>(blendedOperation.get())) { |
| auto& scale = downcast<ScaleTransformOperation>(blendedOperation.get()); |
| return ScaleTransformOperation::create(scale.x(), scale.y(), scale.z(), scale.type()); |
| } |
| return nullptr; |
| } |
| |
| static RefPtr<RotateTransformOperation> blendFunc(const CSSPropertyBlendingClient* client, RotateTransformOperation* from, RotateTransformOperation* to, double progress) |
| { |
| if (!from && !to) |
| return nullptr; |
| |
| RefPtr<RotateTransformOperation> identity; |
| if (!from) { |
| identity = RotateTransformOperation::create(0, to->type()); |
| from = identity.get(); |
| } else if (!to) { |
| identity = RotateTransformOperation::create(0, from->type()); |
| to = identity.get(); |
| } |
| |
| // Ensure the two transforms have the same type. |
| if (!from->isSameType(*to)) { |
| RefPtr<RotateTransformOperation> normalizedFrom; |
| RefPtr<RotateTransformOperation> normalizedTo; |
| if (from->is3DOperation() || to->is3DOperation()) { |
| normalizedFrom = RotateTransformOperation::create(from->x(), from->y(), from->z(), from->angle(), TransformOperation::ROTATE_3D); |
| normalizedTo = RotateTransformOperation::create(to->x(), to->y(), to->z(), to->angle(), TransformOperation::ROTATE_3D); |
| } else { |
| normalizedFrom = RotateTransformOperation::create(from->angle(), TransformOperation::ROTATE); |
| normalizedTo = RotateTransformOperation::create(to->angle(), TransformOperation::ROTATE); |
| } |
| return blendFunc(client, normalizedFrom.get(), normalizedTo.get(), progress); |
| } |
| |
| auto blendedOperation = to->blend(from, progress); |
| if (is<RotateTransformOperation>(blendedOperation.get())) { |
| auto& rotate = downcast<RotateTransformOperation>(blendedOperation.get()); |
| return RotateTransformOperation::create(rotate.x(), rotate.y(), rotate.z(), rotate.angle(), rotate.type()); |
| } |
| return nullptr; |
| } |
| |
| static RefPtr<TranslateTransformOperation> blendFunc(const CSSPropertyBlendingClient* client, TranslateTransformOperation* from, TranslateTransformOperation* to, double progress) |
| { |
| if (!from && !to) |
| return nullptr; |
| |
| RefPtr<TranslateTransformOperation> identity; |
| if (!from) { |
| identity = TranslateTransformOperation::create(Length(0, LengthType::Fixed), Length(0, LengthType::Fixed), Length(0, LengthType::Fixed), to->type()); |
| from = identity.get(); |
| } else if (!to) { |
| identity = TranslateTransformOperation::create(Length(0, LengthType::Fixed), Length(0, LengthType::Fixed), Length(0, LengthType::Fixed), from->type()); |
| to = identity.get(); |
| } |
| |
| // Ensure the two transforms have the same type. |
| if (!from->isSameType(*to)) { |
| RefPtr<TranslateTransformOperation> normalizedFrom; |
| RefPtr<TranslateTransformOperation> normalizedTo; |
| if (from->is3DOperation() || to->is3DOperation()) { |
| normalizedFrom = TranslateTransformOperation::create(from->x(), from->y(), from->z(), TransformOperation::TRANSLATE_3D); |
| normalizedTo = TranslateTransformOperation::create(to->x(), to->y(), to->z(), TransformOperation::TRANSLATE_3D); |
| } else { |
| normalizedFrom = TranslateTransformOperation::create(from->x(), from->y(), TransformOperation::TRANSLATE); |
| normalizedTo = TranslateTransformOperation::create(to->x(), to->y(), TransformOperation::TRANSLATE); |
| } |
| return blendFunc(client, normalizedFrom.get(), normalizedTo.get(), progress); |
| } |
| |
| Ref<TransformOperation> blendedOperation = to->blend(from, progress); |
| if (is<TranslateTransformOperation>(blendedOperation.get())) { |
| TranslateTransformOperation& translate = downcast<TranslateTransformOperation>(blendedOperation.get()); |
| return TranslateTransformOperation::create(translate.x(), translate.y(), translate.z(), translate.type()); |
| } |
| return nullptr; |
| } |
| |
| static inline RefPtr<ClipPathOperation> blendFunc(const CSSPropertyBlendingClient*, ClipPathOperation* from, ClipPathOperation* to, double progress) |
| { |
| if (!from || !to) |
| return to; |
| |
| // Other clip-path operations than BasicShapes can not be animated. |
| if (from->type() != ClipPathOperation::Shape || to->type() != ClipPathOperation::Shape) |
| return to; |
| |
| const BasicShape& fromShape = downcast<ShapeClipPathOperation>(*from).basicShape(); |
| const BasicShape& toShape = downcast<ShapeClipPathOperation>(*to).basicShape(); |
| |
| if (!fromShape.canBlend(toShape)) |
| return to; |
| |
| return ShapeClipPathOperation::create(toShape.blend(fromShape, progress)); |
| } |
| |
| static inline RefPtr<ShapeValue> blendFunc(const CSSPropertyBlendingClient*, ShapeValue* from, ShapeValue* to, double progress) |
| { |
| if (!progress) |
| return from; |
| |
| if (progress == 1.0) |
| return to; |
| |
| ASSERT(from && to); |
| const BasicShape& fromShape = *from->shape(); |
| const BasicShape& toShape = *to->shape(); |
| return ShapeValue::create(toShape.blend(fromShape, progress), to->cssBox()); |
| } |
| |
| static inline RefPtr<FilterOperation> blendFunc(const CSSPropertyBlendingClient*, FilterOperation* from, FilterOperation* to, double progress, bool blendToPassthrough = false) |
| { |
| ASSERT(to); |
| return to->blend(from, progress, blendToPassthrough); |
| } |
| |
| static inline FilterOperations blendFilterOperations(const CSSPropertyBlendingClient* client, const FilterOperations& from, const FilterOperations& to, double progress) |
| { |
| FilterOperations result; |
| size_t fromSize = from.operations().size(); |
| size_t toSize = to.operations().size(); |
| size_t size = std::max(fromSize, toSize); |
| for (size_t i = 0; i < size; i++) { |
| RefPtr<FilterOperation> fromOp = (i < fromSize) ? from.operations()[i].get() : 0; |
| RefPtr<FilterOperation> toOp = (i < toSize) ? to.operations()[i].get() : 0; |
| RefPtr<FilterOperation> blendedOp = toOp ? blendFunc(client, fromOp.get(), toOp.get(), progress) : (fromOp ? blendFunc(client, 0, fromOp.get(), progress, true) : 0); |
| if (blendedOp) |
| result.operations().append(blendedOp); |
| else { |
| auto identityOp = PassthroughFilterOperation::create(); |
| if (progress > 0.5) |
| result.operations().append(toOp ? toOp : WTFMove(identityOp)); |
| else |
| result.operations().append(fromOp ? fromOp : WTFMove(identityOp)); |
| } |
| } |
| return result; |
| } |
| |
| static inline FilterOperations blendFunc(const CSSPropertyBlendingClient* client, const FilterOperations& from, const FilterOperations& to, double progress, CSSPropertyID propertyID = CSSPropertyFilter) |
| { |
| FilterOperations result; |
| |
| // If we have a filter function list, use that to do a per-function animation. |
| |
| bool listsMatch = false; |
| switch (propertyID) { |
| case CSSPropertyFilter: |
| listsMatch = client->filterFunctionListsMatch(); |
| break; |
| #if ENABLE(FILTERS_LEVEL_2) |
| case CSSPropertyWebkitBackdropFilter: |
| listsMatch = client->backdropFilterFunctionListsMatch(); |
| break; |
| #endif |
| case CSSPropertyAppleColorFilter: |
| listsMatch = client->colorFilterFunctionListsMatch(); |
| break; |
| default: |
| break; |
| } |
| |
| if (listsMatch) |
| result = blendFilterOperations(client, from, to, progress); |
| else { |
| // If the filter function lists don't match, we could try to cross-fade, but don't yet have a way to represent that in CSS. |
| // For now we'll just fail to animate. |
| result = to; |
| } |
| |
| return result; |
| } |
| |
| static inline RefPtr<StyleImage> blendFilter(const CSSPropertyBlendingClient* client, CachedImage* image, const FilterOperations& from, const FilterOperations& to, double progress) |
| { |
| ASSERT(image); |
| FilterOperations filterResult = blendFilterOperations(client, from, to, progress); |
| |
| auto imageValue = CSSImageValue::create(*image); |
| auto filterValue = ComputedStyleExtractor::valueForFilter(client->currentStyle(), filterResult, DoNotAdjustPixelValues); |
| |
| auto result = CSSFilterImageValue::create(WTFMove(imageValue), WTFMove(filterValue)); |
| result.get().setFilterOperations(filterResult); |
| return StyleGeneratedImage::create(WTFMove(result)); |
| } |
| |
| static inline Visibility blendFunc(const CSSPropertyBlendingClient* client, Visibility from, Visibility to, double progress) |
| { |
| // Any non-zero result means we consider the object to be visible. Only at 0 do we consider the object to be |
| // invisible. The invisible value we use (Visibility::Hidden vs. Visibility::Collapse) depends on the specified from/to values. |
| double fromVal = from == Visibility::Visible ? 1. : 0.; |
| double toVal = to == Visibility::Visible ? 1. : 0.; |
| if (fromVal == toVal) |
| return to; |
| double result = blendFunc(client, fromVal, toVal, progress); |
| return result > 0. ? Visibility::Visible : (to != Visibility::Visible ? to : from); |
| } |
| |
| static inline TextUnderlineOffset blendFunc(const CSSPropertyBlendingClient* client, const TextUnderlineOffset& from, const TextUnderlineOffset& to, double progress) |
| { |
| if (from.isLength() && to.isLength()) |
| return TextUnderlineOffset::createWithLength(blendFunc(client, from.lengthValue(), to.lengthValue(), progress)); |
| return TextUnderlineOffset::createWithAuto(); |
| } |
| |
| static inline TextDecorationThickness blendFunc(const CSSPropertyBlendingClient* client, const TextDecorationThickness& from, const TextDecorationThickness& to, double progress) |
| { |
| if (from.isLength() && to.isLength()) |
| return TextDecorationThickness::createWithLength(blendFunc(client, from.lengthValue(), to.lengthValue(), progress)); |
| return TextDecorationThickness::createWithAuto(); |
| } |
| |
| static inline LengthBox blendFunc(const CSSPropertyBlendingClient* client, const LengthBox& from, const LengthBox& to, double progress, ValueRange valueRange = ValueRangeNonNegative) |
| { |
| LengthBox result(blendFunc(client, from.top(), to.top(), progress, valueRange), |
| blendFunc(client, from.right(), to.right(), progress, valueRange), |
| blendFunc(client, from.bottom(), to.bottom(), progress, valueRange), |
| blendFunc(client, from.left(), to.left(), progress, valueRange)); |
| return result; |
| } |
| |
| static inline SVGLengthValue blendFunc(const CSSPropertyBlendingClient*, const SVGLengthValue& from, const SVGLengthValue& to, double progress) |
| { |
| return SVGLengthValue::blend(from, to, narrowPrecisionToFloat(progress)); |
| } |
| |
| static inline Vector<SVGLengthValue> blendFunc(const CSSPropertyBlendingClient*, const Vector<SVGLengthValue>& from, const Vector<SVGLengthValue>& to, double progress) |
| { |
| size_t fromLength = from.size(); |
| size_t toLength = to.size(); |
| if (!fromLength) |
| return !progress ? from : to; |
| if (!toLength) |
| return progress == 1 ? from : to; |
| size_t resultLength = fromLength; |
| if (fromLength != toLength) { |
| if (!remainder(std::max(fromLength, toLength), std::min(fromLength, toLength))) |
| resultLength = std::max(fromLength, toLength); |
| else |
| resultLength = fromLength * toLength; |
| } |
| Vector<SVGLengthValue> result(resultLength); |
| for (size_t i = 0; i < resultLength; ++i) |
| result[i] = SVGLengthValue::blend(from[i % fromLength], to[i % toLength], narrowPrecisionToFloat(progress)); |
| return result; |
| } |
| |
| static inline RefPtr<StyleImage> crossfadeBlend(const CSSPropertyBlendingClient*, StyleCachedImage* fromStyleImage, StyleCachedImage* toStyleImage, double progress) |
| { |
| // If progress is at one of the extremes, we want getComputedStyle to show the image, |
| // not a completed cross-fade, so we hand back one of the existing images. |
| if (!progress) |
| return fromStyleImage; |
| if (progress == 1) |
| return toStyleImage; |
| if (!fromStyleImage->cachedImage() || !toStyleImage->cachedImage()) |
| return toStyleImage; |
| |
| auto fromImageValue = CSSImageValue::create(*fromStyleImage->cachedImage()); |
| auto toImageValue = CSSImageValue::create(*toStyleImage->cachedImage()); |
| auto percentageValue = CSSPrimitiveValue::create(progress, CSSUnitType::CSS_NUMBER); |
| |
| auto crossfadeValue = CSSCrossfadeValue::create(WTFMove(fromImageValue), WTFMove(toImageValue), WTFMove(percentageValue)); |
| return StyleGeneratedImage::create(WTFMove(crossfadeValue)); |
| } |
| |
| static inline RefPtr<StyleImage> blendFunc(const CSSPropertyBlendingClient* client, StyleImage* from, StyleImage* to, double progress) |
| { |
| if (!progress) |
| return from; |
| |
| if (progress == 1.0) |
| return to; |
| |
| ASSERT(from && to); |
| |
| from = from->selectedImage(); |
| to = to->selectedImage(); |
| |
| if (!from || !to) |
| return to; |
| |
| // Animation between two generated images. Cross fade for all other cases. |
| if (is<StyleGeneratedImage>(*from) && is<StyleGeneratedImage>(*to)) { |
| CSSImageGeneratorValue& fromGenerated = downcast<StyleGeneratedImage>(*from).imageValue(); |
| CSSImageGeneratorValue& toGenerated = downcast<StyleGeneratedImage>(*to).imageValue(); |
| |
| if (is<CSSFilterImageValue>(fromGenerated) && is<CSSFilterImageValue>(toGenerated)) { |
| // Animation of generated images just possible if input images are equal. |
| // Otherwise fall back to cross fade animation. |
| CSSFilterImageValue& fromFilter = downcast<CSSFilterImageValue>(fromGenerated); |
| CSSFilterImageValue& toFilter = downcast<CSSFilterImageValue>(toGenerated); |
| if (fromFilter.equalInputImages(toFilter) && fromFilter.cachedImage()) |
| return blendFilter(client, fromFilter.cachedImage(), fromFilter.filterOperations(), toFilter.filterOperations(), progress); |
| } |
| |
| if (is<CSSCrossfadeValue>(fromGenerated) && is<CSSCrossfadeValue>(toGenerated)) { |
| CSSCrossfadeValue& fromCrossfade = downcast<CSSCrossfadeValue>(fromGenerated); |
| CSSCrossfadeValue& toCrossfade = downcast<CSSCrossfadeValue>(toGenerated); |
| if (fromCrossfade.equalInputImages(toCrossfade)) { |
| if (auto crossfadeBlend = toCrossfade.blend(fromCrossfade, progress)) |
| return StyleGeneratedImage::create(*crossfadeBlend); |
| } |
| } |
| |
| // FIXME: Add support for animation between two *gradient() functions. |
| // https://bugs.webkit.org/show_bug.cgi?id=119956 |
| } else if (is<StyleGeneratedImage>(*from) && is<StyleCachedImage>(*to)) { |
| CSSImageGeneratorValue& fromGenerated = downcast<StyleGeneratedImage>(*from).imageValue(); |
| if (is<CSSFilterImageValue>(fromGenerated)) { |
| CSSFilterImageValue& fromFilter = downcast<CSSFilterImageValue>(fromGenerated); |
| if (fromFilter.cachedImage() && downcast<StyleCachedImage>(*to).cachedImage() == fromFilter.cachedImage()) |
| return blendFilter(client, fromFilter.cachedImage(), fromFilter.filterOperations(), FilterOperations(), progress); |
| } |
| // FIXME: Add interpolation between cross-fade and image source. |
| } else if (is<StyleCachedImage>(*from) && is<StyleGeneratedImage>(*to)) { |
| CSSImageGeneratorValue& toGenerated = downcast<StyleGeneratedImage>(*to).imageValue(); |
| if (is<CSSFilterImageValue>(toGenerated)) { |
| CSSFilterImageValue& toFilter = downcast<CSSFilterImageValue>(toGenerated); |
| if (toFilter.cachedImage() && downcast<StyleCachedImage>(*from).cachedImage() == toFilter.cachedImage()) |
| return blendFilter(client, toFilter.cachedImage(), FilterOperations(), toFilter.filterOperations(), progress); |
| } |
| // FIXME: Add interpolation between image source and cross-fade. |
| } |
| |
| // FIXME: Add support cross fade between cached and generated images. |
| // https://bugs.webkit.org/show_bug.cgi?id=78293 |
| if (is<StyleCachedImage>(*from) && is<StyleCachedImage>(*to)) |
| return crossfadeBlend(client, downcast<StyleCachedImage>(from), downcast<StyleCachedImage>(to), progress); |
| |
| return to; |
| } |
| |
| static inline NinePieceImage blendFunc(const CSSPropertyBlendingClient* client, const NinePieceImage& from, const NinePieceImage& to, double progress) |
| { |
| if (!from.hasImage() || !to.hasImage()) |
| return to; |
| |
| // FIXME (74112): Support transitioning between NinePieceImages that differ by more than image content. |
| |
| if (from.imageSlices() != to.imageSlices() || from.borderSlices() != to.borderSlices() || from.outset() != to.outset() || from.fill() != to.fill() || from.horizontalRule() != to.horizontalRule() || from.verticalRule() != to.verticalRule()) |
| return to; |
| |
| if (auto* renderer = client->renderer()) { |
| if (from.image()->imageSize(renderer, 1.0) != to.image()->imageSize(renderer, 1.0)) |
| return to; |
| } |
| |
| return NinePieceImage(blendFunc(client, from.image(), to.image(), progress), |
| from.imageSlices(), from.fill(), from.borderSlices(), from.outset(), from.horizontalRule(), from.verticalRule()); |
| } |
| |
| #if ENABLE(VARIATION_FONTS) |
| |
| static inline FontVariationSettings blendFunc(const CSSPropertyBlendingClient* client, const FontVariationSettings& from, const FontVariationSettings& to, double progress) |
| { |
| if (!progress) |
| return from; |
| |
| if (progress == 1.0) |
| return to; |
| |
| ASSERT(from.size() == to.size()); |
| FontVariationSettings result; |
| unsigned size = from.size(); |
| for (unsigned i = 0; i < size; ++i) { |
| auto& fromItem = from.at(i); |
| auto& toItem = to.at(i); |
| ASSERT(fromItem.tag() == toItem.tag()); |
| float interpolated = blendFunc(client, fromItem.value(), toItem.value(), progress); |
| result.insert({ fromItem.tag(), interpolated }); |
| } |
| return result; |
| } |
| |
| #endif |
| |
| static inline FontSelectionValue blendFunc(const CSSPropertyBlendingClient* client, FontSelectionValue from, FontSelectionValue to, double progress) |
| { |
| return FontSelectionValue(std::max(0.0f, blendFunc(client, static_cast<float>(from), static_cast<float>(to), progress))); |
| } |
| |
| static inline Optional<FontSelectionValue> blendFunc(const CSSPropertyBlendingClient* client, Optional<FontSelectionValue> from, Optional<FontSelectionValue> to, double progress) |
| { |
| return blendFunc(client, *from, *to, progress); |
| } |
| |
| class AnimationPropertyWrapperBase { |
| WTF_MAKE_NONCOPYABLE(AnimationPropertyWrapperBase); |
| WTF_MAKE_FAST_ALLOCATED; |
| public: |
| explicit AnimationPropertyWrapperBase(CSSPropertyID property) |
| : m_property(property) |
| { |
| } |
| virtual ~AnimationPropertyWrapperBase() = default; |
| |
| virtual bool isShorthandWrapper() const { return false; } |
| virtual bool equals(const RenderStyle*, const RenderStyle*) const = 0; |
| virtual bool canInterpolate(const RenderStyle*, const RenderStyle*) const { return true; } |
| virtual void blend(const CSSPropertyBlendingClient*, RenderStyle*, const RenderStyle*, const RenderStyle*, double) const = 0; |
| |
| #if !LOG_DISABLED |
| virtual void logBlend(const RenderStyle*, const RenderStyle*, const RenderStyle*, double) const = 0; |
| #endif |
| |
| CSSPropertyID property() const { return m_property; } |
| |
| virtual bool animationIsAccelerated() const { return false; } |
| |
| private: |
| CSSPropertyID m_property; |
| }; |
| |
| template <typename T> |
| class PropertyWrapperGetter : public AnimationPropertyWrapperBase { |
| WTF_MAKE_FAST_ALLOCATED; |
| public: |
| PropertyWrapperGetter(CSSPropertyID property, T (RenderStyle::*getter)() const) |
| : AnimationPropertyWrapperBase(property) |
| , m_getter(getter) |
| { |
| } |
| |
| T value(const RenderStyle* style) const |
| { |
| return (style->*m_getter)(); |
| } |
| |
| private: |
| bool equals(const RenderStyle* a, const RenderStyle* b) const override |
| { |
| if (a == b) |
| return true; |
| if (!a || !b) |
| return false; |
| return value(a) == value(b); |
| } |
| |
| #if !LOG_DISABLED |
| void logBlend(const RenderStyle* from, const RenderStyle* to, const RenderStyle* result, double progress) const final |
| { |
| LOG_WITH_STREAM(Animations, stream << " blending " << getPropertyName(property()) << " from " << value(from) << " to " << value(to) << " at " << TextStream::FormatNumberRespectingIntegers(progress) << " -> " << value(result)); |
| } |
| #endif |
| |
| T (RenderStyle::*m_getter)() const; |
| }; |
| |
| template <typename T> |
| class PropertyWrapper : public PropertyWrapperGetter<T> { |
| WTF_MAKE_FAST_ALLOCATED; |
| public: |
| PropertyWrapper(CSSPropertyID property, T (RenderStyle::*getter)() const, void (RenderStyle::*setter)(T)) |
| : PropertyWrapperGetter<T>(property, getter) |
| , m_setter(setter) |
| { |
| } |
| |
| void blend(const CSSPropertyBlendingClient* client, RenderStyle* destination, const RenderStyle* from, const RenderStyle* to, double progress) const override |
| { |
| (destination->*m_setter)(blendFunc(client, this->value(from), this->value(to), progress)); |
| } |
| |
| protected: |
| void (RenderStyle::*m_setter)(T); |
| }; |
| |
| template <typename T> |
| class PositivePropertyWrapper final : public PropertyWrapper<T> { |
| WTF_MAKE_FAST_ALLOCATED; |
| public: |
| PositivePropertyWrapper(CSSPropertyID property, T (RenderStyle::*getter)() const, void (RenderStyle::*setter)(T)) |
| : PropertyWrapper<T>(property, getter, setter) |
| { |
| } |
| |
| private: |
| void blend(const CSSPropertyBlendingClient* client, RenderStyle* destination, const RenderStyle* from, const RenderStyle* to, double progress) const final |
| { |
| auto blendedValue = blendFunc(client, this->value(from), this->value(to), progress); |
| (destination->*this->m_setter)(blendedValue > 1 ? blendedValue : 1); |
| } |
| }; |
| |
| template <typename T> |
| class DiscretePropertyWrapper final : public PropertyWrapperGetter<T> { |
| WTF_MAKE_FAST_ALLOCATED; |
| public: |
| DiscretePropertyWrapper(CSSPropertyID property, T (RenderStyle::*getter)() const, void (RenderStyle::*setter)(T)) |
| : PropertyWrapperGetter<T>(property, getter) |
| , m_setter(setter) |
| { |
| } |
| |
| private: |
| bool canInterpolate(const RenderStyle*, const RenderStyle*) const final { return false; } |
| |
| void blend(const CSSPropertyBlendingClient*, RenderStyle* destination, const RenderStyle* from, const RenderStyle* to, double progress) const final |
| { |
| ASSERT(!progress || progress == 1.0); |
| (destination->*this->m_setter)(this->value(progress ? to : from)); |
| } |
| |
| void (RenderStyle::*m_setter)(T); |
| }; |
| |
| template <typename T> |
| class RefCountedPropertyWrapper : public PropertyWrapperGetter<T*> { |
| WTF_MAKE_FAST_ALLOCATED; |
| public: |
| RefCountedPropertyWrapper(CSSPropertyID property, T* (RenderStyle::*getter)() const, void (RenderStyle::*setter)(RefPtr<T>&&)) |
| : PropertyWrapperGetter<T*>(property, getter) |
| , m_setter(setter) |
| { |
| } |
| |
| private: |
| void blend(const CSSPropertyBlendingClient* client, RenderStyle* destination, const RenderStyle* from, const RenderStyle* to, double progress) const final |
| { |
| (destination->*this->m_setter)(blendFunc(client, this->value(from), this->value(to), progress)); |
| } |
| |
| void (RenderStyle::*m_setter)(RefPtr<T>&&); |
| }; |
| |
| static bool canInterpolateLengths(const Length& from, const Length& to, bool isLengthPercentage) |
| { |
| if (from.type() == to.type()) |
| return true; |
| |
| // Some properties allow for <length-percentage> and <number> values. We must allow animating |
| // between a <length> and a <percentage>, but exclude animating between a <number> and either |
| // a <length> or <percentage>. We can use Length::isRelative() to determine whether we are |
| // dealing with a <number> as opposed to a <length> or <percentage>. |
| if (isLengthPercentage) { |
| return (from.isFixed() || from.isPercentOrCalculated() || from.isRelative()) |
| && (to.isFixed() || to.isPercentOrCalculated() || to.isRelative()) |
| && from.isRelative() == to.isRelative(); |
| } |
| |
| return false; |
| } |
| |
| class LengthPropertyWrapper : public PropertyWrapperGetter<const Length&> { |
| WTF_MAKE_FAST_ALLOCATED; |
| public: |
| enum class Flags { |
| IsLengthPercentage = 1 << 0, |
| NegativeLengthsAreInvalid = 1 << 1, |
| }; |
| LengthPropertyWrapper(CSSPropertyID property, const Length& (RenderStyle::*getter)() const, void (RenderStyle::*setter)(Length&&), OptionSet<Flags> flags = { }) |
| : PropertyWrapperGetter<const Length&>(property, getter) |
| , m_setter(setter) |
| , m_flags(flags) |
| { |
| } |
| |
| protected: |
| bool canInterpolate(const RenderStyle* from, const RenderStyle* to) const override |
| { |
| return canInterpolateLengths(value(from), value(to), m_flags.contains(Flags::IsLengthPercentage)); |
| } |
| |
| void blend(const CSSPropertyBlendingClient* client, RenderStyle* destination, const RenderStyle* from, const RenderStyle* to, double progress) const override |
| { |
| auto valueRange = m_flags.contains(Flags::NegativeLengthsAreInvalid) ? ValueRangeNonNegative : ValueRangeAll; |
| (destination->*m_setter)(blendFunc(client, value(from), value(to), progress, valueRange)); |
| } |
| |
| private: |
| void (RenderStyle::*m_setter)(Length&&); |
| OptionSet<Flags> m_flags; |
| }; |
| |
| static bool canInterpolateLengthVariants(const LengthSize& from, const LengthSize& to) |
| { |
| bool isLengthPercentage = true; |
| return canInterpolateLengths(from.width, to.width, isLengthPercentage) |
| && canInterpolateLengths(from.height, to.height, isLengthPercentage); |
| } |
| |
| static bool canInterpolateLengthVariants(const GapLength& from, const GapLength& to) |
| { |
| if (from.isNormal() || to.isNormal()) |
| return false; |
| bool isLengthPercentage = true; |
| return canInterpolateLengths(from.length(), to.length(), isLengthPercentage); |
| } |
| |
| class LengthPointPropertyWrapper final : public PropertyWrapperGetter<LengthPoint> { |
| WTF_MAKE_FAST_ALLOCATED; |
| public: |
| LengthPointPropertyWrapper(CSSPropertyID property, LengthPoint (RenderStyle::*getter)() const, void (RenderStyle::*setter)(LengthPoint&&)) |
| : PropertyWrapperGetter<LengthPoint>(property, getter) |
| , m_setter(setter) |
| { |
| } |
| |
| private: |
| void blend(const CSSPropertyBlendingClient* client, RenderStyle* destination, const RenderStyle* from, const RenderStyle* to, double progress) const final |
| { |
| (destination->*m_setter)(blendFunc(client, value(from), value(to), progress)); |
| } |
| |
| void (RenderStyle::*m_setter)(LengthPoint&&); |
| }; |
| |
| template <typename T> |
| class LengthVariantPropertyWrapper final : public PropertyWrapperGetter<const T&> { |
| WTF_MAKE_FAST_ALLOCATED; |
| public: |
| LengthVariantPropertyWrapper(CSSPropertyID property, const T& (RenderStyle::*getter)() const, void (RenderStyle::*setter)(T&&)) |
| : PropertyWrapperGetter<const T&>(property, getter) |
| , m_setter(setter) |
| { |
| } |
| |
| private: |
| bool canInterpolate(const RenderStyle* from, const RenderStyle* to) const final |
| { |
| return canInterpolateLengthVariants(this->value(from), this->value(to)); |
| } |
| |
| void blend(const CSSPropertyBlendingClient* client, RenderStyle* destination, const RenderStyle* from, const RenderStyle* to, double progress) const final |
| { |
| (destination->*m_setter)(blendFunc(client, this->value(from), this->value(to), progress)); |
| } |
| |
| void (RenderStyle::*m_setter)(T&&); |
| }; |
| |
| class LengthBoxPropertyWrapper final : public PropertyWrapperGetter<const LengthBox&> { |
| WTF_MAKE_FAST_ALLOCATED; |
| public: |
| enum class Flags { |
| IsLengthPercentage = 1 << 0, |
| UsesFillKeyword = 1 << 1, |
| AllowsNegativeValues = 1 << 2, |
| }; |
| LengthBoxPropertyWrapper(CSSPropertyID property, const LengthBox& (RenderStyle::*getter)() const, void (RenderStyle::*setter)(LengthBox&&), OptionSet<Flags> flags = { }) |
| : PropertyWrapperGetter<const LengthBox&>(property, getter) |
| , m_setter(setter) |
| , m_flags(flags) |
| { |
| } |
| |
| private: |
| bool canInterpolate(const RenderStyle* from, const RenderStyle* to) const final |
| { |
| if (m_flags.contains(Flags::UsesFillKeyword) && from->borderImage().fill() != to->borderImage().fill()) |
| return false; |
| |
| auto& fromLengthBox = value(from); |
| auto& toLengthBox = value(to); |
| bool isLengthPercentage = m_flags.contains(Flags::IsLengthPercentage); |
| return canInterpolateLengths(fromLengthBox.top(), toLengthBox.top(), isLengthPercentage) |
| && canInterpolateLengths(fromLengthBox.right(), toLengthBox.right(), isLengthPercentage) |
| && canInterpolateLengths(fromLengthBox.bottom(), toLengthBox.bottom(), isLengthPercentage) |
| && canInterpolateLengths(fromLengthBox.left(), toLengthBox.left(), isLengthPercentage); |
| } |
| |
| void blend(const CSSPropertyBlendingClient* client, RenderStyle* destination, const RenderStyle* from, const RenderStyle* to, double progress) const final |
| { |
| if (m_flags.contains(Flags::UsesFillKeyword)) |
| destination->setBorderImageSliceFill((!progress || canInterpolate(from, to) ? from : to)->borderImage().fill()); |
| auto valueRange = m_flags.contains(Flags::AllowsNegativeValues) ? ValueRangeAll : ValueRangeNonNegative; |
| (destination->*m_setter)(blendFunc(client, value(from), value(to), progress, valueRange)); |
| } |
| |
| void (RenderStyle::*m_setter)(LengthBox&&); |
| OptionSet<Flags> m_flags; |
| }; |
| |
| class PropertyWrapperClipPath final : public RefCountedPropertyWrapper<ClipPathOperation> { |
| WTF_MAKE_FAST_ALLOCATED; |
| public: |
| PropertyWrapperClipPath(CSSPropertyID property, ClipPathOperation* (RenderStyle::*getter)() const, void (RenderStyle::*setter)(RefPtr<ClipPathOperation>&&)) |
| : RefCountedPropertyWrapper<ClipPathOperation>(property, getter, setter) |
| { |
| } |
| |
| private: |
| bool equals(const RenderStyle* a, const RenderStyle* b) const final |
| { |
| // If the style pointers are the same, don't bother doing the test. |
| // If either is null, return false. If both are null, return true. |
| if (a == b) |
| return true; |
| if (!a || !b) |
| return false; |
| |
| auto* clipPathA = value(a); |
| auto* clipPathB = value(b); |
| if (clipPathA == clipPathB) |
| return true; |
| if (!clipPathA || !clipPathB) |
| return false; |
| return *clipPathA == *clipPathB; |
| } |
| }; |
| |
| #if ENABLE(VARIATION_FONTS) |
| class PropertyWrapperFontVariationSettings final : public PropertyWrapper<FontVariationSettings> { |
| WTF_MAKE_FAST_ALLOCATED; |
| public: |
| PropertyWrapperFontVariationSettings(CSSPropertyID property, FontVariationSettings (RenderStyle::*getter)() const, void (RenderStyle::*setter)(FontVariationSettings)) |
| : PropertyWrapper<FontVariationSettings>(property, getter, setter) |
| { |
| } |
| |
| private: |
| bool equals(const RenderStyle* a, const RenderStyle* b) const final |
| { |
| // If the style pointers are the same, don't bother doing the test. |
| // If either is null, return false. If both are null, return true. |
| if (a == b) |
| return true; |
| if (!a || !b) |
| return false; |
| return value(a) == value(b); |
| } |
| |
| bool canInterpolate(const RenderStyle* from, const RenderStyle* to) const final |
| { |
| auto fromVariationSettings = value(from); |
| auto toVariationSettings = value(to); |
| |
| if (fromVariationSettings.size() != toVariationSettings.size()) |
| return false; |
| |
| auto size = fromVariationSettings.size(); |
| for (unsigned i = 0; i < size; ++i) { |
| if (fromVariationSettings.at(i).tag() != toVariationSettings.at(i).tag()) |
| return false; |
| } |
| |
| return true; |
| } |
| }; |
| #endif |
| |
| class PropertyWrapperShape final : public RefCountedPropertyWrapper<ShapeValue> { |
| WTF_MAKE_FAST_ALLOCATED; |
| public: |
| PropertyWrapperShape(CSSPropertyID property, ShapeValue* (RenderStyle::*getter)() const, void (RenderStyle::*setter)(RefPtr<ShapeValue>&&)) |
| : RefCountedPropertyWrapper<ShapeValue>(property, getter, setter) |
| { |
| } |
| |
| private: |
| bool equals(const RenderStyle* a, const RenderStyle* b) const final |
| { |
| // If the style pointers are the same, don't bother doing the test. |
| // If either is null, return false. If both are null, return true. |
| if (a == b) |
| return true; |
| if (!a || !b) |
| return false; |
| |
| auto* shapeA = value(a); |
| auto* shapeB = value(b); |
| if (shapeA == shapeB) |
| return true; |
| if (!shapeA || !shapeB) |
| return false; |
| return *shapeA == *shapeB; |
| } |
| |
| bool canInterpolate(const RenderStyle* from, const RenderStyle* to) const final |
| { |
| auto* fromShape = value(from); |
| auto* toShape = value(to); |
| |
| if (!fromShape || !toShape) |
| return false; |
| |
| if (fromShape->type() != ShapeValue::Type::Shape || toShape->type() != ShapeValue::Type::Shape) |
| return false; |
| |
| if (fromShape->cssBox() != toShape->cssBox()) |
| return false; |
| |
| return fromShape->shape()->canBlend(*toShape->shape()); |
| } |
| }; |
| |
| class StyleImagePropertyWrapper final : public RefCountedPropertyWrapper<StyleImage> { |
| WTF_MAKE_FAST_ALLOCATED; |
| public: |
| StyleImagePropertyWrapper(CSSPropertyID property, StyleImage* (RenderStyle::*getter)() const, void (RenderStyle::*setter)(RefPtr<StyleImage>&&)) |
| : RefCountedPropertyWrapper<StyleImage>(property, getter, setter) |
| { |
| } |
| |
| private: |
| bool equals(const RenderStyle* a, const RenderStyle* b) const final |
| { |
| if (a == b) |
| return true; |
| if (!a || !b) |
| return false; |
| |
| auto* imageA = value(a); |
| auto* imageB = value(b); |
| return arePointingToEqualData(imageA, imageB); |
| } |
| |
| bool canInterpolate(const RenderStyle* from, const RenderStyle* to) const final |
| { |
| return value(from) && value(to); |
| } |
| }; |
| |
| template <typename T> |
| class AcceleratedPropertyWrapper final : public PropertyWrapper<T> { |
| WTF_MAKE_FAST_ALLOCATED; |
| public: |
| AcceleratedPropertyWrapper(CSSPropertyID property, T (RenderStyle::*getter)() const, void (RenderStyle::*setter)(T)) |
| : PropertyWrapper<T>(property, getter, setter) |
| { |
| } |
| |
| private: |
| bool animationIsAccelerated() const final { return true; } |
| }; |
| |
| template <typename T> |
| class AcceleratedIndividualTransformPropertyWrapper final : public RefCountedPropertyWrapper<T> { |
| WTF_MAKE_FAST_ALLOCATED; |
| public: |
| AcceleratedIndividualTransformPropertyWrapper(CSSPropertyID property, T* (RenderStyle::*getter)() const, void (RenderStyle::*setter)(RefPtr<T>&&)) |
| : RefCountedPropertyWrapper<T>(property, getter, setter) |
| { |
| } |
| |
| private: |
| bool animationIsAccelerated() const final { return true; } |
| |
| bool equals(const RenderStyle* a, const RenderStyle* b) const final |
| { |
| return arePointingToEqualData(this->value(a), this->value(b)); |
| } |
| }; |
| |
| class PropertyWrapperFilter final : public PropertyWrapper<const FilterOperations&> { |
| WTF_MAKE_FAST_ALLOCATED; |
| public: |
| PropertyWrapperFilter(CSSPropertyID propertyID, const FilterOperations& (RenderStyle::*getter)() const, void (RenderStyle::*setter)(const FilterOperations&)) |
| : PropertyWrapper<const FilterOperations&>(propertyID, getter, setter) |
| { |
| } |
| |
| private: |
| bool animationIsAccelerated() const final |
| { |
| return property() == CSSPropertyFilter |
| #if ENABLE(FILTERS_LEVEL_2) |
| || property() == CSSPropertyWebkitBackdropFilter |
| #endif |
| ; |
| } |
| |
| void blend(const CSSPropertyBlendingClient* client, RenderStyle* destination, const RenderStyle* from, const RenderStyle* to, double progress) const final |
| { |
| (destination->*m_setter)(blendFunc(client, value(from), value(to), progress, property())); |
| } |
| }; |
| |
| static inline size_t shadowListLength(const ShadowData* shadow) |
| { |
| size_t count; |
| for (count = 0; shadow; shadow = shadow->next()) |
| ++count; |
| return count; |
| } |
| |
| static inline const ShadowData* shadowForBlending(const ShadowData* srcShadow, const ShadowData* otherShadow) |
| { |
| static NeverDestroyed<ShadowData> defaultShadowData(LayoutPoint(), 0, 0, ShadowStyle::Normal, false, Color::transparentBlack); |
| static NeverDestroyed<ShadowData> defaultInsetShadowData(LayoutPoint(), 0, 0, ShadowStyle::Inset, false, Color::transparentBlack); |
| static NeverDestroyed<ShadowData> defaultWebKitBoxShadowData(LayoutPoint(), 0, 0, ShadowStyle::Normal, true, Color::transparentBlack); |
| static NeverDestroyed<ShadowData> defaultInsetWebKitBoxShadowData(LayoutPoint(), 0, 0, ShadowStyle::Inset, true, Color::transparentBlack); |
| |
| if (srcShadow) |
| return srcShadow; |
| |
| if (otherShadow->style() == ShadowStyle::Inset) |
| return otherShadow->isWebkitBoxShadow() ? &defaultInsetWebKitBoxShadowData.get() : &defaultInsetShadowData.get(); |
| |
| return otherShadow->isWebkitBoxShadow() ? &defaultWebKitBoxShadowData.get() : &defaultShadowData.get(); |
| } |
| |
| class PropertyWrapperShadow final : public AnimationPropertyWrapperBase { |
| WTF_MAKE_FAST_ALLOCATED; |
| public: |
| PropertyWrapperShadow(CSSPropertyID property, const ShadowData* (RenderStyle::*getter)() const, void (RenderStyle::*setter)(std::unique_ptr<ShadowData>, bool)) |
| : AnimationPropertyWrapperBase(property) |
| , m_getter(getter) |
| , m_setter(setter) |
| { |
| } |
| |
| private: |
| bool equals(const RenderStyle* a, const RenderStyle* b) const final |
| { |
| if (a == b) |
| return true; |
| if (!a || !b) |
| return false; |
| |
| const ShadowData* shadowA = (a->*m_getter)(); |
| const ShadowData* shadowB = (b->*m_getter)(); |
| |
| while (true) { |
| // end of both lists |
| if (!shadowA && !shadowB) |
| return true; |
| |
| // end of just one of the lists |
| if (!shadowA || !shadowB) |
| return false; |
| |
| if (*shadowA != *shadowB) |
| return false; |
| |
| shadowA = shadowA->next(); |
| shadowB = shadowB->next(); |
| } |
| |
| return true; |
| } |
| |
| bool canInterpolate(const RenderStyle* from, const RenderStyle* to) const final |
| { |
| const ShadowData* fromShadow = (from->*m_getter)(); |
| const ShadowData* toShadow = (to->*m_getter)(); |
| |
| // The only scenario where we can't interpolate is if specified items don't have the same shadow style. |
| while (fromShadow && toShadow) { |
| if (fromShadow->style() != toShadow->style()) |
| return false; |
| fromShadow = fromShadow->next(); |
| toShadow = toShadow->next(); |
| } |
| |
| return true; |
| } |
| |
| void blend(const CSSPropertyBlendingClient* client, RenderStyle* destination, const RenderStyle* from, const RenderStyle* to, double progress) const final |
| { |
| const ShadowData* fromShadow = (from->*m_getter)(); |
| const ShadowData* toShadow = (to->*m_getter)(); |
| |
| if (!canInterpolate(from, to)) { |
| ASSERT(!progress || progress == 1.0); |
| auto* shadow = progress ? toShadow : fromShadow; |
| (destination->*m_setter)(shadow ? makeUnique<ShadowData>(*shadow) : nullptr, false); |
| return; |
| } |
| |
| int fromLength = shadowListLength(fromShadow); |
| int toLength = shadowListLength(toShadow); |
| |
| if (fromLength == toLength || (fromLength <= 1 && toLength <= 1)) { |
| (destination->*m_setter)(blendSimpleOrMatchedShadowLists(client, progress, fromShadow, toShadow), false); |
| return; |
| } |
| |
| (destination->*m_setter)(blendMismatchedShadowLists(client, progress, fromShadow, toShadow, fromLength, toLength), false); |
| } |
| |
| #if !LOG_DISABLED |
| void logBlend(const RenderStyle*, const RenderStyle*, const RenderStyle*, double progress) const final |
| { |
| // FIXME: better logging. |
| LOG_WITH_STREAM(Animations, stream << " blending ShadowData at " << TextStream::FormatNumberRespectingIntegers(progress)); |
| } |
| #endif |
| |
| std::unique_ptr<ShadowData> blendSimpleOrMatchedShadowLists(const CSSPropertyBlendingClient* client, double progress, const ShadowData* shadowA, const ShadowData* shadowB) const |
| { |
| std::unique_ptr<ShadowData> newShadowData; |
| ShadowData* lastShadow = 0; |
| |
| while (shadowA || shadowB) { |
| const ShadowData* srcShadow = shadowForBlending(shadowA, shadowB); |
| const ShadowData* dstShadow = shadowForBlending(shadowB, shadowA); |
| |
| std::unique_ptr<ShadowData> blendedShadow = blendFunc(client, srcShadow, dstShadow, progress); |
| ShadowData* blendedShadowPtr = blendedShadow.get(); |
| |
| if (!lastShadow) |
| newShadowData = WTFMove(blendedShadow); |
| else |
| lastShadow->setNext(WTFMove(blendedShadow)); |
| |
| lastShadow = blendedShadowPtr; |
| |
| shadowA = shadowA ? shadowA->next() : 0; |
| shadowB = shadowB ? shadowB->next() : 0; |
| } |
| |
| return newShadowData; |
| } |
| |
| std::unique_ptr<ShadowData> blendMismatchedShadowLists(const CSSPropertyBlendingClient* client, double progress, const ShadowData* shadowA, const ShadowData* shadowB, int fromLength, int toLength) const |
| { |
| // The shadows in ShadowData are stored in reverse order, so when animating mismatched lists, |
| // reverse them and match from the end. |
| Vector<const ShadowData*, 4> fromShadows(fromLength); |
| for (int i = fromLength - 1; i >= 0; --i) { |
| fromShadows[i] = shadowA; |
| shadowA = shadowA->next(); |
| } |
| |
| Vector<const ShadowData*, 4> toShadows(toLength); |
| for (int i = toLength - 1; i >= 0; --i) { |
| toShadows[i] = shadowB; |
| shadowB = shadowB->next(); |
| } |
| |
| std::unique_ptr<ShadowData> newShadowData; |
| |
| int maxLength = std::max(fromLength, toLength); |
| for (int i = 0; i < maxLength; ++i) { |
| const ShadowData* fromShadow = i < fromLength ? fromShadows[i] : 0; |
| const ShadowData* toShadow = i < toLength ? toShadows[i] : 0; |
| |
| const ShadowData* srcShadow = shadowForBlending(fromShadow, toShadow); |
| const ShadowData* dstShadow = shadowForBlending(toShadow, fromShadow); |
| |
| std::unique_ptr<ShadowData> blendedShadow = blendFunc(client, srcShadow, dstShadow, progress); |
| // Insert at the start of the list to preserve the order. |
| blendedShadow->setNext(WTFMove(newShadowData)); |
| newShadowData = WTFMove(blendedShadow); |
| } |
| |
| return newShadowData; |
| } |
| |
| const ShadowData* (RenderStyle::*m_getter)() const; |
| void (RenderStyle::*m_setter)(std::unique_ptr<ShadowData>, bool); |
| }; |
| |
| class PropertyWrapperMaybeInvalidColor final : public AnimationPropertyWrapperBase { |
| WTF_MAKE_FAST_ALLOCATED; |
| public: |
| PropertyWrapperMaybeInvalidColor(CSSPropertyID property, const Color& (RenderStyle::*getter)() const, void (RenderStyle::*setter)(const Color&)) |
| : AnimationPropertyWrapperBase(property) |
| , m_getter(getter) |
| , m_setter(setter) |
| { |
| } |
| |
| private: |
| bool equals(const RenderStyle* a, const RenderStyle* b) const final |
| { |
| if (a == b) |
| return true; |
| if (!a || !b) |
| return false; |
| |
| Color fromColor = value(a); |
| Color toColor = value(b); |
| |
| if (!fromColor.isValid() && !toColor.isValid()) |
| return true; |
| |
| if (!fromColor.isValid()) |
| fromColor = a->color(); |
| if (!toColor.isValid()) |
| toColor = b->color(); |
| |
| return fromColor == toColor; |
| } |
| |
| void blend(const CSSPropertyBlendingClient* client, RenderStyle* destination, const RenderStyle* from, const RenderStyle* to, double progress) const final |
| { |
| Color fromColor = value(from); |
| Color toColor = value(to); |
| |
| if (!fromColor.isValid() && !toColor.isValid()) |
| return; |
| |
| if (!fromColor.isValid()) |
| fromColor = from->color(); |
| if (!toColor.isValid()) |
| toColor = to->color(); |
| (destination->*m_setter)(blendFunc(client, fromColor, toColor, progress)); |
| } |
| |
| Color value(const RenderStyle* style) const |
| { |
| return (style->*m_getter)(); |
| } |
| |
| #if !LOG_DISABLED |
| void logBlend(const RenderStyle* from, const RenderStyle* to, const RenderStyle* result, double progress) const final |
| { |
| // FIXME: better logging. |
| LOG_WITH_STREAM(Animations, stream << " blending " << getPropertyName(property()) << " from " << value(from) << " to " << value(to) << " at " << TextStream::FormatNumberRespectingIntegers(progress) << " -> " << value(result)); |
| } |
| #endif |
| |
| const Color& (RenderStyle::*m_getter)() const; |
| void (RenderStyle::*m_setter)(const Color&); |
| }; |
| |
| |
| enum MaybeInvalidColorTag { MaybeInvalidColor }; |
| class PropertyWrapperVisitedAffectedColor : public AnimationPropertyWrapperBase { |
| WTF_MAKE_FAST_ALLOCATED; |
| public: |
| PropertyWrapperVisitedAffectedColor(CSSPropertyID property, const Color& (RenderStyle::*getter)() const, void (RenderStyle::*setter)(const Color&), const Color& (RenderStyle::*visitedGetter)() const, void (RenderStyle::*visitedSetter)(const Color&)) |
| : AnimationPropertyWrapperBase(property) |
| , m_wrapper(makeUnique<PropertyWrapper<const Color&>>(property, getter, setter)) |
| , m_visitedWrapper(makeUnique<PropertyWrapper<const Color&>>(property, visitedGetter, visitedSetter)) |
| { |
| } |
| PropertyWrapperVisitedAffectedColor(CSSPropertyID property, MaybeInvalidColorTag, const Color& (RenderStyle::*getter)() const, void (RenderStyle::*setter)(const Color&), const Color& (RenderStyle::*visitedGetter)() const, void (RenderStyle::*visitedSetter)(const Color&)) |
| : AnimationPropertyWrapperBase(property) |
| , m_wrapper(makeUnique<PropertyWrapperMaybeInvalidColor>(property, getter, setter)) |
| , m_visitedWrapper(makeUnique<PropertyWrapperMaybeInvalidColor>(property, visitedGetter, visitedSetter)) |
| { |
| } |
| |
| protected: |
| bool equals(const RenderStyle* a, const RenderStyle* b) const override |
| { |
| return m_wrapper->equals(a, b) && m_visitedWrapper->equals(a, b); |
| } |
| |
| void blend(const CSSPropertyBlendingClient* client, RenderStyle* destination, const RenderStyle* from, const RenderStyle* to, double progress) const override |
| { |
| m_wrapper->blend(client, destination, from, to, progress); |
| m_visitedWrapper->blend(client, destination, from, to, progress); |
| } |
| |
| std::unique_ptr<AnimationPropertyWrapperBase> m_wrapper; |
| std::unique_ptr<AnimationPropertyWrapperBase> m_visitedWrapper; |
| |
| private: |
| #if !LOG_DISABLED |
| void logBlend(const RenderStyle* from, const RenderStyle* to, const RenderStyle* result, double progress) const final |
| { |
| m_wrapper->logBlend(from, to, result, progress); |
| m_visitedWrapper->logBlend(from, to, result, progress); |
| } |
| #endif |
| }; |
| |
| static bool canInterpolateCaretColor(const RenderStyle* from, const RenderStyle* to, bool visited) |
| { |
| if (visited) |
| return !from->hasVisitedLinkAutoCaretColor() && !to->hasVisitedLinkAutoCaretColor(); |
| return !from->hasAutoCaretColor() && !to->hasAutoCaretColor(); |
| } |
| |
| class CaretColorPropertyWrapper final : public PropertyWrapperVisitedAffectedColor { |
| WTF_MAKE_FAST_ALLOCATED; |
| public: |
| CaretColorPropertyWrapper() |
| : PropertyWrapperVisitedAffectedColor(CSSPropertyCaretColor, MaybeInvalidColor, &RenderStyle::caretColor, &RenderStyle::setCaretColor, &RenderStyle::visitedLinkCaretColor, &RenderStyle::setVisitedLinkCaretColor) |
| { |
| } |
| |
| private: |
| bool equals(const RenderStyle* a, const RenderStyle* b) const final |
| { |
| return a->hasAutoCaretColor() == b->hasAutoCaretColor() |
| && a->hasVisitedLinkAutoCaretColor() == b->hasVisitedLinkAutoCaretColor() |
| && PropertyWrapperVisitedAffectedColor::equals(a, b); |
| } |
| |
| bool canInterpolate(const RenderStyle* from, const RenderStyle* to) const final |
| { |
| return canInterpolateCaretColor(from, to, false) || canInterpolateCaretColor(from, to, true); |
| } |
| |
| void blend(const CSSPropertyBlendingClient* client, RenderStyle* destination, const RenderStyle* from, const RenderStyle* to, double progress) const final |
| { |
| if (canInterpolateCaretColor(from, to, false)) |
| m_wrapper->blend(client, destination, from, to, progress); |
| else { |
| auto* blendingRenderStyle = progress < 0.5 ? from : to; |
| if (blendingRenderStyle->hasAutoCaretColor()) |
| destination->setHasAutoCaretColor(); |
| else |
| destination->setCaretColor(blendingRenderStyle->caretColor()); |
| } |
| |
| if (canInterpolateCaretColor(from, to, true)) |
| m_visitedWrapper->blend(client, destination, from, to, progress); |
| else { |
| auto* blendingRenderStyle = progress < 0.5 ? from : to; |
| if (blendingRenderStyle->hasVisitedLinkAutoCaretColor()) |
| destination->setHasVisitedLinkAutoCaretColor(); |
| else |
| destination->setVisitedLinkCaretColor(blendingRenderStyle->visitedLinkCaretColor()); |
| } |
| } |
| }; |
| |
| // Wrapper base class for an animatable property in a FillLayer |
| class FillLayerAnimationPropertyWrapperBase { |
| WTF_MAKE_FAST_ALLOCATED; |
| public: |
| FillLayerAnimationPropertyWrapperBase(CSSPropertyID property) |
| : m_property(property) |
| { |
| } |
| virtual ~FillLayerAnimationPropertyWrapperBase() = default; |
| |
| CSSPropertyID property() const { return m_property; } |
| |
| virtual bool equals(const FillLayer*, const FillLayer*) const = 0; |
| virtual void blend(const CSSPropertyBlendingClient*, FillLayer*, const FillLayer*, const FillLayer*, double) const = 0; |
| virtual bool canInterpolate(const FillLayer*, const FillLayer*) const { return true; } |
| |
| #if !LOG_DISABLED |
| virtual void logBlend(const FillLayer* result, const FillLayer*, const FillLayer*, double) const = 0; |
| #endif |
| |
| private: |
| CSSPropertyID m_property; |
| }; |
| |
| template <typename T> |
| class FillLayerPropertyWrapperGetter : public FillLayerAnimationPropertyWrapperBase { |
| WTF_MAKE_FAST_ALLOCATED; |
| WTF_MAKE_NONCOPYABLE(FillLayerPropertyWrapperGetter); |
| public: |
| FillLayerPropertyWrapperGetter(CSSPropertyID property, T (FillLayer::*getter)() const) |
| : FillLayerAnimationPropertyWrapperBase(property) |
| , m_getter(getter) |
| { |
| } |
| |
| protected: |
| bool equals(const FillLayer* a, const FillLayer* b) const override |
| { |
| if (a == b) |
| return true; |
| if (!a || !b) |
| return false; |
| return value(a) == value(b); |
| } |
| |
| T value(const FillLayer* layer) const |
| { |
| return (layer->*m_getter)(); |
| } |
| |
| #if !LOG_DISABLED |
| void logBlend(const FillLayer* result, const FillLayer* from, const FillLayer* to, double progress) const override |
| { |
| LOG_WITH_STREAM(Animations, stream << " blending " << getPropertyName(property()) << " from " << value(from) << " to " << value(to) << " at " << TextStream::FormatNumberRespectingIntegers(progress) << " -> " << value(result)); |
| } |
| #endif |
| |
| private: |
| T (FillLayer::*m_getter)() const; |
| }; |
| |
| template <typename T> |
| class FillLayerPropertyWrapper final : public FillLayerPropertyWrapperGetter<const T&> { |
| WTF_MAKE_FAST_ALLOCATED; |
| public: |
| FillLayerPropertyWrapper(CSSPropertyID property, const T& (FillLayer::*getter)() const, void (FillLayer::*setter)(T)) |
| : FillLayerPropertyWrapperGetter<const T&>(property, getter) |
| , m_setter(setter) |
| { |
| } |
| |
| private: |
| void blend(const CSSPropertyBlendingClient* client, FillLayer* destination, const FillLayer* from, const FillLayer* to, double progress) const final |
| { |
| (destination->*this->m_setter)(blendFunc(client, this->value(from), this->value(to), progress)); |
| } |
| |
| bool canInterpolate(const FillLayer* from, const FillLayer* to) const final |
| { |
| return canInterpolateLengthVariants(this->value(from), this->value(to)); |
| } |
| |
| #if !LOG_DISABLED |
| void logBlend(const FillLayer* result, const FillLayer* from, const FillLayer* to, double progress) const final |
| { |
| LOG_WITH_STREAM(Animations, stream << " blending " << getPropertyName(FillLayerPropertyWrapperGetter<const T&>::property()) |
| << " from " << FillLayerPropertyWrapperGetter<const T&>::value(from) |
| << " to " << FillLayerPropertyWrapperGetter<const T&>::value(to) |
| << " at " << TextStream::FormatNumberRespectingIntegers(progress) << " -> " << FillLayerPropertyWrapperGetter<const T&>::value(result)); |
| } |
| #endif |
| |
| void (FillLayer::*m_setter)(T); |
| }; |
| |
| class FillLayerPositionPropertyWrapper final : public FillLayerPropertyWrapperGetter<const Length&> { |
| WTF_MAKE_FAST_ALLOCATED; |
| public: |
| FillLayerPositionPropertyWrapper(CSSPropertyID property, const Length& (FillLayer::*lengthGetter)() const, void (FillLayer::*lengthSetter)(Length), Edge (FillLayer::*originGetter)() const, void (FillLayer::*originSetter)(Edge), Edge farEdge) |
| : FillLayerPropertyWrapperGetter<const Length&>(property, lengthGetter) |
| , m_lengthSetter(lengthSetter) |
| , m_originGetter(originGetter) |
| , m_originSetter(originSetter) |
| , m_farEdge(farEdge) |
| { |
| } |
| |
| private: |
| bool equals(const FillLayer* a, const FillLayer* b) const final |
| { |
| if (a == b) |
| return true; |
| if (!a || !b) |
| return false; |
| |
| auto fromLength = value(a); |
| auto toLength = value(b); |
| |
| Edge fromEdge = (a->*m_originGetter)(); |
| Edge toEdge = (b->*m_originGetter)(); |
| |
| return fromLength == toLength && fromEdge == toEdge; |
| } |
| |
| void blend(const CSSPropertyBlendingClient* client, FillLayer* destination, const FillLayer* from, const FillLayer* to, double progress) const final |
| { |
| auto fromLength = value(from); |
| auto toLength = value(to); |
| |
| Edge fromEdge = (from->*m_originGetter)(); |
| Edge toEdge = (to->*m_originGetter)(); |
| |
| if (fromEdge != toEdge) { |
| // Convert the right/bottom into a calc expression, |
| if (fromEdge == m_farEdge) |
| fromLength = convertTo100PercentMinusLength(fromLength); |
| else if (toEdge == m_farEdge) { |
| toLength = convertTo100PercentMinusLength(toLength); |
| (destination->*m_originSetter)(fromEdge); // Now we have a calc(100% - l), it's relative to the left/top edge. |
| } |
| } |
| |
| (destination->*m_lengthSetter)(blendFunc(client, fromLength, toLength, progress)); |
| } |
| |
| #if !LOG_DISABLED |
| void logBlend(const FillLayer* result, const FillLayer* from, const FillLayer* to, double progress) const final |
| { |
| LOG_WITH_STREAM(Animations, stream << " blending " << getPropertyName(property()) << " from " << value(from) << " to " << value(to) << " at " << TextStream::FormatNumberRespectingIntegers(progress) << " -> " << value(result)); |
| } |
| #endif |
| |
| void (FillLayer::*m_lengthSetter)(Length); |
| Edge (FillLayer::*m_originGetter)() const; |
| void (FillLayer::*m_originSetter)(Edge); |
| Edge m_farEdge; |
| }; |
| |
| template <typename T> |
| class FillLayerRefCountedPropertyWrapper : public FillLayerPropertyWrapperGetter<T*> { |
| WTF_MAKE_FAST_ALLOCATED; |
| public: |
| FillLayerRefCountedPropertyWrapper(CSSPropertyID property, T* (FillLayer::*getter)() const, void (FillLayer::*setter)(RefPtr<T>&&)) |
| : FillLayerPropertyWrapperGetter<T*>(property, getter) |
| , m_setter(setter) |
| { |
| } |
| |
| private: |
| void blend(const CSSPropertyBlendingClient* client, FillLayer* destination, const FillLayer* from, const FillLayer* to, double progress) const final |
| { |
| (destination->*this->m_setter)(blendFunc(client, this->value(from), this->value(to), progress)); |
| } |
| |
| #if !LOG_DISABLED |
| void logBlend(const FillLayer* result, const FillLayer* from, const FillLayer* to, double progress) const override |
| { |
| LOG_WITH_STREAM(Animations, stream << " blending " << getPropertyName(FillLayerPropertyWrapperGetter<T*>::property()) |
| << " from " << FillLayerPropertyWrapperGetter<T*>::value(from) |
| << " to " << FillLayerPropertyWrapperGetter<T*>::value(to) |
| << " at " << TextStream::FormatNumberRespectingIntegers(progress) << " -> " << FillLayerPropertyWrapperGetter<T*>::value(result)); |
| } |
| #endif |
| |
| void (FillLayer::*m_setter)(RefPtr<T>&&); |
| }; |
| |
| class FillLayerStyleImagePropertyWrapper final : public FillLayerRefCountedPropertyWrapper<StyleImage> { |
| WTF_MAKE_FAST_ALLOCATED; |
| public: |
| FillLayerStyleImagePropertyWrapper(CSSPropertyID property, StyleImage* (FillLayer::*getter)() const, void (FillLayer::*setter)(RefPtr<StyleImage>&&)) |
| : FillLayerRefCountedPropertyWrapper<StyleImage>(property, getter, setter) |
| { |
| } |
| |
| private: |
| bool equals(const FillLayer* a, const FillLayer* b) const final |
| { |
| if (a == b) |
| return true; |
| if (!a || !b) |
| return false; |
| return arePointingToEqualData(value(a), value(b)); |
| } |
| |
| bool canInterpolate(const FillLayer* from, const FillLayer* to) const final |
| { |
| return value(from) && value(to); |
| } |
| |
| #if !LOG_DISABLED |
| void logBlend(const FillLayer* result, const FillLayer* from, const FillLayer* to, double progress) const final |
| { |
| LOG_WITH_STREAM(Animations, stream << " blending " << getPropertyName(property()) << " from " << value(from) << " to " << value(to) << " at " << TextStream::FormatNumberRespectingIntegers(progress) << " -> " << value(result)); |
| } |
| #endif |
| }; |
| |
| class FillLayersPropertyWrapper final : public AnimationPropertyWrapperBase { |
| WTF_MAKE_FAST_ALLOCATED; |
| public: |
| typedef const FillLayer& (RenderStyle::*LayersGetter)() const; |
| typedef FillLayer& (RenderStyle::*LayersAccessor)(); |
| |
| FillLayersPropertyWrapper(CSSPropertyID property, LayersGetter getter, LayersAccessor accessor) |
| : AnimationPropertyWrapperBase(property) |
| , m_layersGetter(getter) |
| , m_layersAccessor(accessor) |
| { |
| switch (property) { |
| case CSSPropertyBackgroundPositionX: |
| case CSSPropertyWebkitMaskPositionX: |
| m_fillLayerPropertyWrapper = makeUnique<FillLayerPositionPropertyWrapper>(property, &FillLayer::xPosition, &FillLayer::setXPosition, &FillLayer::backgroundXOrigin, &FillLayer::setBackgroundXOrigin, Edge::Right); |
| break; |
| case CSSPropertyBackgroundPositionY: |
| case CSSPropertyWebkitMaskPositionY: |
| m_fillLayerPropertyWrapper = makeUnique<FillLayerPositionPropertyWrapper>(property, &FillLayer::yPosition, &FillLayer::setYPosition, &FillLayer::backgroundYOrigin, &FillLayer::setBackgroundYOrigin, Edge::Bottom); |
| break; |
| case CSSPropertyBackgroundSize: |
| case CSSPropertyWebkitBackgroundSize: |
| case CSSPropertyWebkitMaskSize: |
| m_fillLayerPropertyWrapper = makeUnique<FillLayerPropertyWrapper<LengthSize>>(property, &FillLayer::sizeLength, &FillLayer::setSizeLength); |
| break; |
| case CSSPropertyBackgroundImage: |
| m_fillLayerPropertyWrapper = makeUnique<FillLayerStyleImagePropertyWrapper>(property, &FillLayer::image, &FillLayer::setImage); |
| break; |
| default: |
| break; |
| } |
| } |
| |
| private: |
| bool equals(const RenderStyle* a, const RenderStyle* b) const final |
| { |
| if (a == b) |
| return true; |
| if (!a || !b) |
| return false; |
| |
| auto* fromLayer = &(a->*m_layersGetter)(); |
| auto* toLayer = &(b->*m_layersGetter)(); |
| |
| while (fromLayer && toLayer) { |
| if (!m_fillLayerPropertyWrapper->equals(fromLayer, toLayer)) |
| return false; |
| |
| fromLayer = fromLayer->next(); |
| toLayer = toLayer->next(); |
| } |
| |
| return true; |
| } |
| |
| bool canInterpolate(const RenderStyle* from, const RenderStyle* to) const final |
| { |
| auto* fromLayer = &(from->*m_layersGetter)(); |
| auto* toLayer = &(to->*m_layersGetter)(); |
| |
| while (fromLayer && toLayer) { |
| if (fromLayer->sizeType() != toLayer->sizeType()) |
| return false; |
| |
| if (!m_fillLayerPropertyWrapper->canInterpolate(fromLayer, toLayer)) |
| return false; |
| |
| fromLayer = fromLayer->next(); |
| toLayer = toLayer->next(); |
| } |
| |
| return true; |
| } |
| |
| void blend(const CSSPropertyBlendingClient* client, RenderStyle* destination, const RenderStyle* from, const RenderStyle* to, double progress) const final |
| { |
| auto* fromLayer = &(from->*m_layersGetter)(); |
| auto* toLayer = &(to->*m_layersGetter)(); |
| auto* dstLayer = &(destination->*m_layersAccessor)(); |
| |
| while (fromLayer && toLayer && dstLayer) { |
| dstLayer->setSizeType((progress ? toLayer : fromLayer)->sizeType()); |
| m_fillLayerPropertyWrapper->blend(client, dstLayer, fromLayer, toLayer, progress); |
| fromLayer = fromLayer->next(); |
| toLayer = toLayer->next(); |
| dstLayer = dstLayer->next(); |
| } |
| } |
| |
| #if !LOG_DISABLED |
| void logBlend(const RenderStyle* from, const RenderStyle* to, const RenderStyle* result, double progress) const final |
| { |
| auto* fromLayer = &(from->*m_layersGetter)(); |
| auto* toLayer = &(to->*m_layersGetter)(); |
| auto* dstLayer = &(result->*m_layersGetter)(); |
| |
| while (fromLayer && toLayer && dstLayer) { |
| m_fillLayerPropertyWrapper->logBlend(dstLayer, fromLayer, toLayer, progress); |
| fromLayer = fromLayer->next(); |
| toLayer = toLayer->next(); |
| dstLayer = dstLayer->next(); |
| } |
| } |
| #endif |
| |
| std::unique_ptr<FillLayerAnimationPropertyWrapperBase> m_fillLayerPropertyWrapper; |
| LayersGetter m_layersGetter; |
| LayersAccessor m_layersAccessor; |
| }; |
| |
| class ShorthandPropertyWrapper final : public AnimationPropertyWrapperBase { |
| WTF_MAKE_FAST_ALLOCATED; |
| public: |
| ShorthandPropertyWrapper(CSSPropertyID property, Vector<AnimationPropertyWrapperBase*> longhandWrappers) |
| : AnimationPropertyWrapperBase(property) |
| , m_propertyWrappers(WTFMove(longhandWrappers)) |
| { |
| } |
| |
| bool isShorthandWrapper() const final { return true; } |
| |
| const Vector<AnimationPropertyWrapperBase*>& propertyWrappers() const { return m_propertyWrappers; } |
| |
| private: |
| bool equals(const RenderStyle* a, const RenderStyle* b) const final |
| { |
| if (a == b) |
| return true; |
| if (!a || !b) |
| return false; |
| |
| for (auto& wrapper : m_propertyWrappers) { |
| if (!wrapper->equals(a, b)) |
| return false; |
| } |
| return true; |
| } |
| |
| void blend(const CSSPropertyBlendingClient* client, RenderStyle* destination, const RenderStyle* from, const RenderStyle* to, double progress) const final |
| { |
| for (auto& wrapper : m_propertyWrappers) |
| wrapper->blend(client, destination, from, to, progress); |
| } |
| |
| #if !LOG_DISABLED |
| void logBlend(const RenderStyle* from, const RenderStyle* to, const RenderStyle* destination, double progress) const final |
| { |
| for (auto& wrapper : m_propertyWrappers) |
| wrapper->logBlend(from, to, destination, progress); |
| } |
| #endif |
| |
| Vector<AnimationPropertyWrapperBase*> m_propertyWrappers; |
| }; |
| |
| class PropertyWrapperFlex final : public AnimationPropertyWrapperBase { |
| WTF_MAKE_FAST_ALLOCATED; |
| public: |
| PropertyWrapperFlex() |
| : AnimationPropertyWrapperBase(CSSPropertyFlex) |
| { |
| } |
| |
| private: |
| bool equals(const RenderStyle* a, const RenderStyle* b) const final |
| { |
| if (a == b) |
| return true; |
| if (!a || !b) |
| return false; |
| |
| return a->flexBasis() == b->flexBasis() && a->flexGrow() == b->flexGrow() && a->flexShrink() == b->flexShrink(); |
| } |
| |
| bool canInterpolate(const RenderStyle* from, const RenderStyle* to) const final |
| { |
| return from->flexGrow() != to->flexGrow() && from->flexShrink() != to->flexShrink() && canInterpolateLengths(from->flexBasis(), to->flexBasis(), false); |
| } |
| |
| void blend(const CSSPropertyBlendingClient* client, RenderStyle* destination, const RenderStyle* from, const RenderStyle* to, double progress) const final |
| { |
| destination->setFlexBasis(blendFunc(client, from->flexBasis(), to->flexBasis(), progress)); |
| destination->setFlexGrow(blendFunc(client, from->flexGrow(), to->flexGrow(), progress)); |
| destination->setFlexShrink(blendFunc(client, from->flexShrink(), to->flexShrink(), progress)); |
| } |
| |
| #if !LOG_DISABLED |
| void logBlend(const RenderStyle*, const RenderStyle*, const RenderStyle*, double progress) const final |
| { |
| // FIXME: better logging. |
| LOG_WITH_STREAM(Animations, stream << " blending flex at " << TextStream::FormatNumberRespectingIntegers(progress)); |
| } |
| #endif |
| }; |
| |
| class PropertyWrapperSVGPaint final : public AnimationPropertyWrapperBase { |
| WTF_MAKE_FAST_ALLOCATED; |
| public: |
| PropertyWrapperSVGPaint(CSSPropertyID property, SVGPaintType (RenderStyle::*paintTypeGetter)() const, Color (RenderStyle::*getter)() const, void (RenderStyle::*setter)(const Color&)) |
| : AnimationPropertyWrapperBase(property) |
| , m_paintTypeGetter(paintTypeGetter) |
| , m_getter(getter) |
| , m_setter(setter) |
| { |
| } |
| |
| private: |
| bool equals(const RenderStyle* a, const RenderStyle* b) const final |
| { |
| if (a == b) |
| return true; |
| if (!a || !b) |
| return false; |
| |
| if ((a->*m_paintTypeGetter)() != (b->*m_paintTypeGetter)()) |
| return false; |
| |
| // We only support animations between SVGPaints that are pure Color values. |
| // For everything else we must return true for this method, otherwise |
| // we will try to animate between values forever. |
| if ((a->*m_paintTypeGetter)() == SVGPaintType::RGBColor) { |
| Color fromColor = (a->*m_getter)(); |
| Color toColor = (b->*m_getter)(); |
| |
| if (!fromColor.isValid() && !toColor.isValid()) |
| return true; |
| |
| if (!fromColor.isValid()) |
| fromColor = Color(); |
| if (!toColor.isValid()) |
| toColor = Color(); |
| |
| return fromColor == toColor; |
| } |
| return true; |
| } |
| |
| void blend(const CSSPropertyBlendingClient* client, RenderStyle* destination, const RenderStyle* from, const RenderStyle* to, double progress) const final |
| { |
| if ((from->*m_paintTypeGetter)() != SVGPaintType::RGBColor |
| || (to->*m_paintTypeGetter)() != SVGPaintType::RGBColor) |
| return; |
| |
| Color fromColor = (from->*m_getter)(); |
| Color toColor = (to->*m_getter)(); |
| |
| if (!fromColor.isValid() && !toColor.isValid()) |
| return; |
| |
| if (!fromColor.isValid()) |
| fromColor = Color(); |
| if (!toColor.isValid()) |
| toColor = Color(); |
| (destination->*m_setter)(blendFunc(client, fromColor, toColor, progress)); |
| } |
| |
| #if !LOG_DISABLED |
| void logBlend(const RenderStyle*, const RenderStyle*, const RenderStyle*, double progress) const final |
| { |
| // FIXME: better logging. |
| LOG_WITH_STREAM(Animations, stream << " blending SVGPaint at " << TextStream::FormatNumberRespectingIntegers(progress)); |
| } |
| #endif |
| |
| SVGPaintType (RenderStyle::*m_paintTypeGetter)() const; |
| Color (RenderStyle::*m_getter)() const; |
| void (RenderStyle::*m_setter)(const Color&); |
| }; |
| |
| class PropertyWrapperFontStyle final : public PropertyWrapper<Optional<FontSelectionValue>> { |
| WTF_MAKE_FAST_ALLOCATED; |
| public: |
| PropertyWrapperFontStyle() |
| : PropertyWrapper<Optional<FontSelectionValue>>(CSSPropertyFontStyle, &RenderStyle::fontItalic, &RenderStyle::setFontItalic) |
| { |
| } |
| |
| private: |
| bool canInterpolate(const RenderStyle* from, const RenderStyle* to) const final |
| { |
| return from->fontItalic() && to->fontItalic() && from->fontDescription().fontStyleAxis() == FontStyleAxis::slnt && to->fontDescription().fontStyleAxis() == FontStyleAxis::slnt; |
| } |
| |
| void blend(const CSSPropertyBlendingClient* client, RenderStyle* destination, const RenderStyle* from, const RenderStyle* to, double progress) const final |
| { |
| auto discrete = !canInterpolate(from, to); |
| |
| auto blendedStyleAxis = FontStyleAxis::slnt; |
| if (discrete) |
| blendedStyleAxis = (progress < 0.5 ? from : to)->fontDescription().fontStyleAxis(); |
| |
| auto fromFontItalic = from->fontItalic(); |
| auto toFontItalic = to->fontItalic(); |
| auto blendedFontItalic = progress < 0.5 ? fromFontItalic : toFontItalic; |
| if (!discrete) |
| blendedFontItalic = blendFunc(client, fromFontItalic, toFontItalic, progress); |
| |
| FontSelector* currentFontSelector = destination->fontCascade().fontSelector(); |
| auto description = destination->fontDescription(); |
| description.setItalic(blendedFontItalic); |
| description.setFontStyleAxis(blendedStyleAxis); |
| destination->setFontDescription(WTFMove(description)); |
| destination->fontCascade().update(currentFontSelector); |
| } |
| }; |
| |
| template <typename T> |
| class AutoPropertyWrapper final : public PropertyWrapper<T> { |
| WTF_MAKE_FAST_ALLOCATED; |
| public: |
| AutoPropertyWrapper(CSSPropertyID property, T (RenderStyle::*getter)() const, void (RenderStyle::*setter)(T), bool (RenderStyle::*autoGetter)() const, void (RenderStyle::*autoSetter)(), Optional<T> minValue = WTF::nullopt) |
| : PropertyWrapper<T>(property, getter, setter) |
| , m_autoGetter(autoGetter) |
| , m_autoSetter(autoSetter) |
| , m_minValue(minValue) |
| { |
| } |
| |
| private: |
| bool canInterpolate(const RenderStyle* from, const RenderStyle* to) const final |
| { |
| return !(from->*m_autoGetter)() && !(to->*m_autoGetter)(); |
| } |
| |
| void blend(const CSSPropertyBlendingClient* client, RenderStyle* destination, const RenderStyle* from, const RenderStyle* to, double progress) const final |
| { |
| auto blendedValue = blendFunc(client, this->value(from), this->value(to), progress); |
| if (m_minValue) |
| blendedValue = blendedValue > *m_minValue ? blendedValue : *m_minValue; |
| (destination->*this->m_setter)(blendedValue); |
| |
| if (canInterpolate(from, to)) |
| return; |
| |
| ASSERT(!progress || progress == 1.0); |
| if (!progress) { |
| if ((from->*m_autoGetter)()) |
| (destination->*m_autoSetter)(); |
| } else { |
| if ((to->*m_autoGetter)()) |
| (destination->*m_autoSetter)(); |
| } |
| } |
| |
| bool (RenderStyle::*m_autoGetter)() const; |
| void (RenderStyle::*m_autoSetter)(); |
| Optional<T> m_minValue; |
| }; |
| |
| class NonNegativeFloatPropertyWrapper : public PropertyWrapper<float> { |
| WTF_MAKE_FAST_ALLOCATED; |
| public: |
| NonNegativeFloatPropertyWrapper(CSSPropertyID property, float (RenderStyle::*getter)() const, void (RenderStyle::*setter)(float)) |
| : PropertyWrapper<float>(property, getter, setter) |
| { |
| } |
| |
| protected: |
| void blend(const CSSPropertyBlendingClient* client, RenderStyle* destination, const RenderStyle* from, const RenderStyle* to, double progress) const override |
| { |
| auto blendedValue = blendFunc(client, value(from), value(to), progress); |
| (destination->*m_setter)(blendedValue > 0 ? blendedValue : 0); |
| } |
| }; |
| |
| class VerticalAlignWrapper final : public LengthPropertyWrapper { |
| WTF_MAKE_FAST_ALLOCATED; |
| public: |
| VerticalAlignWrapper() |
| : LengthPropertyWrapper(CSSPropertyVerticalAlign, &RenderStyle::verticalAlignLength, &RenderStyle::setVerticalAlignLength, LengthPropertyWrapper::Flags::IsLengthPercentage) |
| { |
| } |
| |
| private: |
| bool canInterpolate(const RenderStyle* from, const RenderStyle* to) const final |
| { |
| return from->verticalAlign() == VerticalAlign::Length && to->verticalAlign() == VerticalAlign::Length && LengthPropertyWrapper::canInterpolate(from, to); |
| } |
| |
| void blend(const CSSPropertyBlendingClient* client, RenderStyle* destination, const RenderStyle* from, const RenderStyle* to, double progress) const final |
| { |
| LengthPropertyWrapper::blend(client, destination, from, to, progress); |
| auto* blendingStyle = !canInterpolate(from, to) && progress ? to : from; |
| destination->setVerticalAlign(blendingStyle->verticalAlign()); |
| } |
| }; |
| |
| class TextIndentWrapper final : public LengthPropertyWrapper { |
| WTF_MAKE_FAST_ALLOCATED; |
| public: |
| TextIndentWrapper() |
| : LengthPropertyWrapper(CSSPropertyTextIndent, &RenderStyle::textIndent, &RenderStyle::setTextIndent, LengthPropertyWrapper::Flags::IsLengthPercentage) |
| { |
| } |
| |
| private: |
| bool canInterpolate(const RenderStyle* from, const RenderStyle* to) const final |
| { |
| if (from->textIndentLine() != to->textIndentLine()) |
| return false; |
| if (from->textIndentType() != to->textIndentType()) |
| return false; |
| return LengthPropertyWrapper::canInterpolate(from, to); |
| } |
| |
| void blend(const CSSPropertyBlendingClient* client, RenderStyle* destination, const RenderStyle* from, const RenderStyle* to, double progress) const final |
| { |
| auto* blendingStyle = !canInterpolate(from, to) && progress ? to : from; |
| destination->setTextIndentLine(blendingStyle->textIndentLine()); |
| destination->setTextIndentType(blendingStyle->textIndentType()); |
| LengthPropertyWrapper::blend(client, destination, from, to, progress); |
| } |
| }; |
| |
| class PerspectiveWrapper final : public NonNegativeFloatPropertyWrapper { |
| WTF_MAKE_FAST_ALLOCATED; |
| public: |
| PerspectiveWrapper() |
| : NonNegativeFloatPropertyWrapper(CSSPropertyPerspective, &RenderStyle::perspective, &RenderStyle::setPerspective) |
| { |
| } |
| |
| private: |
| bool canInterpolate(const RenderStyle* from, const RenderStyle* to) const final |
| { |
| if (!from->hasPerspective() || !to->hasPerspective()) |
| return false; |
| return NonNegativeFloatPropertyWrapper::canInterpolate(from, to); |
| } |
| |
| void blend(const CSSPropertyBlendingClient* client, RenderStyle* destination, const RenderStyle* from, const RenderStyle* to, double progress) const final |
| { |
| if (!canInterpolate(from, to)) |
| (destination->*m_setter)(progress ? value(to) : value(from)); |
| else |
| NonNegativeFloatPropertyWrapper::blend(client, destination, from, to, progress); |
| } |
| }; |
| |
| class TabSizePropertyWrapper final : public PropertyWrapper<const TabSize&> { |
| WTF_MAKE_FAST_ALLOCATED; |
| public: |
| TabSizePropertyWrapper() |
| : PropertyWrapper<const TabSize&>(CSSPropertyTabSize, &RenderStyle::tabSize, &RenderStyle::setTabSize) |
| { |
| } |
| |
| private: |
| bool canInterpolate(const RenderStyle* from, const RenderStyle* to) const final |
| { |
| return value(from).isSpaces() == value(to).isSpaces(); |
| } |
| |
| void blend(const CSSPropertyBlendingClient* client, RenderStyle* destination, const RenderStyle* from, const RenderStyle* to, double progress) const final |
| { |
| if (!canInterpolate(from, to)) |
| (destination->*m_setter)(progress ? value(to) : value(from)); |
| else |
| PropertyWrapper::blend(client, destination, from, to, progress); |
| } |
| }; |
| |
| class PropertyWrapperAspectRatio final : public AnimationPropertyWrapperBase { |
| WTF_MAKE_FAST_ALLOCATED; |
| public: |
| PropertyWrapperAspectRatio() |
| : AnimationPropertyWrapperBase(CSSPropertyAspectRatio) |
| { |
| } |
| |
| bool equals(const RenderStyle* a, const RenderStyle* b) const final |
| { |
| if (a == b) |
| return true; |
| if (!a || !b) |
| return false; |
| |
| return a->aspectRatioType() == b->aspectRatioType() && a->aspectRatioWidth() == b->aspectRatioWidth() && a->aspectRatioHeight() == b->aspectRatioHeight(); |
| } |
| |
| bool canInterpolate(const RenderStyle* from, const RenderStyle* to) const final |
| { |
| return (from->aspectRatioType() == AspectRatioType::Ratio && to->aspectRatioType() == AspectRatioType::Ratio) || (from->aspectRatioType() == AspectRatioType::AutoAndRatio && to->aspectRatioType() == AspectRatioType::AutoAndRatio); |
| } |
| |
| #if !LOG_DISABLED |
| void logBlend(const RenderStyle* from, const RenderStyle* to, const RenderStyle* result, double progress) const final |
| { |
| LOG_WITH_STREAM(Animations, stream << " blending " << getPropertyName(property()) << " from " << from->logicalAspectRatio() << " to " << to->logicalAspectRatio() << " at " << TextStream::FormatNumberRespectingIntegers(progress) << " -> " << result->logicalAspectRatio()); |
| } |
| #endif |
| |
| void blend(const CSSPropertyBlendingClient*, RenderStyle* destination, const RenderStyle* from, const RenderStyle* to, double progress) const final |
| { |
| destination->setAspectRatioType(progress < 0.5 ? from->aspectRatioType() : to->aspectRatioType()); |
| if (canInterpolate(from, to)) { |
| auto aspectRatioDst = WebCore::blend(log(from->logicalAspectRatio()), log(to->logicalAspectRatio()), progress); |
| destination->setAspectRatio(exp(aspectRatioDst), 1); |
| return; |
| } |
| // For auto/auto-zero aspect-ratio we use discrete values, we can't use general |
| // logic since logicalAspectRatio asserts on aspect-ratio type. |
| ASSERT(!progress || progress == 1); |
| auto* applicableStyle = progress ? to : from; |
| destination->setAspectRatio(applicableStyle->aspectRatioWidth(), applicableStyle->aspectRatioHeight()); |
| } |
| }; |
| |
| class CSSPropertyAnimationWrapperMap final { |
| WTF_MAKE_FAST_ALLOCATED; |
| public: |
| static CSSPropertyAnimationWrapperMap& singleton() |
| { |
| // FIXME: This data is never destroyed. Maybe we should ref count it and toss it when the last CSSAnimationController is destroyed? |
| static NeverDestroyed<CSSPropertyAnimationWrapperMap> map; |
| return map; |
| } |
| |
| AnimationPropertyWrapperBase* wrapperForProperty(CSSPropertyID propertyID) |
| { |
| if (propertyID < firstCSSProperty || propertyID > lastCSSProperty) |
| return nullptr; |
| |
| unsigned wrapperIndex = indexFromPropertyID(propertyID); |
| if (wrapperIndex == cInvalidPropertyWrapperIndex) |
| return nullptr; |
| |
| return m_propertyWrappers[wrapperIndex].get(); |
| } |
| |
| AnimationPropertyWrapperBase* wrapperForIndex(unsigned index) |
| { |
| ASSERT(index < m_propertyWrappers.size()); |
| return m_propertyWrappers[index].get(); |
| } |
| |
| unsigned size() |
| { |
| return m_propertyWrappers.size(); |
| } |
| |
| private: |
| CSSPropertyAnimationWrapperMap(); |
| ~CSSPropertyAnimationWrapperMap() = delete; |
| |
| unsigned char& indexFromPropertyID(CSSPropertyID propertyID) |
| { |
| return m_propertyToIdMap[propertyID - firstCSSProperty]; |
| } |
| |
| Vector<std::unique_ptr<AnimationPropertyWrapperBase>> m_propertyWrappers; |
| unsigned char m_propertyToIdMap[numCSSProperties]; |
| |
| static const unsigned char cInvalidPropertyWrapperIndex = UCHAR_MAX; |
| |
| friend class WTF::NeverDestroyed<CSSPropertyAnimationWrapperMap>; |
| }; |
| |
| CSSPropertyAnimationWrapperMap::CSSPropertyAnimationWrapperMap() |
| { |
| // build the list of property wrappers to do the comparisons and blends |
| AnimationPropertyWrapperBase* animatableLonghandPropertyWrappers[] = { |
| new LengthPropertyWrapper(CSSPropertyLeft, &RenderStyle::left, &RenderStyle::setLeft), |
| new LengthPropertyWrapper(CSSPropertyRight, &RenderStyle::right, &RenderStyle::setRight), |
| new LengthPropertyWrapper(CSSPropertyTop, &RenderStyle::top, &RenderStyle::setTop), |
| new LengthPropertyWrapper(CSSPropertyBottom, &RenderStyle::bottom, &RenderStyle::setBottom), |
| |
| new LengthPropertyWrapper(CSSPropertyWidth, &RenderStyle::width, &RenderStyle::setWidth, { LengthPropertyWrapper::Flags::IsLengthPercentage, LengthPropertyWrapper::Flags::NegativeLengthsAreInvalid }), |
| new LengthPropertyWrapper(CSSPropertyMinWidth, &RenderStyle::minWidth, &RenderStyle::setMinWidth, { LengthPropertyWrapper::Flags::IsLengthPercentage, LengthPropertyWrapper::Flags::NegativeLengthsAreInvalid }), |
| new LengthPropertyWrapper(CSSPropertyMaxWidth, &RenderStyle::maxWidth, &RenderStyle::setMaxWidth, { LengthPropertyWrapper::Flags::IsLengthPercentage, LengthPropertyWrapper::Flags::NegativeLengthsAreInvalid }), |
| |
| new LengthPropertyWrapper(CSSPropertyHeight, &RenderStyle::height, &RenderStyle::setHeight, { LengthPropertyWrapper::Flags::IsLengthPercentage, LengthPropertyWrapper::Flags::NegativeLengthsAreInvalid }), |
| new LengthPropertyWrapper(CSSPropertyMinHeight, &RenderStyle::minHeight, &RenderStyle::setMinHeight, { LengthPropertyWrapper::Flags::IsLengthPercentage, LengthPropertyWrapper::Flags::NegativeLengthsAreInvalid }), |
| new LengthPropertyWrapper(CSSPropertyMaxHeight, &RenderStyle::maxHeight, &RenderStyle::setMaxHeight, { LengthPropertyWrapper::Flags::IsLengthPercentage, LengthPropertyWrapper::Flags::NegativeLengthsAreInvalid }), |
| |
| new PropertyWrapperFlex(), |
| |
| new NonNegativeFloatPropertyWrapper(CSSPropertyBorderLeftWidth, &RenderStyle::borderLeftWidth, &RenderStyle::setBorderLeftWidth), |
| new NonNegativeFloatPropertyWrapper(CSSPropertyBorderRightWidth, &RenderStyle::borderRightWidth, &RenderStyle::setBorderRightWidth), |
| new NonNegativeFloatPropertyWrapper(CSSPropertyBorderTopWidth, &RenderStyle::borderTopWidth, &RenderStyle::setBorderTopWidth), |
| new NonNegativeFloatPropertyWrapper(CSSPropertyBorderBottomWidth, &RenderStyle::borderBottomWidth, &RenderStyle::setBorderBottomWidth), |
| new LengthPropertyWrapper(CSSPropertyMarginLeft, &RenderStyle::marginLeft, &RenderStyle::setMarginLeft), |
| new LengthPropertyWrapper(CSSPropertyMarginRight, &RenderStyle::marginRight, &RenderStyle::setMarginRight), |
| new LengthPropertyWrapper(CSSPropertyMarginTop, &RenderStyle::marginTop, &RenderStyle::setMarginTop), |
| new LengthPropertyWrapper(CSSPropertyMarginBottom, &RenderStyle::marginBottom, &RenderStyle::setMarginBottom), |
| new LengthPropertyWrapper(CSSPropertyPaddingLeft, &RenderStyle::paddingLeft, &RenderStyle::setPaddingLeft, { LengthPropertyWrapper::Flags::NegativeLengthsAreInvalid }), |
| new LengthPropertyWrapper(CSSPropertyPaddingRight, &RenderStyle::paddingRight, &RenderStyle::setPaddingRight, { LengthPropertyWrapper::Flags::NegativeLengthsAreInvalid }), |
| new LengthPropertyWrapper(CSSPropertyPaddingTop, &RenderStyle::paddingTop, &RenderStyle::setPaddingTop, { LengthPropertyWrapper::Flags::NegativeLengthsAreInvalid }), |
| new LengthPropertyWrapper(CSSPropertyPaddingBottom, &RenderStyle::paddingBottom, &RenderStyle::setPaddingBottom, { LengthPropertyWrapper::Flags::NegativeLengthsAreInvalid }), |
| |
| new CaretColorPropertyWrapper, |
| |
| new PropertyWrapperVisitedAffectedColor(CSSPropertyColor, &RenderStyle::color, &RenderStyle::setColor, &RenderStyle::visitedLinkColor, &RenderStyle::setVisitedLinkColor), |
| |
| new PropertyWrapperVisitedAffectedColor(CSSPropertyBackgroundColor, MaybeInvalidColor, &RenderStyle::backgroundColor, &RenderStyle::setBackgroundColor, &RenderStyle::visitedLinkBackgroundColor, &RenderStyle::setVisitedLinkBackgroundColor), |
| |
| new FillLayersPropertyWrapper(CSSPropertyBackgroundImage, &RenderStyle::backgroundLayers, &RenderStyle::ensureBackgroundLayers), |
| new StyleImagePropertyWrapper(CSSPropertyListStyleImage, &RenderStyle::listStyleImage, &RenderStyle::setListStyleImage), |
| new StyleImagePropertyWrapper(CSSPropertyWebkitMaskImage, &RenderStyle::maskImage, &RenderStyle::setMaskImage), |
| |
| new StyleImagePropertyWrapper(CSSPropertyBorderImageSource, &RenderStyle::borderImageSource, &RenderStyle::setBorderImageSource), |
| new LengthBoxPropertyWrapper(CSSPropertyBorderImageSlice, &RenderStyle::borderImageSlices, &RenderStyle::setBorderImageSlices, { LengthBoxPropertyWrapper::Flags::UsesFillKeyword }), |
| new LengthBoxPropertyWrapper(CSSPropertyBorderImageWidth, &RenderStyle::borderImageWidth, &RenderStyle::setBorderImageWidth, { LengthBoxPropertyWrapper::Flags::IsLengthPercentage }), |
| new LengthBoxPropertyWrapper(CSSPropertyBorderImageOutset, &RenderStyle::borderImageOutset, &RenderStyle::setBorderImageOutset), |
| |
| new StyleImagePropertyWrapper(CSSPropertyWebkitMaskBoxImageSource, &RenderStyle::maskBoxImageSource, &RenderStyle::setMaskBoxImageSource), |
| new PropertyWrapper<const NinePieceImage&>(CSSPropertyWebkitMaskBoxImage, &RenderStyle::maskBoxImage, &RenderStyle::setMaskBoxImage), |
| |
| new FillLayersPropertyWrapper(CSSPropertyBackgroundPositionX, &RenderStyle::backgroundLayers, &RenderStyle::ensureBackgroundLayers), |
| new FillLayersPropertyWrapper(CSSPropertyBackgroundPositionY, &RenderStyle::backgroundLayers, &RenderStyle::ensureBackgroundLayers), |
| new FillLayersPropertyWrapper(CSSPropertyBackgroundSize, &RenderStyle::backgroundLayers, &RenderStyle::ensureBackgroundLayers), |
| new FillLayersPropertyWrapper(CSSPropertyWebkitBackgroundSize, &RenderStyle::backgroundLayers, &RenderStyle::ensureBackgroundLayers), |
| |
| new FillLayersPropertyWrapper(CSSPropertyWebkitMaskPositionX, &RenderStyle::maskLayers, &RenderStyle::ensureMaskLayers), |
| new FillLayersPropertyWrapper(CSSPropertyWebkitMaskPositionY, &RenderStyle::maskLayers, &RenderStyle::ensureMaskLayers), |
| new FillLayersPropertyWrapper(CSSPropertyWebkitMaskSize, &RenderStyle::maskLayers, &RenderStyle::ensureMaskLayers), |
| |
| new LengthPointPropertyWrapper(CSSPropertyObjectPosition, &RenderStyle::objectPosition, &RenderStyle::setObjectPosition), |
| |
| new PropertyWrapper<float>(CSSPropertyFontSize, &RenderStyle::computedFontSize, &RenderStyle::setFontSize), |
| new PropertyWrapper<unsigned short>(CSSPropertyColumnRuleWidth, &RenderStyle::columnRuleWidth, &RenderStyle::setColumnRuleWidth), |
| new LengthVariantPropertyWrapper<GapLength>(CSSPropertyColumnGap, &RenderStyle::columnGap, &RenderStyle::setColumnGap), |
| new LengthVariantPropertyWrapper<GapLength>(CSSPropertyRowGap, &RenderStyle::rowGap, &RenderStyle::setRowGap), |
| new AutoPropertyWrapper<unsigned short>(CSSPropertyColumnCount, &RenderStyle::columnCount, &RenderStyle::setColumnCount, &RenderStyle::hasAutoColumnCount, &RenderStyle::setHasAutoColumnCount, 1), |
| new AutoPropertyWrapper<float>(CSSPropertyColumnWidth, &RenderStyle::columnWidth, &RenderStyle::setColumnWidth, &RenderStyle::hasAutoColumnWidth, &RenderStyle::setHasAutoColumnWidth, 0), |
| new NonNegativeFloatPropertyWrapper(CSSPropertyWebkitBorderHorizontalSpacing, &RenderStyle::horizontalBorderSpacing, &RenderStyle::setHorizontalBorderSpacing), |
| new NonNegativeFloatPropertyWrapper(CSSPropertyWebkitBorderVerticalSpacing, &RenderStyle::verticalBorderSpacing, &RenderStyle::setVerticalBorderSpacing), |
| new AutoPropertyWrapper<int>(CSSPropertyZIndex, &RenderStyle::specifiedZIndex, &RenderStyle::setSpecifiedZIndex, &RenderStyle::hasAutoSpecifiedZIndex, &RenderStyle::setHasAutoSpecifiedZIndex), |
| new PositivePropertyWrapper<unsigned short>(CSSPropertyOrphans, &RenderStyle::orphans, &RenderStyle::setOrphans), |
| new PositivePropertyWrapper<unsigned short>(CSSPropertyWidows, &RenderStyle::widows, &RenderStyle::setWidows), |
| new LengthPropertyWrapper(CSSPropertyLineHeight, &RenderStyle::specifiedLineHeight, &RenderStyle::setLineHeight), |
| new PropertyWrapper<float>(CSSPropertyOutlineOffset, &RenderStyle::outlineOffset, &RenderStyle::setOutlineOffset), |
| new NonNegativeFloatPropertyWrapper(CSSPropertyOutlineWidth, &RenderStyle::outlineWidth, &RenderStyle::setOutlineWidth), |
| new PropertyWrapper<float>(CSSPropertyLetterSpacing, &RenderStyle::letterSpacing, &RenderStyle::setLetterSpacing), |
| new LengthPropertyWrapper(CSSPropertyWordSpacing, &RenderStyle::wordSpacing, &RenderStyle::setWordSpacing), |
| new TextIndentWrapper, |
| new VerticalAlignWrapper, |
| |
| new PerspectiveWrapper, |
| new LengthPropertyWrapper(CSSPropertyPerspectiveOriginX, &RenderStyle::perspectiveOriginX, &RenderStyle::setPerspectiveOriginX, LengthPropertyWrapper::Flags::IsLengthPercentage), |
| new LengthPropertyWrapper(CSSPropertyPerspectiveOriginY, &RenderStyle::perspectiveOriginY, &RenderStyle::setPerspectiveOriginY, LengthPropertyWrapper::Flags::IsLengthPercentage), |
| new LengthPropertyWrapper(CSSPropertyTransformOriginX, &RenderStyle::transformOriginX, &RenderStyle::setTransformOriginX, LengthPropertyWrapper::Flags::IsLengthPercentage), |
| new LengthPropertyWrapper(CSSPropertyTransformOriginY, &RenderStyle::transformOriginY, &RenderStyle::setTransformOriginY, LengthPropertyWrapper::Flags::IsLengthPercentage), |
| new PropertyWrapper<float>(CSSPropertyTransformOriginZ, &RenderStyle::transformOriginZ, &RenderStyle::setTransformOriginZ), |
| new LengthVariantPropertyWrapper<LengthSize>(CSSPropertyBorderTopLeftRadius, &RenderStyle::borderTopLeftRadius, &RenderStyle::setBorderTopLeftRadius), |
| new LengthVariantPropertyWrapper<LengthSize>(CSSPropertyBorderTopRightRadius, &RenderStyle::borderTopRightRadius, &RenderStyle::setBorderTopRightRadius), |
| new LengthVariantPropertyWrapper<LengthSize>(CSSPropertyBorderBottomLeftRadius, &RenderStyle::borderBottomLeftRadius, &RenderStyle::setBorderBottomLeftRadius), |
| new LengthVariantPropertyWrapper<LengthSize>(CSSPropertyBorderBottomRightRadius, &RenderStyle::borderBottomRightRadius, &RenderStyle::setBorderBottomRightRadius), |
| new PropertyWrapper<Visibility>(CSSPropertyVisibility, &RenderStyle::visibility, &RenderStyle::setVisibility), |
| new PropertyWrapper<float>(CSSPropertyZoom, &RenderStyle::zoom, &RenderStyle::setZoomWithoutReturnValue), |
| |
| new LengthBoxPropertyWrapper(CSSPropertyClip, &RenderStyle::clip, &RenderStyle::setClip, { LengthBoxPropertyWrapper::Flags::AllowsNegativeValues }), |
| |
| new AcceleratedPropertyWrapper<float>(CSSPropertyOpacity, &RenderStyle::opacity, &RenderStyle::setOpacity), |
| new AcceleratedPropertyWrapper<const TransformOperations&>(CSSPropertyTransform, &RenderStyle::transform, &RenderStyle::setTransform), |
| |
| new AcceleratedIndividualTransformPropertyWrapper<ScaleTransformOperation>(CSSPropertyScale, &RenderStyle::scale, &RenderStyle::setScale), |
| new AcceleratedIndividualTransformPropertyWrapper<RotateTransformOperation>(CSSPropertyRotate, &RenderStyle::rotate, &RenderStyle::setRotate), |
| new AcceleratedIndividualTransformPropertyWrapper<TranslateTransformOperation>(CSSPropertyTranslate, &RenderStyle::translate, &RenderStyle::setTranslate), |
| |
| new PropertyWrapperFilter(CSSPropertyFilter, &RenderStyle::filter, &RenderStyle::setFilter), |
| #if ENABLE(FILTERS_LEVEL_2) |
| new PropertyWrapperFilter(CSSPropertyWebkitBackdropFilter, &RenderStyle::backdropFilter, &RenderStyle::setBackdropFilter), |
| #endif |
| new PropertyWrapperFilter(CSSPropertyAppleColorFilter, &RenderStyle::appleColorFilter, &RenderStyle::setAppleColorFilter), |
| |
| new PropertyWrapperClipPath(CSSPropertyClipPath, &RenderStyle::clipPath, &RenderStyle::setClipPath), |
| |
| new PropertyWrapperShape(CSSPropertyShapeOutside, &RenderStyle::shapeOutside, &RenderStyle::setShapeOutside), |
| new LengthPropertyWrapper(CSSPropertyShapeMargin, &RenderStyle::shapeMargin, &RenderStyle::setShapeMargin, { LengthPropertyWrapper::Flags::NegativeLengthsAreInvalid }), |
| new PropertyWrapper<float>(CSSPropertyShapeImageThreshold, &RenderStyle::shapeImageThreshold, &RenderStyle::setShapeImageThreshold), |
| |
| new PropertyWrapperVisitedAffectedColor(CSSPropertyColumnRuleColor, MaybeInvalidColor, &RenderStyle::columnRuleColor, &RenderStyle::setColumnRuleColor, &RenderStyle::visitedLinkColumnRuleColor, &RenderStyle::setVisitedLinkColumnRuleColor), |
| new PropertyWrapperVisitedAffectedColor(CSSPropertyWebkitTextStrokeColor, MaybeInvalidColor, &RenderStyle::textStrokeColor, &RenderStyle::setTextStrokeColor, &RenderStyle::visitedLinkTextStrokeColor, &RenderStyle::setVisitedLinkTextStrokeColor), |
| new PropertyWrapperVisitedAffectedColor(CSSPropertyWebkitTextFillColor, MaybeInvalidColor, &RenderStyle::textFillColor, &RenderStyle::setTextFillColor, &RenderStyle::visitedLinkTextFillColor, &RenderStyle::setVisitedLinkTextFillColor), |
| new PropertyWrapperVisitedAffectedColor(CSSPropertyBorderLeftColor, MaybeInvalidColor, &RenderStyle::borderLeftColor, &RenderStyle::setBorderLeftColor, &RenderStyle::visitedLinkBorderLeftColor, &RenderStyle::setVisitedLinkBorderLeftColor), |
| new PropertyWrapperVisitedAffectedColor(CSSPropertyBorderRightColor, MaybeInvalidColor, &RenderStyle::borderRightColor, &RenderStyle::setBorderRightColor, &RenderStyle::visitedLinkBorderRightColor, &RenderStyle::setVisitedLinkBorderRightColor), |
| new PropertyWrapperVisitedAffectedColor(CSSPropertyBorderTopColor, MaybeInvalidColor, &RenderStyle::borderTopColor, &RenderStyle::setBorderTopColor, &RenderStyle::visitedLinkBorderTopColor, &RenderStyle::setVisitedLinkBorderTopColor), |
| new PropertyWrapperVisitedAffectedColor(CSSPropertyBorderBottomColor, MaybeInvalidColor, &RenderStyle::borderBottomColor, &RenderStyle::setBorderBottomColor, &RenderStyle::visitedLinkBorderBottomColor, &RenderStyle::setVisitedLinkBorderBottomColor), |
| new PropertyWrapperVisitedAffectedColor(CSSPropertyOutlineColor, MaybeInvalidColor, &RenderStyle::outlineColor, &RenderStyle::setOutlineColor, &RenderStyle::visitedLinkOutlineColor, &RenderStyle::setVisitedLinkOutlineColor), |
| |
| new PropertyWrapperShadow(CSSPropertyBoxShadow, &RenderStyle::boxShadow, &RenderStyle::setBoxShadow), |
| new PropertyWrapperShadow(CSSPropertyWebkitBoxShadow, &RenderStyle::boxShadow, &RenderStyle::setBoxShadow), |
| new PropertyWrapperShadow(CSSPropertyTextShadow, &RenderStyle::textShadow, &RenderStyle::setTextShadow), |
| |
| new PropertyWrapperSVGPaint(CSSPropertyFill, &RenderStyle::fillPaintType, &RenderStyle::fillPaintColor, &RenderStyle::setFillPaintColor), |
| new PropertyWrapper<float>(CSSPropertyFillOpacity, &RenderStyle::fillOpacity, &RenderStyle::setFillOpacity), |
| |
| new PropertyWrapperSVGPaint(CSSPropertyStroke, &RenderStyle::strokePaintType, &RenderStyle::strokePaintColor, &RenderStyle::setStrokePaintColor), |
| new PropertyWrapper<float>(CSSPropertyStrokeOpacity, &RenderStyle::strokeOpacity, &RenderStyle::setStrokeOpacity), |
| new PropertyWrapper<Vector<SVGLengthValue>>(CSSPropertyStrokeDasharray, &RenderStyle::strokeDashArray, &RenderStyle::setStrokeDashArray), |
| new PropertyWrapper<float>(CSSPropertyStrokeMiterlimit, &RenderStyle::strokeMiterLimit, &RenderStyle::setStrokeMiterLimit), |
| |
| new LengthPropertyWrapper(CSSPropertyCx, &RenderStyle::cx, &RenderStyle::setCx), |
| new LengthPropertyWrapper(CSSPropertyCy, &RenderStyle::cy, &RenderStyle::setCy), |
| new LengthPropertyWrapper(CSSPropertyR, &RenderStyle::r, &RenderStyle::setR), |
| new LengthPropertyWrapper(CSSPropertyRx, &RenderStyle::rx, &RenderStyle::setRx), |
| new LengthPropertyWrapper(CSSPropertyRy, &RenderStyle::ry, &RenderStyle::setRy), |
| new LengthPropertyWrapper(CSSPropertyStrokeDashoffset, &RenderStyle::strokeDashOffset, &RenderStyle::setStrokeDashOffset), |
| new LengthPropertyWrapper(CSSPropertyStrokeWidth, &RenderStyle::strokeWidth, &RenderStyle::setStrokeWidth), |
| new LengthPropertyWrapper(CSSPropertyX, &RenderStyle::x, &RenderStyle::setX), |
| new LengthPropertyWrapper(CSSPropertyY, &RenderStyle::y, &RenderStyle::setY), |
| |
| new PropertyWrapper<float>(CSSPropertyFloodOpacity, &RenderStyle::floodOpacity, &RenderStyle::setFloodOpacity), |
| new PropertyWrapperMaybeInvalidColor(CSSPropertyFloodColor, &RenderStyle::floodColor, &RenderStyle::setFloodColor), |
| |
| new PropertyWrapper<float>(CSSPropertyStopOpacity, &RenderStyle::stopOpacity, &RenderStyle::setStopOpacity), |
| new PropertyWrapperMaybeInvalidColor(CSSPropertyStopColor, &RenderStyle::stopColor, &RenderStyle::setStopColor), |
| |
| new PropertyWrapperMaybeInvalidColor(CSSPropertyLightingColor, &RenderStyle::lightingColor, &RenderStyle::setLightingColor), |
| |
| new PropertyWrapper<SVGLengthValue>(CSSPropertyBaselineShift, &RenderStyle::baselineShiftValue, &RenderStyle::setBaselineShiftValue), |
| new PropertyWrapper<SVGLengthValue>(CSSPropertyKerning, &RenderStyle::kerning, &RenderStyle::setKerning), |
| #if ENABLE(VARIATION_FONTS) |
| new PropertyWrapperFontVariationSettings(CSSPropertyFontVariationSettings, &RenderStyle::fontVariationSettings, &RenderStyle::setFontVariationSettings), |
| #endif |
| new PropertyWrapper<FontSelectionValue>(CSSPropertyFontWeight, &RenderStyle::fontWeight, &RenderStyle::setFontWeight), |
| new PropertyWrapper<FontSelectionValue>(CSSPropertyFontStretch, &RenderStyle::fontStretch, &RenderStyle::setFontStretch), |
| new PropertyWrapperFontStyle(), |
| new PropertyWrapper<TextDecorationThickness>(CSSPropertyTextDecorationThickness, &RenderStyle::textDecorationThickness, &RenderStyle::setTextDecorationThickness), |
| new PropertyWrapper<TextUnderlineOffset>(CSSPropertyTextUnderlineOffset, &RenderStyle::textUnderlineOffset, &RenderStyle::setTextUnderlineOffset), |
| new PropertyWrapperVisitedAffectedColor(CSSPropertyTextDecorationColor, &RenderStyle::textDecorationColor, &RenderStyle::setTextDecorationColor, &RenderStyle::visitedLinkTextDecorationColor, &RenderStyle::setVisitedLinkTextDecorationColor), |
| |
| new LengthPropertyWrapper(CSSPropertyFlexBasis, &RenderStyle::flexBasis, &RenderStyle::setFlexBasis, { LengthPropertyWrapper::Flags::NegativeLengthsAreInvalid }), |
| new NonNegativeFloatPropertyWrapper(CSSPropertyFlexGrow, &RenderStyle::flexGrow, &RenderStyle::setFlexGrow), |
| new NonNegativeFloatPropertyWrapper(CSSPropertyFlexShrink, &RenderStyle::flexShrink, &RenderStyle::setFlexShrink), |
| new PropertyWrapper<int>(CSSPropertyOrder, &RenderStyle::order, &RenderStyle::setOrder), |
| |
| new TabSizePropertyWrapper, |
| |
| // FIXME: The following properties are currently not animatable but should be: |
| // background-attachment, background-blend-mode,background-clip, background-origin, |
| // background-repeat, border-image-repeat, clip-rule, color-interpolation, |
| // color-interpolation-filters, counter-increment, counter-reset, dominant-baseline, |
| // fill-rule, font-family, font-feature-settings, font-kerning, font-language-override, |
| // font-synthesis, font-variant-alternates, font-variant-caps, font-variant-east-asian, |
| // font-variant-ligatures, font-variant-numeric, font-variant-position, grid-template-areas, |
| // ime-mode, marker-end, marker-mid, marker-start, mask, mask-clip, mask-composite, mask-image, |
| // mask-mode, mask-origin, mask-repeat, mask-type, offset-distance, perspective-origin, quotes, |
| // ruby-align, scroll-behavior, shape-rendering, stroke-linecap, stroke-linejoin, text-align-last, |
| // text-anchor, text-emphasis-style, text-rendering, vector-effect |
| new DiscretePropertyWrapper<const StyleContentAlignmentData&>(CSSPropertyAlignContent, &RenderStyle::alignContent, &RenderStyle::setAlignContent), |
| new DiscretePropertyWrapper<const StyleSelfAlignmentData&>(CSSPropertyAlignItems, &RenderStyle::alignItems, &RenderStyle::setAlignItems), |
| new DiscretePropertyWrapper<const StyleSelfAlignmentData&>(CSSPropertyAlignSelf, &RenderStyle::alignSelf, &RenderStyle::setAlignSelf), |
| new DiscretePropertyWrapper<BackfaceVisibility>(CSSPropertyWebkitBackfaceVisibility, &RenderStyle::backfaceVisibility, &RenderStyle::setBackfaceVisibility), |
| new DiscretePropertyWrapper<BorderStyle>(CSSPropertyBorderBottomStyle, &RenderStyle::borderBottomStyle, &RenderStyle::setBorderBottomStyle), |
| new DiscretePropertyWrapper<BorderCollapse>(CSSPropertyBorderCollapse, &RenderStyle::borderCollapse, &RenderStyle::setBorderCollapse), |
| new DiscretePropertyWrapper<BorderStyle>(CSSPropertyBorderLeftStyle, &RenderStyle::borderLeftStyle, &RenderStyle::setBorderLeftStyle), |
| new DiscretePropertyWrapper<BorderStyle>(CSSPropertyBorderRightStyle, &RenderStyle::borderRightStyle, &RenderStyle::setBorderRightStyle), |
| new DiscretePropertyWrapper<BorderStyle>(CSSPropertyBorderTopStyle, &RenderStyle::borderTopStyle, &RenderStyle::setBorderTopStyle), |
| new DiscretePropertyWrapper<BoxSizing>(CSSPropertyBoxSizing, &RenderStyle::boxSizing, &RenderStyle::setBoxSizing), |
| new DiscretePropertyWrapper<CaptionSide>(CSSPropertyCaptionSide, &RenderStyle::captionSide, &RenderStyle::setCaptionSide), |
| new DiscretePropertyWrapper<Clear>(CSSPropertyClear, &RenderStyle::clear, &RenderStyle::setClear), |
| new DiscretePropertyWrapper<PrintColorAdjust>(CSSPropertyWebkitPrintColorAdjust, &RenderStyle::printColorAdjust, &RenderStyle::setPrintColorAdjust), |
| new DiscretePropertyWrapper<ColumnFill>(CSSPropertyColumnFill, &RenderStyle::columnFill, &RenderStyle::setColumnFill), |
| new DiscretePropertyWrapper<BorderStyle>(CSSPropertyColumnRuleStyle, &RenderStyle::columnRuleStyle, &RenderStyle::setColumnRuleStyle), |
| new DiscretePropertyWrapper<BorderStyle>(CSSPropertyColumnRuleStyle, &RenderStyle::columnRuleStyle, &RenderStyle::setColumnRuleStyle), |
| new DiscretePropertyWrapper<CursorType>(CSSPropertyCursor, &RenderStyle::cursor, &RenderStyle::setCursor), |
| new DiscretePropertyWrapper<EmptyCell>(CSSPropertyEmptyCells, &RenderStyle::emptyCells, &RenderStyle::setEmptyCells), |
| new DiscretePropertyWrapper<FlexDirection>(CSSPropertyFlexDirection, &RenderStyle::flexDirection, &RenderStyle::setFlexDirection), |
| new DiscretePropertyWrapper<FlexWrap>(CSSPropertyFlexWrap, &RenderStyle::flexWrap, &RenderStyle::setFlexWrap), |
| new DiscretePropertyWrapper<Float>(CSSPropertyFloat, &RenderStyle::floating, &RenderStyle::setFloating), |
| new DiscretePropertyWrapper<const Vector<GridTrackSize>&>(CSSPropertyGridAutoColumns, &RenderStyle::gridAutoColumns, &RenderStyle::setGridAutoColumns), |
| new DiscretePropertyWrapper<GridAutoFlow>(CSSPropertyGridAutoFlow, &RenderStyle::gridAutoFlow, &RenderStyle::setGridAutoFlow), |
| new DiscretePropertyWrapper<const Vector<GridTrackSize>&>(CSSPropertyGridAutoRows, &RenderStyle::gridAutoRows, &RenderStyle::setGridAutoRows), |
| new DiscretePropertyWrapper<const GridPosition&>(CSSPropertyGridColumnEnd, &RenderStyle::gridItemColumnEnd, &RenderStyle::setGridItemColumnEnd), |
| new DiscretePropertyWrapper<const GridPosition&>(CSSPropertyGridColumnStart, &RenderStyle::gridItemColumnStart, &RenderStyle::setGridItemColumnStart), |
| new DiscretePropertyWrapper<const GridPosition&>(CSSPropertyGridRowEnd, &RenderStyle::gridItemRowEnd, &RenderStyle::setGridItemRowEnd), |
| new DiscretePropertyWrapper<const GridPosition&>(CSSPropertyGridRowStart, &RenderStyle::gridItemRowStart, &RenderStyle::setGridItemRowStart), |
| new DiscretePropertyWrapper<Hyphens>(CSSPropertyWebkitHyphens, &RenderStyle::hyphens, &RenderStyle::setHyphens), |
| new DiscretePropertyWrapper<ImageOrientation>(CSSPropertyImageOrientation, &RenderStyle::imageOrientation, &RenderStyle::setImageOrientation), |
| new DiscretePropertyWrapper<const IntSize&>(CSSPropertyWebkitInitialLetter, &RenderStyle::initialLetter, &RenderStyle::setInitialLetter), |
| new DiscretePropertyWrapper<const StyleContentAlignmentData&>(CSSPropertyJustifyContent, &RenderStyle::justifyContent, &RenderStyle::setJustifyContent), |
| new DiscretePropertyWrapper<const StyleSelfAlignmentData&>(CSSPropertyJustifyItems, &RenderStyle::justifyItems, &RenderStyle::setJustifyItems), |
| new DiscretePropertyWrapper<const StyleSelfAlignmentData&>(CSSPropertyJustifySelf, &RenderStyle::justifySelf, &RenderStyle::setJustifySelf), |
| new DiscretePropertyWrapper<ListStylePosition>(CSSPropertyListStylePosition, &RenderStyle::listStylePosition, &RenderStyle::setListStylePosition), |
| new DiscretePropertyWrapper<ListStyleType>(CSSPropertyListStyleType, &RenderStyle::listStyleType, &RenderStyle::setListStyleType), |
| new DiscretePropertyWrapper<ObjectFit>(CSSPropertyObjectFit, &RenderStyle::objectFit, &RenderStyle::setObjectFit), |
| new DiscretePropertyWrapper<BorderStyle>(CSSPropertyOutlineStyle, &RenderStyle::outlineStyle, &RenderStyle::setOutlineStyle), |
| new DiscretePropertyWrapper<OverflowWrap>(CSSPropertyOverflowWrap, &RenderStyle::overflowWrap, &RenderStyle::setOverflowWrap), |
| new DiscretePropertyWrapper<Overflow>(CSSPropertyOverflowX, &RenderStyle::overflowX, &RenderStyle::setOverflowX), |
| new DiscretePropertyWrapper<Overflow>(CSSPropertyOverflowY, &RenderStyle::overflowY, &RenderStyle::setOverflowY), |
| new DiscretePropertyWrapper<BreakBetween>(CSSPropertyPageBreakAfter, &RenderStyle::breakAfter, &RenderStyle::setBreakAfter), |
| new DiscretePropertyWrapper<BreakBetween>(CSSPropertyPageBreakBefore, &RenderStyle::breakBefore, &RenderStyle::setBreakBefore), |
| new DiscretePropertyWrapper<BreakInside>(CSSPropertyPageBreakInside, &RenderStyle::breakInside, &RenderStyle::setBreakInside), |
| new DiscretePropertyWrapper<PaintOrder>(CSSPropertyPaintOrder, &RenderStyle::paintOrder, &RenderStyle::setPaintOrder), |
| new DiscretePropertyWrapper<PointerEvents>(CSSPropertyPointerEvents, &RenderStyle::pointerEvents, &RenderStyle::setPointerEvents), |
| new DiscretePropertyWrapper<PositionType>(CSSPropertyPosition, &RenderStyle::position, &RenderStyle::setPosition), |
| new DiscretePropertyWrapper<Resize>(CSSPropertyResize, &RenderStyle::resize, &RenderStyle::setResize), |
| new DiscretePropertyWrapper<RubyPosition>(CSSPropertyWebkitRubyPosition, &RenderStyle::rubyPosition, &RenderStyle::setRubyPosition), |
| new DiscretePropertyWrapper<TableLayoutType>(CSSPropertyTableLayout, &RenderStyle::tableLayout, &RenderStyle::setTableLayout), |
| new DiscretePropertyWrapper<TextAlignMode>(CSSPropertyTextAlign, &RenderStyle::textAlign, &RenderStyle::setTextAlign), |
| new DiscretePropertyWrapper<OptionSet<TextDecoration>>(CSSPropertyTextDecorationLine, &RenderStyle::textDecoration, &RenderStyle::setTextDecoration), |
| new DiscretePropertyWrapper<TextDecorationStyle>(CSSPropertyTextDecorationStyle, &RenderStyle::textDecorationStyle, &RenderStyle::setTextDecorationStyle), |
| new DiscretePropertyWrapper<const Color&>(CSSPropertyWebkitTextEmphasisColor, &RenderStyle::textEmphasisColor, &RenderStyle::setTextEmphasisColor), |
| new DiscretePropertyWrapper<OptionSet<TextEmphasisPosition>>(CSSPropertyWebkitTextEmphasisPosition, &RenderStyle::textEmphasisPosition, &RenderStyle::setTextEmphasisPosition), |
| new DiscretePropertyWrapper<TextOverflow>(CSSPropertyTextOverflow, &RenderStyle::textOverflow, &RenderStyle::setTextOverflow), |
| new DiscretePropertyWrapper<OptionSet<TouchAction>>(CSSPropertyTouchAction, &RenderStyle::touchActions, &RenderStyle::setTouchActions), |
| new DiscretePropertyWrapper<TextTransform>(CSSPropertyTextTransform, &RenderStyle::textTransform, &RenderStyle::setTextTransform), |
| new DiscretePropertyWrapper<TransformBox>(CSSPropertyTransformBox, &RenderStyle::transformBox, &RenderStyle::setTransformBox), |
| new DiscretePropertyWrapper<TransformStyle3D>(CSSPropertyTransformStyle, &RenderStyle::transformStyle3D, &RenderStyle::setTransformStyle3D), |
| new DiscretePropertyWrapper<WhiteSpace>(CSSPropertyWhiteSpace, &RenderStyle::whiteSpace, &RenderStyle::setWhiteSpace), |
| new DiscretePropertyWrapper<WordBreak>(CSSPropertyWordBreak, &RenderStyle::wordBreak, &RenderStyle::setWordBreak), |
| |
| #if ENABLE(CSS_BOX_DECORATION_BREAK) |
| new DiscretePropertyWrapper<BoxDecorationBreak>(CSSPropertyWebkitBoxDecorationBreak, &RenderStyle::boxDecorationBreak, &RenderStyle::setBoxDecorationBreak), |
| #endif |
| #if ENABLE(CSS_COMPOSITING) |
| new DiscretePropertyWrapper<Isolation>(CSSPropertyIsolation, &RenderStyle::isolation, &RenderStyle::setIsolation), |
| new DiscretePropertyWrapper<BlendMode>(CSSPropertyMixBlendMode, &RenderStyle::blendMode, &RenderStyle::setBlendMode), |
| #endif |
| new PropertyWrapperAspectRatio, |
| }; |
| const unsigned animatableLonghandPropertiesCount = WTF_ARRAY_LENGTH(animatableLonghandPropertyWrappers); |
| |
| static const CSSPropertyID animatableShorthandProperties[] = { |
| CSSPropertyBackground, // for background-color, background-position, background-image |
| CSSPropertyBackgroundPosition, |
| CSSPropertyFont, // for font-size, font-weight |
| CSSPropertyWebkitMask, // for mask-position |
| CSSPropertyWebkitMaskPosition, |
| CSSPropertyBorderTop, CSSPropertyBorderRight, CSSPropertyBorderBottom, CSSPropertyBorderLeft, |
| CSSPropertyBorderColor, |
| CSSPropertyBorderRadius, |
| CSSPropertyBorderWidth, |
| CSSPropertyBorder, |
| CSSPropertyBorderImage, |
| CSSPropertyBorderSpacing, |
| CSSPropertyListStyle, // for list-style-image |
| CSSPropertyMargin, |
| CSSPropertyOutline, |
| CSSPropertyPadding, |
| CSSPropertyWebkitTextStroke, |
| CSSPropertyColumnRule, |
| CSSPropertyWebkitBorderRadius, |
| CSSPropertyTransformOrigin, |
| CSSPropertyPerspectiveOrigin |
| }; |
| const unsigned animatableShorthandPropertiesCount = WTF_ARRAY_LENGTH(animatableShorthandProperties); |
| |
| // TODO: |
| // |
| // CSSPropertyVerticalAlign |
| // |
| // Compound properties that have components that should be animatable: |
| // |
| // CSSPropertyColumns |
| // CSSPropertyWebkitBoxReflect |
| |
| // Make sure unused slots have a value |
| for (int i = 0; i < numCSSProperties; ++i) |
| m_propertyToIdMap[i] = cInvalidPropertyWrapperIndex; |
| |
| COMPILE_ASSERT(animatableLonghandPropertiesCount + animatableShorthandPropertiesCount < UCHAR_MAX, numberOfAnimatablePropertiesMustBeLessThanUCharMax); |
| m_propertyWrappers.reserveInitialCapacity(animatableLonghandPropertiesCount + animatableShorthandPropertiesCount); |
| |
| // First we put the non-shorthand property wrappers into the map, so the shorthand-building |
| // code can find them. |
| |
| for (unsigned i = 0; i < animatableLonghandPropertiesCount; ++i) { |
| AnimationPropertyWrapperBase* wrapper = animatableLonghandPropertyWrappers[i]; |
| m_propertyWrappers.uncheckedAppend(std::unique_ptr<AnimationPropertyWrapperBase>(wrapper)); |
| indexFromPropertyID(wrapper->property()) = i; |
| } |
| |
| for (size_t i = 0; i < animatableShorthandPropertiesCount; ++i) { |
| CSSPropertyID propertyID = animatableShorthandProperties[i]; |
| auto shorthand = shorthandForProperty(propertyID); |
| if (!shorthand.length()) |
| continue; |
| |
| Vector<AnimationPropertyWrapperBase*> longhandWrappers; |
| longhandWrappers.reserveInitialCapacity(shorthand.length()); |
| for (auto longhand : shorthand) { |
| unsigned wrapperIndex = indexFromPropertyID(longhand); |
| if (wrapperIndex == cInvalidPropertyWrapperIndex) |
| continue; |
| ASSERT(m_propertyWrappers[wrapperIndex]); |
| longhandWrappers.uncheckedAppend(m_propertyWrappers[wrapperIndex].get()); |
| } |
| |
| m_propertyWrappers.uncheckedAppend(makeUnique<ShorthandPropertyWrapper>(propertyID, WTFMove(longhandWrappers))); |
| indexFromPropertyID(propertyID) = animatableLonghandPropertiesCount + i; |
| } |
| } |
| |
| static bool gatherEnclosingShorthandProperties(CSSPropertyID property, AnimationPropertyWrapperBase* wrapper, HashSet<CSSPropertyID>& propertySet) |
| { |
| if (!wrapper->isShorthandWrapper()) |
| return false; |
| |
| ShorthandPropertyWrapper* shorthandWrapper = static_cast<ShorthandPropertyWrapper*>(wrapper); |
| bool contained = false; |
| for (auto& currWrapper : shorthandWrapper->propertyWrappers()) { |
| if (gatherEnclosingShorthandProperties(property, currWrapper, propertySet) || currWrapper->property() == property) |
| contained = true; |
| } |
| |
| if (contained) |
| propertySet.add(wrapper->property()); |
| |
| return contained; |
| } |
| |
| void CSSPropertyAnimation::blendProperties(const CSSPropertyBlendingClient* client, CSSPropertyID property, RenderStyle* destination, const RenderStyle* from, const RenderStyle* to, double progress) |
| { |
| ASSERT(property != CSSPropertyInvalid); |
| |
| AnimationPropertyWrapperBase* wrapper = CSSPropertyAnimationWrapperMap::singleton().wrapperForProperty(property); |
| if (wrapper) { |
| // https://drafts.csswg.org/web-animations-1/#discrete |
| // The property’s values cannot be meaningfully combined, thus it is not additive and |
| // interpolation swaps from Va to Vb at 50% (p=0.5). |
| if (!wrapper->canInterpolate(from, to)) |
| progress = progress < 0.5 ? 0 : 1; |
| wrapper->blend(client, destination, from, to, progress); |
| #if !LOG_DISABLED |
| wrapper->logBlend(from, to, destination, progress); |
| #endif |
| } |
| } |
| |
| bool CSSPropertyAnimation::isPropertyAnimatable(CSSPropertyID property) |
| { |
| return CSSPropertyAnimationWrapperMap::singleton().wrapperForProperty(property); |
| } |
| |
| bool CSSPropertyAnimation::animationOfPropertyIsAccelerated(CSSPropertyID property) |
| { |
| AnimationPropertyWrapperBase* wrapper = CSSPropertyAnimationWrapperMap::singleton().wrapperForProperty(property); |
| return wrapper ? wrapper->animationIsAccelerated() : false; |
| } |
| |
| // Note: this is inefficient. It's only called from pauseTransitionAtTime(). |
| HashSet<CSSPropertyID> CSSPropertyAnimation::animatableShorthandsAffectingProperty(CSSPropertyID property) |
| { |
| CSSPropertyAnimationWrapperMap& map = CSSPropertyAnimationWrapperMap::singleton(); |
| |
| HashSet<CSSPropertyID> foundProperties; |
| for (unsigned i = 0; i < map.size(); ++i) |
| gatherEnclosingShorthandProperties(property, map.wrapperForIndex(i), foundProperties); |
| |
| return foundProperties; |
| } |
| |
| bool CSSPropertyAnimation::propertiesEqual(CSSPropertyID property, const RenderStyle* a, const RenderStyle* b) |
| { |
| AnimationPropertyWrapperBase* wrapper = CSSPropertyAnimationWrapperMap::singleton().wrapperForProperty(property); |
| if (wrapper) |
| return wrapper->equals(a, b); |
| return true; |
| } |
| |
| bool CSSPropertyAnimation::canPropertyBeInterpolated(CSSPropertyID property, const RenderStyle* from, const RenderStyle* to) |
| { |
| AnimationPropertyWrapperBase* wrapper = CSSPropertyAnimationWrapperMap::singleton().wrapperForProperty(property); |
| if (wrapper) |
| return wrapper->canInterpolate(from, to); |
| return false; |
| } |
| |
| CSSPropertyID CSSPropertyAnimation::getPropertyAtIndex(int i, Optional<bool>& isShorthand) |
| { |
| CSSPropertyAnimationWrapperMap& map = CSSPropertyAnimationWrapperMap::singleton(); |
| |
| if (i < 0 || static_cast<unsigned>(i) >= map.size()) |
| return CSSPropertyInvalid; |
| |
| AnimationPropertyWrapperBase* wrapper = map.wrapperForIndex(i); |
| isShorthand = wrapper->isShorthandWrapper(); |
| return wrapper->property(); |
| } |
| |
| int CSSPropertyAnimation::getNumProperties() |
| { |
| return CSSPropertyAnimationWrapperMap::singleton().size(); |
| } |
| |
| } |