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

Side by Side Diff: Source/core/animation/AnimationPlayer.cpp

Issue 534193002: Web-Animations: Implement idle state for AnimationPlayers. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 3 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 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 { 45 {
46 static unsigned next = 0; 46 static unsigned next = 0;
47 return ++next; 47 return ++next;
48 } 48 }
49 49
50 } 50 }
51 51
52 PassRefPtrWillBeRawPtr<AnimationPlayer> AnimationPlayer::create(ExecutionContext * executionContext, AnimationTimeline& timeline, AnimationNode* content) 52 PassRefPtrWillBeRawPtr<AnimationPlayer> AnimationPlayer::create(ExecutionContext * executionContext, AnimationTimeline& timeline, AnimationNode* content)
53 { 53 {
54 RefPtrWillBeRawPtr<AnimationPlayer> player = adoptRefWillBeNoop(new Animatio nPlayer(executionContext, timeline, content)); 54 RefPtrWillBeRawPtr<AnimationPlayer> player = adoptRefWillBeNoop(new Animatio nPlayer(executionContext, timeline, content));
55 player->uncancel();
55 timeline.document()->compositorPendingAnimations().add(player.get()); 56 timeline.document()->compositorPendingAnimations().add(player.get());
56 player->suspendIfNeeded(); 57 player->suspendIfNeeded();
57 return player.release(); 58 return player.release();
58 } 59 }
59 60
60 AnimationPlayer::AnimationPlayer(ExecutionContext* executionContext, AnimationTi meline& timeline, AnimationNode* content) 61 AnimationPlayer::AnimationPlayer(ExecutionContext* executionContext, AnimationTi meline& timeline, AnimationNode* content)
61 : ActiveDOMObject(executionContext) 62 : ActiveDOMObject(executionContext)
62 , m_playbackRate(1) 63 , m_playbackRate(1)
63 , m_startTime(nullValue()) 64 , m_startTime(nullValue())
64 , m_holdTime(0) 65 , m_holdTime(0)
65 , m_sequenceNumber(nextSequenceNumber()) 66 , m_sequenceNumber(nextSequenceNumber())
66 , m_content(content) 67 , m_content(content)
67 , m_timeline(&timeline) 68 , m_timeline(&timeline)
68 , m_paused(false) 69 , m_paused(false)
69 , m_held(true) 70 , m_held(true)
70 , m_isPausedForTesting(false) 71 , m_isPausedForTesting(false)
71 , m_outdated(true) 72 , m_outdated(true)
72 , m_finished(false) 73 , m_finished(true)
73 , m_compositorState(nullptr) 74 , m_compositorState(nullptr)
74 , m_compositorPending(true) 75 , m_compositorPending(true)
75 , m_currentTimePending(false) 76 , m_currentTimePending(false)
77 , m_idle(true)
76 { 78 {
77 ScriptWrappable::init(this); 79 ScriptWrappable::init(this);
78 if (m_content) { 80 if (m_content) {
79 if (m_content->player()) 81 if (m_content->player()) {
80 m_content->player()->cancel(); 82 m_content->player()->cancel();
83 m_content->player()->setSource(0);
84 }
81 m_content->attach(this); 85 m_content->attach(this);
82 } 86 }
83 } 87 }
84 88
85 AnimationPlayer::~AnimationPlayer() 89 AnimationPlayer::~AnimationPlayer()
86 { 90 {
87 #if !ENABLE(OILPAN) 91 #if !ENABLE(OILPAN)
88 if (m_content) 92 if (m_content)
89 m_content->detach(); 93 m_content->detach();
90 if (m_timeline) 94 if (m_timeline)
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 m_holdTime = m_playbackRate < 0 ? 0 : sourceEnd(); 148 m_holdTime = m_playbackRate < 0 ? 0 : sourceEnd();
145 } 149 }
146 150
147 double AnimationPlayer::startTime() const 151 double AnimationPlayer::startTime() const
148 { 152 {
149 return m_startTime * 1000; 153 return m_startTime * 1000;
150 } 154 }
151 155
152 double AnimationPlayer::currentTime() 156 double AnimationPlayer::currentTime()
153 { 157 {
154 if (m_currentTimePending) 158 if (m_currentTimePending || m_idle)
155 return std::numeric_limits<double>::quiet_NaN(); 159 return std::numeric_limits<double>::quiet_NaN();
156 return currentTimeInternal() * 1000; 160 return currentTimeInternal() * 1000;
157 } 161 }
158 162
159 double AnimationPlayer::currentTimeInternal() 163 double AnimationPlayer::currentTimeInternal()
160 { 164 {
161 updateCurrentTimingState(TimingUpdateOnDemand); 165 updateCurrentTimingState(TimingUpdateOnDemand);
162 if (m_held) 166 if (m_held)
163 return m_holdTime; 167 return m_holdTime;
164 return calculateCurrentTime(); 168 return calculateCurrentTime();
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 return; 355 return;
352 356
353 setCompositorPending(true); 357 setCompositorPending(true);
354 358
355 double storedCurrentTime = currentTimeInternal(); 359 double storedCurrentTime = currentTimeInternal();
356 if (m_content) 360 if (m_content)
357 m_content->detach(); 361 m_content->detach();
358 m_content = newSource; 362 m_content = newSource;
359 if (newSource) { 363 if (newSource) {
360 // FIXME: This logic needs to be updated once groups are implemented 364 // FIXME: This logic needs to be updated once groups are implemented
361 if (newSource->player()) 365 if (newSource->player()) {
362 newSource->player()->cancel(); 366 newSource->player()->cancel();
367 newSource->player()->setSource(0);
368 }
363 newSource->attach(this); 369 newSource->attach(this);
364 setOutdated(); 370 setOutdated();
365 } 371 }
366 setCurrentTimeInternal(storedCurrentTime, TimingUpdateOnDemand); 372 setCurrentTimeInternal(storedCurrentTime, TimingUpdateOnDemand);
367 } 373 }
368 374
369 String AnimationPlayer::playState() 375 String AnimationPlayer::playState()
370 { 376 {
371 switch (playStateInternal()) { 377 switch (playStateInternal()) {
372 case Idle: 378 case Idle:
373 return "idle"; 379 return "idle";
374 case Pending: 380 case Pending:
375 return "pending"; 381 return "pending";
376 case Running: 382 case Running:
377 return "running"; 383 return "running";
378 case Paused: 384 case Paused:
379 return "paused"; 385 return "paused";
380 case Finished: 386 case Finished:
381 return "finished"; 387 return "finished";
382 default: 388 default:
383 ASSERT_NOT_REACHED(); 389 ASSERT_NOT_REACHED();
384 return ""; 390 return "";
385 } 391 }
386 } 392 }
387 393
388 AnimationPlayer::AnimationPlayState AnimationPlayer::playStateInternal() 394 AnimationPlayer::AnimationPlayState AnimationPlayer::playStateInternal()
389 { 395 {
390 // FIXME(shanestephens): Add clause for in-idle-state here. 396 if (m_idle)
397 return Idle;
391 if (m_currentTimePending || (isNull(m_startTime) && !m_paused && m_playbackR ate != 0)) 398 if (m_currentTimePending || (isNull(m_startTime) && !m_paused && m_playbackR ate != 0))
392 return Pending; 399 return Pending;
393 // FIXME(shanestephens): Add idle handling here.
394 if (m_paused) 400 if (m_paused)
395 return Paused; 401 return Paused;
396 if (finished()) 402 if (finished())
397 return Finished; 403 return Finished;
398 return Running; 404 return Running;
399 } 405 }
400 406
401 void AnimationPlayer::pause() 407 void AnimationPlayer::pause()
402 { 408 {
403 if (m_paused) 409 if (m_paused)
(...skipping 22 matching lines...) Expand all
426 m_paused = false; 432 m_paused = false;
427 setCurrentTimeInternal(currentTimeInternal(), TimingUpdateOnDemand); 433 setCurrentTimeInternal(currentTimeInternal(), TimingUpdateOnDemand);
428 } 434 }
429 435
430 void AnimationPlayer::play() 436 void AnimationPlayer::play()
431 { 437 {
432 if (!playing()) 438 if (!playing())
433 m_startTime = nullValue(); 439 m_startTime = nullValue();
434 440
435 setCompositorPending(); 441 setCompositorPending();
442 uncancel();
436 unpauseInternal(); 443 unpauseInternal();
437 if (!m_content) 444 if (!m_content)
438 return; 445 return;
439 double currentTime = this->currentTimeInternal(); 446 double currentTime = this->currentTimeInternal();
440 if (m_playbackRate > 0 && (currentTime < 0 || currentTime >= sourceEnd())) 447 if (m_playbackRate > 0 && (currentTime < 0 || currentTime >= sourceEnd()))
441 setCurrentTimeInternal(0, TimingUpdateOnDemand); 448 setCurrentTimeInternal(0, TimingUpdateOnDemand);
442 else if (m_playbackRate < 0 && (currentTime <= 0 || currentTime > sourceEnd( ))) 449 else if (m_playbackRate < 0 && (currentTime <= 0 || currentTime > sourceEnd( )))
443 setCurrentTimeInternal(sourceEnd(), TimingUpdateOnDemand); 450 setCurrentTimeInternal(sourceEnd(), TimingUpdateOnDemand);
444 m_finished = false; 451 m_finished = false;
445 } 452 }
446 453
447 void AnimationPlayer::reverse() 454 void AnimationPlayer::reverse()
448 { 455 {
449 if (!m_playbackRate) { 456 if (!m_playbackRate) {
450 return; 457 return;
451 } 458 }
459
460 uncancel();
461
452 if (m_content) { 462 if (m_content) {
453 if (m_playbackRate > 0 && currentTimeInternal() > sourceEnd()) { 463 if (m_playbackRate > 0 && currentTimeInternal() > sourceEnd()) {
454 setCurrentTimeInternal(sourceEnd(), TimingUpdateOnDemand); 464 setCurrentTimeInternal(sourceEnd(), TimingUpdateOnDemand);
455 ASSERT(finished()); 465 ASSERT(finished());
456 } else if (m_playbackRate < 0 && currentTimeInternal() < 0) { 466 } else if (m_playbackRate < 0 && currentTimeInternal() < 0) {
457 setCurrentTimeInternal(0, TimingUpdateOnDemand); 467 setCurrentTimeInternal(0, TimingUpdateOnDemand);
458 ASSERT(finished()); 468 ASSERT(finished());
459 } 469 }
460 } 470 }
461 setPlaybackRate(-m_playbackRate); 471 setPlaybackRate(-m_playbackRate);
462 unpauseInternal(); 472 unpauseInternal();
463 } 473 }
464 474
465 void AnimationPlayer::finish(ExceptionState& exceptionState) 475 void AnimationPlayer::finish(ExceptionState& exceptionState)
466 { 476 {
467 if (!m_playbackRate) { 477 if (!m_playbackRate) {
468 return; 478 return;
469 } 479 }
470 if (m_playbackRate > 0 && sourceEnd() == std::numeric_limits<double>::infini ty()) { 480 if (m_playbackRate > 0 && sourceEnd() == std::numeric_limits<double>::infini ty()) {
471 exceptionState.throwDOMException(InvalidStateError, "AnimationPlayer has source content whose end time is infinity."); 481 exceptionState.throwDOMException(InvalidStateError, "AnimationPlayer has source content whose end time is infinity.");
472 return; 482 return;
473 } 483 }
474 if (playing()) { 484 if (playing()) {
475 setCompositorPending(); 485 setCompositorPending();
476 } 486 }
487
488 uncancel();
489 m_startTime = 0;
490
477 if (m_playbackRate < 0) { 491 if (m_playbackRate < 0) {
478 setCurrentTimeInternal(0, TimingUpdateOnDemand); 492 setCurrentTimeInternal(0, TimingUpdateOnDemand);
479 } else { 493 } else {
480 setCurrentTimeInternal(sourceEnd(), TimingUpdateOnDemand); 494 setCurrentTimeInternal(sourceEnd(), TimingUpdateOnDemand);
481 } 495 }
482 ASSERT(finished()); 496 ASSERT(finished());
483 } 497 }
484 498
485 const AtomicString& AnimationPlayer::interfaceName() const 499 const AtomicString& AnimationPlayer::interfaceName() const
486 { 500 {
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 } 602 }
589 603
590 bool AnimationPlayer::update(TimingUpdateReason reason) 604 bool AnimationPlayer::update(TimingUpdateReason reason)
591 { 605 {
592 if (!m_timeline) 606 if (!m_timeline)
593 return false; 607 return false;
594 608
595 updateCurrentTimingState(reason); 609 updateCurrentTimingState(reason);
596 m_outdated = false; 610 m_outdated = false;
597 611
598 if (m_content) { 612 if (m_content && !m_idle) {
599 double inheritedTime = isNull(m_timeline->currentTimeInternal()) ? nullV alue() : currentTimeInternal(); 613 double inheritedTime = isNull(m_timeline->currentTimeInternal()) ? nullV alue() : currentTimeInternal();
600 m_content->updateInheritedTime(inheritedTime, reason); 614 m_content->updateInheritedTime(inheritedTime, reason);
601 } 615 }
602 616
603 if (finished() && !m_finished) { 617 if ((m_idle || finished()) && !m_finished) {
604 if (reason == TimingUpdateForAnimationFrame && hasStartTime()) { 618 if (reason == TimingUpdateForAnimationFrame && (m_idle || hasStartTime() )) {
605 const AtomicString& eventType = EventTypeNames::finish; 619 const AtomicString& eventType = EventTypeNames::finish;
606 if (executionContext() && hasEventListeners(eventType)) { 620 if (executionContext() && hasEventListeners(eventType)) {
607 m_pendingFinishedEvent = AnimationPlayerEvent::create(eventType, currentTime(), timeline()->currentTime()); 621 m_pendingFinishedEvent = AnimationPlayerEvent::create(eventType, currentTime(), timeline()->currentTime());
608 m_pendingFinishedEvent->setTarget(this); 622 m_pendingFinishedEvent->setTarget(this);
609 m_pendingFinishedEvent->setCurrentTarget(this); 623 m_pendingFinishedEvent->setCurrentTarget(this);
610 m_timeline->document()->enqueueAnimationFrameEvent(m_pendingFini shedEvent); 624 m_timeline->document()->enqueueAnimationFrameEvent(m_pendingFini shedEvent);
611 } 625 }
612 m_finished = true; 626 m_finished = true;
613 } 627 }
614 } 628 }
615 ASSERT(!m_outdated); 629 ASSERT(!m_outdated);
616 return !m_finished || !finished(); 630 return !m_finished;
617 } 631 }
618 632
619 double AnimationPlayer::timeToEffectChange() 633 double AnimationPlayer::timeToEffectChange()
620 { 634 {
621 ASSERT(!m_outdated); 635 ASSERT(!m_outdated);
622 if (m_held || !hasStartTime()) 636 if (m_held || !hasStartTime())
623 return std::numeric_limits<double>::infinity(); 637 return std::numeric_limits<double>::infinity();
624 if (!m_content) 638 if (!m_content)
625 return -currentTimeInternal() / m_playbackRate; 639 return -currentTimeInternal() / m_playbackRate;
626 if (m_playbackRate > 0) 640 if (m_playbackRate > 0)
627 return m_content->timeToForwardsEffectChange() / m_playbackRate; 641 return m_content->timeToForwardsEffectChange() / m_playbackRate;
628 return m_content->timeToReverseEffectChange() / -m_playbackRate; 642 return m_content->timeToReverseEffectChange() / -m_playbackRate;
629 } 643 }
630 644
631 void AnimationPlayer::cancel() 645 void AnimationPlayer::cancel()
632 { 646 {
633 setSource(0); 647 m_idle = true;
648 m_startTime = nullValue();
649 setCompositorPending();
634 } 650 }
635 651
636 #if !ENABLE(OILPAN) 652 #if !ENABLE(OILPAN)
637 bool AnimationPlayer::canFree() const 653 bool AnimationPlayer::canFree() const
638 { 654 {
639 ASSERT(m_content); 655 ASSERT(m_content);
640 return hasOneRef() && m_content->isAnimation() && m_content->hasOneRef(); 656 return hasOneRef() && m_content->isAnimation() && m_content->hasOneRef();
641 } 657 }
642 #endif 658 #endif
643 659
(...skipping 16 matching lines...) Expand all
660 676
661 void AnimationPlayer::trace(Visitor* visitor) 677 void AnimationPlayer::trace(Visitor* visitor)
662 { 678 {
663 visitor->trace(m_content); 679 visitor->trace(m_content);
664 visitor->trace(m_timeline); 680 visitor->trace(m_timeline);
665 visitor->trace(m_pendingFinishedEvent); 681 visitor->trace(m_pendingFinishedEvent);
666 EventTargetWithInlineData::trace(visitor); 682 EventTargetWithInlineData::trace(visitor);
667 } 683 }
668 684
669 } // namespace 685 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698