Make flex-grow and flex-shrink interpolation continuous with 0

The current flex-grow and flex-shrink interpolation code will not smoothly
interpolate values with 0.
This patch removes this special behaviour as there is no specification text
justifying this behaviour.
Without this behaviour we can simplify the Constraint enum out of AnimatableDouble.

BUG=522817

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

git-svn-id: svn://svn.chromium.org/blink/trunk@201097 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 67d872d5
...@@ -40,11 +40,18 @@ assertInterpolation({ ...@@ -40,11 +40,18 @@ assertInterpolation({
{at: 1.5, is: '2.5'}, {at: 1.5, is: '2.5'},
]); ]);
assertNoInterpolation({ assertInterpolation({
property: 'flex-grow', property: 'flex-grow',
from: 'initial', from: 'initial',
to: '2', to: '2',
}); }, [
{at: -0.3, is: '0'},
{at: 0, is: '0'},
{at: 0.3, is: '0.6'},
{at: 0.6, is: '1.2'},
{at: 1, is: '2'},
{at: 1.5, is: '3'},
]);
assertInterpolation({ assertInterpolation({
property: 'flex-grow', property: 'flex-grow',
...@@ -59,11 +66,18 @@ assertInterpolation({ ...@@ -59,11 +66,18 @@ assertInterpolation({
{at: 1.5, is: '1.5'}, {at: 1.5, is: '1.5'},
]); ]);
assertNoInterpolation({ assertInterpolation({
property: 'flex-grow', property: 'flex-grow',
from: 'unset', from: 'unset',
to: '2', to: '2',
}); }, [
{at: -0.3, is: '0'},
{at: 0, is: '0'},
{at: 0.3, is: '0.6'},
{at: 0.6, is: '1.2'},
{at: 1, is: '2'},
{at: 1.5, is: '3'},
]);
assertInterpolation({ assertInterpolation({
property: 'flex-grow', property: 'flex-grow',
...@@ -76,13 +90,21 @@ assertInterpolation({ ...@@ -76,13 +90,21 @@ assertInterpolation({
{at: 0.3, is: '1.3'}, {at: 0.3, is: '1.3'},
{at: 0.6, is: '1.6'}, {at: 0.6, is: '1.6'},
{at: 1, is: '2'}, {at: 1, is: '2'},
{at: 1.5, is: '2.5'} {at: 1.5, is: '2.5'},
]); ]);
assertNoInterpolation({ assertInterpolation({
property: 'flex-grow', property: 'flex-grow',
from: '0', from: '0',
to: '1', to: '1',
}); }, [
{at: -5, is: '0'},
{at: -0.3, is: '0'},
{at: 0, is: '0'},
{at: 0.3, is: '0.3'},
{at: 0.6, is: '0.6'},
{at: 1, is: '1'},
{at: 1.5, is: '1.5'},
]);
</script> </script>
</body> </body>
...@@ -74,13 +74,21 @@ assertInterpolation({ ...@@ -74,13 +74,21 @@ assertInterpolation({
{at: 0.3, is: '1.3'}, {at: 0.3, is: '1.3'},
{at: 0.6, is: '1.6'}, {at: 0.6, is: '1.6'},
{at: 1, is: '2'}, {at: 1, is: '2'},
{at: 1.5, is: '2.5'} {at: 1.5, is: '2.5'},
]); ]);
assertNoInterpolation({ assertInterpolation({
property: 'flex-shrink', property: 'flex-shrink',
from: '0', from: '0',
to: '1', to: '1',
}); }, [
{at: -5, is: '0'},
{at: -0.3, is: '0'},
{at: 0, is: '0'},
{at: 0.3, is: '0.3'},
{at: 0.6, is: '0.6'},
{at: 1, is: '1'},
{at: 1.5, is: '1.5'},
]);
</script> </script>
</body> </body>
PASS - "-webkit-flex" property for "row1" element at 0.2s saw something close to: 140,0,0 PASS - "-webkit-flex" property for "row1" element at 0.2s saw something close to: 140,0,0
PASS - "-webkit-flex" property for "column1" element at 0.2s saw something close to: 0,0,40 PASS - "-webkit-flex" property for "column1" element at 0.2s saw something close to: 80,0,40
PASS - "-webkit-flex" property for "negative1" element at 0.2s saw something close to: 100,100,60 PASS - "-webkit-flex" property for "negative1" element at 0.2s saw something close to: 100,100,60
PASS - "-webkit-flex" property for "no-flex1" element at 0.2s saw something close to: 0,0,0 PASS - "-webkit-flex" property for "no-flex1" element at 0.2s saw something close to: 80,0,0
PASS - "-webkit-flex" property for "row1" element at 0.8s saw something close to: 260,0,0 PASS - "-webkit-flex" property for "row1" element at 0.8s saw something close to: 260,0,0
PASS - "-webkit-flex" property for "column1" element at 0.8s saw something close to: 0,0,160 PASS - "-webkit-flex" property for "column1" element at 0.8s saw something close to: 20,0,160
PASS - "-webkit-flex" property for "negative1" element at 0.8s saw something close to: 100,100,90 PASS - "-webkit-flex" property for "negative1" element at 0.8s saw something close to: 100,100,90
PASS - "-webkit-flex" property for "no-flex1" element at 0.8s saw something close to: 0,0,0 PASS - "-webkit-flex" property for "no-flex1" element at 0.8s saw something close to: 20,0,0
...@@ -58,13 +58,13 @@ ...@@ -58,13 +58,13 @@
const expectedValues = [ const expectedValues = [
// [time, element-id, property, expected-value, tolerance] // [time, element-id, property, expected-value, tolerance]
[0.2, 'row1', '-webkit-flex', [140, 0, 0], 10], [0.2, 'row1', '-webkit-flex', [140, 0, 0], 10],
[0.2, 'column1', '-webkit-flex', [0, 0, 40], 10], // grow/shrink do not transition to/from zero [0.2, 'column1', '-webkit-flex', [80, 0, 40], 10],
[0.2, 'negative1', '-webkit-flex', [100, 100, 60], 10], [0.2, 'negative1', '-webkit-flex', [100, 100, 60], 10],
[0.2, 'no-flex1', '-webkit-flex', [0, 0, 0], 10], // grow/shrink do not transition to/from zero [0.2, 'no-flex1', '-webkit-flex', [80, 0, 0], 10],
[0.8, 'row1', '-webkit-flex', [260, 0, 0], 10], [0.8, 'row1', '-webkit-flex', [260, 0, 0], 10],
[0.8, 'column1', '-webkit-flex', [0, 0, 160], 10], // grow/shrink do not transition to/from zero [0.8, 'column1', '-webkit-flex', [20, 0, 160], 10],
[0.8, 'negative1', '-webkit-flex', [100, 100, 90], 10], [0.8, 'negative1', '-webkit-flex', [100, 100, 90], 10],
[0.8, 'no-flex1', '-webkit-flex', [0, 0, 0], 10], // grow/shrink do not transition to/from zero [0.8, 'no-flex1', '-webkit-flex', [20, 0, 0], 10],
]; ];
function setupTest() function setupTest()
......
...@@ -36,18 +36,9 @@ ...@@ -36,18 +36,9 @@
namespace blink { namespace blink {
bool AnimatableDouble::usesDefaultInterpolationWith(const AnimatableValue* value) const
{
const AnimatableDouble* other = toAnimatableDouble(value);
return (m_constraint == InterpolationIsNonContinuousWithZero) && (!m_number || !other->m_number);
}
PassRefPtrWillBeRawPtr<AnimatableValue> AnimatableDouble::interpolateTo(const AnimatableValue* value, double fraction) const PassRefPtrWillBeRawPtr<AnimatableValue> AnimatableDouble::interpolateTo(const AnimatableValue* value, double fraction) const
{ {
const AnimatableDouble* other = toAnimatableDouble(value); const AnimatableDouble* other = toAnimatableDouble(value);
ASSERT(m_constraint == other->m_constraint);
if ((m_constraint == InterpolationIsNonContinuousWithZero) && (!m_number || !other->m_number))
return defaultInterpolateTo(this, value, fraction);
return AnimatableDouble::create(blend(m_number, other->m_number, fraction)); return AnimatableDouble::create(blend(m_number, other->m_number, fraction));
} }
......
...@@ -40,14 +40,9 @@ class CORE_EXPORT AnimatableDouble final : public AnimatableValue { ...@@ -40,14 +40,9 @@ class CORE_EXPORT AnimatableDouble final : public AnimatableValue {
public: public:
~AnimatableDouble() override { } ~AnimatableDouble() override { }
enum Constraint { static PassRefPtrWillBeRawPtr<AnimatableDouble> create(double number)
Unconstrained,
InterpolationIsNonContinuousWithZero,
};
static PassRefPtrWillBeRawPtr<AnimatableDouble> create(double number, Constraint constraint = Unconstrained)
{ {
return adoptRefWillBeNoop(new AnimatableDouble(number, constraint)); return adoptRefWillBeNoop(new AnimatableDouble(number));
} }
double toDouble() const { return m_number; } double toDouble() const { return m_number; }
...@@ -56,19 +51,16 @@ public: ...@@ -56,19 +51,16 @@ public:
protected: protected:
PassRefPtrWillBeRawPtr<AnimatableValue> interpolateTo(const AnimatableValue*, double fraction) const override; PassRefPtrWillBeRawPtr<AnimatableValue> interpolateTo(const AnimatableValue*, double fraction) const override;
bool usesDefaultInterpolationWith(const AnimatableValue*) const override;
private: private:
AnimatableDouble(double number, Constraint constraint) AnimatableDouble(double number)
: m_number(number) : m_number(number)
, m_constraint(constraint)
{ {
} }
AnimatableType type() const override { return TypeDouble; } AnimatableType type() const override { return TypeDouble; }
bool equalTo(const AnimatableValue*) const override; bool equalTo(const AnimatableValue*) const override;
double m_number; double m_number;
Constraint m_constraint;
}; };
DEFINE_ANIMATABLE_VALUE_TYPE_CASTS(AnimatableDouble, isDouble()); DEFINE_ANIMATABLE_VALUE_TYPE_CASTS(AnimatableDouble, isDouble());
......
...@@ -112,9 +112,9 @@ static PassRefPtrWillBeRawPtr<AnimatableValue> createFromLineHeight(const Length ...@@ -112,9 +112,9 @@ static PassRefPtrWillBeRawPtr<AnimatableValue> createFromLineHeight(const Length
return createFromLength(length, style); return createFromLength(length, style);
} }
inline static PassRefPtrWillBeRawPtr<AnimatableValue> createFromDouble(double value, AnimatableDouble::Constraint constraint = AnimatableDouble::Unconstrained) inline static PassRefPtrWillBeRawPtr<AnimatableValue> createFromDouble(double value)
{ {
return AnimatableDouble::create(value, constraint); return AnimatableDouble::create(value);
} }
inline static PassRefPtrWillBeRawPtr<AnimatableValue> createFromLengthBox(const LengthBox& lengthBox, const ComputedStyle& style) inline static PassRefPtrWillBeRawPtr<AnimatableValue> createFromLengthBox(const LengthBox& lengthBox, const ComputedStyle& style)
...@@ -379,9 +379,9 @@ PassRefPtrWillBeRawPtr<AnimatableValue> CSSAnimatableValueFactory::create(CSSPro ...@@ -379,9 +379,9 @@ PassRefPtrWillBeRawPtr<AnimatableValue> CSSAnimatableValueFactory::create(CSSPro
style.svgStyle().fillPaintColor(), style.svgStyle().visitedLinkFillPaintColor(), style.svgStyle().fillPaintColor(), style.svgStyle().visitedLinkFillPaintColor(),
style.svgStyle().fillPaintUri(), style.svgStyle().visitedLinkFillPaintUri()); style.svgStyle().fillPaintUri(), style.svgStyle().visitedLinkFillPaintUri());
case CSSPropertyFlexGrow: case CSSPropertyFlexGrow:
return createFromDouble(style.flexGrow(), AnimatableDouble::InterpolationIsNonContinuousWithZero); return createFromDouble(style.flexGrow());
case CSSPropertyFlexShrink: case CSSPropertyFlexShrink:
return createFromDouble(style.flexShrink(), AnimatableDouble::InterpolationIsNonContinuousWithZero); return createFromDouble(style.flexShrink());
case CSSPropertyFlexBasis: case CSSPropertyFlexBasis:
return createFromLength(style.flexBasis(), style); return createFromLength(style.flexBasis(), style);
case CSSPropertyFloodColor: case CSSPropertyFloodColor:
...@@ -518,7 +518,9 @@ PassRefPtrWillBeRawPtr<AnimatableValue> CSSAnimatableValueFactory::create(CSSPro ...@@ -518,7 +518,9 @@ PassRefPtrWillBeRawPtr<AnimatableValue> CSSAnimatableValueFactory::create(CSSPro
case CSSPropertyWebkitMaskSize: case CSSPropertyWebkitMaskSize:
return createFromFillLayers<CSSPropertyWebkitMaskSize>(style.maskLayers(), style); return createFromFillLayers<CSSPropertyWebkitMaskSize>(style.maskLayers(), style);
case CSSPropertyPerspective: case CSSPropertyPerspective:
return createFromDouble(style.perspective(), AnimatableDouble::InterpolationIsNonContinuousWithZero); if (style.perspective() == 0)
return AnimatableUnknown::create(CSSPrimitiveValue::createIdentifier(CSSValueNone));
return createFromDouble(style.perspective());
case CSSPropertyPerspectiveOrigin: case CSSPropertyPerspectiveOrigin:
return createFromLengthPoint(style.perspectiveOrigin(), style); return createFromLengthPoint(style.perspectiveOrigin(), style);
case CSSPropertyShapeOutside: case CSSPropertyShapeOutside:
......
...@@ -582,7 +582,7 @@ void AnimatedStyleBuilder::applyProperty(CSSPropertyID property, StyleResolverSt ...@@ -582,7 +582,7 @@ void AnimatedStyleBuilder::applyProperty(CSSPropertyID property, StyleResolverSt
setOnFillLayers<CSSPropertyWebkitMaskSize>(style->accessMaskLayers(), value, state); setOnFillLayers<CSSPropertyWebkitMaskSize>(style->accessMaskLayers(), value, state);
return; return;
case CSSPropertyPerspective: case CSSPropertyPerspective:
style->setPerspective(clampTo<float>(toAnimatableDouble(value)->toDouble())); style->setPerspective(value->isDouble() ? clampTo<float>(toAnimatableDouble(value)->toDouble()) : 0);
return; return;
case CSSPropertyPerspectiveOrigin: case CSSPropertyPerspectiveOrigin:
style->setPerspectiveOrigin(animatableValueToLengthPoint(value, state)); style->setPerspectiveOrigin(animatableValueToLengthPoint(value, state));
......
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