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

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

Issue 48523004: Have Player take the DocumentTimeline object by reference (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 1 month 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
« no previous file with comments | « Source/core/animation/Player.h ('k') | Source/core/animation/PlayerTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 19 matching lines...) Expand all
30 30
31 31
32 #include "config.h" 32 #include "config.h"
33 #include "core/animation/Player.h" 33 #include "core/animation/Player.h"
34 34
35 #include "core/animation/DocumentTimeline.h" 35 #include "core/animation/DocumentTimeline.h"
36 #include "core/animation/TimedItem.h" 36 #include "core/animation/TimedItem.h"
37 37
38 namespace WebCore { 38 namespace WebCore {
39 39
40 PassRefPtr<Player> Player::create(DocumentTimeline* timeline, TimedItem* content ) 40 PassRefPtr<Player> Player::create(DocumentTimeline& timeline, TimedItem* content )
41 { 41 {
42 ASSERT(timeline);
43 return adoptRef(new Player(timeline, content)); 42 return adoptRef(new Player(timeline, content));
44 } 43 }
45 44
46 Player::Player(DocumentTimeline* timeline, TimedItem* content) 45 Player::Player(DocumentTimeline& timeline, TimedItem* content)
47 : m_pauseStartTime(nullValue()) 46 : m_pauseStartTime(nullValue())
48 , m_playbackRate(1) 47 , m_playbackRate(1)
49 , m_timeDrift(0) 48 , m_timeDrift(0)
50 , m_startTime(effectiveTime(timeline->currentTime())) 49 , m_startTime(effectiveTime(timeline.currentTime()))
51 , m_content(content) 50 , m_content(content)
52 , m_timeline(timeline) 51 , m_timeline(timeline)
53 , m_isPausedForTesting(false) 52 , m_isPausedForTesting(false)
54 { 53 {
55 ASSERT(m_startTime >= 0); 54 ASSERT(m_startTime >= 0);
56 if (m_content) 55 if (m_content)
57 m_content->attach(this); 56 m_content->attach(this);
58 update(); 57 update();
59 } 58 }
60 59
61 Player::~Player() 60 Player::~Player()
62 { 61 {
63 if (m_content) 62 if (m_content)
64 m_content->detach(); 63 m_content->detach();
65 } 64 }
66 65
67 double Player::currentTimeBeforeDrift() const 66 double Player::currentTimeBeforeDrift() const
68 { 67 {
69 return (effectiveTime(m_timeline->currentTime()) - m_startTime) * m_playback Rate; 68 return (effectiveTime(m_timeline.currentTime()) - m_startTime) * m_playbackR ate;
70 } 69 }
71 70
72 double Player::pausedTimeDrift() const 71 double Player::pausedTimeDrift() const
73 { 72 {
74 ASSERT(pausedInternal()); 73 ASSERT(pausedInternal());
75 return currentTimeBeforeDrift() - m_pauseStartTime; 74 return currentTimeBeforeDrift() - m_pauseStartTime;
76 } 75 }
77 76
78 double Player::timeDrift() const 77 double Player::timeDrift() const
79 { 78 {
80 return pausedInternal() ? pausedTimeDrift() : m_timeDrift; 79 return pausedInternal() ? pausedTimeDrift() : m_timeDrift;
81 } 80 }
82 81
83 double Player::currentTime() const 82 double Player::currentTime() const
84 { 83 {
85 return currentTimeBeforeDrift() - timeDrift(); 84 return currentTimeBeforeDrift() - timeDrift();
86 } 85 }
87 86
88 bool Player::update(double* timeToEffectChange) 87 bool Player::update(double* timeToEffectChange)
89 { 88 {
90 if (!m_content) { 89 if (!m_content) {
91 if (timeToEffectChange) 90 if (timeToEffectChange)
92 *timeToEffectChange = std::numeric_limits<double>::infinity(); 91 *timeToEffectChange = std::numeric_limits<double>::infinity();
93 return false; 92 return false;
94 } 93 }
95 94
96 double newTime = isNull(m_timeline->currentTime()) ? nullValue() : currentTi me(); 95 double newTime = isNull(m_timeline.currentTime()) ? nullValue() : currentTim e();
97 m_content->updateInheritedTime(newTime); 96 m_content->updateInheritedTime(newTime);
98 if (timeToEffectChange) 97 if (timeToEffectChange)
99 *timeToEffectChange = m_content->timeToEffectChange(); 98 *timeToEffectChange = m_content->timeToEffectChange();
100 return m_content->isCurrent() || m_content->isInEffect(); 99 return m_content->isCurrent() || m_content->isInEffect();
101 } 100 }
102 101
103 void Player::cancel() 102 void Player::cancel()
104 { 103 {
105 if (!m_content) 104 if (!m_content)
106 return; 105 return;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 } 146 }
148 147
149 void Player::setPlaybackRate(double newRate) 148 void Player::setPlaybackRate(double newRate)
150 { 149 {
151 double previousTime = currentTime(); 150 double previousTime = currentTime();
152 m_playbackRate = newRate; 151 m_playbackRate = newRate;
153 setCurrentTime(previousTime); 152 setCurrentTime(previousTime);
154 } 153 }
155 154
156 } // namespace 155 } // namespace
OLDNEW
« no previous file with comments | « Source/core/animation/Player.h ('k') | Source/core/animation/PlayerTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698