PassRefPtrWillBeRawPtr<AnimatableValue> AnimatableStrokeDasharrayList::interpolateTo(const AnimatableValue* value, double fraction) const { WillBeHeapVector<RefPtrWillBeMember<AnimatableValue> > from = m_values; WillBeHeapVector<RefPtrWillBeMember<AnimatableValue> > to = toAnimatableStrokeDasharrayList(value)->m_values; // The spec states that if the sum of all values is zero, this should be // treated like a value of 'none', which means that a solid line is drawn. // Since we animate to and from values of zero, treat a value of 'none' the // same. If both the two and from values are 'none', we return 'none' // rather than '0 0'. if (from.isEmpty() && to.isEmpty()) return takeConstRef(this); if (from.isEmpty() || to.isEmpty()) { DEFINE_STATIC_REF_WILL_BE_PERSISTENT(AnimatableSVGLength, zeroPixels, (AnimatableSVGLength::create(SVGLength::create()))); if (from.isEmpty()) { from.append(zeroPixels); from.append(zeroPixels); } if (to.isEmpty()) { to.append(zeroPixels); to.append(zeroPixels); } } WillBeHeapVector<RefPtrWillBeMember<AnimatableValue> > interpolatedValues; bool success = interpolateLists(from, to, fraction, interpolatedValues); ASSERT_UNUSED(success, success); return adoptRefWillBeNoop(new AnimatableStrokeDasharrayList(interpolatedValues)); }
PassRefPtr<AnimatableValue> AnimatableStrokeDasharrayList::interpolateTo( const AnimatableValue* value, double fraction) const { if (usesDefaultInterpolationWith(value)) return defaultInterpolateTo(this, value, fraction); Vector<RefPtr<AnimatableValue>> from = m_values; Vector<RefPtr<AnimatableValue>> to = toAnimatableStrokeDasharrayList(value)->m_values; // The spec states that if the sum of all values is zero, this should be // treated like a value of 'none', which means that a solid line is drawn. // Since we animate to and from values of zero, treat a value of 'none' the // same. If both the two and from values are 'none', we return 'none' // rather than '0 0'. if (from.isEmpty() && to.isEmpty()) return takeConstRef(this); if (from.isEmpty() || to.isEmpty()) { DEFINE_STATIC_REF(AnimatableLength, zeroPixels, (AnimatableLength::create(Length(Fixed), 1))); if (from.isEmpty()) { from.append(zeroPixels); from.append(zeroPixels); } if (to.isEmpty()) { to.append(zeroPixels); to.append(zeroPixels); } } Vector<RefPtr<AnimatableValue>> interpolatedValues; bool success = interpolateLists(from, to, fraction, interpolatedValues); ALLOW_UNUSED_LOCAL(success); return adoptRef(new AnimatableStrokeDasharrayList(interpolatedValues)); }
PassRefPtrWillBeRawPtr<AnimatableValue> AnimatableRepeatable::interpolateTo(const AnimatableValue* value, double fraction) const { WillBeHeapVector<RefPtrWillBeMember<AnimatableValue>> interpolatedValues; bool success = interpolateLists(m_values, toAnimatableRepeatable(value)->m_values, fraction, interpolatedValues); if (success) return create(interpolatedValues); return defaultInterpolateTo(this, value, fraction); }
TEST_F(AnimationInterpolableValueTest, SimpleList) { OwnPtrWillBeRawPtr<InterpolableList> listA = InterpolableList::create(3); listA->set(0, InterpolableNumber::create(0)); listA->set(1, InterpolableNumber::create(42)); listA->set(2, InterpolableNumber::create(20.5)); OwnPtrWillBeRawPtr<InterpolableList> listB = InterpolableList::create(3); listB->set(0, InterpolableNumber::create(100)); listB->set(1, InterpolableNumber::create(-200)); listB->set(2, InterpolableNumber::create(300)); RefPtrWillBeRawPtr<Interpolation> i = interpolateLists(listA.release(), listB.release(), 0.3); InterpolableList* outList = toInterpolableList(interpolationValue(*i.get())); EXPECT_FLOAT_EQ(30, toInterpolableNumber(outList->get(0))->value()); EXPECT_FLOAT_EQ(-30.6f, toInterpolableNumber(outList->get(1))->value()); EXPECT_FLOAT_EQ(104.35f, toInterpolableNumber(outList->get(2))->value()); }
TEST_F(AnimationInterpolableValueTest, NestedList) { OwnPtrWillBeRawPtr<InterpolableList> listA = InterpolableList::create(3); listA->set(0, InterpolableNumber::create(0)); OwnPtrWillBeRawPtr<InterpolableList> subListA = InterpolableList::create(1); subListA->set(0, InterpolableNumber::create(100)); listA->set(1, subListA.release()); listA->set(2, InterpolableBool::create(false)); OwnPtrWillBeRawPtr<InterpolableList> listB = InterpolableList::create(3); listB->set(0, InterpolableNumber::create(100)); OwnPtrWillBeRawPtr<InterpolableList> subListB = InterpolableList::create(1); subListB->set(0, InterpolableNumber::create(50)); listB->set(1, subListB.release()); listB->set(2, InterpolableBool::create(true)); RefPtrWillBeRawPtr<Interpolation> i = interpolateLists(listA.release(), listB.release(), 0.5); InterpolableList* outList = toInterpolableList(interpolationValue(*i.get())); EXPECT_FLOAT_EQ(50, toInterpolableNumber(outList->get(0))->value()); EXPECT_FLOAT_EQ(75, toInterpolableNumber(toInterpolableList(outList->get(1))->get(0))->value()); EXPECT_TRUE(toInterpolableBool(outList->get(2))->value()); }