1c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles)/* 2c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles) * Copyright (C) 2013 Google Inc. All rights reserved. 3c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles) * 4c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles) * Redistribution and use in source and binary forms, with or without 5c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles) * modification, are permitted provided that the following conditions are 6c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles) * met: 7c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles) * 8c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles) * * Redistributions of source code must retain the above copyright 9c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles) * notice, this list of conditions and the following disclaimer. 10c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles) * * Redistributions in binary form must reproduce the above 11c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles) * copyright notice, this list of conditions and the following disclaimer 12c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles) * in the documentation and/or other materials provided with the 13c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles) * distribution. 14c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles) * * Neither the name of Google Inc. nor the names of its 15c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles) * contributors may be used to endorse or promote products derived from 16c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles) * this software without specific prior written permission. 17c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles) * 18c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles) * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles) * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles) * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles) * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles) * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles) * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles) * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles) * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles) * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles) */ 30c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles) 31c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles)#include "config.h" 32197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#include "core/animation/animatable/AnimatableImage.h" 33c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles) 34c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles)#include "core/css/CSSImageValue.h" 35c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles)#include "core/rendering/style/StyleGeneratedImage.h" 36c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles)#include "wtf/MathExtras.h" 37c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles) 38c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)namespace blink { 39c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles) 4009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)// FIXME: Once cross-fade works on generated image types, remove this method. 4109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)bool AnimatableImage::usesDefaultInterpolationWith(const AnimatableValue* value) const 4209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){ 4343e7502580f146aa5b3db8267ba6dbb5c733a489Torne (Richard Coles) if (!m_value->isImageValue()) 4409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return true; 4543e7502580f146aa5b3db8267ba6dbb5c733a489Torne (Richard Coles) if (!toAnimatableImage(value)->toCSSValue()->isImageValue()) 4609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return true; 4709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return false; 4809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)} 4909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 5007a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben MurdochPassRefPtrWillBeRawPtr<AnimatableValue> AnimatableImage::interpolateTo(const AnimatableValue* value, double fraction) const 51c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles){ 5243e7502580f146aa5b3db8267ba6dbb5c733a489Torne (Richard Coles) if (fraction <= 0 || fraction >= 1 || usesDefaultInterpolationWith(value)) 53a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) return defaultInterpolateTo(this, value, fraction); 5443e7502580f146aa5b3db8267ba6dbb5c733a489Torne (Richard Coles) 5543e7502580f146aa5b3db8267ba6dbb5c733a489Torne (Richard Coles) CSSValue* fromValue = toCSSValue(); 5643e7502580f146aa5b3db8267ba6dbb5c733a489Torne (Richard Coles) CSSValue* toValue = toAnimatableImage(value)->toCSSValue(); 5743e7502580f146aa5b3db8267ba6dbb5c733a489Torne (Richard Coles) 5809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) RefPtrWillBeRawPtr<CSSCrossfadeValue> crossfadeValue = CSSCrossfadeValue::create(fromValue, toValue); 591e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) crossfadeValue->setPercentage(CSSPrimitiveValue::create(fraction, CSSPrimitiveValue::CSS_NUMBER)); 6043e7502580f146aa5b3db8267ba6dbb5c733a489Torne (Richard Coles) return create(crossfadeValue); 61c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles)} 62c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles) 631e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)bool AnimatableImage::equalTo(const AnimatableValue* value) const 641e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles){ 6543e7502580f146aa5b3db8267ba6dbb5c733a489Torne (Richard Coles) return m_value->equals(*toAnimatableImage(value)->m_value.get()); 661e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)} 671e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) 68c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles)} 69