Exemple #1
0
TEST_F(AnimationAnimationTest, CanCreateAnAnimation)
{
    v8::Isolate* isolate = v8::Isolate::GetCurrent();
    v8::HandleScope scope(isolate);
    v8::Local<v8::Context> context = v8::Context::New(isolate);
    v8::Context::Scope contextScope(context);

    Vector<Dictionary> jsKeyframes;
    v8::Handle<v8::Object> keyframe1 = v8::Object::New(isolate);
    v8::Handle<v8::Object> keyframe2 = v8::Object::New(isolate);

    setV8ObjectPropertyAsString(keyframe1, "width", "100px");
    setV8ObjectPropertyAsString(keyframe1, "offset", "0");
    setV8ObjectPropertyAsString(keyframe1, "easing", "ease-in-out");
    setV8ObjectPropertyAsString(keyframe2, "width", "0px");
    setV8ObjectPropertyAsString(keyframe2, "offset", "1");
    setV8ObjectPropertyAsString(keyframe2, "easing", "cubic-bezier(1, 1, 0.3, 0.3)");

    jsKeyframes.append(Dictionary(keyframe1, isolate));
    jsKeyframes.append(Dictionary(keyframe2, isolate));

    String value1;
    ASSERT_TRUE(jsKeyframes[0].get("width", value1));
    ASSERT_EQ("100px", value1);

    String value2;
    ASSERT_TRUE(jsKeyframes[1].get("width", value2));
    ASSERT_EQ("0px", value2);

    RefPtr<Animation> animation = createAnimation(element.get(), jsKeyframes, 0);

    Element* target = animation->target();
    EXPECT_EQ(*element.get(), *target);

    const KeyframeEffectModel::KeyframeVector keyframes =
        toKeyframeEffectModel(animation->effect())->getFrames();

    EXPECT_EQ(0, keyframes[0]->offset());
    EXPECT_EQ(1, keyframes[1]->offset());

    const AnimatableValue* keyframe1Width = keyframes[0]->propertyValue(CSSPropertyWidth);
    const AnimatableValue* keyframe2Width = keyframes[1]->propertyValue(CSSPropertyWidth);
    ASSERT(keyframe1Width);
    ASSERT(keyframe2Width);

    EXPECT_TRUE(keyframe1Width->isLength());
    EXPECT_TRUE(keyframe2Width->isLength());

    EXPECT_EQ("100px", toAnimatableLength(keyframe1Width)->toCSSValue()->cssText());
    EXPECT_EQ("0px", toAnimatableLength(keyframe2Width)->toCSSValue()->cssText());

    EXPECT_EQ(*(CubicBezierTimingFunction::preset(CubicBezierTimingFunction::EaseInOut)), *keyframes[0]->easing());
    EXPECT_EQ(*(CubicBezierTimingFunction::create(1, 1, 0.3, 0.3).get()), *keyframes[1]->easing());
}
Exemple #2
0
TEST_F(AnimationElementAnimationTest, CanStartAnAnimation)
{
    v8::Isolate* isolate = v8::Isolate::GetCurrent();
    v8::HandleScope scope(isolate);
    v8::Local<v8::Context> context = v8::Context::New(isolate);
    v8::Context::Scope contextScope(context);

    Vector<Dictionary> jsKeyframes;
    v8::Handle<v8::Object> keyframe1 = v8::Object::New();
    v8::Handle<v8::Object> keyframe2 = v8::Object::New();

    setV8ObjectProperty(keyframe1, "width", "100px");
    setV8ObjectProperty(keyframe1, "offset", "0");
    setV8ObjectProperty(keyframe2, "width", "0px");
    setV8ObjectProperty(keyframe2, "offset", "1");

    jsKeyframes.append(Dictionary(keyframe1, isolate));
    jsKeyframes.append(Dictionary(keyframe2, isolate));

    String value1;
    ASSERT_TRUE(jsKeyframes[0].get("width", value1));
    ASSERT_EQ("100px", value1);

    String value2;
    ASSERT_TRUE(jsKeyframes[1].get("width", value2));
    ASSERT_EQ("0px", value2);

    startAnimation(element.get(), jsKeyframes);

    Player* player = document->timeline()->players().at(0).get();

    Animation* animation = toAnimation(player->source());

    Element* target = animation->target();
    EXPECT_EQ(*element.get(), *target);

    const KeyframeAnimationEffect::KeyframeVector keyframes =
        toKeyframeAnimationEffect(animation->effect())->getFrames();

    EXPECT_EQ(0, keyframes[0]->offset());
    EXPECT_EQ(1, keyframes[1]->offset());

    const AnimatableValue* keyframe1Width = keyframes[0]->propertyValue(CSSPropertyWidth);
    const AnimatableValue* keyframe2Width = keyframes[1]->propertyValue(CSSPropertyWidth);
    ASSERT(keyframe1Width);
    ASSERT(keyframe2Width);

    EXPECT_TRUE(keyframe1Width->isLength());
    EXPECT_TRUE(keyframe2Width->isLength());

    EXPECT_EQ("100px", toAnimatableLength(keyframe1Width)->toCSSValue()->cssText());
    EXPECT_EQ("0px", toAnimatableLength(keyframe2Width)->toCSSValue()->cssText());
}
PassRefPtr<SVGDashArray> AnimatableStrokeDasharrayList::toSVGDashArray(float zoom) const
{
    RefPtr<SVGDashArray> lengths = SVGDashArray::create();
    for (const auto& dashLength : m_values)
        lengths->append(toAnimatableLength(dashLength.get())->getLength(zoom, ValueRangeNonNegative));
    return lengths.release();
}
bool AnimatableLength::equalTo(const AnimatableValue* value) const
{
    const AnimatableLength* length = toAnimatableLength(value);
    if (m_lengthUnitType != length->m_lengthUnitType)
        return false;
    if (isCalc())
        return m_calcExpression == length->m_calcExpression || m_calcExpression->equals(*length->m_calcExpression);
    return m_lengthValue == length->m_lengthValue;
}
PassRefPtrWillBeRawPtr<AnimatableValue> AnimatableLength::interpolateTo(const AnimatableValue* value, double fraction) const
{
    const AnimatableLength* length = toAnimatableLength(value);
    CSSPrimitiveValue::LengthUnitType type = commonUnitType(length);
    if (!isCalc(type))
        return AnimatableLength::create(blend(m_lengthValue, length->m_lengthValue, fraction), type);

    // FIXME(crbug.com/168840): Support for viewport units in calc needs to be added before we can blend them with other units.
    if (isViewportUnit() || length->isViewportUnit())
        return defaultInterpolateTo(this, value, fraction);

    return AnimatableLength::create(scale(1 - fraction).get(), length->scale(fraction).get());
}
void expectDoubleValue(double expectedValue, PassRefPtr<Interpolation> interpolationValue)
{
    LegacyStyleInterpolation* interpolation = toLegacyStyleInterpolation(interpolationValue.get());
    RefPtr<AnimatableValue> value = interpolation->currentValue();

    ASSERT_TRUE(value->isLength() || value->isUnknown());

    double actualValue;
    if (value->isLength())
        actualValue = toAnimatableLength(value.get())->getLength(1, ValueRangeAll).value();
    else
        actualValue = toCSSPrimitiveValue(toAnimatableUnknown(value.get())->toCSSValue().get())->getDoubleValue();

    EXPECT_FLOAT_EQ(static_cast<float>(expectedValue), actualValue);
}
void PrintTo(const AnimatableValue& animValue, ::std::ostream* os)
{
    if (animValue.isClipPathOperation())
        PrintTo(*(toAnimatableClipPathOperation(&animValue)), os);
    else if (animValue.isColor())
        PrintTo(*(toAnimatableColor(&animValue)), os);
    else if (animValue.isDouble())
        PrintTo(*(toAnimatableDouble(&animValue)), os);
    else if (animValue.isImage())
        PrintTo(*(toAnimatableImage(&animValue)), os);
    else if (animValue.isLength())
        PrintTo(*(toAnimatableLength(&animValue)), os);
    else if (animValue.isLengthBox())
        PrintTo(*(toAnimatableLengthBox(&animValue)), os);
    else if (animValue.isLengthPoint())
        PrintTo(*(toAnimatableLengthPoint(&animValue)), os);
    else if (animValue.isLengthSize())
        PrintTo(*(toAnimatableLengthSize(&animValue)), os);
    else if (animValue.isNeutral())
        PrintTo(*(static_cast<const AnimatableNeutral*>(&animValue)), os);
    else if (animValue.isRepeatable())
        PrintTo(*(toAnimatableRepeatable(&animValue)), os);
    else if (animValue.isSVGLength())
        PrintTo(*(toAnimatableSVGLength(&animValue)), os);
    else if (animValue.isSVGPaint())
        PrintTo(*(toAnimatableSVGPaint(&animValue)), os);
    else if (animValue.isShapeValue())
        PrintTo(*(toAnimatableShapeValue(&animValue)), os);
    else if (animValue.isStrokeDasharrayList())
        PrintTo(*(toAnimatableStrokeDasharrayList(&animValue)), os);
    else if (animValue.isTransform())
        PrintTo(*(toAnimatableTransform(&animValue)), os);
    else if (animValue.isUnknown())
        PrintTo(*(toAnimatableUnknown(&animValue)), os);
    else if (animValue.isVisibility())
        PrintTo(*(toAnimatableVisibility(&animValue)), os);
    else
        *os << "Unknown AnimatableValue - update ifelse chain in AnimatableValueTestHelper.h";
}
bool AnimatableLength::equalTo(const AnimatableValue* value) const
{
    const AnimatableLength* length = toAnimatableLength(value);
    return m_pixels == length->m_pixels && m_percent == length->m_percent && m_hasPixels == length->m_hasPixels && m_hasPercent == length->m_hasPercent;
}
PassRefPtr<AnimatableValue> AnimatableLength::interpolateTo(const AnimatableValue* value, double fraction) const
{
    const AnimatableLength* length = toAnimatableLength(value);
    return create(blend(m_pixels, length->m_pixels, fraction), blend(m_percent, length->m_percent, fraction),
        m_hasPixels || length->m_hasPixels, m_hasPercent || length->m_hasPercent);
}
static bool sidesHaveSameUnits(const AnimatableValue* sideA, const AnimatableValue* sideB)
{
    if (!sideA->isLength() || !sideB->isLength())
        return false;
    return toAnimatableLength(sideA)->hasSameUnits(toAnimatableLength(sideB));
}
bool AnimatableLength::usesDefaultInterpolationWith(const AnimatableValue* value) const
{
    const AnimatableLength* length = toAnimatableLength(value);
    CSSPrimitiveValue::LengthUnitType type = commonUnitType(length);
    return isCalc(type) && (isViewportUnit() || length->isViewportUnit());
}