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

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

Issue 1081753002: Devtools Animations: Support multiple frames in the animation timeline (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: New frame instrumentation on agent Created 5 years, 8 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 | Annotate | Revision Log
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/Animation.h" 9 #include "core/animation/Animation.h"
10 #include "core/animation/AnimationEffect.h" 10 #include "core/animation/AnimationEffect.h"
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 201
202 RefPtr<TypeBuilder::Animation::AnimationNode> animationObject = buildObjectF orAnimation(toAnimation(player.source()), animationType == AnimationType::CSSTra nsition); 202 RefPtr<TypeBuilder::Animation::AnimationNode> animationObject = buildObjectF orAnimation(toAnimation(player.source()), animationType == AnimationType::CSSTra nsition);
203 if (keyframeRule) 203 if (keyframeRule)
204 animationObject->setKeyframesRule(keyframeRule); 204 animationObject->setKeyframesRule(keyframeRule);
205 205
206 RefPtr<TypeBuilder::Animation::AnimationPlayer> playerObject = TypeBuilder:: Animation::AnimationPlayer::create() 206 RefPtr<TypeBuilder::Animation::AnimationPlayer> playerObject = TypeBuilder:: Animation::AnimationPlayer::create()
207 .setId(id) 207 .setId(id)
208 .setPausedState(player.paused()) 208 .setPausedState(player.paused())
209 .setPlayState(player.playState()) 209 .setPlayState(player.playState())
210 .setPlaybackRate(player.playbackRate()) 210 .setPlaybackRate(player.playbackRate())
211 .setStartTime(player.startTime()) 211 .setStartTime(normalizedStartTime(player))
212 .setCurrentTime(player.currentTime()) 212 .setCurrentTime(player.currentTime())
213 .setSource(animationObject.release()) 213 .setSource(animationObject.release())
214 .setType(animationType); 214 .setType(animationType);
215 return playerObject.release(); 215 return playerObject.release();
216 } 216 }
217 217
218 PassRefPtr<TypeBuilder::Array<TypeBuilder::Animation::AnimationPlayer> > Inspect orAnimationAgent::buildArrayForAnimationPlayers(Element& element, const WillBeHe apVector<RefPtrWillBeMember<AnimationPlayer> > players) 218 PassRefPtr<TypeBuilder::Array<TypeBuilder::Animation::AnimationPlayer> > Inspect orAnimationAgent::buildArrayForAnimationPlayers(Element& element, const WillBeHe apVector<RefPtrWillBeMember<AnimationPlayer> > players)
219 { 219 {
220 RefPtr<TypeBuilder::Array<TypeBuilder::Animation::AnimationPlayer> > animati onPlayersArray = TypeBuilder::Array<TypeBuilder::Animation::AnimationPlayer>::cr eate(); 220 RefPtr<TypeBuilder::Array<TypeBuilder::Animation::AnimationPlayer> > animati onPlayersArray = TypeBuilder::Array<TypeBuilder::Animation::AnimationPlayer>::cr eate();
221 for (const auto& it : players) { 221 for (const auto& it : players) {
(...skipping 14 matching lines...) Expand all
236 WillBeHeapVector<RefPtrWillBeMember<AnimationPlayer> > players; 236 WillBeHeapVector<RefPtrWillBeMember<AnimationPlayer> > players;
237 if (!includeSubtreeAnimations) 237 if (!includeSubtreeAnimations)
238 players = ElementAnimation::getAnimationPlayers(*element); 238 players = ElementAnimation::getAnimationPlayers(*element);
239 else 239 else
240 players = element->ownerDocument()->timeline().getAnimationPlayers(); 240 players = element->ownerDocument()->timeline().getAnimationPlayers();
241 animationPlayersArray = buildArrayForAnimationPlayers(*element, players); 241 animationPlayersArray = buildArrayForAnimationPlayers(*element, players);
242 } 242 }
243 243
244 void InspectorAnimationAgent::getPlaybackRate(ErrorString*, double* playbackRate ) 244 void InspectorAnimationAgent::getPlaybackRate(ErrorString*, double* playbackRate )
245 { 245 {
246 *playbackRate = m_pageAgent->inspectedFrame()->document()->timeline().playba ckRate(); 246 *playbackRate = referenceTimeline().playbackRate();
247 } 247 }
248 248
249 void InspectorAnimationAgent::setPlaybackRate(ErrorString*, double playbackRate) 249 void InspectorAnimationAgent::setPlaybackRate(ErrorString*, double playbackRate)
250 { 250 {
251 for (Frame* frame = m_pageAgent->inspectedFrame(); frame; frame = frame->tre e().traverseNext(m_pageAgent->inspectedFrame())) { 251 for (Frame* frame = m_pageAgent->inspectedFrame(); frame; frame = frame->tre e().traverseNext(m_pageAgent->inspectedFrame())) {
252 if (frame->isLocalFrame()) 252 if (frame->isLocalFrame())
253 toLocalFrame(frame)->document()->timeline().setPlaybackRate(playback Rate); 253 toLocalFrame(frame)->document()->timeline().setPlaybackRate(playback Rate);
254 } 254 }
255 } 255 }
256 256
257 void InspectorAnimationAgent::setCurrentTime(ErrorString*, double currentTime) 257 void InspectorAnimationAgent::setCurrentTime(ErrorString*, double currentTime)
258 { 258 {
259 m_pageAgent->inspectedFrame()->document()->timeline().setCurrentTime(current Time); 259 double timeDelta = currentTime - referenceTimeline().currentTime();
260 for (Frame* frame = m_pageAgent->inspectedFrame(); frame; frame = frame->tre e().traverseNext(m_pageAgent->inspectedFrame())) {
261 if (frame->isLocalFrame()) {
262 AnimationTimeline& timeline = toLocalFrame(frame)->document()->timel ine();
263 timeline.setCurrentTime(timeline.currentTime() + timeDelta);
264 }
265 }
260 } 266 }
261 267
262 void InspectorAnimationAgent::setTiming(ErrorString* errorString, const String& playerId, double duration, double delay) 268 void InspectorAnimationAgent::setTiming(ErrorString* errorString, const String& playerId, double duration, double delay)
263 { 269 {
264 AnimationPlayer* player = assertAnimationPlayer(errorString, playerId); 270 AnimationPlayer* player = assertAnimationPlayer(errorString, playerId);
265 if (!player) 271 if (!player)
266 return; 272 return;
267 273
268 AnimationType type = m_idToAnimationType.get(playerId); 274 AnimationType type = m_idToAnimationType.get(playerId);
269 if (type == AnimationType::CSSTransition) { 275 if (type == AnimationType::CSSTransition) {
(...skipping 25 matching lines...) Expand all
295 301
296 void InspectorAnimationAgent::didCreateAnimationPlayer(AnimationPlayer* player) 302 void InspectorAnimationAgent::didCreateAnimationPlayer(AnimationPlayer* player)
297 { 303 {
298 const String& playerId = String::number(player->sequenceNumber()); 304 const String& playerId = String::number(player->sequenceNumber());
299 if (m_idToAnimationPlayer.get(playerId)) 305 if (m_idToAnimationPlayer.get(playerId))
300 return; 306 return;
301 307
302 // Check threshold 308 // Check threshold
303 double latestStartTime = 0; 309 double latestStartTime = 0;
304 for (const auto& p : m_idToAnimationPlayer.values()) 310 for (const auto& p : m_idToAnimationPlayer.values())
305 latestStartTime = max(latestStartTime, p->startTime()); 311 latestStartTime = max(latestStartTime, normalizedStartTime(*p));
306 312
307 bool reset = false; 313 bool reset = false;
308 if (player->startTime() - latestStartTime > 1000) { 314 const double threshold = 1000;
315 if (normalizedStartTime(*player) - latestStartTime > threshold) {
309 reset = true; 316 reset = true;
310 m_idToAnimationPlayer.clear(); 317 m_idToAnimationPlayer.clear();
311 m_idToAnimationType.clear(); 318 m_idToAnimationType.clear();
312 } 319 }
313 320
314 frontend()->animationPlayerCreated(buildObjectForAnimationPlayer(*player), r eset); 321 frontend()->animationPlayerCreated(buildObjectForAnimationPlayer(*player), r eset);
315 } 322 }
316 323
317 void InspectorAnimationAgent::didCancelAnimationPlayer(AnimationPlayer* player) 324 void InspectorAnimationAgent::didCancelAnimationPlayer(AnimationPlayer* player)
318 { 325 {
319 const String& playerId = String::number(player->sequenceNumber()); 326 const String& playerId = String::number(player->sequenceNumber());
320 if (!m_idToAnimationPlayer.get(playerId)) 327 if (!m_idToAnimationPlayer.get(playerId))
321 return; 328 return;
322 frontend()->animationPlayerCanceled(playerId); 329 frontend()->animationPlayerCanceled(playerId);
323 } 330 }
324 331
332 void InspectorAnimationAgent::documentAttachedToFrame(LocalFrame* frame)
333 {
334 ASSERT(frame->document());
335 frame->document()->timeline().setPlaybackRate(referenceTimeline().playbackRa te());
336 }
337
325 AnimationPlayer* InspectorAnimationAgent::assertAnimationPlayer(ErrorString* err orString, const String& id) 338 AnimationPlayer* InspectorAnimationAgent::assertAnimationPlayer(ErrorString* err orString, const String& id)
326 { 339 {
327 AnimationPlayer* player = m_idToAnimationPlayer.get(id); 340 AnimationPlayer* player = m_idToAnimationPlayer.get(id);
328 if (!player) { 341 if (!player) {
329 *errorString = "Could not find animation player with given id"; 342 *errorString = "Could not find animation player with given id";
330 return nullptr; 343 return nullptr;
331 } 344 }
332 return player; 345 return player;
333 } 346 }
334 347
348 AnimationTimeline& InspectorAnimationAgent::referenceTimeline()
349 {
350 return m_pageAgent->inspectedFrame()->document()->timeline();
351 }
352
353 double InspectorAnimationAgent::normalizedStartTime(AnimationPlayer& player)
354 {
355 if (referenceTimeline().playbackRate() == 0)
356 return player.startTime() + referenceTimeline().currentTime() - player.t imeline()->currentTime();
357 return player.startTime() + (player.timeline()->zeroTime() - referenceTimeli ne().zeroTime()) * 1000 * referenceTimeline().playbackRate();
358 }
359
335 DEFINE_TRACE(InspectorAnimationAgent) 360 DEFINE_TRACE(InspectorAnimationAgent)
336 { 361 {
337 #if ENABLE(OILPAN) 362 #if ENABLE(OILPAN)
338 visitor->trace(m_pageAgent); 363 visitor->trace(m_pageAgent);
339 visitor->trace(m_domAgent); 364 visitor->trace(m_domAgent);
340 visitor->trace(m_idToAnimationPlayer); 365 visitor->trace(m_idToAnimationPlayer);
341 visitor->trace(m_idToAnimationType); 366 visitor->trace(m_idToAnimationType);
342 #endif 367 #endif
343 InspectorBaseAgent::trace(visitor); 368 InspectorBaseAgent::trace(visitor);
344 } 369 }
345 370
346 } 371 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698