Web Animations API: Avoid style resolution when calling element.animate()

This patch removes a style recalc that occurred every time
element.animate() was being called regardless of the input.
This is no longer needed now that we are able to defer keyframe
resolution the style recalc using DeferredLegacyStyleInterpolation.

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

git-svn-id: svn://svn.chromium.org/blink/trunk@176485 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 00f958af
...@@ -6,6 +6,13 @@ PASS: font-size from [4px] to [14px] was [7px] at 0.3 ...@@ -6,6 +6,13 @@ PASS: font-size from [4px] to [14px] was [7px] at 0.3
PASS: font-size from [4px] to [14px] was [10px] at 0.6 PASS: font-size from [4px] to [14px] was [10px] at 0.6
PASS: font-size from [4px] to [14px] was [14px] at 1 PASS: font-size from [4px] to [14px] was [14px] at 1
PASS: font-size from [4px] to [14px] was [19px] at 1.5 PASS: font-size from [4px] to [14px] was [19px] at 1.5
PASS: font-size from [x-small] to [20px] was [0px] at -2
PASS: font-size from [x-small] to [20px] was [7px] at -0.3
PASS: font-size from [x-small] to [20px] was [10px] at 0
PASS: font-size from [x-small] to [20px] was [13px] at 0.3
PASS: font-size from [x-small] to [20px] was [16px] at 0.6
PASS: font-size from [x-small] to [20px] was [20px] at 1
PASS: font-size from [x-small] to [20px] was [25px] at 1.5
Web Animations API: Web Animations API:
PASS: fontSize from [4px] to [14px] was [0px] at -2 PASS: fontSize from [4px] to [14px] was [0px] at -2
...@@ -15,4 +22,11 @@ PASS: fontSize from [4px] to [14px] was [7px] at 0.3 ...@@ -15,4 +22,11 @@ PASS: fontSize from [4px] to [14px] was [7px] at 0.3
PASS: fontSize from [4px] to [14px] was [10px] at 0.6 PASS: fontSize from [4px] to [14px] was [10px] at 0.6
PASS: fontSize from [4px] to [14px] was [14px] at 1 PASS: fontSize from [4px] to [14px] was [14px] at 1
PASS: fontSize from [4px] to [14px] was [19px] at 1.5 PASS: fontSize from [4px] to [14px] was [19px] at 1.5
PASS: fontSize from [x-small] to [20px] was [0px] at -2
PASS: fontSize from [x-small] to [20px] was [7px] at -0.3
PASS: fontSize from [x-small] to [20px] was [10px] at 0
PASS: fontSize from [x-small] to [20px] was [13px] at 0.3
PASS: fontSize from [x-small] to [20px] was [16px] at 0.6
PASS: fontSize from [x-small] to [20px] was [20px] at 1
PASS: fontSize from [x-small] to [20px] was [25px] at 1.5
...@@ -27,5 +27,18 @@ assertInterpolation({ ...@@ -27,5 +27,18 @@ assertInterpolation({
{at: 1, is: '14px'}, {at: 1, is: '14px'},
{at: 1.5, is: '19px'}, {at: 1.5, is: '19px'},
]); ]);
assertInterpolation({
property: 'font-size',
from: 'x-small',
to: '20px'
}, [
{at: -2, is: '0px'}, // CSS font-size can't be negative.
{at: -0.3, is: '7px'},
{at: 0, is: '10px'},
{at: 0.3, is: '13px'},
{at: 0.6, is: '16px'},
{at: 1, is: '20px'},
{at: 1.5, is: '25px'},
]);
</script> </script>
</body> </body>
...@@ -5,6 +5,13 @@ PASS: outline-width from [0px] to [10px] was [3px] at 0.3 ...@@ -5,6 +5,13 @@ PASS: outline-width from [0px] to [10px] was [3px] at 0.3
PASS: outline-width from [0px] to [10px] was [6px] at 0.6 PASS: outline-width from [0px] to [10px] was [6px] at 0.6
PASS: outline-width from [0px] to [10px] was [10px] at 1 PASS: outline-width from [0px] to [10px] was [10px] at 1
PASS: outline-width from [0px] to [10px] was [15px] at 1.5 PASS: outline-width from [0px] to [10px] was [15px] at 1.5
PASS: outline-width from [thick] to [15px] was [0px] at -2
PASS: outline-width from [thick] to [15px] was [2px] at -0.3
PASS: outline-width from [thick] to [15px] was [5px] at 0
PASS: outline-width from [thick] to [15px] was [8px] at 0.3
PASS: outline-width from [thick] to [15px] was [11px] at 0.6
PASS: outline-width from [thick] to [15px] was [15px] at 1
PASS: outline-width from [thick] to [15px] was [20px] at 1.5
Web Animations API: Web Animations API:
PASS: outlineWidth from [0px] to [10px] was [0px] at -0.3 PASS: outlineWidth from [0px] to [10px] was [0px] at -0.3
...@@ -13,4 +20,11 @@ PASS: outlineWidth from [0px] to [10px] was [3px] at 0.3 ...@@ -13,4 +20,11 @@ PASS: outlineWidth from [0px] to [10px] was [3px] at 0.3
PASS: outlineWidth from [0px] to [10px] was [6px] at 0.6 PASS: outlineWidth from [0px] to [10px] was [6px] at 0.6
PASS: outlineWidth from [0px] to [10px] was [10px] at 1 PASS: outlineWidth from [0px] to [10px] was [10px] at 1
PASS: outlineWidth from [0px] to [10px] was [15px] at 1.5 PASS: outlineWidth from [0px] to [10px] was [15px] at 1.5
PASS: outlineWidth from [thick] to [15px] was [0px] at -2
PASS: outlineWidth from [thick] to [15px] was [2px] at -0.3
PASS: outlineWidth from [thick] to [15px] was [5px] at 0
PASS: outlineWidth from [thick] to [15px] was [8px] at 0.3
PASS: outlineWidth from [thick] to [15px] was [11px] at 0.6
PASS: outlineWidth from [thick] to [15px] was [15px] at 1
PASS: outlineWidth from [thick] to [15px] was [20px] at 1.5
...@@ -28,5 +28,18 @@ assertInterpolation({ ...@@ -28,5 +28,18 @@ assertInterpolation({
{at: 1, is: '10px'}, {at: 1, is: '10px'},
{at: 1.5, is: '15px'} {at: 1.5, is: '15px'}
]); ]);
assertInterpolation({
property: 'outline-width',
from: 'thick',
to: '15px'
}, [
{at: -2, is: '0px'}, // CSS outline-width can't be negative.
{at: -0.3, is: '2px'},
{at: 0, is: '5px'},
{at: 0.3, is: '8px'},
{at: 0.6, is: '11px'},
{at: 1, is: '15px'},
{at: 1.5, is: '20px'}
]);
</script> </script>
</body> </body>
...@@ -45,11 +45,11 @@ protected: ...@@ -45,11 +45,11 @@ protected:
template<typename T> template<typename T>
static PassRefPtrWillBeRawPtr<Animation> createAnimation(Element* element, Vector<Dictionary> keyframeDictionaryVector, T timingInput, ExceptionState& exceptionState) static PassRefPtrWillBeRawPtr<Animation> createAnimation(Element* element, Vector<Dictionary> keyframeDictionaryVector, T timingInput, ExceptionState& exceptionState)
{ {
return Animation::create(element, EffectInput::convert(element, keyframeDictionaryVector, exceptionState, true), timingInput); return Animation::create(element, EffectInput::convert(element, keyframeDictionaryVector, exceptionState), timingInput);
} }
static PassRefPtrWillBeRawPtr<Animation> createAnimation(Element* element, Vector<Dictionary> keyframeDictionaryVector, ExceptionState& exceptionState) static PassRefPtrWillBeRawPtr<Animation> createAnimation(Element* element, Vector<Dictionary> keyframeDictionaryVector, ExceptionState& exceptionState)
{ {
return Animation::create(element, EffectInput::convert(element, keyframeDictionaryVector, exceptionState, true)); return Animation::create(element, EffectInput::convert(element, keyframeDictionaryVector, exceptionState));
} }
v8::Isolate* m_isolate; v8::Isolate* m_isolate;
......
...@@ -43,20 +43,10 @@ ...@@ -43,20 +43,10 @@
namespace WebCore { namespace WebCore {
// FIXME: Remove this once we've removed the dependency on Element. PassRefPtrWillBeRawPtr<AnimationEffect> EffectInput::convert(Element* element, const Vector<Dictionary>& keyframeDictionaryVector, ExceptionState& exceptionState)
static bool checkDocumentAndRenderer(Element* element)
{ {
if (!element || !element->inActiveDocument()) // FIXME: Remove the dependency on element.
return false; if (!element)
element->document().updateRenderTreeIfNeeded();
return element->renderer();
}
PassRefPtrWillBeRawPtr<AnimationEffect> EffectInput::convert(Element* element, const Vector<Dictionary>& keyframeDictionaryVector, ExceptionState& exceptionState, bool unsafe)
{
// FIXME: This test will not be neccessary once resolution of keyframe values occurs at
// animation application time.
if (!unsafe && !checkDocumentAndRenderer(element))
return nullptr; return nullptr;
StyleSheetContents* styleSheetContents = element->document().elementSheet().contents(); StyleSheetContents* styleSheetContents = element->document().elementSheet().contents();
......
...@@ -17,7 +17,7 @@ class ExceptionState; ...@@ -17,7 +17,7 @@ class ExceptionState;
class EffectInput { class EffectInput {
public: public:
static PassRefPtrWillBeRawPtr<AnimationEffect> convert(Element*, const Vector<Dictionary>& keyframeDictionaryVector, ExceptionState&, bool unsafe = false); static PassRefPtrWillBeRawPtr<AnimationEffect> convert(Element*, const Vector<Dictionary>& keyframeDictionaryVector, ExceptionState&);
}; };
} // namespace WebCore } // namespace WebCore
......
...@@ -50,7 +50,7 @@ TEST_F(AnimationEffectInputTest, SortedOffsets) ...@@ -50,7 +50,7 @@ TEST_F(AnimationEffectInputTest, SortedOffsets)
jsKeyframes.append(Dictionary(keyframe1, m_isolate)); jsKeyframes.append(Dictionary(keyframe1, m_isolate));
jsKeyframes.append(Dictionary(keyframe2, m_isolate)); jsKeyframes.append(Dictionary(keyframe2, m_isolate));
RefPtrWillBeRawPtr<AnimationEffect> animationEffect = EffectInput::convert(element.get(), jsKeyframes, exceptionState, true); RefPtrWillBeRawPtr<AnimationEffect> animationEffect = EffectInput::convert(element.get(), jsKeyframes, exceptionState);
EXPECT_FALSE(exceptionState.hadException()); EXPECT_FALSE(exceptionState.hadException());
const KeyframeEffectModelBase& keyframeEffect = *toKeyframeEffectModelBase(animationEffect.get()); const KeyframeEffectModelBase& keyframeEffect = *toKeyframeEffectModelBase(animationEffect.get());
EXPECT_EQ(1.0, keyframeEffect.getFrames()[1]->offset()); EXPECT_EQ(1.0, keyframeEffect.getFrames()[1]->offset());
...@@ -70,7 +70,7 @@ TEST_F(AnimationEffectInputTest, UnsortedOffsets) ...@@ -70,7 +70,7 @@ TEST_F(AnimationEffectInputTest, UnsortedOffsets)
jsKeyframes.append(Dictionary(keyframe1, m_isolate)); jsKeyframes.append(Dictionary(keyframe1, m_isolate));
jsKeyframes.append(Dictionary(keyframe2, m_isolate)); jsKeyframes.append(Dictionary(keyframe2, m_isolate));
RefPtrWillBeRawPtr<AnimationEffect> animationEffect = EffectInput::convert(element.get(), jsKeyframes, exceptionState, true); RefPtrWillBeRawPtr<AnimationEffect> animationEffect = EffectInput::convert(element.get(), jsKeyframes, exceptionState);
EXPECT_FALSE(exceptionState.hadException()); EXPECT_FALSE(exceptionState.hadException());
const KeyframeEffectModelBase& keyframeEffect = *toKeyframeEffectModelBase(animationEffect.get()); const KeyframeEffectModelBase& keyframeEffect = *toKeyframeEffectModelBase(animationEffect.get());
EXPECT_EQ(1.0, keyframeEffect.getFrames()[1]->offset()); EXPECT_EQ(1.0, keyframeEffect.getFrames()[1]->offset());
...@@ -93,7 +93,7 @@ TEST_F(AnimationEffectInputTest, LooslySorted) ...@@ -93,7 +93,7 @@ TEST_F(AnimationEffectInputTest, LooslySorted)
jsKeyframes.append(Dictionary(keyframe2, m_isolate)); jsKeyframes.append(Dictionary(keyframe2, m_isolate));
jsKeyframes.append(Dictionary(keyframe3, m_isolate)); jsKeyframes.append(Dictionary(keyframe3, m_isolate));
RefPtrWillBeRawPtr<AnimationEffect> animationEffect = EffectInput::convert(element.get(), jsKeyframes, exceptionState, true); RefPtrWillBeRawPtr<AnimationEffect> animationEffect = EffectInput::convert(element.get(), jsKeyframes, exceptionState);
EXPECT_FALSE(exceptionState.hadException()); EXPECT_FALSE(exceptionState.hadException());
const KeyframeEffectModelBase& keyframeEffect = *toKeyframeEffectModelBase(animationEffect.get()); const KeyframeEffectModelBase& keyframeEffect = *toKeyframeEffectModelBase(animationEffect.get());
EXPECT_EQ(1, keyframeEffect.getFrames()[2]->offset()); EXPECT_EQ(1, keyframeEffect.getFrames()[2]->offset());
...@@ -117,7 +117,7 @@ TEST_F(AnimationEffectInputTest, Invalid) ...@@ -117,7 +117,7 @@ TEST_F(AnimationEffectInputTest, Invalid)
jsKeyframes.append(Dictionary(keyframe2, m_isolate)); jsKeyframes.append(Dictionary(keyframe2, m_isolate));
jsKeyframes.append(Dictionary(keyframe3, m_isolate)); jsKeyframes.append(Dictionary(keyframe3, m_isolate));
RefPtrWillBeRawPtr<AnimationEffect> animationEffect ALLOW_UNUSED = EffectInput::convert(element.get(), jsKeyframes, exceptionState, true); RefPtrWillBeRawPtr<AnimationEffect> animationEffect ALLOW_UNUSED = EffectInput::convert(element.get(), jsKeyframes, exceptionState);
EXPECT_TRUE(exceptionState.hadException()); EXPECT_TRUE(exceptionState.hadException());
EXPECT_EQ(InvalidModificationError, exceptionState.code()); EXPECT_EQ(InvalidModificationError, exceptionState.code());
} }
......
...@@ -74,18 +74,19 @@ PassRefPtrWillBeRawPtr<Interpolation> StringKeyframe::PropertySpecificKeyframe:: ...@@ -74,18 +74,19 @@ PassRefPtrWillBeRawPtr<Interpolation> StringKeyframe::PropertySpecificKeyframe::
if (!CSSAnimations::isAnimatableProperty(property)) if (!CSSAnimations::isAnimatableProperty(property))
return DefaultStyleInterpolation::create(fromCSSValue, toCSSValue, property); return DefaultStyleInterpolation::create(fromCSSValue, toCSSValue, property);
// FIXME: add non-negative CSSPropertyFontSize and CSSPropertyOutlineWidth
switch (property) { switch (property) {
case CSSPropertyBorderBottomWidth: case CSSPropertyBorderBottomWidth:
case CSSPropertyBorderLeftWidth: case CSSPropertyBorderLeftWidth:
case CSSPropertyBorderRightWidth: case CSSPropertyBorderRightWidth:
case CSSPropertyBorderTopWidth: case CSSPropertyBorderTopWidth:
case CSSPropertyFontSize:
case CSSPropertyHeight: case CSSPropertyHeight:
case CSSPropertyLineHeight: case CSSPropertyLineHeight:
case CSSPropertyMaxHeight: case CSSPropertyMaxHeight:
case CSSPropertyMaxWidth: case CSSPropertyMaxWidth:
case CSSPropertyMinHeight: case CSSPropertyMinHeight:
case CSSPropertyMinWidth: case CSSPropertyMinWidth:
case CSSPropertyOutlineWidth:
case CSSPropertyPaddingBottom: case CSSPropertyPaddingBottom:
case CSSPropertyPaddingLeft: case CSSPropertyPaddingLeft:
case CSSPropertyPaddingRight: case CSSPropertyPaddingRight:
...@@ -119,6 +120,7 @@ PassRefPtrWillBeRawPtr<Interpolation> StringKeyframe::PropertySpecificKeyframe:: ...@@ -119,6 +120,7 @@ PassRefPtrWillBeRawPtr<Interpolation> StringKeyframe::PropertySpecificKeyframe::
// FIXME: Remove the use of AnimatableValues, RenderStyles and Elements here. // FIXME: Remove the use of AnimatableValues, RenderStyles and Elements here.
// FIXME: Remove this cache // FIXME: Remove this cache
ASSERT(element);
if (!m_animatableValueCache) if (!m_animatableValueCache)
m_animatableValueCache = StyleResolver::createAnimatableValueSnapshot(*element, property, *fromCSSValue); m_animatableValueCache = StyleResolver::createAnimatableValueSnapshot(*element, property, *fromCSSValue);
......
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