| OLD | NEW |
| 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 Loading... |
| 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 if (m_content) { | 79 if (m_content) { |
| 78 if (m_content->player()) | 80 if (m_content->player()) { |
| 79 m_content->player()->cancel(); | 81 m_content->player()->cancel(); |
| 82 m_content->player()->setSource(0); |
| 83 } |
| 80 m_content->attach(this); | 84 m_content->attach(this); |
| 81 } | 85 } |
| 82 } | 86 } |
| 83 | 87 |
| 84 AnimationPlayer::~AnimationPlayer() | 88 AnimationPlayer::~AnimationPlayer() |
| 85 { | 89 { |
| 86 #if !ENABLE(OILPAN) | 90 #if !ENABLE(OILPAN) |
| 87 if (m_content) | 91 if (m_content) |
| 88 m_content->detach(); | 92 m_content->detach(); |
| 89 if (m_timeline) | 93 if (m_timeline) |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 m_holdTime = m_playbackRate < 0 ? 0 : sourceEnd(); | 147 m_holdTime = m_playbackRate < 0 ? 0 : sourceEnd(); |
| 144 } | 148 } |
| 145 | 149 |
| 146 double AnimationPlayer::startTime() const | 150 double AnimationPlayer::startTime() const |
| 147 { | 151 { |
| 148 return m_startTime * 1000; | 152 return m_startTime * 1000; |
| 149 } | 153 } |
| 150 | 154 |
| 151 double AnimationPlayer::currentTime() | 155 double AnimationPlayer::currentTime() |
| 152 { | 156 { |
| 153 if (m_currentTimePending) | 157 if (m_currentTimePending || m_idle) |
| 154 return std::numeric_limits<double>::quiet_NaN(); | 158 return std::numeric_limits<double>::quiet_NaN(); |
| 155 return currentTimeInternal() * 1000; | 159 return currentTimeInternal() * 1000; |
| 156 } | 160 } |
| 157 | 161 |
| 158 double AnimationPlayer::currentTimeInternal() | 162 double AnimationPlayer::currentTimeInternal() |
| 159 { | 163 { |
| 160 updateCurrentTimingState(TimingUpdateOnDemand); | 164 updateCurrentTimingState(TimingUpdateOnDemand); |
| 161 if (m_held) | 165 if (m_held) |
| 162 return m_holdTime; | 166 return m_holdTime; |
| 163 return calculateCurrentTime(); | 167 return calculateCurrentTime(); |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 Loading... |
| 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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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) { |
| 599 double inheritedTime = isNull(m_timeline->currentTimeInternal()) ? nullV
alue() : currentTimeInternal(); | 613 double inheritedTime = m_idle || isNull(m_timeline->currentTimeInternal(
)) ? nullValue() : 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 double eventCurrentTime = currentTimeInternal() * 1000; |
| 622 m_pendingFinishedEvent = AnimationPlayerEvent::create(eventType,
eventCurrentTime, timeline()->currentTime()); |
| 608 m_pendingFinishedEvent->setTarget(this); | 623 m_pendingFinishedEvent->setTarget(this); |
| 609 m_pendingFinishedEvent->setCurrentTarget(this); | 624 m_pendingFinishedEvent->setCurrentTarget(this); |
| 610 m_timeline->document()->enqueueAnimationFrameEvent(m_pendingFini
shedEvent); | 625 m_timeline->document()->enqueueAnimationFrameEvent(m_pendingFini
shedEvent); |
| 611 } | 626 } |
| 612 m_finished = true; | 627 m_finished = true; |
| 613 } | 628 } |
| 614 } | 629 } |
| 615 ASSERT(!m_outdated); | 630 ASSERT(!m_outdated); |
| 616 return !m_finished || !finished(); | 631 return !m_finished; |
| 617 } | 632 } |
| 618 | 633 |
| 619 double AnimationPlayer::timeToEffectChange() | 634 double AnimationPlayer::timeToEffectChange() |
| 620 { | 635 { |
| 621 ASSERT(!m_outdated); | 636 ASSERT(!m_outdated); |
| 622 if (m_held || !hasStartTime()) | 637 if (m_held || !hasStartTime()) |
| 623 return std::numeric_limits<double>::infinity(); | 638 return std::numeric_limits<double>::infinity(); |
| 624 if (!m_content) | 639 if (!m_content) |
| 625 return -currentTimeInternal() / m_playbackRate; | 640 return -currentTimeInternal() / m_playbackRate; |
| 626 if (m_playbackRate > 0) | 641 if (m_playbackRate > 0) |
| 627 return m_content->timeToForwardsEffectChange() / m_playbackRate; | 642 return m_content->timeToForwardsEffectChange() / m_playbackRate; |
| 628 return m_content->timeToReverseEffectChange() / -m_playbackRate; | 643 return m_content->timeToReverseEffectChange() / -m_playbackRate; |
| 629 } | 644 } |
| 630 | 645 |
| 631 void AnimationPlayer::cancel() | 646 void AnimationPlayer::cancel() |
| 632 { | 647 { |
| 633 setSource(0); | 648 m_holdTime = currentTimeInternal(); |
| 649 m_held = true; |
| 650 m_idle = true; |
| 651 m_startTime = nullValue(); |
| 652 setCompositorPending(); |
| 634 } | 653 } |
| 635 | 654 |
| 636 #if !ENABLE(OILPAN) | 655 #if !ENABLE(OILPAN) |
| 637 bool AnimationPlayer::canFree() const | 656 bool AnimationPlayer::canFree() const |
| 638 { | 657 { |
| 639 ASSERT(m_content); | 658 ASSERT(m_content); |
| 640 return hasOneRef() && m_content->isAnimation() && m_content->hasOneRef(); | 659 return hasOneRef() && m_content->isAnimation() && m_content->hasOneRef(); |
| 641 } | 660 } |
| 642 #endif | 661 #endif |
| 643 | 662 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 660 | 679 |
| 661 void AnimationPlayer::trace(Visitor* visitor) | 680 void AnimationPlayer::trace(Visitor* visitor) |
| 662 { | 681 { |
| 663 visitor->trace(m_content); | 682 visitor->trace(m_content); |
| 664 visitor->trace(m_timeline); | 683 visitor->trace(m_timeline); |
| 665 visitor->trace(m_pendingFinishedEvent); | 684 visitor->trace(m_pendingFinishedEvent); |
| 666 EventTargetWithInlineData::trace(visitor); | 685 EventTargetWithInlineData::trace(visitor); |
| 667 } | 686 } |
| 668 | 687 |
| 669 } // namespace | 688 } // namespace |
| OLD | NEW |