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
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 [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:
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
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 [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({
{at: 1, is: '14px'},
{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>
</body>
......@@ -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 [10px] at 1
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:
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
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 [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({
{at: 1, is: '10px'},
{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>
</body>
......@@ -45,11 +45,11 @@ protected:
template<typename T>
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)
{
return Animation::create(element, EffectInput::convert(element, keyframeDictionaryVector, exceptionState, true));
return Animation::create(element, EffectInput::convert(element, keyframeDictionaryVector, exceptionState));
}
v8::Isolate* m_isolate;
......
......@@ -43,20 +43,10 @@
namespace WebCore {
// FIXME: Remove this once we've removed the dependency on Element.
static bool checkDocumentAndRenderer(Element* element)
PassRefPtrWillBeRawPtr<AnimationEffect> EffectInput::convert(Element* element, const Vector<Dictionary>& keyframeDictionaryVector, ExceptionState& exceptionState)
{
if (!element || !element->inActiveDocument())
return false;
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))
// FIXME: Remove the dependency on element.
if (!element)
return nullptr;
StyleSheetContents* styleSheetContents = element->document().elementSheet().contents();
......
......@@ -17,7 +17,7 @@ class ExceptionState;
class EffectInput {
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
......
......@@ -50,7 +50,7 @@ TEST_F(AnimationEffectInputTest, SortedOffsets)
jsKeyframes.append(Dictionary(keyframe1, 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());
const KeyframeEffectModelBase& keyframeEffect = *toKeyframeEffectModelBase(animationEffect.get());
EXPECT_EQ(1.0, keyframeEffect.getFrames()[1]->offset());
......@@ -70,7 +70,7 @@ TEST_F(AnimationEffectInputTest, UnsortedOffsets)
jsKeyframes.append(Dictionary(keyframe1, 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());
const KeyframeEffectModelBase& keyframeEffect = *toKeyframeEffectModelBase(animationEffect.get());
EXPECT_EQ(1.0, keyframeEffect.getFrames()[1]->offset());
......@@ -93,7 +93,7 @@ TEST_F(AnimationEffectInputTest, LooslySorted)
jsKeyframes.append(Dictionary(keyframe2, 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());
const KeyframeEffectModelBase& keyframeEffect = *toKeyframeEffectModelBase(animationEffect.get());
EXPECT_EQ(1, keyframeEffect.getFrames()[2]->offset());
......@@ -117,7 +117,7 @@ TEST_F(AnimationEffectInputTest, Invalid)
jsKeyframes.append(Dictionary(keyframe2, 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_EQ(InvalidModificationError, exceptionState.code());
}
......
......@@ -74,18 +74,19 @@ PassRefPtrWillBeRawPtr<Interpolation> StringKeyframe::PropertySpecificKeyframe::
if (!CSSAnimations::isAnimatableProperty(property))
return DefaultStyleInterpolation::create(fromCSSValue, toCSSValue, property);
// FIXME: add non-negative CSSPropertyFontSize and CSSPropertyOutlineWidth
switch (property) {
case CSSPropertyBorderBottomWidth:
case CSSPropertyBorderLeftWidth:
case CSSPropertyBorderRightWidth:
case CSSPropertyBorderTopWidth:
case CSSPropertyFontSize:
case CSSPropertyHeight:
case CSSPropertyLineHeight:
case CSSPropertyMaxHeight:
case CSSPropertyMaxWidth:
case CSSPropertyMinHeight:
case CSSPropertyMinWidth:
case CSSPropertyOutlineWidth:
case CSSPropertyPaddingBottom:
case CSSPropertyPaddingLeft:
case CSSPropertyPaddingRight:
......@@ -119,6 +120,7 @@ PassRefPtrWillBeRawPtr<Interpolation> StringKeyframe::PropertySpecificKeyframe::
// FIXME: Remove the use of AnimatableValues, RenderStyles and Elements here.
// FIXME: Remove this cache
ASSERT(element);
if (!m_animatableValueCache)
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