OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (C) 2014 Google Inc. All rights reserved. |
| 3 * |
| 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are |
| 6 * met: |
| 7 * |
| 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above |
| 11 * copyright notice, this list of conditions and the following disclaimer |
| 12 * in the documentation and/or other materials provided with the |
| 13 * distribution. |
| 14 * * Neither the name of Google Inc. nor the names of its |
| 15 * contributors may be used to endorse or promote products derived from |
| 16 * this software without specific prior written permission. |
| 17 * |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ |
| 30 |
| 31 #ifndef Interpolation_h |
| 32 #define Interpolation_h |
| 33 |
| 34 #include "core/animation/InterpolableValue.h" |
| 35 #include "wtf/RefCounted.h" |
| 36 |
| 37 namespace WebCore { |
| 38 |
| 39 class StyleResolverState; |
| 40 |
| 41 class Interpolation : public RefCounted<Interpolation> { |
| 42 public: |
| 43 static PassRefPtr<Interpolation> create(PassOwnPtr<InterpolableValue> start,
PassOwnPtr<InterpolableValue> end) |
| 44 { |
| 45 return adoptRef(new Interpolation(start, end)); |
| 46 } |
| 47 |
| 48 void interpolate(int iteration, double fraction) const |
| 49 { |
| 50 if (m_cachedFraction != fraction || m_cachedIteration != iteration) |
| 51 { |
| 52 m_cachedValue = m_start->interpolate(*m_end, fraction); |
| 53 m_cachedIteration = iteration; |
| 54 m_cachedFraction = fraction; |
| 55 } |
| 56 } |
| 57 |
| 58 protected: |
| 59 const OwnPtr<InterpolableValue> m_start; |
| 60 const OwnPtr<InterpolableValue> m_end; |
| 61 |
| 62 mutable double m_cachedFraction; |
| 63 mutable int m_cachedIteration; |
| 64 mutable OwnPtr<InterpolableValue> m_cachedValue; |
| 65 |
| 66 Interpolation(PassOwnPtr<InterpolableValue> start, PassOwnPtr<InterpolableVa
lue> end) |
| 67 : m_start(start) |
| 68 , m_end(end) |
| 69 , m_cachedFraction(0) |
| 70 , m_cachedValue(m_start->clone()) |
| 71 { } |
| 72 }; |
| 73 |
| 74 class StyleInterpolation : public Interpolation { |
| 75 public: |
| 76 // 1) convert m_cachedValue into an X |
| 77 // 2) shove X into StyleResolverState |
| 78 // X can be: |
| 79 // (1) a CSSValue (and applied via StyleBuilder::applyProperty) |
| 80 // (2) an AnimatableValue (and applied via // AnimatedStyleBuilder::applyPro
perty) |
| 81 // (3) a custom value that is inserted directly into the StyleResolverState. |
| 82 virtual void apply(StyleResolverState& state) const = 0; |
| 83 |
| 84 CSSPropertyID id() const { return m_id; } |
| 85 |
| 86 protected: |
| 87 CSSPropertyID m_id; |
| 88 |
| 89 StyleInterpolation(PassOwnPtr<InterpolableValue> start, PassOwnPtr<Interpola
bleValue> end, CSSPropertyID id) |
| 90 : Interpolation(start, end) |
| 91 , m_id(id) |
| 92 { } |
| 93 }; |
| 94 |
| 95 class LegacyStyleInterpolation : public StyleInterpolation { |
| 96 public: |
| 97 static PassRefPtr<LegacyStyleInterpolation> create(PassRefPtr<AnimatableValu
e> start, PassRefPtr<AnimatableValue> end, CSSPropertyID id) |
| 98 { |
| 99 return adoptRef(new LegacyStyleInterpolation(InterpolableAnimatableValue
::create(start), InterpolableAnimatableValue::create(end), id)); |
| 100 } |
| 101 |
| 102 virtual void apply(StyleResolverState& state) const; |
| 103 |
| 104 AnimatableValue* currentValue() const { |
| 105 InterpolableAnimatableValue *value = static_cast<InterpolableAnimatableV
alue *>(m_cachedValue.get()); |
| 106 return value->value(); |
| 107 } |
| 108 |
| 109 private: |
| 110 LegacyStyleInterpolation(PassOwnPtr<InterpolableValue> start, PassOwnPtr<Int
erpolableValue> end, CSSPropertyID id) |
| 111 : StyleInterpolation(start, end, id) |
| 112 { } |
| 113 }; |
| 114 |
| 115 } |
| 116 #endif |
OLD | NEW |