Commit a8e124a2 authored by alancutter's avatar alancutter Committed by Commit bot

Web Animations: Add SVGIntegerOptionalIntegerInterpolationType

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

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

BUG=530436

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

Cr-Commit-Position: refs/heads/master@{#361289}
parent d5f70f69
<!DOCTYPE html>
<html>
<body>
<template id="target-template">
<svg width="0" height="0">
<defs>
<filter>
<feConvolveMatrix kernelMatrix="100 200 300 400" class="target" />
</filter>
</defs>
</svg>
</template>
<script src="../svg-attribute-interpolation/resources/interpolation-test.js"></script>
<script>
'use strict';
assertAttributeInterpolation({
property: 'order',
underlying: '1',
from: '1, 6',
fromComposite: 'add',
to: '3, 4',
toComposite: 'add',
}, [
{at: -0.4, is: '1, 8'},
{at: 0, is: '2, 7'},
{at: 0.2, is: '2, 7'},
{at: 0.6, is: '3, 6'},
{at: 1, is: '4, 5'},
{at: 1.4, is: '5, 4'},
]);
assertAttributeInterpolation({
property: 'order',
underlying: '3',
from: '1, 3',
fromComposite: 'replace',
to: '3',
toComposite: 'add',
}, [
{at: -0.4, is: '1, 2'},
{at: 0, is: '1, 3'},
{at: 0.2, is: '2, 4'},
{at: 0.6, is: '4, 5'},
{at: 1, is: '6, 6'},
{at: 1.4, is: '8, 7'},
]);
assertAttributeInterpolation({
property: 'order',
underlying: '3, 5',
from: neutralKeyframe,
to: '1',
toComposite: 'replace',
}, [
{at: -0.4, is: '4, 7'},
{at: 0, is: '3, 5'},
{at: 0.2, is: '3, 4'},
{at: 0.6, is: '2, 3'},
{at: 1, is: '1, 1'},
{at: 1.4, is: '1, 1'},
]);
</script>
</body>
</html>
...@@ -410,8 +410,8 @@ ...@@ -410,8 +410,8 @@
assertionCode += `\n}, [\n`; assertionCode += `\n}, [\n`;
rebaseline.appendChild(document.createTextNode(assertionCode)); rebaseline.appendChild(document.createTextNode(assertionCode));
var rebaselineExpectation; var rebaselineExpectation = document.createTextNode('');
rebaseline.appendChild(rebaselineExpectation = document.createTextNode('')); rebaseline.appendChild(rebaselineExpectation);
rebaseline.appendChild(document.createTextNode(']);\n\n')); rebaseline.appendChild(document.createTextNode(']);\n\n'));
} }
......
// 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/IntegerOptionalIntegerSVGInterpolation.h"
#include "core/SVGNames.h"
namespace blink {
namespace {
// For order, the values must be integers greater than zero.
// For filterRes, negative values are an error. Zero values disable rendering of the element which referenced the filter.
PassRefPtrWillBeRawPtr<SVGInteger> toPositiveInteger(const InterpolableValue* number, int min)
{
return SVGInteger::create(clampTo<int>(roundf(toInterpolableNumber(number)->value()), min));
}
} // namespace
PassOwnPtr<InterpolableValue> IntegerOptionalIntegerSVGInterpolation::toInterpolableValue(SVGPropertyBase* value)
{
RefPtrWillBeRawPtr<SVGIntegerOptionalInteger> integerOptionalInteger = toSVGIntegerOptionalInteger(value);
OwnPtr<InterpolableList> result = InterpolableList::create(2);
result->set(0, InterpolableNumber::create(integerOptionalInteger->firstInteger()->value()));
result->set(1, InterpolableNumber::create(integerOptionalInteger->secondInteger()->value()));
return result.release();
}
PassRefPtrWillBeRawPtr<SVGIntegerOptionalInteger> IntegerOptionalIntegerSVGInterpolation::fromInterpolableValue(const InterpolableValue& value, int min)
{
const InterpolableList& list = toInterpolableList(value);
return SVGIntegerOptionalInteger::create(
toPositiveInteger(list.get(0), min),
toPositiveInteger(list.get(1), min));
}
}
// 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 IntegerOptionalIntegerSVGInterpolation_h
#define IntegerOptionalIntegerSVGInterpolation_h
#include "core/animation/SVGInterpolation.h"
#include "core/svg/SVGIntegerOptionalInteger.h"
#include "platform/heap/Handle.h"
namespace blink {
class SVGIntegerOptionalInteger;
class IntegerOptionalIntegerSVGInterpolation : public SVGInterpolation {
public:
static PassRefPtr<IntegerOptionalIntegerSVGInterpolation> create(SVGPropertyBase* start, SVGPropertyBase* end, PassRefPtrWillBeRawPtr<SVGAnimatedPropertyBase> attribute, int min)
{
return adoptRef(new IntegerOptionalIntegerSVGInterpolation(toInterpolableValue(start), toInterpolableValue(end), attribute, min));
}
PassRefPtrWillBeRawPtr<SVGPropertyBase> interpolatedValue(SVGElement&) const final
{
return fromInterpolableValue(*m_cachedValue, m_min);
}
private:
IntegerOptionalIntegerSVGInterpolation(PassOwnPtr<InterpolableValue> start, PassOwnPtr<InterpolableValue> end, PassRefPtrWillBeRawPtr<SVGAnimatedPropertyBase> attribute, int min)
: SVGInterpolation(start, end, attribute)
, m_min(min)
{
}
static PassOwnPtr<InterpolableValue> toInterpolableValue(SVGPropertyBase*);
static PassRefPtrWillBeRawPtr<SVGIntegerOptionalInteger> fromInterpolableValue(const InterpolableValue&, int);
const int m_min;
};
}
#endif // IntegerOptionalIntegerSVGInterpolation_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/SVGIntegerOptionalIntegerInterpolationType.h"
#include "core/animation/InterpolationEnvironment.h"
#include "core/svg/SVGIntegerOptionalInteger.h"
namespace blink {
PassOwnPtr<InterpolationValue> SVGIntegerOptionalIntegerInterpolationType::maybeConvertNeutral(const UnderlyingValue&, ConversionCheckers&) const
{
OwnPtr<InterpolableList> result = InterpolableList::create(2);
result->set(0, InterpolableNumber::create(0));
result->set(1, InterpolableNumber::create(0));
return InterpolationValue::create(*this, result.release());
}
PassOwnPtr<InterpolationValue> SVGIntegerOptionalIntegerInterpolationType::maybeConvertSVGValue(const SVGPropertyBase& svgValue) const
{
if (svgValue.type() != AnimatedIntegerOptionalInteger)
return nullptr;
const SVGIntegerOptionalInteger& integerOptionalInteger = toSVGIntegerOptionalInteger(svgValue);
OwnPtr<InterpolableList> result = InterpolableList::create(2);
result->set(0, InterpolableNumber::create(integerOptionalInteger.firstInteger()->value()));
result->set(1, InterpolableNumber::create(integerOptionalInteger.secondInteger()->value()));
return InterpolationValue::create(*this, result.release());
}
static PassRefPtrWillBeRawPtr<SVGInteger> toPositiveInteger(const InterpolableValue* number)
{
return SVGInteger::create(clampTo<int>(roundf(toInterpolableNumber(number)->value()), 1));
}
PassRefPtrWillBeRawPtr<SVGPropertyBase> SVGIntegerOptionalIntegerInterpolationType::appliedSVGValue(const InterpolableValue& interpolableValue, const NonInterpolableValue*) const
{
const InterpolableList& list = toInterpolableList(interpolableValue);
return SVGIntegerOptionalInteger::create(
toPositiveInteger(list.get(0)),
toPositiveInteger(list.get(1)));
}
} // 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 SVGIntegerOptionalIntegerInterpolationType_h
#define SVGIntegerOptionalIntegerInterpolationType_h
#include "core/animation/NumberAttributeFunctions.h"
#include "core/animation/SVGInterpolationType.h"
namespace blink {
class SVGIntegerOptionalIntegerInterpolationType : public SVGInterpolationType {
public:
SVGIntegerOptionalIntegerInterpolationType(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 // SVGIntegerOptionalIntegerInterpolationType_h
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
#include "core/animation/DoubleStyleInterpolation.h" #include "core/animation/DoubleStyleInterpolation.h"
#include "core/animation/FilterStyleInterpolation.h" #include "core/animation/FilterStyleInterpolation.h"
#include "core/animation/ImageSliceStyleInterpolation.h" #include "core/animation/ImageSliceStyleInterpolation.h"
#include "core/animation/IntegerOptionalIntegerSVGInterpolation.h"
#include "core/animation/InterpolationType.h" #include "core/animation/InterpolationType.h"
#include "core/animation/InvalidatableInterpolation.h" #include "core/animation/InvalidatableInterpolation.h"
#include "core/animation/LegacyStyleInterpolation.h" #include "core/animation/LegacyStyleInterpolation.h"
...@@ -36,6 +35,7 @@ ...@@ -36,6 +35,7 @@
#include "core/animation/RectSVGInterpolation.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/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"
...@@ -272,6 +272,8 @@ const InterpolationTypes* applicableTypesForProperty(PropertyHandle property) ...@@ -272,6 +272,8 @@ const InterpolationTypes* applicableTypesForProperty(PropertyHandle property)
|| attribute == SVGNames::targetXAttr || attribute == SVGNames::targetXAttr
|| attribute == SVGNames::targetYAttr) { || attribute == SVGNames::targetYAttr) {
applicableTypes->append(adoptPtr(new SVGIntegerInterpolationType(attribute))); applicableTypes->append(adoptPtr(new SVGIntegerInterpolationType(attribute)));
} else if (attribute == SVGNames::orderAttr) {
applicableTypes->append(adoptPtr(new SVGIntegerOptionalIntegerInterpolationType(attribute)));
} else if (attribute == SVGNames::amplitudeAttr } else if (attribute == SVGNames::amplitudeAttr
|| attribute == SVGNames::azimuthAttr || attribute == SVGNames::azimuthAttr
|| attribute == SVGNames::biasAttr || attribute == SVGNames::biasAttr
...@@ -564,10 +566,6 @@ PassRefPtr<Interpolation> createSVGInterpolation(SVGPropertyBase* fromValue, SVG ...@@ -564,10 +566,6 @@ PassRefPtr<Interpolation> createSVGInterpolation(SVGPropertyBase* fromValue, SVG
RefPtr<Interpolation> interpolation = nullptr; RefPtr<Interpolation> interpolation = nullptr;
ASSERT(fromValue->type() == toValue->type()); ASSERT(fromValue->type() == toValue->type());
switch (fromValue->type()) { switch (fromValue->type()) {
case AnimatedIntegerOptionalInteger: {
int min = &attribute->attributeName() == &SVGNames::orderAttr ? 1 : 0;
return IntegerOptionalIntegerSVGInterpolation::create(fromValue, toValue, attribute, min);
}
case AnimatedLength: case AnimatedLength:
return LengthSVGInterpolation::create(fromValue, toValue, attribute); return LengthSVGInterpolation::create(fromValue, toValue, attribute);
case AnimatedLengthList: case AnimatedLengthList:
...@@ -588,6 +586,7 @@ PassRefPtr<Interpolation> createSVGInterpolation(SVGPropertyBase* fromValue, SVG ...@@ -588,6 +586,7 @@ PassRefPtr<Interpolation> createSVGInterpolation(SVGPropertyBase* fromValue, SVG
// Handled by SVGInterpolationTypes. // Handled by SVGInterpolationTypes.
case AnimatedAngle: case AnimatedAngle:
case AnimatedInteger: case AnimatedInteger:
case AnimatedIntegerOptionalInteger:
case AnimatedNumber: case AnimatedNumber:
case AnimatedNumberOptionalNumber: case AnimatedNumberOptionalNumber:
case AnimatedPoints: case AnimatedPoints:
......
...@@ -868,8 +868,6 @@ ...@@ -868,8 +868,6 @@
'animation/ImageSliceStyleInterpolation.h', 'animation/ImageSliceStyleInterpolation.h',
'animation/InertEffect.cpp', 'animation/InertEffect.cpp',
'animation/InertEffect.h', 'animation/InertEffect.h',
'animation/IntegerOptionalIntegerSVGInterpolation.cpp',
'animation/IntegerOptionalIntegerSVGInterpolation.h',
'animation/IntegerSVGInterpolation.h', 'animation/IntegerSVGInterpolation.h',
'animation/InterpolableValue.cpp', 'animation/InterpolableValue.cpp',
'animation/InterpolableValue.h', 'animation/InterpolableValue.h',
...@@ -913,6 +911,8 @@ ...@@ -913,6 +911,8 @@
'animation/SVGAngleInterpolationType.h', 'animation/SVGAngleInterpolationType.h',
'animation/SVGIntegerInterpolationType.cpp', 'animation/SVGIntegerInterpolationType.cpp',
'animation/SVGIntegerInterpolationType.h', 'animation/SVGIntegerInterpolationType.h',
'animation/SVGIntegerOptionalIntegerInterpolationType.cpp',
'animation/SVGIntegerOptionalIntegerInterpolationType.h',
'animation/SVGInterpolation.cpp', 'animation/SVGInterpolation.cpp',
'animation/SVGInterpolation.h', 'animation/SVGInterpolation.h',
'animation/SVGInterpolationType.cpp', 'animation/SVGInterpolationType.cpp',
......
...@@ -59,8 +59,8 @@ public: ...@@ -59,8 +59,8 @@ public:
static AnimatedPropertyType classType() { return AnimatedIntegerOptionalInteger; } static AnimatedPropertyType classType() { return AnimatedIntegerOptionalInteger; }
PassRefPtrWillBeRawPtr<SVGInteger> firstInteger() { return m_firstInteger; } PassRefPtrWillBeRawPtr<SVGInteger> firstInteger() const { return m_firstInteger; }
PassRefPtrWillBeRawPtr<SVGInteger> secondInteger() { return m_secondInteger; } PassRefPtrWillBeRawPtr<SVGInteger> secondInteger() const { return m_secondInteger; }
DECLARE_VIRTUAL_TRACE(); DECLARE_VIRTUAL_TRACE();
......
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