| 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 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 Loading... |
| 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 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 return; | 356 return; |
| 353 | 357 |
| 354 setCompositorPending(true); | 358 setCompositorPending(true); |
| 355 | 359 |
| 356 double storedCurrentTime = currentTimeInternal(); | 360 double storedCurrentTime = currentTimeInternal(); |
| 357 if (m_content) | 361 if (m_content) |
| 358 m_content->detach(); | 362 m_content->detach(); |
| 359 m_content = newSource; | 363 m_content = newSource; |
| 360 if (newSource) { | 364 if (newSource) { |
| 361 // FIXME: This logic needs to be updated once groups are implemented | 365 // FIXME: This logic needs to be updated once groups are implemented |
| 362 if (newSource->player()) | 366 if (newSource->player()) { |
| 363 newSource->player()->cancel(); | 367 newSource->player()->cancel(); |
| 368 newSource->player()->setSource(0); |
| 369 } |
| 364 newSource->attach(this); | 370 newSource->attach(this); |
| 365 setOutdated(); | 371 setOutdated(); |
| 366 } | 372 } |
| 367 setCurrentTimeInternal(storedCurrentTime, TimingUpdateOnDemand); | 373 setCurrentTimeInternal(storedCurrentTime, TimingUpdateOnDemand); |
| 368 } | 374 } |
| 369 | 375 |
| 370 String AnimationPlayer::playState() | 376 String AnimationPlayer::playState() |
| 371 { | 377 { |
| 372 switch (playStateInternal()) { | 378 switch (playStateInternal()) { |
| 373 case Idle: | 379 case Idle: |
| 374 return "idle"; | 380 return "idle"; |
| 375 case Pending: | 381 case Pending: |
| 376 return "pending"; | 382 return "pending"; |
| 377 case Running: | 383 case Running: |
| 378 return "running"; | 384 return "running"; |
| 379 case Paused: | 385 case Paused: |
| 380 return "paused"; | 386 return "paused"; |
| 381 case Finished: | 387 case Finished: |
| 382 return "finished"; | 388 return "finished"; |
| 383 default: | 389 default: |
| 384 ASSERT_NOT_REACHED(); | 390 ASSERT_NOT_REACHED(); |
| 385 return ""; | 391 return ""; |
| 386 } | 392 } |
| 387 } | 393 } |
| 388 | 394 |
| 389 AnimationPlayer::AnimationPlayState AnimationPlayer::playStateInternal() | 395 AnimationPlayer::AnimationPlayState AnimationPlayer::playStateInternal() |
| 390 { | 396 { |
| 391 // FIXME(shanestephens): Add clause for in-idle-state here. | 397 if (m_idle) |
| 398 return Idle; |
| 392 if (m_currentTimePending || (isNull(m_startTime) && !m_paused && m_playbackR
ate != 0)) | 399 if (m_currentTimePending || (isNull(m_startTime) && !m_paused && m_playbackR
ate != 0)) |
| 393 return Pending; | 400 return Pending; |
| 394 // FIXME(shanestephens): Add idle handling here. | |
| 395 if (m_paused) | 401 if (m_paused) |
| 396 return Paused; | 402 return Paused; |
| 397 if (finished()) | 403 if (finished()) |
| 398 return Finished; | 404 return Finished; |
| 399 return Running; | 405 return Running; |
| 400 } | 406 } |
| 401 | 407 |
| 402 void AnimationPlayer::pause() | 408 void AnimationPlayer::pause() |
| 403 { | 409 { |
| 404 if (m_paused) | 410 if (m_paused) |
| (...skipping 22 matching lines...) Expand all Loading... |
| 427 m_paused = false; | 433 m_paused = false; |
| 428 setCurrentTimeInternal(currentTimeInternal(), TimingUpdateOnDemand); | 434 setCurrentTimeInternal(currentTimeInternal(), TimingUpdateOnDemand); |
| 429 } | 435 } |
| 430 | 436 |
| 431 void AnimationPlayer::play() | 437 void AnimationPlayer::play() |
| 432 { | 438 { |
| 433 if (!playing()) | 439 if (!playing()) |
| 434 m_startTime = nullValue(); | 440 m_startTime = nullValue(); |
| 435 | 441 |
| 436 setCompositorPending(); | 442 setCompositorPending(); |
| 443 uncancel(); |
| 437 unpauseInternal(); | 444 unpauseInternal(); |
| 438 if (!m_content) | 445 if (!m_content) |
| 439 return; | 446 return; |
| 440 double currentTime = this->currentTimeInternal(); | 447 double currentTime = this->currentTimeInternal(); |
| 441 if (m_playbackRate > 0 && (currentTime < 0 || currentTime >= sourceEnd())) | 448 if (m_playbackRate > 0 && (currentTime < 0 || currentTime >= sourceEnd())) |
| 442 setCurrentTimeInternal(0, TimingUpdateOnDemand); | 449 setCurrentTimeInternal(0, TimingUpdateOnDemand); |
| 443 else if (m_playbackRate < 0 && (currentTime <= 0 || currentTime > sourceEnd(
))) | 450 else if (m_playbackRate < 0 && (currentTime <= 0 || currentTime > sourceEnd(
))) |
| 444 setCurrentTimeInternal(sourceEnd(), TimingUpdateOnDemand); | 451 setCurrentTimeInternal(sourceEnd(), TimingUpdateOnDemand); |
| 445 m_finished = false; | 452 m_finished = false; |
| 446 } | 453 } |
| 447 | 454 |
| 448 void AnimationPlayer::reverse() | 455 void AnimationPlayer::reverse() |
| 449 { | 456 { |
| 450 if (!m_playbackRate) { | 457 if (!m_playbackRate) { |
| 451 return; | 458 return; |
| 452 } | 459 } |
| 460 |
| 461 uncancel(); |
| 462 |
| 453 if (m_content) { | 463 if (m_content) { |
| 454 if (m_playbackRate > 0 && currentTimeInternal() > sourceEnd()) { | 464 if (m_playbackRate > 0 && currentTimeInternal() > sourceEnd()) { |
| 455 setCurrentTimeInternal(sourceEnd(), TimingUpdateOnDemand); | 465 setCurrentTimeInternal(sourceEnd(), TimingUpdateOnDemand); |
| 456 ASSERT(finished()); | 466 ASSERT(finished()); |
| 457 } else if (m_playbackRate < 0 && currentTimeInternal() < 0) { | 467 } else if (m_playbackRate < 0 && currentTimeInternal() < 0) { |
| 458 setCurrentTimeInternal(0, TimingUpdateOnDemand); | 468 setCurrentTimeInternal(0, TimingUpdateOnDemand); |
| 459 ASSERT(finished()); | 469 ASSERT(finished()); |
| 460 } | 470 } |
| 461 } | 471 } |
| 462 setPlaybackRate(-m_playbackRate); | 472 setPlaybackRate(-m_playbackRate); |
| 463 unpauseInternal(); | 473 unpauseInternal(); |
| 464 } | 474 } |
| 465 | 475 |
| 466 void AnimationPlayer::finish(ExceptionState& exceptionState) | 476 void AnimationPlayer::finish(ExceptionState& exceptionState) |
| 467 { | 477 { |
| 468 if (!m_playbackRate) { | 478 if (!m_playbackRate) { |
| 469 return; | 479 return; |
| 470 } | 480 } |
| 471 if (m_playbackRate > 0 && sourceEnd() == std::numeric_limits<double>::infini
ty()) { | 481 if (m_playbackRate > 0 && sourceEnd() == std::numeric_limits<double>::infini
ty()) { |
| 472 exceptionState.throwDOMException(InvalidStateError, "AnimationPlayer has
source content whose end time is infinity."); | 482 exceptionState.throwDOMException(InvalidStateError, "AnimationPlayer has
source content whose end time is infinity."); |
| 473 return; | 483 return; |
| 474 } | 484 } |
| 475 if (playing()) { | 485 if (playing()) { |
| 476 setCompositorPending(); | 486 setCompositorPending(); |
| 477 } | 487 } |
| 488 |
| 489 uncancel(); |
| 490 m_startTime = 0; |
| 491 |
| 478 if (m_playbackRate < 0) { | 492 if (m_playbackRate < 0) { |
| 479 setCurrentTimeInternal(0, TimingUpdateOnDemand); | 493 setCurrentTimeInternal(0, TimingUpdateOnDemand); |
| 480 } else { | 494 } else { |
| 481 setCurrentTimeInternal(sourceEnd(), TimingUpdateOnDemand); | 495 setCurrentTimeInternal(sourceEnd(), TimingUpdateOnDemand); |
| 482 } | 496 } |
| 483 ASSERT(finished()); | 497 ASSERT(finished()); |
| 484 } | 498 } |
| 485 | 499 |
| 486 const AtomicString& AnimationPlayer::interfaceName() const | 500 const AtomicString& AnimationPlayer::interfaceName() const |
| 487 { | 501 { |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 589 } | 603 } |
| 590 | 604 |
| 591 bool AnimationPlayer::update(TimingUpdateReason reason) | 605 bool AnimationPlayer::update(TimingUpdateReason reason) |
| 592 { | 606 { |
| 593 if (!m_timeline) | 607 if (!m_timeline) |
| 594 return false; | 608 return false; |
| 595 | 609 |
| 596 updateCurrentTimingState(reason); | 610 updateCurrentTimingState(reason); |
| 597 m_outdated = false; | 611 m_outdated = false; |
| 598 | 612 |
| 599 if (m_content) { | 613 if (m_content && !m_idle) { |
| 600 double inheritedTime = isNull(m_timeline->currentTimeInternal()) ? nullV
alue() : currentTimeInternal(); | 614 double inheritedTime = isNull(m_timeline->currentTimeInternal()) ? nullV
alue() : currentTimeInternal(); |
| 601 m_content->updateInheritedTime(inheritedTime, reason); | 615 m_content->updateInheritedTime(inheritedTime, reason); |
| 602 } | 616 } |
| 603 | 617 |
| 604 if (finished() && !m_finished) { | 618 if ((m_idle || finished()) && !m_finished) { |
| 605 if (reason == TimingUpdateForAnimationFrame && hasStartTime()) { | 619 if (reason == TimingUpdateForAnimationFrame && (m_idle || hasStartTime()
)) { |
| 606 const AtomicString& eventType = EventTypeNames::finish; | 620 const AtomicString& eventType = EventTypeNames::finish; |
| 607 if (executionContext() && hasEventListeners(eventType)) { | 621 if (executionContext() && hasEventListeners(eventType)) { |
| 608 m_pendingFinishedEvent = AnimationPlayerEvent::create(eventType,
currentTime(), timeline()->currentTime()); | 622 m_pendingFinishedEvent = AnimationPlayerEvent::create(eventType,
currentTime(), timeline()->currentTime()); |
| 609 m_pendingFinishedEvent->setTarget(this); | 623 m_pendingFinishedEvent->setTarget(this); |
| 610 m_pendingFinishedEvent->setCurrentTarget(this); | 624 m_pendingFinishedEvent->setCurrentTarget(this); |
| 611 m_timeline->document()->enqueueAnimationFrameEvent(m_pendingFini
shedEvent); | 625 m_timeline->document()->enqueueAnimationFrameEvent(m_pendingFini
shedEvent); |
| 612 } | 626 } |
| 613 m_finished = true; | 627 m_finished = true; |
| 614 } | 628 } |
| 615 } | 629 } |
| 616 ASSERT(!m_outdated); | 630 ASSERT(!m_outdated); |
| 617 return !m_finished || !finished(); | 631 return !m_finished; |
| 618 } | 632 } |
| 619 | 633 |
| 620 double AnimationPlayer::timeToEffectChange() | 634 double AnimationPlayer::timeToEffectChange() |
| 621 { | 635 { |
| 622 ASSERT(!m_outdated); | 636 ASSERT(!m_outdated); |
| 623 if (m_held || !hasStartTime()) | 637 if (m_held || !hasStartTime()) |
| 624 return std::numeric_limits<double>::infinity(); | 638 return std::numeric_limits<double>::infinity(); |
| 625 if (!m_content) | 639 if (!m_content) |
| 626 return -currentTimeInternal() / m_playbackRate; | 640 return -currentTimeInternal() / m_playbackRate; |
| 627 if (m_playbackRate > 0) | 641 if (m_playbackRate > 0) |
| 628 return m_content->timeToForwardsEffectChange() / m_playbackRate; | 642 return m_content->timeToForwardsEffectChange() / m_playbackRate; |
| 629 return m_content->timeToReverseEffectChange() / -m_playbackRate; | 643 return m_content->timeToReverseEffectChange() / -m_playbackRate; |
| 630 } | 644 } |
| 631 | 645 |
| 632 void AnimationPlayer::cancel() | 646 void AnimationPlayer::cancel() |
| 633 { | 647 { |
| 634 setSource(0); | 648 m_idle = true; |
| 649 m_startTime = nullValue(); |
| 650 setCompositorPending(); |
| 635 } | 651 } |
| 636 | 652 |
| 637 #if !ENABLE(OILPAN) | 653 #if !ENABLE(OILPAN) |
| 638 bool AnimationPlayer::canFree() const | 654 bool AnimationPlayer::canFree() const |
| 639 { | 655 { |
| 640 ASSERT(m_content); | 656 ASSERT(m_content); |
| 641 return hasOneRef() && m_content->isAnimation() && m_content->hasOneRef(); | 657 return hasOneRef() && m_content->isAnimation() && m_content->hasOneRef(); |
| 642 } | 658 } |
| 643 #endif | 659 #endif |
| 644 | 660 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 661 | 677 |
| 662 void AnimationPlayer::trace(Visitor* visitor) | 678 void AnimationPlayer::trace(Visitor* visitor) |
| 663 { | 679 { |
| 664 visitor->trace(m_content); | 680 visitor->trace(m_content); |
| 665 visitor->trace(m_timeline); | 681 visitor->trace(m_timeline); |
| 666 visitor->trace(m_pendingFinishedEvent); | 682 visitor->trace(m_pendingFinishedEvent); |
| 667 EventTargetWithInlineData::trace(visitor); | 683 EventTargetWithInlineData::trace(visitor); |
| 668 } | 684 } |
| 669 | 685 |
| 670 } // namespace | 686 } // namespace |
| OLD | NEW |