[Web Animations] Make KeyframeEffect target nullable and read-write
authorgraouts@webkit.org <graouts@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 13 Feb 2018 22:43:50 +0000 (22:43 +0000)
committergraouts@webkit.org <graouts@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 13 Feb 2018 22:43:50 +0000 (22:43 +0000)
commitbd3315a5fd933de773706ae5990fd6f702d62281
tree3b86a5c628009325a052ca093cdc6b5b6367950d
parentd0b929d48f883f707ae63a32315109c56193cdae
[Web Animations] Make KeyframeEffect target nullable and read-write
https://bugs.webkit.org/show_bug.cgi?id=182741

Reviewed by Dean Jackson.

LayoutTests/imported/w3c:

Update test expectations for tests that use null KeyframeEffect targets and tests that update their target.

* web-platform-tests/web-animations/animation-model/animation-types/accumulation-per-property-expected.txt:
* web-platform-tests/web-animations/animation-model/animation-types/addition-per-property-expected.txt:
* web-platform-tests/web-animations/animation-model/animation-types/discrete-expected.txt:
* web-platform-tests/web-animations/animation-model/animation-types/interpolation-per-property-expected.txt:
* web-platform-tests/web-animations/animation-model/animation-types/visibility-expected.txt:
* web-platform-tests/web-animations/animation-model/keyframe-effects/effect-value-iteration-composite-operation-expected.txt:
* web-platform-tests/web-animations/animation-model/keyframe-effects/effect-value-transformed-distance-expected.txt:
* web-platform-tests/web-animations/interfaces/Animatable/animate-no-browsing-context-expected.txt:
* web-platform-tests/web-animations/interfaces/Animation/cancel-expected.txt:
* web-platform-tests/web-animations/interfaces/KeyframeEffect/idlharness-expected.txt:
* web-platform-tests/web-animations/interfaces/KeyframeEffect/iterationComposite-expected.txt:
* web-platform-tests/web-animations/interfaces/KeyframeEffect/processing-a-keyframes-argument-001-expected.txt:
* web-platform-tests/web-animations/interfaces/KeyframeEffect/target-expected.txt:
* web-platform-tests/web-animations/timing-model/timelines/document-timelines-expected.txt:

Source/WebCore:

We used to completely disregard null targets, for instance not parsing keyframes, but targets
can be null and are also supposed to be read-write for KeyframeEffect. We now update the IDL
for KeyframeEffect to mark the target property as read-write and update the implementation
to correctly handle null targets by creating a StyleResolver based on the ScriptExecutionContext's
document's document element (the <html> element in practice) and not the target itself, since it
can be null.

This revealed a few issues in our implementation by allowing more WPT tests to run. So we also
ensure that:

- we don't crash when parsing font-related properties by calling update() on the generated
RenderStyle's FontCascade when parsing keyframes.

- CSS properties are provided as camel-case and not as hyphenated form

- values provided in keyframes dictionaries are only read for valid properties

- styles for effect targets are invalidated as soon as the timing model for that animation
is changed

We also rename AnimationTimeline::animationTimingModelDidChange() to AnimationTimeline::timingModelDidChange()
since the previous name didn't add useful information and we're adding a new WebAnimation::timingModelDidChange()
method, so having the two methods have a similar name made more sense.

* animation/Animatable.idl: Call animate() with a ScriptExecutionContext rather than a ScriptState
so that the ScriptExecutionContext can be passed to the KeyframeEffectReadOnly constructor.
* animation/AnimationEffectReadOnly.h: Add a new invalidate() method, designed to be subclassed, that
is called when the timing model for this effect or owning animation has changed.
* animation/AnimationTimeline.cpp: Rename animationTimingModelDidChange() to timingModelDidChange().
(WebCore::AnimationTimeline::addAnimation):
(WebCore::AnimationTimeline::removeAnimation):
(WebCore::AnimationTimeline::setCurrentTime):
* animation/AnimationTimeline.h: Rename animationTimingModelDidChange() to timingModelDidChange().
(WebCore::AnimationTimeline::timingModelDidChange):
(WebCore::AnimationTimeline::animationTimingModelDidChange): Deleted.
* animation/DocumentTimeline.cpp: Rename animationTimingModelDidChange() to timingModelDidChange().
(WebCore::DocumentTimeline::timingModelDidChange):
(WebCore::DocumentTimeline::updateAnimations):
(WebCore::DocumentTimeline::animationTimingModelDidChange): Deleted.
* animation/DocumentTimeline.h: Rename animationTimingModelDidChange() to timingModelDidChange().
* animation/KeyframeEffect.cpp: Expect a ScriptExecutionContext rather than a ScriptState.
(WebCore::KeyframeEffect::create):
(WebCore::KeyframeEffect::setKeyframes):
* animation/KeyframeEffect.h: Expect a ScriptExecutionContext rather than a ScriptState.
* animation/KeyframeEffect.idl: Expect a ScriptExecutionContext rather than a ScriptState and make the
target property read-write.
* animation/KeyframeEffectReadOnly.cpp:
(WebCore::IDLAttributeNameToAnimationPropertyName): Move this function below CSSPropertyIDToIDLAttributeName
so that it can call that function. We also check that we reject CSS properties that are not provided in
camel-case form (eg. "font-size" vs. "fontSize").
(WebCore::processIterableKeyframes): Only read the JS values if we know that the provided JS property name
maps to a valid CSS property.
(WebCore::KeyframeEffectReadOnly::create): Expect a ScriptExecutionContext rather than a ScriptState.
(WebCore::KeyframeEffectReadOnly::processKeyframes): Expect a ScriptExecutionContext rather than a ScriptState
and use the context's document to get an HTML element to create a StyleResolver. We also call update() on the
generated RenderStyle's FontCascade since otherwise we would hit an ASSERT in FontCascade when parsing font-related
CSS properties.
(WebCore::KeyframeEffectReadOnly::setTarget): Notify the animation that the effect target has changed and invalidate
the style of the new target and the old targets, if any.
(WebCore::KeyframeEffectReadOnly::invalidate): Invalidate the target's style. This method is called by setTarget()
and WebAnimation::timingModelDidChange().
* animation/KeyframeEffectReadOnly.h: Expect a ScriptExecutionContext rather than a ScriptState.
* animation/KeyframeEffectReadOnly.idl: Expect a ScriptExecutionContext rather than a ScriptState.
* animation/WebAnimation.cpp:
(WebCore::WebAnimation::timingModelDidChange): We add this new method such that any place in WebAnimation where we
know the animation's timing model has changed we can invalidate the associated effect, if any, as well as notify
the timeline, if any. We used to only notify the timeline and, as a result, only invalidate the associated effect
in the next display monitor refresh.
(WebCore::WebAnimation::effectTargetDidChange): This method is called in KeyframeEffectReadOnly::setTarget() to inform
the animation of the previous effect target and the new one upon a target change. This allows us to forward this information
onto the timeline so that we correctly add or remove the targets from the list of animated elements.
(WebCore::WebAnimation::setStartTime):
* animation/WebAnimation.h: Expose the new effectTargetDidChange() and timingModelDidChange() methods.
* dom/Element.cpp: Expect a ScriptExecutionContext rather than a ScriptState.
(WebCore::Element::animate):
* dom/Element.h: Expect a ScriptExecutionContext rather than a ScriptState.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@228437 268f45cc-cd09-0410-ab3c-d52691b4dbfc
32 files changed:
LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/web-animations/animation-model/animation-types/accumulation-per-property-expected.txt
LayoutTests/imported/w3c/web-platform-tests/web-animations/animation-model/animation-types/addition-per-property-expected.txt
LayoutTests/imported/w3c/web-platform-tests/web-animations/animation-model/animation-types/discrete-expected.txt
LayoutTests/imported/w3c/web-platform-tests/web-animations/animation-model/animation-types/interpolation-per-property-expected.txt
LayoutTests/imported/w3c/web-platform-tests/web-animations/animation-model/animation-types/visibility-expected.txt
LayoutTests/imported/w3c/web-platform-tests/web-animations/animation-model/keyframe-effects/effect-value-iteration-composite-operation-expected.txt
LayoutTests/imported/w3c/web-platform-tests/web-animations/animation-model/keyframe-effects/effect-value-transformed-distance-expected.txt
LayoutTests/imported/w3c/web-platform-tests/web-animations/interfaces/Animatable/animate-no-browsing-context-expected.txt
LayoutTests/imported/w3c/web-platform-tests/web-animations/interfaces/Animation/cancel-expected.txt
LayoutTests/imported/w3c/web-platform-tests/web-animations/interfaces/KeyframeEffect/idlharness-expected.txt
LayoutTests/imported/w3c/web-platform-tests/web-animations/interfaces/KeyframeEffect/iterationComposite-expected.txt
LayoutTests/imported/w3c/web-platform-tests/web-animations/interfaces/KeyframeEffect/processing-a-keyframes-argument-001-expected.txt
LayoutTests/imported/w3c/web-platform-tests/web-animations/interfaces/KeyframeEffect/target-expected.txt
LayoutTests/imported/w3c/web-platform-tests/web-animations/timing-model/timelines/document-timelines-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/animation/Animatable.idl
Source/WebCore/animation/AnimationEffectReadOnly.h
Source/WebCore/animation/AnimationTimeline.cpp
Source/WebCore/animation/AnimationTimeline.h
Source/WebCore/animation/DocumentTimeline.cpp
Source/WebCore/animation/DocumentTimeline.h
Source/WebCore/animation/KeyframeEffect.cpp
Source/WebCore/animation/KeyframeEffect.h
Source/WebCore/animation/KeyframeEffect.idl
Source/WebCore/animation/KeyframeEffectReadOnly.cpp
Source/WebCore/animation/KeyframeEffectReadOnly.h
Source/WebCore/animation/KeyframeEffectReadOnly.idl
Source/WebCore/animation/WebAnimation.cpp
Source/WebCore/animation/WebAnimation.h
Source/WebCore/dom/Element.cpp
Source/WebCore/dom/Element.h