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 18 matching lines...) Expand all Loading... |
29 */ | 29 */ |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 #include "core/animation/AnimationPlayer.h" | 32 #include "core/animation/AnimationPlayer.h" |
33 | 33 |
34 #include "core/animation/Animation.h" | 34 #include "core/animation/Animation.h" |
35 #include "core/animation/AnimationTimeline.h" | 35 #include "core/animation/AnimationTimeline.h" |
36 #include "core/dom/Document.h" | 36 #include "core/dom/Document.h" |
37 #include "core/events/AnimationPlayerEvent.h" | 37 #include "core/events/AnimationPlayerEvent.h" |
38 #include "core/frame/UseCounter.h" | 38 #include "core/frame/UseCounter.h" |
| 39 #include "platform/TraceEvent.h" |
39 | 40 |
40 namespace blink { | 41 namespace blink { |
41 | 42 |
42 namespace { | 43 namespace { |
43 | 44 |
44 static unsigned nextSequenceNumber() | 45 static unsigned nextSequenceNumber() |
45 { | 46 { |
46 static unsigned next = 0; | 47 static unsigned next = 0; |
47 return ++next; | 48 return ++next; |
48 } | 49 } |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 outdated = true; | 119 outdated = true; |
119 m_holdTime = newCurrentTime; | 120 m_holdTime = newCurrentTime; |
120 if (m_paused || !m_playbackRate) { | 121 if (m_paused || !m_playbackRate) { |
121 m_startTime = nullValue(); | 122 m_startTime = nullValue(); |
122 } else if (isLimited && std::isnan(m_startTime) && reason == TimingUpdat
eForAnimationFrame) { | 123 } else if (isLimited && std::isnan(m_startTime) && reason == TimingUpdat
eForAnimationFrame) { |
123 m_startTime = calculateStartTime(newCurrentTime); | 124 m_startTime = calculateStartTime(newCurrentTime); |
124 } | 125 } |
125 } else { | 126 } else { |
126 m_holdTime = nullValue(); | 127 m_holdTime = nullValue(); |
127 m_startTime = calculateStartTime(newCurrentTime); | 128 m_startTime = calculateStartTime(newCurrentTime); |
128 m_finished = false; | 129 setFinished(false); |
129 outdated = true; | 130 outdated = true; |
130 } | 131 } |
131 | 132 |
132 if (outdated) { | 133 if (outdated) { |
133 setOutdated(); | 134 setOutdated(); |
134 } | 135 } |
135 } | 136 } |
136 | 137 |
137 // Update timing to reflect updated animation clock due to tick | 138 // Update timing to reflect updated animation clock due to tick |
138 void AnimationPlayer::updateCurrentTimingState(TimingUpdateReason reason) | 139 void AnimationPlayer::updateCurrentTimingState(TimingUpdateReason reason) |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 setCompositorPending(); | 450 setCompositorPending(); |
450 uncancel(); | 451 uncancel(); |
451 unpauseInternal(); | 452 unpauseInternal(); |
452 if (!m_content) | 453 if (!m_content) |
453 return; | 454 return; |
454 double currentTime = this->currentTimeInternal(); | 455 double currentTime = this->currentTimeInternal(); |
455 if (m_playbackRate > 0 && (currentTime < 0 || currentTime >= sourceEnd())) | 456 if (m_playbackRate > 0 && (currentTime < 0 || currentTime >= sourceEnd())) |
456 setCurrentTimeInternal(0, TimingUpdateOnDemand); | 457 setCurrentTimeInternal(0, TimingUpdateOnDemand); |
457 else if (m_playbackRate < 0 && (currentTime <= 0 || currentTime > sourceEnd(
))) | 458 else if (m_playbackRate < 0 && (currentTime <= 0 || currentTime > sourceEnd(
))) |
458 setCurrentTimeInternal(sourceEnd(), TimingUpdateOnDemand); | 459 setCurrentTimeInternal(sourceEnd(), TimingUpdateOnDemand); |
459 m_finished = false; | 460 setFinished(false); |
460 } | 461 } |
461 | 462 |
462 void AnimationPlayer::reverse() | 463 void AnimationPlayer::reverse() |
463 { | 464 { |
464 if (!m_playbackRate) { | 465 if (!m_playbackRate) { |
465 return; | 466 return; |
466 } | 467 } |
467 | 468 |
468 uncancel(); | 469 uncancel(); |
469 setPlaybackRate(-m_playbackRate); | 470 setPlaybackRate(-m_playbackRate); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 return ActiveDOMObject::executionContext(); | 506 return ActiveDOMObject::executionContext(); |
506 } | 507 } |
507 | 508 |
508 bool AnimationPlayer::hasPendingActivity() const | 509 bool AnimationPlayer::hasPendingActivity() const |
509 { | 510 { |
510 return m_pendingFinishedEvent || (!m_finished && hasEventListeners(EventType
Names::finish)); | 511 return m_pendingFinishedEvent || (!m_finished && hasEventListeners(EventType
Names::finish)); |
511 } | 512 } |
512 | 513 |
513 void AnimationPlayer::stop() | 514 void AnimationPlayer::stop() |
514 { | 515 { |
515 m_finished = true; | 516 setFinished(true); |
516 m_pendingFinishedEvent = nullptr; | 517 m_pendingFinishedEvent = nullptr; |
517 } | 518 } |
518 | 519 |
519 bool AnimationPlayer::dispatchEvent(PassRefPtrWillBeRawPtr<Event> event) | 520 bool AnimationPlayer::dispatchEvent(PassRefPtrWillBeRawPtr<Event> event) |
520 { | 521 { |
521 if (m_pendingFinishedEvent == event) | 522 if (m_pendingFinishedEvent == event) |
522 m_pendingFinishedEvent = nullptr; | 523 m_pendingFinishedEvent = nullptr; |
523 return EventTargetWithInlineData::dispatchEvent(event); | 524 return EventTargetWithInlineData::dispatchEvent(event); |
524 } | 525 } |
525 | 526 |
526 void AnimationPlayer::setPlaybackRate(double playbackRate) | 527 void AnimationPlayer::setPlaybackRate(double playbackRate) |
527 { | 528 { |
528 if (!std::isfinite(playbackRate)) | 529 if (!std::isfinite(playbackRate)) |
529 return; | 530 return; |
530 if (playbackRate == m_playbackRate) | 531 if (playbackRate == m_playbackRate) |
531 return; | 532 return; |
532 | 533 |
533 setCompositorPending(); | 534 setCompositorPending(); |
534 if (!finished() && !paused() && hasStartTime()) | 535 if (!finished() && !paused() && hasStartTime()) |
535 m_currentTimePending = true; | 536 m_currentTimePending = true; |
536 | 537 |
537 double storedCurrentTime = currentTimeInternal(); | 538 double storedCurrentTime = currentTimeInternal(); |
538 if ((m_playbackRate < 0 && playbackRate >= 0) || (m_playbackRate > 0 && play
backRate <= 0)) | 539 if ((m_playbackRate < 0 && playbackRate >= 0) || (m_playbackRate > 0 && play
backRate <= 0)) |
539 m_finished = false; | 540 setFinished(false); |
540 | 541 |
541 m_playbackRate = playbackRate; | 542 m_playbackRate = playbackRate; |
542 m_startTime = std::numeric_limits<double>::quiet_NaN(); | 543 m_startTime = std::numeric_limits<double>::quiet_NaN(); |
543 setCurrentTimeInternal(storedCurrentTime, TimingUpdateOnDemand); | 544 setCurrentTimeInternal(storedCurrentTime, TimingUpdateOnDemand); |
544 } | 545 } |
545 | 546 |
546 void AnimationPlayer::setOutdated() | 547 void AnimationPlayer::setOutdated() |
547 { | 548 { |
548 m_outdated = true; | 549 m_outdated = true; |
549 if (m_timeline) | 550 if (m_timeline) |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
616 if ((m_idle || finished()) && !m_finished) { | 617 if ((m_idle || finished()) && !m_finished) { |
617 if (reason == TimingUpdateForAnimationFrame && (m_idle || hasStartTime()
)) { | 618 if (reason == TimingUpdateForAnimationFrame && (m_idle || hasStartTime()
)) { |
618 const AtomicString& eventType = EventTypeNames::finish; | 619 const AtomicString& eventType = EventTypeNames::finish; |
619 if (executionContext() && hasEventListeners(eventType)) { | 620 if (executionContext() && hasEventListeners(eventType)) { |
620 double eventCurrentTime = currentTimeInternal() * 1000; | 621 double eventCurrentTime = currentTimeInternal() * 1000; |
621 m_pendingFinishedEvent = AnimationPlayerEvent::create(eventType,
eventCurrentTime, timeline()->currentTime()); | 622 m_pendingFinishedEvent = AnimationPlayerEvent::create(eventType,
eventCurrentTime, timeline()->currentTime()); |
622 m_pendingFinishedEvent->setTarget(this); | 623 m_pendingFinishedEvent->setTarget(this); |
623 m_pendingFinishedEvent->setCurrentTarget(this); | 624 m_pendingFinishedEvent->setCurrentTarget(this); |
624 m_timeline->document()->enqueueAnimationFrameEvent(m_pendingFini
shedEvent); | 625 m_timeline->document()->enqueueAnimationFrameEvent(m_pendingFini
shedEvent); |
625 } | 626 } |
626 m_finished = true; | 627 setFinished(true); |
627 } | 628 } |
628 } | 629 } |
629 ASSERT(!m_outdated); | 630 ASSERT(!m_outdated); |
630 return !m_finished; | 631 return !m_finished; |
631 } | 632 } |
632 | 633 |
633 double AnimationPlayer::timeToEffectChange() | 634 double AnimationPlayer::timeToEffectChange() |
634 { | 635 { |
635 ASSERT(!m_outdated); | 636 ASSERT(!m_outdated); |
636 if (m_held || !hasStartTime()) | 637 if (m_held || !hasStartTime()) |
637 return std::numeric_limits<double>::infinity(); | 638 return std::numeric_limits<double>::infinity(); |
638 if (!m_content) | 639 if (!m_content) |
639 return -currentTimeInternal() / m_playbackRate; | 640 return -currentTimeInternal() / m_playbackRate; |
640 if (m_playbackRate > 0) | 641 if (m_playbackRate > 0) |
641 return m_content->timeToForwardsEffectChange() / m_playbackRate; | 642 return m_content->timeToForwardsEffectChange() / m_playbackRate; |
642 return m_content->timeToReverseEffectChange() / -m_playbackRate; | 643 return m_content->timeToReverseEffectChange() / -m_playbackRate; |
643 } | 644 } |
644 | 645 |
| 646 void AnimationPlayer::setFinished(bool finished) |
| 647 { |
| 648 if (m_finished && !finished) { |
| 649 if (m_content) { |
| 650 TRACE_EVENT_ASYNC_BEGIN1("blink", "Animation", this, "Name", TRACE_S
TR_COPY(m_content->name().utf8().data())); |
| 651 } else { |
| 652 TRACE_EVENT_ASYNC_BEGIN0("blink", "Animation", this); |
| 653 } |
| 654 } |
| 655 if (!m_finished && finished) { |
| 656 TRACE_EVENT_ASYNC_END0("blink", "Animation", this); |
| 657 } |
| 658 m_finished = finished; |
| 659 } |
| 660 |
645 void AnimationPlayer::cancel() | 661 void AnimationPlayer::cancel() |
646 { | 662 { |
| 663 if (m_idle) |
| 664 return; |
| 665 |
647 m_holdTime = currentTimeInternal(); | 666 m_holdTime = currentTimeInternal(); |
648 m_held = true; | 667 m_held = true; |
649 m_idle = true; | 668 m_idle = true; |
650 m_startTime = nullValue(); | 669 m_startTime = nullValue(); |
651 m_currentTimePending = false; | 670 m_currentTimePending = false; |
652 setCompositorPending(); | 671 setCompositorPending(); |
653 } | 672 } |
654 | 673 |
| 674 void AnimationPlayer::uncancel() |
| 675 { |
| 676 if (!m_idle) |
| 677 return; |
| 678 |
| 679 m_idle = false; |
| 680 m_held = true; |
| 681 m_holdTime = 0; |
| 682 setFinished(false); |
| 683 } |
| 684 |
| 685 |
655 #if !ENABLE(OILPAN) | 686 #if !ENABLE(OILPAN) |
656 bool AnimationPlayer::canFree() const | 687 bool AnimationPlayer::canFree() const |
657 { | 688 { |
658 ASSERT(m_content); | 689 ASSERT(m_content); |
659 return hasOneRef() && m_content->isAnimation() && m_content->hasOneRef(); | 690 return hasOneRef() && m_content->isAnimation() && m_content->hasOneRef(); |
660 } | 691 } |
661 #endif | 692 #endif |
662 | 693 |
663 bool AnimationPlayer::addEventListener(const AtomicString& eventType, PassRefPtr
<EventListener> listener, bool useCapture) | 694 bool AnimationPlayer::addEventListener(const AtomicString& eventType, PassRefPtr
<EventListener> listener, bool useCapture) |
664 { | 695 { |
(...skipping 14 matching lines...) Expand all Loading... |
679 | 710 |
680 void AnimationPlayer::trace(Visitor* visitor) | 711 void AnimationPlayer::trace(Visitor* visitor) |
681 { | 712 { |
682 visitor->trace(m_content); | 713 visitor->trace(m_content); |
683 visitor->trace(m_timeline); | 714 visitor->trace(m_timeline); |
684 visitor->trace(m_pendingFinishedEvent); | 715 visitor->trace(m_pendingFinishedEvent); |
685 EventTargetWithInlineData::trace(visitor); | 716 EventTargetWithInlineData::trace(visitor); |
686 } | 717 } |
687 | 718 |
688 } // namespace | 719 } // namespace |
OLD | NEW |