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 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 return 0; | 300 return 0; |
301 return (m_timeline->effectiveTime() - m_startTime) * m_playbackRate; | 301 return (m_timeline->effectiveTime() - m_startTime) * m_playbackRate; |
302 } | 302 } |
303 | 303 |
304 void AnimationPlayer::setCurrentTime(double newCurrentTime) | 304 void AnimationPlayer::setCurrentTime(double newCurrentTime) |
305 { | 305 { |
306 if (!std::isfinite(newCurrentTime)) | 306 if (!std::isfinite(newCurrentTime)) |
307 return; | 307 return; |
308 | 308 |
309 setCompositorPending(); | 309 setCompositorPending(); |
310 | 310 m_currentTimePending = false; |
311 // Setting current time while pending forces a start time. | |
312 if (m_currentTimePending) { | |
313 m_startTime = 0; | |
314 m_currentTimePending = false; | |
315 } | |
316 | |
317 setCurrentTimeInternal(newCurrentTime / 1000, TimingUpdateOnDemand); | 311 setCurrentTimeInternal(newCurrentTime / 1000, TimingUpdateOnDemand); |
318 } | 312 } |
319 | 313 |
320 void AnimationPlayer::setStartTime(double startTime) | 314 void AnimationPlayer::setStartTime(double startTime) |
321 { | 315 { |
322 if (m_paused) // FIXME: Should this throw an exception? | 316 if (m_paused || m_idle) |
323 return; | 317 return; |
324 if (!std::isfinite(startTime)) | 318 if (!std::isfinite(startTime)) |
325 return; | 319 return; |
326 if (startTime == m_startTime) | 320 if (startTime == m_startTime) |
327 return; | 321 return; |
328 | 322 |
329 setCompositorPending(); | 323 setCompositorPending(); |
330 m_currentTimePending = false; | 324 m_currentTimePending = false; |
331 setStartTimeInternal(startTime / 1000); | 325 setStartTimeInternal(startTime / 1000); |
332 } | 326 } |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 m_finished = false; | 459 m_finished = false; |
466 } | 460 } |
467 | 461 |
468 void AnimationPlayer::reverse() | 462 void AnimationPlayer::reverse() |
469 { | 463 { |
470 if (!m_playbackRate) { | 464 if (!m_playbackRate) { |
471 return; | 465 return; |
472 } | 466 } |
473 | 467 |
474 uncancel(); | 468 uncancel(); |
475 | |
476 if (m_content) { | |
477 if (m_playbackRate > 0 && currentTimeInternal() > sourceEnd()) { | |
478 setCurrentTimeInternal(sourceEnd(), TimingUpdateOnDemand); | |
479 ASSERT(finished()); | |
480 } else if (m_playbackRate < 0 && currentTimeInternal() < 0) { | |
481 setCurrentTimeInternal(0, TimingUpdateOnDemand); | |
482 ASSERT(finished()); | |
483 } | |
484 } | |
485 setPlaybackRate(-m_playbackRate); | 469 setPlaybackRate(-m_playbackRate); |
486 unpauseInternal(); | 470 play(); |
487 } | 471 } |
488 | 472 |
489 void AnimationPlayer::finish(ExceptionState& exceptionState) | 473 void AnimationPlayer::finish(ExceptionState& exceptionState) |
490 { | 474 { |
491 if (!m_playbackRate) { | 475 if (!m_playbackRate || m_idle) { |
492 return; | 476 return; |
493 } | 477 } |
494 if (m_playbackRate > 0 && sourceEnd() == std::numeric_limits<double>::infini
ty()) { | 478 if (m_playbackRate > 0 && sourceEnd() == std::numeric_limits<double>::infini
ty()) { |
495 exceptionState.throwDOMException(InvalidStateError, "AnimationPlayer has
source content whose end time is infinity."); | 479 exceptionState.throwDOMException(InvalidStateError, "AnimationPlayer has
source content whose end time is infinity."); |
496 return; | 480 return; |
497 } | 481 } |
498 if (playing()) { | 482 if (playing()) { |
499 setCompositorPending(); | 483 setCompositorPending(); |
500 } | 484 } |
501 | 485 |
502 uncancel(); | 486 uncancel(); |
503 m_startTime = 0; | |
504 | 487 |
505 if (m_playbackRate < 0) { | 488 double newCurrentTime = m_playbackRate < 0 ? 0 : sourceEnd(); |
506 setCurrentTimeInternal(0, TimingUpdateOnDemand); | 489 setCurrentTimeInternal(newCurrentTime, TimingUpdateOnDemand); |
507 } else { | 490 if (!paused()) { |
508 setCurrentTimeInternal(sourceEnd(), TimingUpdateOnDemand); | 491 m_startTime = calculateStartTime(newCurrentTime); |
509 } | 492 } |
| 493 |
| 494 m_currentTimePending = false; |
510 ASSERT(finished()); | 495 ASSERT(finished()); |
511 } | 496 } |
512 | 497 |
513 const AtomicString& AnimationPlayer::interfaceName() const | 498 const AtomicString& AnimationPlayer::interfaceName() const |
514 { | 499 { |
515 return EventTargetNames::AnimationPlayer; | 500 return EventTargetNames::AnimationPlayer; |
516 } | 501 } |
517 | 502 |
518 ExecutionContext* AnimationPlayer::executionContext() const | 503 ExecutionContext* AnimationPlayer::executionContext() const |
519 { | 504 { |
(...skipping 19 matching lines...) Expand all Loading... |
539 } | 524 } |
540 | 525 |
541 void AnimationPlayer::setPlaybackRate(double playbackRate) | 526 void AnimationPlayer::setPlaybackRate(double playbackRate) |
542 { | 527 { |
543 if (!std::isfinite(playbackRate)) | 528 if (!std::isfinite(playbackRate)) |
544 return; | 529 return; |
545 if (playbackRate == m_playbackRate) | 530 if (playbackRate == m_playbackRate) |
546 return; | 531 return; |
547 | 532 |
548 setCompositorPending(); | 533 setCompositorPending(); |
549 if (!finished() && !paused()) | 534 if (!finished() && !paused() && hasStartTime()) |
550 m_currentTimePending = true; | 535 m_currentTimePending = true; |
551 | 536 |
552 double storedCurrentTime = currentTimeInternal(); | 537 double storedCurrentTime = currentTimeInternal(); |
553 if ((m_playbackRate < 0 && playbackRate >= 0) || (m_playbackRate > 0 && play
backRate <= 0)) | 538 if ((m_playbackRate < 0 && playbackRate >= 0) || (m_playbackRate > 0 && play
backRate <= 0)) |
554 m_finished = false; | 539 m_finished = false; |
555 | 540 |
556 m_playbackRate = playbackRate; | 541 m_playbackRate = playbackRate; |
557 m_startTime = std::numeric_limits<double>::quiet_NaN(); | 542 m_startTime = std::numeric_limits<double>::quiet_NaN(); |
558 setCurrentTimeInternal(storedCurrentTime, TimingUpdateOnDemand); | 543 setCurrentTimeInternal(storedCurrentTime, TimingUpdateOnDemand); |
559 } | 544 } |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
656 return m_content->timeToForwardsEffectChange() / m_playbackRate; | 641 return m_content->timeToForwardsEffectChange() / m_playbackRate; |
657 return m_content->timeToReverseEffectChange() / -m_playbackRate; | 642 return m_content->timeToReverseEffectChange() / -m_playbackRate; |
658 } | 643 } |
659 | 644 |
660 void AnimationPlayer::cancel() | 645 void AnimationPlayer::cancel() |
661 { | 646 { |
662 m_holdTime = currentTimeInternal(); | 647 m_holdTime = currentTimeInternal(); |
663 m_held = true; | 648 m_held = true; |
664 m_idle = true; | 649 m_idle = true; |
665 m_startTime = nullValue(); | 650 m_startTime = nullValue(); |
| 651 m_currentTimePending = false; |
666 setCompositorPending(); | 652 setCompositorPending(); |
667 } | 653 } |
668 | 654 |
669 #if !ENABLE(OILPAN) | 655 #if !ENABLE(OILPAN) |
670 bool AnimationPlayer::canFree() const | 656 bool AnimationPlayer::canFree() const |
671 { | 657 { |
672 ASSERT(m_content); | 658 ASSERT(m_content); |
673 return hasOneRef() && m_content->isAnimation() && m_content->hasOneRef(); | 659 return hasOneRef() && m_content->isAnimation() && m_content->hasOneRef(); |
674 } | 660 } |
675 #endif | 661 #endif |
(...skipping 17 matching lines...) Expand all Loading... |
693 | 679 |
694 void AnimationPlayer::trace(Visitor* visitor) | 680 void AnimationPlayer::trace(Visitor* visitor) |
695 { | 681 { |
696 visitor->trace(m_content); | 682 visitor->trace(m_content); |
697 visitor->trace(m_timeline); | 683 visitor->trace(m_timeline); |
698 visitor->trace(m_pendingFinishedEvent); | 684 visitor->trace(m_pendingFinishedEvent); |
699 EventTargetWithInlineData::trace(visitor); | 685 EventTargetWithInlineData::trace(visitor); |
700 } | 686 } |
701 | 687 |
702 } // namespace | 688 } // namespace |
OLD | NEW |