Commit 5be143be authored by alancutter's avatar alancutter Committed by Commit bot

Web Animations: Add SVGRectInterpolationType

This change migrates the "viewBox" SVG attribute animations over to
SVGRectInterpolationType and enables additive keyframe composite modes
as well as neutral keyframes.

This is a rebased reupload of: https://codereview.chromium.org/1431593004

BUG=530436

Review URL: https://codereview.chromium.org/1415513010

Cr-Commit-Position: refs/heads/master@{#361294}
parent b36f7565
<!DOCTYPE html>
<html>
<body>
<template id="target-template">
<svg width="0" height="0">
<defs>
<marker class="target" />
</defs>
</svg>
</template>
<script src="../svg-attribute-interpolation/resources/interpolation-test.js"></script>
<script>
'use strict';
assertAttributeInterpolation({
property: 'viewBox',
underlying: '10, 10, 10, 10',
from: '10, 20, 80, 90',
fromComposite: 'add',
to: '20, 30, 70, 80',
toComposite: 'add',
}, [
{at: -0.4, is: '16, 26, 94, 104'},
{at: 0, is: '20, 30, 90, 100'},
{at: 0.2, is: '22, 32, 88, 98'},
{at: 0.6, is: '26, 36, 84, 94'},
{at: 1, is: '30, 40, 80, 90'},
{at: 1.4, is: '34, 44, 76, 86'},
]);
assertAttributeInterpolation({
property: 'viewBox',
underlying: '10, 10, 10, 10',
from: '10, 20, 80, 90',
fromComposite: 'add',
to: '20, 30, 70, 80',
toComposite: 'replace',
}, [
{at: -0.4, is: '20, 30, 98, 108'},
{at: 0, is: '20, 30, 90, 100'},
{at: 0.2, is: '20, 30, 86, 96'},
{at: 0.6, is: '20, 30, 78, 88'},
{at: 1, is: '20, 30, 70, 80'},
{at: 1.4, is: '20, 30, 62, 72'},
]);
assertAttributeInterpolation({
property: 'viewBox',
underlying: '10, 10, 10, 10',
from: '10, 20, 80, 90',
fromComposite: 'replace',
to: '20, 30, 70, 80',
toComposite: 'add',
}, [
{at: -0.4, is: '2, 12, 80, 90'},
{at: 0, is: '10, 20, 80, 90'},
{at: 0.2, is: '14, 24, 80, 90'},
{at: 0.6, is: '22, 32, 80, 90'},
{at: 1, is: '30, 40, 80, 90'},
{at: 1.4, is: '38, 48, 80, 90'},
]);
assertAttributeInterpolation({
property: 'viewBox',
underlying: '10, 20, 80, 90',
from: neutralKeyframe,
to: '20, 30, 70, 80',
toComposite: 'replace',
}, [
{at: -0.4, is: '6, 16, 84, 94'},
{at: 0, is: '10, 20, 80, 90'},
{at: 0.2, is: '12, 22, 78, 88'},
{at: 0.6, is: '16, 26, 74, 84'},
{at: 1, is: '20, 30, 70, 80'},
{at: 1.4, is: '24, 34, 66, 76'},
]);
</script>
</body>
</html>
...@@ -139,7 +139,7 @@ ...@@ -139,7 +139,7 @@
} }
function serializeSVGRect(rect) { function serializeSVGRect(rect) {
return String([rect.x, rect.y, rect.width, rect.height]); return [rect.x, rect.y, rect.width, rect.height].join(', ');
} }
function serializeSVGTransformList(transformList) { function serializeSVGTransformList(transformList) {
......
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "config.h"
#include "core/animation/RectSVGInterpolation.h"
#include "wtf/StdLibExtras.h"
namespace blink {
PassOwnPtr<InterpolableValue> RectSVGInterpolation::toInterpolableValue(SVGPropertyBase* value)
{
RefPtrWillBeRawPtr<SVGRect> rect = toSVGRect(value);
float element[] = { rect->x(), rect->y(), rect->width(), rect->height() };
OwnPtr<InterpolableList> result = InterpolableList::create(WTF_ARRAY_LENGTH(element));
for (size_t i = 0; i < WTF_ARRAY_LENGTH(element); i++) {
result->set(i, InterpolableNumber::create(element[i]));
}
return result.release();
}
PassRefPtrWillBeRawPtr<SVGRect> RectSVGInterpolation::fromInterpolableValue(const InterpolableValue& value)
{
const InterpolableList& list = toInterpolableList(value);
RefPtrWillBeRawPtr<SVGRect> result = SVGRect::create();
result->setX(toInterpolableNumber(list.get(0))->value());
result->setY(toInterpolableNumber(list.get(1))->value());
result->setWidth(toInterpolableNumber(list.get(2))->value());
result->setHeight(toInterpolableNumber(list.get(3))->value());
return result;
}
}
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef RectSVGInterpolation_h
#define RectSVGInterpolation_h
#include "core/animation/SVGInterpolation.h"
#include "core/svg/SVGRect.h"
namespace blink {
class SVGRect;
class RectSVGInterpolation : public SVGInterpolation {
public:
static PassRefPtr<RectSVGInterpolation> create(SVGPropertyBase* start, SVGPropertyBase* end, PassRefPtrWillBeRawPtr<SVGAnimatedPropertyBase> attribute)
{
return adoptRef(new RectSVGInterpolation(toInterpolableValue(start), toInterpolableValue(end), attribute));
}
PassRefPtrWillBeRawPtr<SVGPropertyBase> interpolatedValue(SVGElement&) const final
{
return fromInterpolableValue(*m_cachedValue);
}
private:
RectSVGInterpolation(PassOwnPtr<InterpolableValue> start, PassOwnPtr<InterpolableValue> end, PassRefPtrWillBeRawPtr<SVGAnimatedPropertyBase> attribute)
: SVGInterpolation(start, end, attribute)
{
}
static PassOwnPtr<InterpolableValue> toInterpolableValue(SVGPropertyBase*);
static PassRefPtrWillBeRawPtr<SVGRect> fromInterpolableValue(const InterpolableValue&);
};
}
#endif // RectSVGInterpolation_h
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "config.h"
#include "core/animation/SVGRectInterpolationType.h"
#include "core/animation/InterpolationEnvironment.h"
#include "core/animation/StringKeyframe.h"
#include "core/svg/SVGRect.h"
#include "wtf/StdLibExtras.h"
namespace blink {
enum RectComponentIndex {
RectX,
RectY,
RectWidth,
RectHeight,
RectComponentIndexCount,
};
PassOwnPtr<InterpolationValue> SVGRectInterpolationType::maybeConvertNeutral(const UnderlyingValue&, ConversionCheckers&) const
{
OwnPtr<InterpolableList> result = InterpolableList::create(RectComponentIndexCount);
for (size_t i = 0; i < RectComponentIndexCount; i++)
result->set(i, InterpolableNumber::create(0));
return InterpolationValue::create(*this, result.release());
}
PassOwnPtr<InterpolationValue> SVGRectInterpolationType::maybeConvertSVGValue(const SVGPropertyBase& svgValue) const
{
if (svgValue.type() != AnimatedRect)
return nullptr;
const SVGRect& rect = toSVGRect(svgValue);
OwnPtr<InterpolableList> result = InterpolableList::create(RectComponentIndexCount);
result->set(RectX, InterpolableNumber::create(rect.x()));
result->set(RectY, InterpolableNumber::create(rect.y()));
result->set(RectWidth, InterpolableNumber::create(rect.width()));
result->set(RectHeight, InterpolableNumber::create(rect.height()));
return InterpolationValue::create(*this, result.release());
}
PassRefPtrWillBeRawPtr<SVGPropertyBase> SVGRectInterpolationType::appliedSVGValue(const InterpolableValue& interpolableValue, const NonInterpolableValue*) const
{
const InterpolableList& list = toInterpolableList(interpolableValue);
RefPtrWillBeRawPtr<SVGRect> result = SVGRect::create();
result->setX(toInterpolableNumber(list.get(RectX))->value());
result->setY(toInterpolableNumber(list.get(RectY))->value());
result->setWidth(toInterpolableNumber(list.get(RectWidth))->value());
result->setHeight(toInterpolableNumber(list.get(RectHeight))->value());
return result;
}
} // namespace blink
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SVGRectInterpolationType_h
#define SVGRectInterpolationType_h
#include "core/animation/SVGInterpolationType.h"
namespace blink {
class SVGRectInterpolationType : public SVGInterpolationType {
public:
SVGRectInterpolationType(const QualifiedName& attribute)
: SVGInterpolationType(attribute)
{ }
private:
PassOwnPtr<InterpolationValue> maybeConvertNeutral(const UnderlyingValue&, ConversionCheckers&) const final;
PassOwnPtr<InterpolationValue> maybeConvertSVGValue(const SVGPropertyBase& svgValue) const final;
PassRefPtrWillBeRawPtr<SVGPropertyBase> appliedSVGValue(const InterpolableValue&, const NonInterpolableValue*) const final;
};
} // namespace blink
#endif // SVGRectInterpolationType_h
...@@ -32,13 +32,13 @@ ...@@ -32,13 +32,13 @@
#include "core/animation/ListStyleInterpolation.h" #include "core/animation/ListStyleInterpolation.h"
#include "core/animation/NumberSVGInterpolation.h" #include "core/animation/NumberSVGInterpolation.h"
#include "core/animation/PathSVGInterpolation.h" #include "core/animation/PathSVGInterpolation.h"
#include "core/animation/RectSVGInterpolation.h"
#include "core/animation/SVGAngleInterpolationType.h" #include "core/animation/SVGAngleInterpolationType.h"
#include "core/animation/SVGIntegerInterpolationType.h" #include "core/animation/SVGIntegerInterpolationType.h"
#include "core/animation/SVGIntegerOptionalIntegerInterpolationType.h" #include "core/animation/SVGIntegerOptionalIntegerInterpolationType.h"
#include "core/animation/SVGNumberInterpolationType.h" #include "core/animation/SVGNumberInterpolationType.h"
#include "core/animation/SVGNumberOptionalNumberInterpolationType.h" #include "core/animation/SVGNumberOptionalNumberInterpolationType.h"
#include "core/animation/SVGPointListInterpolationType.h" #include "core/animation/SVGPointListInterpolationType.h"
#include "core/animation/SVGRectInterpolationType.h"
#include "core/animation/SVGStrokeDasharrayStyleInterpolation.h" #include "core/animation/SVGStrokeDasharrayStyleInterpolation.h"
#include "core/animation/SVGValueInterpolationType.h" #include "core/animation/SVGValueInterpolationType.h"
#include "core/animation/TransformSVGInterpolation.h" #include "core/animation/TransformSVGInterpolation.h"
...@@ -307,6 +307,8 @@ const InterpolationTypes* applicableTypesForProperty(PropertyHandle property) ...@@ -307,6 +307,8 @@ const InterpolationTypes* applicableTypesForProperty(PropertyHandle property)
applicableTypes->append(adoptPtr(new SVGNumberOptionalNumberInterpolationType(attribute))); applicableTypes->append(adoptPtr(new SVGNumberOptionalNumberInterpolationType(attribute)));
} else if (attribute == SVGNames::pointsAttr) { } else if (attribute == SVGNames::pointsAttr) {
applicableTypes->append(adoptPtr(new SVGPointListInterpolationType(attribute))); applicableTypes->append(adoptPtr(new SVGPointListInterpolationType(attribute)));
} else if (attribute == SVGNames::viewBoxAttr) {
applicableTypes->append(adoptPtr(new SVGRectInterpolationType(attribute)));
} else if (attribute == HTMLNames::classAttr } else if (attribute == HTMLNames::classAttr
|| attribute == SVGNames::clipPathUnitsAttr || attribute == SVGNames::clipPathUnitsAttr
|| attribute == SVGNames::edgeModeAttr || attribute == SVGNames::edgeModeAttr
...@@ -577,8 +579,6 @@ PassRefPtr<Interpolation> createSVGInterpolation(SVGPropertyBase* fromValue, SVG ...@@ -577,8 +579,6 @@ PassRefPtr<Interpolation> createSVGInterpolation(SVGPropertyBase* fromValue, SVG
case AnimatedPath: case AnimatedPath:
interpolation = PathSVGInterpolation::maybeCreate(fromValue, toValue, attribute); interpolation = PathSVGInterpolation::maybeCreate(fromValue, toValue, attribute);
break; break;
case AnimatedRect:
return RectSVGInterpolation::create(fromValue, toValue, attribute);
case AnimatedTransformList: case AnimatedTransformList:
interpolation = ListSVGInterpolation<TransformSVGInterpolation>::maybeCreate(fromValue, toValue, attribute); interpolation = ListSVGInterpolation<TransformSVGInterpolation>::maybeCreate(fromValue, toValue, attribute);
break; break;
...@@ -590,6 +590,7 @@ PassRefPtr<Interpolation> createSVGInterpolation(SVGPropertyBase* fromValue, SVG ...@@ -590,6 +590,7 @@ PassRefPtr<Interpolation> createSVGInterpolation(SVGPropertyBase* fromValue, SVG
case AnimatedNumber: case AnimatedNumber:
case AnimatedNumberOptionalNumber: case AnimatedNumberOptionalNumber:
case AnimatedPoints: case AnimatedPoints:
case AnimatedRect:
ASSERT_NOT_REACHED(); ASSERT_NOT_REACHED();
// Fallthrough. // Fallthrough.
......
...@@ -905,8 +905,6 @@ ...@@ -905,8 +905,6 @@
'animation/PrimitiveInterpolation.h', 'animation/PrimitiveInterpolation.h',
'animation/PropertyHandle.cpp', 'animation/PropertyHandle.cpp',
'animation/PropertyHandle.h', 'animation/PropertyHandle.h',
'animation/RectSVGInterpolation.cpp',
'animation/RectSVGInterpolation.h',
'animation/SVGAngleInterpolationType.cpp', 'animation/SVGAngleInterpolationType.cpp',
'animation/SVGAngleInterpolationType.h', 'animation/SVGAngleInterpolationType.h',
'animation/SVGIntegerInterpolationType.cpp', 'animation/SVGIntegerInterpolationType.cpp',
...@@ -924,6 +922,8 @@ ...@@ -924,6 +922,8 @@
'animation/SVGPointListInterpolationType.cpp', 'animation/SVGPointListInterpolationType.cpp',
'animation/SVGPointListInterpolationType.h', 'animation/SVGPointListInterpolationType.h',
'animation/SVGStrokeDasharrayStyleInterpolation.cpp', 'animation/SVGStrokeDasharrayStyleInterpolation.cpp',
'animation/SVGRectInterpolationType.cpp',
'animation/SVGRectInterpolationType.h',
'animation/SVGStrokeDasharrayStyleInterpolation.h', 'animation/SVGStrokeDasharrayStyleInterpolation.h',
'animation/SVGValueInterpolationType.cpp', 'animation/SVGValueInterpolationType.cpp',
'animation/SVGValueInterpolationType.h', 'animation/SVGValueInterpolationType.h',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment