Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(156)

Side by Side Diff: Source/core/inspector/InspectorAnimationAgent.cpp

Issue 664993002: Devtools Animations: Display keyframes for CSS Animations in inspector (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 6
7 #include "core/inspector/InspectorAnimationAgent.h" 7 #include "core/inspector/InspectorAnimationAgent.h"
8 8
9 #include "core/animation/AnimationNode.h" 9 #include "core/animation/AnimationNode.h"
10 #include "core/animation/AnimationPlayer.h" 10 #include "core/animation/AnimationPlayer.h"
11 #include "core/animation/ElementAnimation.h" 11 #include "core/animation/ElementAnimation.h"
12 #include "core/css/CSSKeyframeRule.h"
13 #include "core/css/CSSKeyframesRule.h"
12 #include "core/inspector/InspectorDOMAgent.h" 14 #include "core/inspector/InspectorDOMAgent.h"
15 #include "core/inspector/InspectorStyleSheet.h"
13 16
14 namespace blink { 17 namespace blink {
15 18
16 InspectorAnimationAgent::InspectorAnimationAgent(InspectorDOMAgent* domAgent) 19 InspectorAnimationAgent::InspectorAnimationAgent(InspectorDOMAgent* domAgent)
17 : InspectorBaseAgent<InspectorAnimationAgent>("Animation") 20 : InspectorBaseAgent<InspectorAnimationAgent>("Animation")
18 , m_domAgent(domAgent) 21 , m_domAgent(domAgent)
19 , m_frontend(0) 22 , m_frontend(0)
20 { 23 {
21 } 24 }
22 25
(...skipping 16 matching lines...) Expand all
39 { 42 {
40 animationPlayersArray = TypeBuilder::Array<TypeBuilder::Animation::Animation Player>::create(); 43 animationPlayersArray = TypeBuilder::Array<TypeBuilder::Animation::Animation Player>::create();
41 Element* element = m_domAgent->assertElement(errorString, nodeId); 44 Element* element = m_domAgent->assertElement(errorString, nodeId);
42 if (!element) 45 if (!element)
43 return; 46 return;
44 m_idToAnimationPlayer.clear(); 47 m_idToAnimationPlayer.clear();
45 WillBeHeapVector<RefPtrWillBeMember<AnimationPlayer> > players = ElementAnim ation::getAnimationPlayers(*element); 48 WillBeHeapVector<RefPtrWillBeMember<AnimationPlayer> > players = ElementAnim ation::getAnimationPlayers(*element);
46 for (WillBeHeapVector<RefPtrWillBeMember<AnimationPlayer> >::iterator it = p layers.begin(); it != players.end(); ++it) { 49 for (WillBeHeapVector<RefPtrWillBeMember<AnimationPlayer> >::iterator it = p layers.begin(); it != players.end(); ++it) {
47 AnimationPlayer& player = *(it->get()); 50 AnimationPlayer& player = *(it->get());
48 m_idToAnimationPlayer.set(playerId(player), &player); 51 m_idToAnimationPlayer.set(playerId(player), &player);
49 RefPtr<TypeBuilder::Animation::AnimationPlayer> animationPlayerObject = buildObjectForAnimationPlayer(player); 52 RefPtr<TypeBuilder::Animation::AnimationPlayer> animationPlayerObject;
53 // FIXME: Add support for web animations
54 if (element->activeAnimations()->cssAnimations().getAnimationNameForInsp ector(player)) {
55 RefPtr<TypeBuilder::Animation::KeyframesRule> keyframeRule = getObje ctForStyleRuleKeyframes(*element, player);
56 animationPlayerObject = buildObjectForAnimationPlayer(player, keyfra meRule);
pfeldman 2014/10/23 06:37:00 keyframeRule.release()
samli 2014/10/24 05:06:19 Done.
57 } else {
58 animationPlayerObject = buildObjectForAnimationPlayer(player);
59 }
50 animationPlayersArray->addItem(animationPlayerObject); 60 animationPlayersArray->addItem(animationPlayerObject);
51 } 61 }
52 } 62 }
53 63
54 void InspectorAnimationAgent::pauseAnimationPlayer(ErrorString* errorString, con st String& id, RefPtr<TypeBuilder::Animation::AnimationPlayer>& animationPlayer) 64 void InspectorAnimationAgent::pauseAnimationPlayer(ErrorString* errorString, con st String& id, RefPtr<TypeBuilder::Animation::AnimationPlayer>& animationPlayer)
55 { 65 {
56 AnimationPlayer* player = assertAnimationPlayer(errorString, id); 66 AnimationPlayer* player = assertAnimationPlayer(errorString, id);
57 if (!player) 67 if (!player)
58 return; 68 return;
59 player->pause(); 69 player->pause();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 return player; 107 return player;
98 } 108 }
99 109
100 String InspectorAnimationAgent::playerId(AnimationPlayer& player) 110 String InspectorAnimationAgent::playerId(AnimationPlayer& player)
101 { 111 {
102 return String::number(player.sequenceNumber()); 112 return String::number(player.sequenceNumber());
103 } 113 }
104 114
105 PassRefPtr<TypeBuilder::Animation::AnimationPlayer> InspectorAnimationAgent::bui ldObjectForAnimationPlayer(AnimationPlayer& animationPlayer) 115 PassRefPtr<TypeBuilder::Animation::AnimationPlayer> InspectorAnimationAgent::bui ldObjectForAnimationPlayer(AnimationPlayer& animationPlayer)
106 { 116 {
117 return buildObjectForAnimationPlayer(animationPlayer, nullptr);
pfeldman 2014/10/23 06:37:00 inline and simplify code above?
samli 2014/10/24 05:06:19 Done.
118 }
119
120 PassRefPtr<TypeBuilder::Animation::AnimationPlayer> InspectorAnimationAgent::bui ldObjectForAnimationPlayer(AnimationPlayer& animationPlayer, PassRefPtr<TypeBuil der::Animation::KeyframesRule> keyframeRule)
121 {
122 RefPtr<TypeBuilder::Animation::AnimationNode> animationObject = buildObjectF orAnimationNode(animationPlayer.source());
123 if (keyframeRule)
124 animationObject->setKeyframesRule(keyframeRule);
125
107 RefPtr<TypeBuilder::Animation::AnimationPlayer> playerObject = TypeBuilder:: Animation::AnimationPlayer::create() 126 RefPtr<TypeBuilder::Animation::AnimationPlayer> playerObject = TypeBuilder:: Animation::AnimationPlayer::create()
108 .setId(playerId(animationPlayer)) 127 .setId(playerId(animationPlayer))
109 .setPausedState(animationPlayer.paused()) 128 .setPausedState(animationPlayer.paused())
110 .setPlayState(animationPlayer.playState()) 129 .setPlayState(animationPlayer.playState())
111 .setPlaybackRate(animationPlayer.playbackRate()) 130 .setPlaybackRate(animationPlayer.playbackRate())
112 .setStartTime(animationPlayer.startTime()) 131 .setStartTime(animationPlayer.startTime())
113 .setCurrentTime(animationPlayer.currentTime()) 132 .setCurrentTime(animationPlayer.currentTime())
114 .setSource(buildObjectForAnimationNode(*(animationPlayer.source()))); 133 .setSource(animationObject.release());
115 return playerObject.release(); 134 return playerObject.release();
116 } 135 }
117 136
118 PassRefPtr<TypeBuilder::Animation::AnimationNode> InspectorAnimationAgent::build ObjectForAnimationNode(AnimationNode& animationNode) 137 PassRefPtr<TypeBuilder::Animation::AnimationNode> InspectorAnimationAgent::build ObjectForAnimationNode(AnimationNode* animationNode)
119 { 138 {
120 RefPtr<TypeBuilder::Animation::AnimationNode> animationObject = TypeBuilder: :Animation::AnimationNode::create() 139 RefPtr<TypeBuilder::Animation::AnimationNode> animationObject = TypeBuilder: :Animation::AnimationNode::create()
121 .setStartDelay(animationNode.specifiedTiming().startDelay) 140 .setStartDelay(animationNode->specifiedTiming().startDelay)
122 .setPlaybackRate(animationNode.specifiedTiming().playbackRate) 141 .setPlaybackRate(animationNode->specifiedTiming().playbackRate)
123 .setIterationStart(animationNode.specifiedTiming().iterationStart) 142 .setIterationStart(animationNode->specifiedTiming().iterationStart)
124 .setIterationCount(animationNode.specifiedTiming().iterationCount) 143 .setIterationCount(animationNode->specifiedTiming().iterationCount)
125 .setDuration(animationNode.duration()) 144 .setDuration(animationNode->duration())
126 .setDirection(animationNode.specifiedTiming().direction) 145 .setDirection(animationNode->specifiedTiming().direction)
127 .setFillMode(animationNode.specifiedTiming().fillMode) 146 .setFillMode(animationNode->specifiedTiming().fillMode)
128 .setTimeFraction(animationNode.timeFraction()) 147 .setTimeFraction(animationNode->timeFraction())
129 .setName(animationNode.name()); 148 .setName(animationNode->name());
130 return animationObject.release(); 149 return animationObject.release();
131 } 150 }
132 151
152 PassRefPtr<TypeBuilder::Animation::KeyframesRule> InspectorAnimationAgent::getOb jectForStyleRuleKeyframes(const Element& element, const AnimationPlayer& player)
153 {
154 StyleResolver& styleResolver = element.ownerDocument()->ensureStyleResolver( );
155 // FIXME: Add support for web anim
156 CSSAnimations& cssAnimations = element.activeAnimations()->cssAnimations();
157 const AtomicString* animationName = cssAnimations.getAnimationNameForInspect or(player);
158 ASSERT(animationName);
159 const StyleRuleKeyframes* keyframes = cssAnimations.matchScopedKeyframesRule (&styleResolver, &element, animationName->impl());
160
161 return buildObjectForStyleRuleKeyframes(keyframes);
162 }
163
164 PassRefPtr<TypeBuilder::Animation::KeyframesRule> InspectorAnimationAgent::build ObjectForStyleRuleKeyframes(const StyleRuleKeyframes* keyframesRule)
165 {
166 RefPtr<TypeBuilder::Array<TypeBuilder::Animation::KeyframeStyle> > keyframes = TypeBuilder::Array<TypeBuilder::Animation::KeyframeStyle>::create();
167 const WillBeHeapVector<RefPtrWillBeMember<StyleKeyframe> >& styleKeyframes = keyframesRule->keyframes();
168 for (const auto& styleKeyframe : styleKeyframes)
169 keyframes->addItem(buildObjectForStyleKeyframe(styleKeyframe.get()));
170
171 RefPtr<TypeBuilder::Animation::KeyframesRule> keyframesObject = TypeBuilder: :Animation::KeyframesRule::create()
172 .setKeyframes(keyframes);
173 keyframesObject->setName(keyframesRule->name());
174 return keyframesObject.release();
175 }
176
177 PassRefPtr<TypeBuilder::Animation::KeyframeStyle> InspectorAnimationAgent::build ObjectForStyleKeyframe(StyleKeyframe* keyframe)
178 {
179 RefPtrWillBeRawPtr<InspectorStyle> inspectorStyle = InspectorStyle::create(I nspectorCSSId(), keyframe->mutableProperties().ensureCSSStyleDeclaration(), 0);
180 RefPtr<TypeBuilder::Animation::KeyframeStyle> keyframeObject = TypeBuilder:: Animation::KeyframeStyle::create()
181 .setOffset(keyframe->keyText())
182 .setStyle(inspectorStyle->buildObjectForStyle());
183 return keyframeObject.release();
184 }
185
133 void InspectorAnimationAgent::trace(Visitor* visitor) 186 void InspectorAnimationAgent::trace(Visitor* visitor)
134 { 187 {
135 #if ENABLE(OILPAN) 188 #if ENABLE(OILPAN)
136 visitor->trace(m_idToAnimationPlayer); 189 visitor->trace(m_idToAnimationPlayer);
137 visitor->trace(m_domAgent); 190 visitor->trace(m_domAgent);
138 #endif 191 #endif
139 InspectorBaseAgent::trace(visitor); 192 InspectorBaseAgent::trace(visitor);
140 } 193 }
141 194
142 } 195 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698