Commit 31feb8c8 authored by George Steel's avatar George Steel Committed by Commit Bot

Stop setting Animation id to transition property and animation name.

Update devtools to no longer require the id property as identifying the
animation name or transition property and instead use the proper IDL
hierarchy and properties.

Bug: 849927
Change-Id: I85a1c6eda7f176ce23906ee64b4c9c2d3374c57c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1740647
Auto-Submit: George Steel <gtsteel@chromium.org>
Reviewed-by: default avatarRobert Flack <flackr@chromium.org>
Commit-Queue: George Steel <gtsteel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#686500}
parent afe8f695
...@@ -99,6 +99,9 @@ class CORE_EXPORT Animation : public EventTargetWithInlineData, ...@@ -99,6 +99,9 @@ class CORE_EXPORT Animation : public EventTargetWithInlineData,
~Animation() override; ~Animation() override;
void Dispose(); void Dispose();
virtual bool IsCSSAnimation() const { return false; }
virtual bool IsCSSTransition() const { return false; }
// Returns whether the animation is finished. // Returns whether the animation is finished.
bool Update(TimingUpdateReason); bool Update(TimingUpdateReason);
......
...@@ -21,12 +21,6 @@ CSSAnimation::CSSAnimation(ExecutionContext* execution_context, ...@@ -21,12 +21,6 @@ CSSAnimation::CSSAnimation(ExecutionContext* execution_context,
AnimationEffect* content, AnimationEffect* content,
const String& animation_name) const String& animation_name)
: Animation(execution_context, timeline, content), : Animation(execution_context, timeline, content),
animation_name_(animation_name) { animation_name_(animation_name) {}
setId(animation_name);
}
const String& CSSAnimation::animationName() const {
return animation_name_;
}
} // namespace blink } // namespace blink
...@@ -24,12 +24,20 @@ class CORE_EXPORT CSSAnimation : public Animation { ...@@ -24,12 +24,20 @@ class CORE_EXPORT CSSAnimation : public Animation {
AnimationEffect*, AnimationEffect*,
const String& animation_name); const String& animation_name);
const String& animationName() const; bool IsCSSAnimation() const final { return true; }
const String& animationName() const { return animation_name_; }
private: private:
String animation_name_; String animation_name_;
}; };
DEFINE_TYPE_CASTS(CSSAnimation,
Animation,
animation,
animation->IsCSSAnimation(),
animation.IsCSSAnimation());
} // namespace blink } // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_ANIMATION_CSS_CSS_ANIMATION_H_ #endif // THIRD_PARTY_BLINK_RENDERER_CORE_ANIMATION_CSS_CSS_ANIMATION_H_
...@@ -225,24 +225,6 @@ double StartTimeFromDelay(double start_delay) { ...@@ -225,24 +225,6 @@ double StartTimeFromDelay(double start_delay) {
CSSAnimations::CSSAnimations() = default; CSSAnimations::CSSAnimations() = default;
bool CSSAnimations::IsAnimationForInspector(const Animation& animation) {
for (const auto& running_animation : running_animations_) {
if (running_animation->animation->SequenceNumber() ==
animation.SequenceNumber())
return true;
}
return false;
}
bool CSSAnimations::IsTransitionAnimationForInspector(
const Animation& animation) const {
for (const auto& it : transitions_) {
if (it.value.animation->SequenceNumber() == animation.SequenceNumber())
return true;
}
return false;
}
namespace { namespace {
const KeyframeEffectModelBase* GetKeyframeEffectModelBase( const KeyframeEffectModelBase* GetKeyframeEffectModelBase(
......
...@@ -57,9 +57,6 @@ class CORE_EXPORT CSSAnimations final { ...@@ -57,9 +57,6 @@ class CORE_EXPORT CSSAnimations final {
public: public:
CSSAnimations(); CSSAnimations();
bool IsAnimationForInspector(const Animation&);
bool IsTransitionAnimationForInspector(const Animation&) const;
static const StylePropertyShorthand& PropertiesForTransitionAll(); static const StylePropertyShorthand& PropertiesForTransitionAll();
static bool IsAnimationAffectingProperty(const CSSProperty&); static bool IsAnimationAffectingProperty(const CSSProperty&);
static bool IsAffectedByKeyframesFromScope(const Element&, const TreeScope&); static bool IsAffectedByKeyframesFromScope(const Element&, const TreeScope&);
......
...@@ -19,9 +19,7 @@ CSSTransition::CSSTransition(ExecutionContext* execution_context, ...@@ -19,9 +19,7 @@ CSSTransition::CSSTransition(ExecutionContext* execution_context,
AnimationEffect* content, AnimationEffect* content,
const PropertyHandle& transition_property) const PropertyHandle& transition_property)
: Animation(execution_context, timeline, content), : Animation(execution_context, timeline, content),
transition_property_(transition_property) { transition_property_(transition_property) {}
setId(transitionProperty());
}
AtomicString CSSTransition::transitionProperty() const { AtomicString CSSTransition::transitionProperty() const {
return transition_property_.GetCSSPropertyName().ToAtomicString(); return transition_property_.GetCSSPropertyName().ToAtomicString();
......
...@@ -23,12 +23,23 @@ class CORE_EXPORT CSSTransition : public Animation { ...@@ -23,12 +23,23 @@ class CORE_EXPORT CSSTransition : public Animation {
AnimationEffect*, AnimationEffect*,
const PropertyHandle& transition_property); const PropertyHandle& transition_property);
bool IsCSSTransition() const final { return true; }
AtomicString transitionProperty() const; AtomicString transitionProperty() const;
const CSSProperty& TransitionCSSProperty() const {
return transition_property_.GetCSSProperty();
}
private: private:
PropertyHandle transition_property_; PropertyHandle transition_property_;
}; };
DEFINE_TYPE_CASTS(CSSTransition,
Animation,
animation,
animation->IsCSSTransition(),
animation.IsCSSTransition());
} // namespace blink } // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_ANIMATION_CSS_CSS_TRANSITION_H_ #endif // THIRD_PARTY_BLINK_RENDERER_CORE_ANIMATION_CSS_CSS_TRANSITION_H_
...@@ -10,7 +10,9 @@ ...@@ -10,7 +10,9 @@
#include "third_party/blink/renderer/core/animation/animation.h" #include "third_party/blink/renderer/core/animation/animation.h"
#include "third_party/blink/renderer/core/animation/animation_effect.h" #include "third_party/blink/renderer/core/animation/animation_effect.h"
#include "third_party/blink/renderer/core/animation/computed_effect_timing.h" #include "third_party/blink/renderer/core/animation/computed_effect_timing.h"
#include "third_party/blink/renderer/core/animation/css/css_animation.h"
#include "third_party/blink/renderer/core/animation/css/css_animations.h" #include "third_party/blink/renderer/core/animation/css/css_animations.h"
#include "third_party/blink/renderer/core/animation/css/css_transition.h"
#include "third_party/blink/renderer/core/animation/effect_model.h" #include "third_party/blink/renderer/core/animation/effect_model.h"
#include "third_party/blink/renderer/core/animation/element_animations.h" #include "third_party/blink/renderer/core/animation/element_animations.h"
#include "third_party/blink/renderer/core/animation/keyframe_effect.h" #include "third_party/blink/renderer/core/animation/keyframe_effect.h"
...@@ -34,6 +36,21 @@ ...@@ -34,6 +36,21 @@
namespace blink { namespace blink {
namespace {
String AnimationDisplayName(const Animation& animation) {
if (!animation.id().IsEmpty())
return animation.id();
else if (animation.IsCSSAnimation())
return ToCSSAnimation(animation).animationName();
else if (animation.IsCSSTransition())
return ToCSSTransition(animation).transitionProperty();
else
return animation.id();
}
} // namespace
using protocol::Response; using protocol::Response;
InspectorAnimationAgent::InspectorAnimationAgent( InspectorAnimationAgent::InspectorAnimationAgent(
...@@ -65,7 +82,6 @@ Response InspectorAnimationAgent::disable() { ...@@ -65,7 +82,6 @@ Response InspectorAnimationAgent::disable() {
enabled_.Clear(); enabled_.Clear();
instrumenting_agents_->RemoveInspectorAnimationAgent(this); instrumenting_agents_->RemoveInspectorAnimationAgent(this);
id_to_animation_.clear(); id_to_animation_.clear();
id_to_animation_type_.clear();
id_to_animation_clone_.clear(); id_to_animation_clone_.clear();
cleared_animations_.clear(); cleared_animations_.clear();
return Response::OK(); return Response::OK();
...@@ -74,7 +90,6 @@ Response InspectorAnimationAgent::disable() { ...@@ -74,7 +90,6 @@ Response InspectorAnimationAgent::disable() {
void InspectorAnimationAgent::DidCommitLoadForLocalFrame(LocalFrame* frame) { void InspectorAnimationAgent::DidCommitLoadForLocalFrame(LocalFrame* frame) {
if (frame == inspected_frames_->Root()) { if (frame == inspected_frames_->Root()) {
id_to_animation_.clear(); id_to_animation_.clear();
id_to_animation_type_.clear();
id_to_animation_clone_.clear(); id_to_animation_clone_.clear();
cleared_animations_.clear(); cleared_animations_.clear();
} }
...@@ -145,47 +160,32 @@ BuildObjectForAnimationKeyframes(const KeyframeEffect* effect) { ...@@ -145,47 +160,32 @@ BuildObjectForAnimationKeyframes(const KeyframeEffect* effect) {
std::unique_ptr<protocol::Animation::Animation> std::unique_ptr<protocol::Animation::Animation>
InspectorAnimationAgent::BuildObjectForAnimation(blink::Animation& animation) { InspectorAnimationAgent::BuildObjectForAnimation(blink::Animation& animation) {
String animation_type; String animation_type = AnimationType::WebAnimation;
std::unique_ptr<protocol::Animation::AnimationEffect> animation_effect_object; std::unique_ptr<protocol::Animation::AnimationEffect> animation_effect_object;
if (!animation.effect()) { if (animation.effect()) {
animation_type = AnimationType::WebAnimation; animation_effect_object =
} else { BuildObjectForAnimationEffect(ToKeyframeEffect(animation.effect()));
const Element* element = ToKeyframeEffect(animation.effect())->target();
std::unique_ptr<protocol::Animation::KeyframesRule> keyframe_rule;
if (!element) { if (animation.IsCSSTransition()) {
animation_type = AnimationType::WebAnimation; animation_type = AnimationType::CSSTransition;
} else { } else {
CSSAnimations& css_animations = animation_effect_object->setKeyframesRule(
element->GetElementAnimations()->CssAnimations(); BuildObjectForAnimationKeyframes(
ToKeyframeEffect(animation.effect())));
if (css_animations.IsTransitionAnimationForInspector(animation)) { if (animation.IsCSSAnimation())
// CSS Transitions animation_type = AnimationType::CSSAnimation;
animation_type = AnimationType::CSSTransition;
} else {
// Keyframe based animations
keyframe_rule = BuildObjectForAnimationKeyframes(
ToKeyframeEffect(animation.effect()));
animation_type = css_animations.IsAnimationForInspector(animation)
? AnimationType::CSSAnimation
: AnimationType::WebAnimation;
}
} }
animation_effect_object =
BuildObjectForAnimationEffect(ToKeyframeEffect(animation.effect()));
animation_effect_object->setKeyframesRule(std::move(keyframe_rule));
} }
String id = String::Number(animation.SequenceNumber()); String id = String::Number(animation.SequenceNumber());
id_to_animation_.Set(id, &animation); id_to_animation_.Set(id, &animation);
id_to_animation_type_.Set(id, animation_type);
std::unique_ptr<protocol::Animation::Animation> animation_object = std::unique_ptr<protocol::Animation::Animation> animation_object =
protocol::Animation::Animation::create() protocol::Animation::Animation::create()
.setId(id) .setId(id)
.setName(animation.id()) .setName(AnimationDisplayName(animation))
.setPausedState(animation.Paused()) .setPausedState(animation.Paused())
.setPlayState(animation.playState()) .setPlayState(animation.playState())
.setPlaybackRate(animation.playbackRate()) .setPlaybackRate(animation.playbackRate())
...@@ -343,7 +343,6 @@ Response InspectorAnimationAgent::releaseAnimations( ...@@ -343,7 +343,6 @@ Response InspectorAnimationAgent::releaseAnimations(
clone->cancel(); clone->cancel();
id_to_animation_clone_.erase(animation_id); id_to_animation_clone_.erase(animation_id);
id_to_animation_.erase(animation_id); id_to_animation_.erase(animation_id);
id_to_animation_type_.erase(animation_id);
cleared_animations_.insert(animation_id); cleared_animations_.insert(animation_id);
} }
return Response::OK(); return Response::OK();
...@@ -417,26 +416,28 @@ String InspectorAnimationAgent::CreateCSSId(blink::Animation& animation) { ...@@ -417,26 +416,28 @@ String InspectorAnimationAgent::CreateCSSId(blink::Animation& animation) {
&GetCSSPropertyTransitionProperty(), &GetCSSPropertyTransitionProperty(),
&GetCSSPropertyTransitionTimingFunction(), &GetCSSPropertyTransitionTimingFunction(),
}; };
String type =
id_to_animation_type_.at(String::Number(animation.SequenceNumber()));
DCHECK_NE(type, AnimationType::WebAnimation);
KeyframeEffect* effect = ToKeyframeEffect(animation.effect()); KeyframeEffect* effect = ToKeyframeEffect(animation.effect());
Vector<const CSSProperty*> css_properties; Vector<const CSSProperty*> css_properties;
if (type == AnimationType::CSSAnimation) { if (animation.IsCSSAnimation()) {
for (const CSSProperty* property : g_animation_properties) for (const CSSProperty* property : g_animation_properties)
css_properties.push_back(property); css_properties.push_back(property);
} else { } else if (animation.IsCSSTransition()) {
for (const CSSProperty* property : g_transition_properties) for (const CSSProperty* property : g_transition_properties)
css_properties.push_back(property); css_properties.push_back(property);
css_properties.push_back(&CSSProperty::Get(cssPropertyID(animation.id()))); css_properties.push_back(
&ToCSSTransition(animation).TransitionCSSProperty());
} else {
NOTREACHED();
} }
Element* element = effect->target(); Element* element = effect->target();
HeapVector<Member<CSSStyleDeclaration>> styles = HeapVector<Member<CSSStyleDeclaration>> styles =
css_agent_->MatchingStyles(element); css_agent_->MatchingStyles(element);
Digestor digestor(kHashAlgorithmSha1); Digestor digestor(kHashAlgorithmSha1);
digestor.UpdateUtf8(type); digestor.UpdateUtf8(animation.IsCSSTransition()
? AnimationType::CSSTransition
: AnimationType::CSSAnimation);
digestor.UpdateUtf8(animation.id()); digestor.UpdateUtf8(animation.id());
for (const CSSProperty* property : css_properties) { for (const CSSProperty* property : css_properties) {
CSSStyleDeclaration* style = CSSStyleDeclaration* style =
......
...@@ -87,7 +87,6 @@ class CORE_EXPORT InspectorAnimationAgent final ...@@ -87,7 +87,6 @@ class CORE_EXPORT InspectorAnimationAgent final
v8_inspector::V8InspectorSession* v8_session_; v8_inspector::V8InspectorSession* v8_session_;
HeapHashMap<String, Member<blink::Animation>> id_to_animation_; HeapHashMap<String, Member<blink::Animation>> id_to_animation_;
HeapHashMap<String, Member<blink::Animation>> id_to_animation_clone_; HeapHashMap<String, Member<blink::Animation>> id_to_animation_clone_;
HashMap<String, String> id_to_animation_type_;
bool is_cloning_; bool is_cloning_;
HashSet<String> cleared_animations_; HashSet<String> cleared_animations_;
InspectorAgentState::Boolean enabled_; InspectorAgentState::Boolean enabled_;
......
This is a testharness.js-based test.
FAIL Animation.id for CSS Animations assert_equals: id for CSS Animation is initially empty expected "" but got "abc"
Harness: the test ran to completion.
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