Ignore:
Timestamp:
Sep 4, 2013, 11:50:05 PM (12 years ago)
Author:
[email protected]
Message:

Support interpolation between cross-fade() images
https://bugs.webkit.org/show_bug.cgi?id=119955

Reviewed by Darin Adler.

Source/WebCore:

With this patch, CSS can animate from one -webkit-cross-fade
function to another, when the input images are the same in the
same order.

  • css/CSSCrossfadeValue.cpp: Added blend function.

(WebCore::blendFunc):
(WebCore::CSSCrossfadeValue::blend):
(WebCore::CSSCrossfadeValue::equals):
(WebCore::CSSCrossfadeValue::equalInputImages):

  • css/CSSCrossfadeValue.h: Added save casting functions.

(WebCore::toCSSCrossfadeValue):

  • css/CSSValue.h:

(WebCore::CSSValue::isCrossfadeValue):

  • page/animation/CSSPropertyAnimation.cpp: Add another condition to

interpolate between two -webkit-cross-fade functions.

(WebCore::blendFunc):

LayoutTests:

Test interpolation from one cross-fade function to another. Changed pixel test
to a ref test.

  • animations/cross-fade-background-image.html:
  • animations/cross-fade-background-image-expected.html: Added.
  • platform/mac/animations/cross-fade-background-image-expected.png: Removed.
  • platform/mac/animations/cross-fade-background-image-expected.txt: Removed.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/css/CSSCrossfadeValue.cpp

    r155060 r155100  
    11/*
    22 * Copyright (C) 2011 Apple Inc.  All rights reserved.
     3 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    2728#include "CSSCrossfadeValue.h"
    2829
     30#include "AnimationUtilities.h"
    2931#include "CSSImageValue.h"
    3032#include "CachedResourceLoader.h"
     
    3739
    3840namespace WebCore {
     41
     42static inline double blendFunc(double from, double to, double progress)
     43{
     44    return blend(from, to, progress);
     45}
    3946
    4047static bool subimageKnownToBeOpaque(CSSValue* value, const RenderObject* renderer)
     
    179186}
    180187
     188PassRefPtr<CSSCrossfadeValue> CSSCrossfadeValue::blend(const CSSCrossfadeValue& from, double progress) const
     189{
     190    ASSERT(equalInputImages(from));
     191    RefPtr<StyleCachedImage> toStyledImage = StyleCachedImage::create(m_cachedToImage.get());
     192    RefPtr<StyleCachedImage> fromStyledImage = StyleCachedImage::create(m_cachedFromImage.get());
     193
     194    RefPtr<CSSImageValue> fromImageValue = CSSImageValue::create(m_cachedFromImage->url(), fromStyledImage.get());
     195    RefPtr<CSSImageValue> toImageValue = CSSImageValue::create(m_cachedToImage->url(), toStyledImage.get());
     196
     197    RefPtr<CSSCrossfadeValue> crossfadeValue = CSSCrossfadeValue::create(fromImageValue, toImageValue);
     198
     199    double fromPercentage = from.m_percentageValue->getDoubleValue();
     200    if (from.m_percentageValue->isPercentage())
     201        fromPercentage /= 100.0;
     202    double toPercentage = m_percentageValue->getDoubleValue();
     203    if (m_percentageValue->isPercentage())
     204        toPercentage /= 100.0;
     205    crossfadeValue->setPercentage(CSSPrimitiveValue::create(blendFunc(fromPercentage, toPercentage, progress), CSSPrimitiveValue::CSS_NUMBER));
     206    return crossfadeValue.release();
     207}
     208
    181209bool CSSCrossfadeValue::equals(const CSSCrossfadeValue& other) const
    182210{
     211    return equalInputImages(other)
     212        && compareCSSValuePtr(m_percentageValue, other.m_percentageValue);
     213}
     214
     215
     216bool CSSCrossfadeValue::equalInputImages(const CSSCrossfadeValue& other) const
     217{
    183218    return compareCSSValuePtr(m_fromValue, other.m_fromValue)
    184         && compareCSSValuePtr(m_toValue, other.m_toValue)
    185         && compareCSSValuePtr(m_percentageValue, other.m_percentageValue);
     219        && compareCSSValuePtr(m_toValue, other.m_toValue);
    186220}
    187221
Note: See TracChangeset for help on using the changeset viewer.